ImageTest.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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;
  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. ASSERT_EQUAL(image_isTexture(image), true); // Okay
  68. image = image_create_RgbaU8(16384, 4);
  69. ASSERT_EQUAL(image_isTexture(image), true); // Okay
  70. image = image_create_RgbaU8(16384 + 1, 4);
  71. ASSERT_EQUAL(image_isTexture(image), false); // Too wide and not power-of-two width
  72. image = image_create_RgbaU8(32768, 4);
  73. ASSERT_EQUAL(image_isTexture(image), false); // Too wide
  74. image = image_create_RgbaU8(4, 16384 + 1);
  75. ASSERT_EQUAL(image_isTexture(image), false); // Too high and not power-of-two height
  76. image = image_create_RgbaU8(4, 32768);
  77. ASSERT_EQUAL(image_isTexture(image), false); // Too high
  78. }
  79. END_TEST