write_image.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_WRITE_IMAGE_H
  9. #define IGL_STB_WRITE_IMAGE_H
  10. #include "../igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <string>
  13. namespace igl
  14. {
  15. namespace stb
  16. {
  17. /// Writes an image to a file
  18. ///
  19. /// Supported file formats (based on STB):
  20. ///
  21. /// JPEG
  22. /// PNG
  23. /// TGA
  24. /// BMP
  25. ///
  26. /// @param[in] R red channel
  27. /// @param[in] G green channel
  28. /// @param[in] B blue channel
  29. /// @param[in] A alpha channel
  30. /// @param[in] image_file path to image file
  31. /// @param[in] quality (only for jpg file) jpeg quality
  32. /// @returns true on success, false on errors
  33. ///
  34. IGL_INLINE bool write_image
  35. (
  36. const std::string image_file,
  37. const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
  38. const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
  39. const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
  40. const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A,
  41. const int quality=90
  42. );
  43. /// Raw image writer.
  44. ///
  45. /// @param[in] image_file path to image file
  46. /// @param[in] width image width
  47. /// @param[in] height image height
  48. /// @param[in] rgba_data raw image data
  49. /// @param[in] quality (only for jpg file) jpeg quality
  50. /// @returns true on success, false on errors
  51. ///
  52. IGL_INLINE bool write_image(
  53. const std::string image_file,
  54. const int width,
  55. const int height,
  56. const unsigned char * rgba_data,
  57. const int quality = 90);
  58. }
  59. }
  60. #ifndef IGL_STATIC_LIBRARY
  61. # include "write_image.cpp"
  62. #endif
  63. #endif