ImageTests.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <core/Logger.h>
  2. #include <stdio.h>
  3. #include "../Tests.h"
  4. #include "core/Image.h"
  5. static void testReadPNG8(const char* path, const char* name, int width,
  6. int height, int channels) {
  7. char fullPath[512];
  8. snprintf(fullPath, sizeof(fullPath), "%s/%s.png", path, name);
  9. Image8 image;
  10. TEST_BOOL(width == 0, initImage8(&image, fullPath));
  11. if(width != 0) {
  12. TEST_NOT_NULL(image.data);
  13. }
  14. TEST_INT(width, image.width);
  15. TEST_INT(height, image.height);
  16. TEST_INT(channels, image.channels);
  17. destroyImage8(&image);
  18. }
  19. static void testReadPNG16(const char* path, const char* name, int width,
  20. int height, int channels) {
  21. char fullPath[512];
  22. snprintf(fullPath, sizeof(fullPath), "%s/%s.png", path, name);
  23. Image16 image;
  24. TEST_BOOL(width == 0, initImage16(&image, fullPath));
  25. if(width != 0) {
  26. TEST_NOT_NULL(image.data);
  27. }
  28. TEST_INT(width, image.width);
  29. TEST_INT(height, image.height);
  30. TEST_INT(channels, image.channels);
  31. destroyImage16(&image);
  32. }
  33. void testImageReader(const char* path) {
  34. testReadPNG8(path, "rgb8", 32, 64, 3);
  35. testReadPNG8(path, "rgb16", 32, 64, 3);
  36. testReadPNG8(path, "rgba8", 32, 64, 4);
  37. testReadPNG8(path, "rgba16", 32, 64, 4);
  38. testReadPNG8(path, "gray8", 32, 64, 1);
  39. testReadPNG8(path, "gray16", 32, 64, 1);
  40. testReadPNG8(path, "graya8", 32, 64, 2);
  41. testReadPNG8(path, "graya16", 32, 64, 2);
  42. logLevel = LOG_NONE;
  43. testReadPNG8(path, "nope", 0, 0, 0);
  44. logLevel = LOG_DEBUG;
  45. testReadPNG16(path, "rgb8", 32, 64, 3);
  46. testReadPNG16(path, "rgb16", 32, 64, 3);
  47. testReadPNG16(path, "rgba8", 32, 64, 4);
  48. testReadPNG16(path, "rgba16", 32, 64, 4);
  49. testReadPNG16(path, "gray8", 32, 64, 1);
  50. testReadPNG16(path, "gray16", 32, 64, 1);
  51. testReadPNG16(path, "graya8", 32, 64, 2);
  52. testReadPNG16(path, "graya16", 32, 64, 2);
  53. logLevel = LOG_NONE;
  54. testReadPNG16(path, "nope", 0, 0, 0);
  55. logLevel = LOG_DEBUG;
  56. }