png.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Known chunk types
  2. #define PNG_IHDR 'IHDR'
  3. #define PNG_IDAT 'IDAT'
  4. #define PNG_IEND 'IEND'
  5. #define PNG_tEXt 'tEXt'
  6. #define PNG_PLTE 'PLTE'
  7. #define PNG_bKGD 'bKGD'
  8. #define PNG_cHRM 'cHRM'
  9. #define PNG_gAMA 'gAMA'
  10. #define PNG_hIST 'hIST'
  11. #define PNG_iCCP 'iCCP'
  12. #define PNG_iTXt 'iTXt'
  13. #define PNG_oFFs 'oFFs'
  14. #define PNG_pCAL 'pCAL'
  15. #define PNG_sCAL 'sCAL'
  16. #define PNG_pHYs 'pHYs'
  17. #define PNG_sBIT 'sBIT'
  18. #define PNG_sPLT 'sPLT'
  19. #define PNG_sRGB 'sRGB'
  20. #define PNG_tIME 'tIME'
  21. #define PNG_tRNS 'tRNS'
  22. #define PNG_zTXt 'zTXt'
  23. // Filter values
  24. #define PNG_FILTER_VALUE_NONE 0
  25. #define PNG_FILTER_VALUE_SUB 1
  26. #define PNG_FILTER_VALUE_UP 2
  27. #define PNG_FILTER_VALUE_AVG 3
  28. #define PNG_FILTER_VALUE_PAETH 4
  29. #define PNG_FILTER_NUM 5
  30. // Common defines and typedefs
  31. #define MAX_PNG_WIDTH 4096
  32. #define MAX_PNG_DEPTH 4
  33. typedef unsigned char byte;
  34. typedef unsigned short word;
  35. typedef unsigned long ulong;
  36. #pragma pack(push)
  37. #pragma pack(1)
  38. typedef struct png_ihdr_s
  39. {
  40. ulong width;
  41. ulong height;
  42. byte bitdepth; // Bits per sample (not per pixel)
  43. byte colortype; // bit 0 - palette; bit 1 - RGB; bit 2 - alpha channel
  44. byte compression; // 0 for zip - error otherwise
  45. byte filter; // 0 for adaptive with the 5 basic types - error otherwise
  46. byte interlace; // 0 for no interlace - 1 for Adam7 interlace
  47. } png_ihdr_t;
  48. #pragma pack(pop)
  49. typedef struct png_image_s
  50. {
  51. byte *data;
  52. ulong width;
  53. ulong height;
  54. ulong bytedepth;
  55. bool isimage;
  56. } png_image_t;
  57. bool LoadPNG32 (char *name, byte **pixels, int *width, int *height, int *bytedepth);
  58. bool LoadPNG8 (char *name, byte **pixels, int *width, int *height);
  59. bool PNG_Save(const char *name, byte *data, int width, int height, int bytedepth);
  60. // end