ImageTests.c 2.0 KB

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