pvpngreader.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // pngreader.h - Public Domain - see unlicense at bottom of pvpngreader.cpp
  2. #pragma once
  3. #include <stdint.h>
  4. namespace pv_png
  5. {
  6. // PNG color types
  7. enum
  8. {
  9. PNG_COLOR_TYPE_GREYSCALE = 0,
  10. PNG_COLOR_TYPE_TRUECOLOR = 2,
  11. PNG_COLOR_TYPE_PALETTIZED = 3,
  12. PNG_COLOR_TYPE_GREYSCALE_ALPHA = 4,
  13. PNG_COLOR_TYPE_TRUECOLOR_ALPHA = 6
  14. };
  15. // PNG file description
  16. struct png_info
  17. {
  18. uint32_t m_width;
  19. uint32_t m_height;
  20. uint32_t m_num_chans; // The number of channels, factoring in transparency. Ranges from [1-4].
  21. uint32_t m_bit_depth; // PNG ihdr bit depth: 1, 2, 4, 8 or 16
  22. uint32_t m_color_type; // PNG ihdr color type, PNG_COLOR_TYPE_GRAYSCALE etc.
  23. bool m_has_gamma; // true if the PNG file had a GAMA chunk
  24. uint32_t m_gamma_value; // PNG GAMA chunk value, scaled by 100000
  25. bool m_has_trns; // true if the PNG file used colorkey transparency
  26. };
  27. // Retrieved information about the PNG file.
  28. // Returns false on any errors.
  29. bool get_png_info(const void* pImage_buf, size_t buf_size, png_info& info);
  30. // Input parameters:
  31. // pImage_buf, buf_size - pointer to PNG image data
  32. // desired_chans - desired number of output channels. 0=auto, 1=grayscale, 2=grayscale alpha, 3=24bpp RGB, 4=32bpp RGBA
  33. //
  34. // Output parameters:
  35. // width, height - PNG image resolution
  36. // num_chans - actual number of channels in PNG, from [1,4] (factoring in transparency)
  37. //
  38. // Returns nullptr on any errors.
  39. void* load_png(const void* pImage_buf, size_t buf_size, uint32_t desired_chans, uint32_t &width, uint32_t &height, uint32_t& num_chans);
  40. }