ImageTest.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "../testTools.h"
  2. START_TEST(Image)
  3. { // ImageU8
  4. ImageU8 imageA;
  5. ASSERT_EQUAL(image_exists(imageA), false);
  6. imageA = image_create_U8(17, 9);
  7. ASSERT_EQUAL(image_exists(imageA), true);
  8. ASSERT_EQUAL(image_useCount(imageA), 1);
  9. ASSERT_EQUAL(image_getWidth(imageA), 17);
  10. ASSERT_EQUAL(image_getHeight(imageA), 9);
  11. ASSERT_EQUAL(image_getStride(imageA), 32);
  12. ASSERT_EQUAL(image_getBound(imageA), IRect(0, 0, 17, 9));
  13. ImageU8 imageB; // Create empty image reference
  14. ASSERT_EQUAL(image_useCount(imageA), 1);
  15. ASSERT_EQUAL(image_useCount(imageB), 0);
  16. imageB = imageA; // Shallow copy of reference
  17. ASSERT_EQUAL(image_useCount(imageA), 2);
  18. ASSERT_EQUAL(image_useCount(imageB), 2);
  19. imageA = ImageU8(); // Remove original reference to the image
  20. ASSERT_EQUAL(image_useCount(imageA), 0);
  21. ASSERT_EQUAL(image_useCount(imageB), 1);
  22. }
  23. { // ImageF32
  24. ImageF32 image;
  25. ASSERT_EQUAL(image_exists(image), false);
  26. image = image_create_F32(3, 48);
  27. ASSERT_EQUAL(image_exists(image), true);
  28. ASSERT_EQUAL(image_useCount(image), 1);
  29. ASSERT_EQUAL(image_getWidth(image), 3);
  30. ASSERT_EQUAL(image_getHeight(image), 48);
  31. ASSERT_EQUAL(image_getStride(image), 16);
  32. ASSERT_EQUAL(image_getBound(image), IRect(0, 0, 3, 48));
  33. }
  34. { // ImageRgbaU8
  35. ImageRgbaU8 image;
  36. ASSERT_EQUAL(image_exists(image), false);
  37. image = image_create_RgbaU8(52, 12);
  38. ASSERT_EQUAL(image_exists(image), true);
  39. ASSERT_EQUAL(image_useCount(image), 1);
  40. ASSERT_EQUAL(image_getWidth(image), 52);
  41. ASSERT_EQUAL(image_getHeight(image), 12);
  42. ASSERT_EQUAL(image_getStride(image), 208);
  43. ASSERT_EQUAL(image_getBound(image), IRect(0, 0, 52, 12));
  44. }
  45. { // RGBA Texture
  46. ImageRgbaU8 image;
  47. image = image_create_RgbaU8(256, 256);
  48. ASSERT_EQUAL(image_hasPyramid(image), false);
  49. image_generatePyramid(image);
  50. ASSERT_EQUAL(image_hasPyramid(image), true);
  51. image_removePyramid(image);
  52. ASSERT_EQUAL(image_hasPyramid(image), false);
  53. image_generatePyramid(image);
  54. ASSERT_EQUAL(image_hasPyramid(image), true);
  55. }
  56. { // Texture criterias
  57. ImageRgbaU8 image, subImage;
  58. image = image_create_RgbaU8(2, 2);
  59. ASSERT_EQUAL(image_isTexture(image), false); // Too small
  60. image = image_create_RgbaU8(13, 8);
  61. ASSERT_EQUAL(image_isTexture(image), false); // Not power-of-two width
  62. image = image_create_RgbaU8(4, 7);
  63. ASSERT_EQUAL(image_isTexture(image), false); // Not power-of-two height
  64. image = image_create_RgbaU8(4, 4);
  65. ASSERT_EQUAL(image_isTexture(image), true); // Okay
  66. image = image_create_RgbaU8(4, 16384);
  67. subImage = image_getSubImage(image, IRect(0, 0, 4, 128));
  68. ASSERT_EQUAL(image_isTexture(image), true); // Okay
  69. ASSERT_EQUAL(image_isTexture(subImage), true); // Okay to use full-width vertical sub-images
  70. image = image_create_RgbaU8(16384, 4);
  71. subImage = image_getSubImage(image, IRect(0, 0, 128, 4));
  72. ASSERT_EQUAL(image_isTexture(image), true); // Okay
  73. ASSERT_EQUAL(image_isTexture(subImage), false); // Not okay to use partial width leading to partial stride
  74. image = image_create_RgbaU8(16384 + 1, 4);
  75. ASSERT_EQUAL(image_isTexture(image), false); // Too wide and not power-of-two width
  76. image = image_create_RgbaU8(32768, 4);
  77. ASSERT_EQUAL(image_isTexture(image), false); // Too wide
  78. image = image_create_RgbaU8(4, 16384 + 1);
  79. ASSERT_EQUAL(image_isTexture(image), false); // Too high and not power-of-two height
  80. image = image_create_RgbaU8(4, 32768);
  81. ASSERT_EQUAL(image_isTexture(image), false); // Too high
  82. }
  83. { // Sub-images
  84. ImageU8 parentImage = image_fromAscii(
  85. "< .x>"
  86. "< .. .. >"
  87. "<..x..x..>"
  88. "<.xx..xx.>"
  89. "< ..xx.. >"
  90. "< ..xx.. >"
  91. "<.xx..xx.>"
  92. "<..x..x..>"
  93. "< .. .. >"
  94. );
  95. ImageU8 upperLeftSubImage = image_getSubImage(parentImage, IRect(0, 0, 4, 4));
  96. ImageU8 upperRightSubImage = image_getSubImage(parentImage, IRect(4, 0, 4, 4));
  97. ImageU8 lowerLeftSubImage = image_getSubImage(parentImage, IRect(0, 4, 4, 4));
  98. ImageU8 lowerRightSubImage = image_getSubImage(parentImage, IRect(4, 4, 4, 4));
  99. ImageU8 centerSubImage = image_getSubImage(parentImage, IRect(2, 2, 4, 4));
  100. ASSERT_EQUAL(image_maxDifference(upperLeftSubImage, image_fromAscii(
  101. "< .x>"
  102. "< .. >"
  103. "<..x.>"
  104. "<.xx.>"
  105. "< ..x>"
  106. )), 0);
  107. ASSERT_EQUAL(image_maxDifference(upperRightSubImage, image_fromAscii(
  108. "< .x>"
  109. "< .. >"
  110. "<.x..>"
  111. "<.xx.>"
  112. "<x.. >"
  113. )), 0);
  114. ASSERT_EQUAL(image_maxDifference(lowerLeftSubImage, image_fromAscii(
  115. "< .x>"
  116. "< ..x>"
  117. "<.xx.>"
  118. "<..x.>"
  119. "< .. >"
  120. )), 0);
  121. ASSERT_EQUAL(image_maxDifference(lowerRightSubImage, image_fromAscii(
  122. "< .x>"
  123. "<x.. >"
  124. "<.xx.>"
  125. "<.x..>"
  126. "< .. >"
  127. )), 0);
  128. ASSERT_EQUAL(image_maxDifference(centerSubImage, image_fromAscii(
  129. "< .x>"
  130. "<x..x>"
  131. "<.xx.>"
  132. "<.xx.>"
  133. "<x..x>"
  134. )), 0);
  135. image_fill(centerSubImage, 0);
  136. ASSERT_EQUAL(image_maxDifference(parentImage, image_fromAscii(
  137. "< .x>"
  138. "< .. .. >"
  139. "<..x..x..>"
  140. "<.x x.>"
  141. "< . . >"
  142. "< . . >"
  143. "<.x x.>"
  144. "<..x..x..>"
  145. "< .. .. >"
  146. )), 0);
  147. }
  148. END_TEST