io.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #ifndef IO_H
  3. #define IO_H
  4. #include "MMBitmap.h"
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. enum _MMImageType {
  8. kInvalidImageType = 0,
  9. kPNGImageType,
  10. kBMPImageType /* Currently only PNG and BMP are supported. */
  11. };
  12. typedef uint16_t MMImageType;
  13. enum _MMIOError {
  14. kMMIOUnsupportedTypeError = 0
  15. };
  16. typedef uint16_t MMIOError;
  17. const char *getExtension(const char *fname, size_t len);
  18. /* Returns best guess at the MMImageType based on a file extension, or
  19. * |kInvalidImageType| if no matching type was found. */
  20. MMImageType imageTypeFromExtension(const char *ext);
  21. /* Attempts to parse the file of the given type at the given path.
  22. * |filepath| is an ASCII string describing the absolute POSIX path.
  23. * Returns new bitmap (to be destroy()'d by caller) on success, NULL on error.
  24. * If |error| is non-NULL, it will be set to the error code on return.
  25. */
  26. MMBitmapRef newMMBitmapFromFile(const char *path, MMImageType type, MMIOError *err);
  27. /* Saves |bitmap| to a file of the given type at the given path.
  28. * |filepath| is an ASCII string describing the absolute POSIX path.
  29. * Returns 0 on success, -1 on error. */
  30. int saveMMBitmapToFile(MMBitmapRef bitmap, const char *path, MMImageType type);
  31. /* Returns description of given error code.
  32. * Returned string is constant and hence should not be freed. */
  33. const char *MMIOErrorString(MMImageType type, MMIOError error);
  34. #endif /* IO_H */