ImageTests.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include "../Tests.h"
  3. #include "core/Image.h"
  4. static void testReadPNG8(const char* path, const char* name, int width,
  5. int height, int channels) {
  6. char fullPath[512];
  7. snprintf(fullPath, sizeof(fullPath), "%s/%s.png", path, name);
  8. CoreImage8 image;
  9. CORE_TEST_BOOL(width == 0, coreInitImage8(&image, fullPath));
  10. if(width != 0) {
  11. CORE_TEST_NOT_NULL(image.data);
  12. }
  13. CORE_TEST_INT(width, image.width);
  14. CORE_TEST_INT(height, image.height);
  15. CORE_TEST_INT(channels, image.channels);
  16. coreDestroyImage8(&image);
  17. }
  18. static void testReadPNG16(const char* path, const char* name, int width,
  19. int height, int channels) {
  20. char fullPath[512];
  21. snprintf(fullPath, sizeof(fullPath), "%s/%s.png", path, name);
  22. CoreImage16 image;
  23. CORE_TEST_BOOL(width == 0, coreInitImage16(&image, fullPath));
  24. if(width != 0) {
  25. CORE_TEST_NOT_NULL(image.data);
  26. }
  27. CORE_TEST_INT(width, image.width);
  28. CORE_TEST_INT(height, image.height);
  29. CORE_TEST_INT(channels, image.channels);
  30. coreDestroyImage16(&image);
  31. }
  32. void coreTestImageReader(const char* path) {
  33. testReadPNG8(path, "rgb8", 32, 64, 3);
  34. testReadPNG8(path, "rgb16", 32, 64, 3);
  35. testReadPNG8(path, "rgba8", 32, 64, 4);
  36. testReadPNG8(path, "rgba16", 32, 64, 4);
  37. testReadPNG8(path, "gray8", 32, 64, 1);
  38. testReadPNG8(path, "gray16", 32, 64, 1);
  39. testReadPNG8(path, "graya8", 32, 64, 2);
  40. testReadPNG8(path, "graya16", 32, 64, 2);
  41. testReadPNG8(path, "nope", 0, 0, 0);
  42. testReadPNG16(path, "rgb8", 32, 64, 3);
  43. testReadPNG16(path, "rgb16", 32, 64, 3);
  44. testReadPNG16(path, "rgba8", 32, 64, 4);
  45. testReadPNG16(path, "rgba16", 32, 64, 4);
  46. testReadPNG16(path, "gray8", 32, 64, 1);
  47. testReadPNG16(path, "gray16", 32, 64, 1);
  48. testReadPNG16(path, "graya8", 32, 64, 2);
  49. testReadPNG16(path, "graya16", 32, 64, 2);
  50. testReadPNG16(path, "nope", 0, 0, 0);
  51. }