read_image.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Daniele Panozzo <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_STB_READ_IMAGE_H
  9. #define IGL_STB_READ_IMAGE_H
  10. #include "../igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <string>
  13. namespace igl
  14. {
  15. namespace stb
  16. {
  17. // Read an image from a file into 4 memory buffers
  18. //
  19. // Supported file formats (based on STB):
  20. //
  21. // JPEG baseline & progressive (12 bpc/arithmetic not supported, same as stock IJG lib)
  22. // PNG 1/2/4/8/16-bit-per-channel
  23. // TGA (not sure what subset, if a subset)
  24. // BMP non-1bpp, non-RLE
  25. // PSD (composited view only, no extra channels, 8/16 bit-per-channel)
  26. // GIF (*comp always reports as 4-channel)
  27. // HDR (radiance rgbE format)
  28. // PIC (Softimage PIC)
  29. // PNM (PPM and PGM binary only)
  30. //
  31. // Input:
  32. // image_file path to .png file
  33. // Output:
  34. // R,G,B,A texture channels
  35. // Returns true on success, false on failure
  36. //
  37. IGL_INLINE bool read_image(const std::string image_file,
  38. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
  39. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
  40. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
  41. Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A
  42. );
  43. }
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "read_image.cpp"
  47. #endif
  48. #endif