png_io.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #ifndef PNG_IO_H
  3. #define PNG_IO_H
  4. // #include "MMBitmap_c.h"
  5. // #include "io_c.h"
  6. enum _PNGReadError {
  7. kPNGGenericError = 0,
  8. kPNGReadError,
  9. kPNGAccessError,
  10. kPNGInvalidHeaderError
  11. };
  12. typedef MMIOError MMPNGReadError;
  13. /* Returns description of given MMPNGReadError.
  14. * Returned string is constant and hence should not be freed. */
  15. const char *MMPNGReadErrorString(MMIOError error);
  16. /* Attempts to read PNG file at path; returns new MMBitmap on success, or
  17. * NULL on error. If |error| is non-NULL, it will be set to the error code
  18. * on return.
  19. * Responsibility for destroy()'ing returned MMBitmap is left up to caller. */
  20. MMBitmapRef newMMBitmapFromPNG(const char *path, MMPNGReadError *error);
  21. /* Attempts to write PNG at path; returns 0 on success, -1 on error. */
  22. int saveMMBitmapAsPNG(MMBitmapRef bitmap, const char *path);
  23. /* Returns a buffer containing the raw PNG file data, ready to be saved to a
  24. * file. |len| will be set to the number of bytes allocated in the returned
  25. * buffer (it cannot be NULL).
  26. *
  27. * Responsibility for free()'ing data is left up to the caller. */
  28. uint8_t *createPNGData(MMBitmapRef bitmap, size_t *len);
  29. #endif /* PNG_IO_H */