ImageTest.cpp 5.1 KB

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