TestConvert.cpp 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. #include "TestConvert.h"
  2. #include <string>
  3. using namespace std;
  4. using namespace NICE;
  5. CPPUNIT_TEST_SUITE_REGISTRATION( TestConvert );
  6. void TestConvert::setUp()
  7. {
  8. }
  9. void TestConvert::tearDown()
  10. {
  11. }
  12. void TestConvert::testColorspaceConversion()
  13. {
  14. ColorImage src(9,1);
  15. src.setPixelQuick( 0, 0, 0, 0, 0);
  16. src.setPixelQuick( 1, 0, 255, 255, 255);
  17. src.setPixelQuick( 2, 0, 255, 0, 0);
  18. src.setPixelQuick( 3, 0, 255, 255, 0);
  19. src.setPixelQuick( 4, 0, 0, 255, 0);
  20. src.setPixelQuick( 5, 0, 0, 255, 255);
  21. src.setPixelQuick( 6, 0, 0, 0, 255);
  22. src.setPixelQuick( 7, 0, 255, 0, 255);
  23. src.setPixelQuick( 8, 0, 255, 0, 0);
  24. // rgbToHSV, HSVToRGB
  25. {
  26. // rgbToHSV
  27. ColorImage* result = rgbToHSV(src);
  28. // H
  29. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(0,0,0)), 1); // R=G=B -> H undef.
  30. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(1,0,0)), 1); // R=G=B -> H undef.
  31. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(2,0,0)), 1);
  32. CPPUNIT_ASSERT_DOUBLES_EQUAL( 42, static_cast<double>(result->getPixelQuick(3,0,0)), 1);
  33. CPPUNIT_ASSERT_DOUBLES_EQUAL( 85, static_cast<double>(result->getPixelQuick(4,0,0)), 1);
  34. CPPUNIT_ASSERT_DOUBLES_EQUAL( 127, static_cast<double>(result->getPixelQuick(5,0,0)), 1);
  35. CPPUNIT_ASSERT_DOUBLES_EQUAL( 170, static_cast<double>(result->getPixelQuick(6,0,0)), 1);
  36. CPPUNIT_ASSERT_DOUBLES_EQUAL( 212, static_cast<double>(result->getPixelQuick(7,0,0)), 1);
  37. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(8,0,0)), 1);
  38. // S
  39. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(0,0,1)), 1); // R=G=B=0 -> S undef.
  40. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(1,0,1)), 1);
  41. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick(2,0,1)), 1);
  42. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick(3,0,1)), 1);
  43. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick(4,0,1)), 1);
  44. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick(5,0,1)), 1);
  45. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick(6,0,1)), 1);
  46. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick(7,0,1)), 1);
  47. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(8,0,1)), 1);
  48. // V
  49. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(0,0,2)), 1);
  50. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(1,0,2)), 1);
  51. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(2,0,2)), 1);
  52. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(3,0,2)), 1);
  53. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(4,0,2)), 1);
  54. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(5,0,2)), 1);
  55. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(6,0,2)), 1);
  56. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(7,0,2)), 1);
  57. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(8,0,2)), 1);
  58. // hsvToRGB
  59. ColorImage* result2 = hsvToRGB(*result);
  60. // R
  61. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(0,0,0)), 1);
  62. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(1,0,0)), 1);
  63. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(2,0,0)), 1);
  64. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(3,0,0)), 1);
  65. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(4,0,0)), 1);
  66. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(5,0,0)), 1);
  67. CPPUNIT_ASSERT_DOUBLES_EQUAL( 1, static_cast<double>(result2->getPixelQuick(6,0,0)), 1);
  68. CPPUNIT_ASSERT_DOUBLES_EQUAL( 252, static_cast<double>(result2->getPixelQuick(7,0,0)), 1);
  69. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(8,0,0)), 1);
  70. // G
  71. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(0,0,1)), 1);
  72. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(1,0,1)), 1);
  73. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(2,0,1)), 1);
  74. CPPUNIT_ASSERT_DOUBLES_EQUAL( 252, static_cast<double>(result2->getPixelQuick(3,0,1)), 1);
  75. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(4,0,1)), 1);
  76. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(5,0,1)), 1);
  77. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(6,0,1)), 1);
  78. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(7,0,1)), 1);
  79. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(8,0,1)), 1);
  80. // B
  81. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(0,0,2)), 1);
  82. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(1,0,2)), 1);
  83. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(2,0,2)), 1);
  84. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(3,0,2)), 1);
  85. CPPUNIT_ASSERT_DOUBLES_EQUAL( 1, static_cast<double>(result2->getPixelQuick(4,0,2)), 1);
  86. CPPUNIT_ASSERT_DOUBLES_EQUAL( 252, static_cast<double>(result2->getPixelQuick(5,0,2)), 1);
  87. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(6,0,2)), 1);
  88. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result2->getPixelQuick(7,0,2)), 1);
  89. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(8,0,2)), 1);
  90. }
  91. // rgbToYUV, yuvToRGB
  92. {
  93. // rgbToYUV
  94. ColorImage* result = rgbToYUV(src);
  95. // Y
  96. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(0,0,0)), 1);
  97. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick(1,0,0)), 1);
  98. CPPUNIT_ASSERT_DOUBLES_EQUAL( 76, static_cast<double>(result->getPixelQuick(2,0,0)), 1);
  99. CPPUNIT_ASSERT_DOUBLES_EQUAL( 225, static_cast<double>(result->getPixelQuick(3,0,0)), 1);
  100. CPPUNIT_ASSERT_DOUBLES_EQUAL( 149, static_cast<double>(result->getPixelQuick(4,0,0)), 1);
  101. CPPUNIT_ASSERT_DOUBLES_EQUAL( 178, static_cast<double>(result->getPixelQuick(5,0,0)), 1);
  102. CPPUNIT_ASSERT_DOUBLES_EQUAL( 29, static_cast<double>(result->getPixelQuick(6,0,0)), 1);
  103. CPPUNIT_ASSERT_DOUBLES_EQUAL( 105, static_cast<double>(result->getPixelQuick(7,0,0)), 1);
  104. CPPUNIT_ASSERT_DOUBLES_EQUAL( 76, static_cast<double>(result->getPixelQuick(8,0,0)), 1);
  105. // U
  106. CPPUNIT_ASSERT_DOUBLES_EQUAL( 128, static_cast<double>(result->getPixelQuick(0,0,1)), 1);
  107. CPPUNIT_ASSERT_DOUBLES_EQUAL( 128, static_cast<double>(result->getPixelQuick(1,0,1)), 1);
  108. CPPUNIT_ASSERT_DOUBLES_EQUAL( 90, static_cast<double>(result->getPixelQuick(2,0,1)), 1);
  109. CPPUNIT_ASSERT_DOUBLES_EQUAL( 17, static_cast<double>(result->getPixelQuick(3,0,1)), 1);
  110. CPPUNIT_ASSERT_DOUBLES_EQUAL( 54, static_cast<double>(result->getPixelQuick(4,0,1)), 1);
  111. CPPUNIT_ASSERT_DOUBLES_EQUAL( 165, static_cast<double>(result->getPixelQuick(5,0,1)), 1);
  112. CPPUNIT_ASSERT_DOUBLES_EQUAL( 239, static_cast<double>(result->getPixelQuick(6,0,1)), 1);
  113. CPPUNIT_ASSERT_DOUBLES_EQUAL( 201, static_cast<double>(result->getPixelQuick(7,0,1)), 1);
  114. CPPUNIT_ASSERT_DOUBLES_EQUAL( 90, static_cast<double>(result->getPixelQuick(8,0,1)), 1);
  115. // V
  116. CPPUNIT_ASSERT_DOUBLES_EQUAL( 128, static_cast<double>(result->getPixelQuick(0,0,2)), 1);
  117. CPPUNIT_ASSERT_DOUBLES_EQUAL( 128, static_cast<double>(result->getPixelQuick(1,0,2)), 1);
  118. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(2,0,2)), 1);
  119. CPPUNIT_ASSERT_DOUBLES_EQUAL( 153, static_cast<double>(result->getPixelQuick(3,0,2)), 1);
  120. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(4,0,2)), 1);
  121. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick(5,0,2)), 1);
  122. CPPUNIT_ASSERT_DOUBLES_EQUAL( 102, static_cast<double>(result->getPixelQuick(6,0,2)), 1);
  123. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(7,0,2)), 1);
  124. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<double>(result->getPixelQuick(8,0,2)), 1);
  125. // yuvToRGB
  126. ColorImage* result2 = yuvToRGB(*result);
  127. // R
  128. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(0,0,0)), 1);
  129. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result2->getPixelQuick(1,0,0)), 1);
  130. CPPUNIT_ASSERT_DOUBLES_EQUAL( 220, static_cast<double>(result2->getPixelQuick(2,0,0)), 1);
  131. CPPUNIT_ASSERT_DOUBLES_EQUAL( 253, static_cast<double>(result2->getPixelQuick(3,0,0)), 1);
  132. CPPUNIT_ASSERT_DOUBLES_EQUAL( 3, static_cast<double>(result2->getPixelQuick(4,0,0)), 1);
  133. CPPUNIT_ASSERT_DOUBLES_EQUAL( 32, static_cast<double>(result2->getPixelQuick(5,0,0)), 1);
  134. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(6,0,0)), 1);
  135. CPPUNIT_ASSERT_DOUBLES_EQUAL( 249, static_cast<double>(result2->getPixelQuick(7,0,0)), 1);
  136. CPPUNIT_ASSERT_DOUBLES_EQUAL( 220, static_cast<double>(result2->getPixelQuick(8,0,0)), 1);
  137. // G
  138. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(0,0,1)), 1);
  139. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result2->getPixelQuick(1,0,1)), 1);
  140. CPPUNIT_ASSERT_DOUBLES_EQUAL( 16, static_cast<double>(result2->getPixelQuick(2,0,1)), 1);
  141. CPPUNIT_ASSERT_DOUBLES_EQUAL( 253, static_cast<double>(result2->getPixelQuick(3,0,1)), 1);
  142. CPPUNIT_ASSERT_DOUBLES_EQUAL( 252, static_cast<double>(result2->getPixelQuick(4,0,1)), 1);
  143. CPPUNIT_ASSERT_DOUBLES_EQUAL( 237, static_cast<double>(result2->getPixelQuick(5,0,1)), 1);
  144. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(6,0,1)), 1);
  145. CPPUNIT_ASSERT_DOUBLES_EQUAL( 2, static_cast<double>(result2->getPixelQuick(7,0,1)), 1);
  146. CPPUNIT_ASSERT_DOUBLES_EQUAL( 16, static_cast<double>(result2->getPixelQuick(8,0,1)), 1);
  147. // B
  148. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(0,0,2)), 1);
  149. CPPUNIT_ASSERT_DOUBLES_EQUAL( 253, static_cast<double>(result2->getPixelQuick(1,0,2)), 1);
  150. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(2,0,2)), 1);
  151. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(3,0,2)), 1);
  152. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(4,0,2)), 1);
  153. CPPUNIT_ASSERT_DOUBLES_EQUAL( 253, static_cast<double>(result2->getPixelQuick(5,0,2)), 1);
  154. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result2->getPixelQuick(6,0,2)), 1);
  155. CPPUNIT_ASSERT_DOUBLES_EQUAL( 253, static_cast<double>(result2->getPixelQuick(7,0,2)), 1);
  156. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result2->getPixelQuick(8,0,2)), 1);
  157. }
  158. }
  159. void TestConvert::testImageConversion()
  160. {
  161. // rgbToGray
  162. {
  163. // Ipp8u
  164. {
  165. ColorImage src(13,1);
  166. src.setPixelQuick( 0,0, 0, 0, 0);
  167. src.setPixelQuick( 1,0, 255, 0, 0);
  168. src.setPixelQuick( 2,0, 0,255, 0);
  169. src.setPixelQuick( 3,0, 0, 0,255);
  170. src.setPixelQuick( 4,0, 255,255, 0);
  171. src.setPixelQuick( 5,0, 0,255,255);
  172. src.setPixelQuick( 6,0, 255, 0,255);
  173. src.setPixelQuick( 7,0, 255,255,255);
  174. src.setPixelQuick( 8,0, 100,100,100);
  175. src.setPixelQuick( 9,0, 150,150,150);
  176. src.setPixelQuick(10,0, 128, 0, 0);
  177. src.setPixelQuick(11,0, 0,128, 0);
  178. src.setPixelQuick(12,0, 0, 0,128);
  179. Image* result = rgbToGray(src);
  180. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<double>(result->getPixelQuick( 0,0)), 1);
  181. CPPUNIT_ASSERT_DOUBLES_EQUAL( 76, static_cast<double>(result->getPixelQuick( 1,0)), 1);
  182. CPPUNIT_ASSERT_DOUBLES_EQUAL( 149, static_cast<double>(result->getPixelQuick( 2,0)), 1);
  183. CPPUNIT_ASSERT_DOUBLES_EQUAL( 29, static_cast<double>(result->getPixelQuick( 3,0)), 1);
  184. CPPUNIT_ASSERT_DOUBLES_EQUAL( 225, static_cast<double>(result->getPixelQuick( 4,0)), 1);
  185. CPPUNIT_ASSERT_DOUBLES_EQUAL( 178, static_cast<double>(result->getPixelQuick( 5,0)), 1);
  186. CPPUNIT_ASSERT_DOUBLES_EQUAL( 105, static_cast<double>(result->getPixelQuick( 6,0)), 1);
  187. CPPUNIT_ASSERT_DOUBLES_EQUAL( 254, static_cast<double>(result->getPixelQuick( 7,0)), 1);
  188. CPPUNIT_ASSERT_DOUBLES_EQUAL( 99, static_cast<double>(result->getPixelQuick( 8,0)), 1);
  189. CPPUNIT_ASSERT_DOUBLES_EQUAL( 149, static_cast<double>(result->getPixelQuick( 9,0)), 1);
  190. CPPUNIT_ASSERT_DOUBLES_EQUAL( 38, static_cast<double>(result->getPixelQuick(10,0)), 1);
  191. CPPUNIT_ASSERT_DOUBLES_EQUAL( 75, static_cast<double>(result->getPixelQuick(11,0)), 1);
  192. CPPUNIT_ASSERT_DOUBLES_EQUAL( 14, static_cast<double>(result->getPixelQuick(12,0)), 1);
  193. // test again with optional lut
  194. ImageT<int>* lut = rgbToGrayLUT();
  195. CPPUNIT_ASSERT_EQUAL(256, static_cast<int>(lut->width()));
  196. CPPUNIT_ASSERT_EQUAL( 3, static_cast<int>(lut->height()));
  197. Image* result2 = new Image(src.width(), src.height());
  198. CPPUNIT_ASSERT_EQUAL(src.width() , static_cast<int>(result2->width()));
  199. CPPUNIT_ASSERT_EQUAL(src.height(), static_cast<int>(result2->height()));
  200. result2 = rgbToGray(src, result2, lut);
  201. for(int i=0; i<=12; ++i)
  202. CPPUNIT_ASSERT_DOUBLES_EQUAL( static_cast<int>(result->getPixelQuick(i,0)),
  203. static_cast<int>(result2->getPixelQuick(i,0)), 1);
  204. }
  205. // Ipp32f
  206. {
  207. ColorImageT<Ipp32f> src(13,1);
  208. src.setPixelQuick( 0,0, 0, 0, 0);
  209. src.setPixelQuick( 1,0, 255, 0, 0);
  210. src.setPixelQuick( 2,0, 0,255, 0);
  211. src.setPixelQuick( 3,0, 0, 0,255);
  212. src.setPixelQuick( 4,0, 255,255, 0);
  213. src.setPixelQuick( 5,0, 0,255,255);
  214. src.setPixelQuick( 6,0, 255, 0,255);
  215. src.setPixelQuick( 7,0, 255,255,255);
  216. src.setPixelQuick( 8,0, 100,100,100);
  217. src.setPixelQuick( 9,0, 150,150,150);
  218. src.setPixelQuick(10,0, 128, 0, 0);
  219. src.setPixelQuick(11,0, 0,128, 0);
  220. src.setPixelQuick(12,0, 0, 0,128);
  221. FloatImage* result = rgbToGray(src);
  222. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0000, static_cast<double>(result->getPixelQuick( 0,0)),0.0001);
  223. CPPUNIT_ASSERT_DOUBLES_EQUAL( 76.2450, static_cast<double>(result->getPixelQuick( 1,0)),0.0001);
  224. CPPUNIT_ASSERT_DOUBLES_EQUAL( 149.6850, static_cast<double>(result->getPixelQuick( 2,0)),0.0001);
  225. CPPUNIT_ASSERT_DOUBLES_EQUAL( 29.0700, static_cast<double>(result->getPixelQuick( 3,0)),0.0001);
  226. CPPUNIT_ASSERT_DOUBLES_EQUAL( 225.9300, static_cast<double>(result->getPixelQuick( 4,0)),0.0001);
  227. CPPUNIT_ASSERT_DOUBLES_EQUAL( 178.7550, static_cast<double>(result->getPixelQuick( 5,0)),0.0001);
  228. CPPUNIT_ASSERT_DOUBLES_EQUAL( 105.3150, static_cast<double>(result->getPixelQuick( 6,0)),0.0001);
  229. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255.0000, static_cast<double>(result->getPixelQuick( 7,0)),0.0001);
  230. CPPUNIT_ASSERT_DOUBLES_EQUAL( 100.0000, static_cast<double>(result->getPixelQuick( 8,0)),0.0001);
  231. CPPUNIT_ASSERT_DOUBLES_EQUAL( 150.0000, static_cast<double>(result->getPixelQuick( 9,0)),0.0001);
  232. CPPUNIT_ASSERT_DOUBLES_EQUAL( 38.2720, static_cast<double>(result->getPixelQuick(10,0)),0.0001);
  233. CPPUNIT_ASSERT_DOUBLES_EQUAL( 75.1360, static_cast<double>(result->getPixelQuick(11,0)),0.0001);
  234. CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.5920, static_cast<double>(result->getPixelQuick(12,0)),0.0001);
  235. }
  236. }
  237. // grayToRGB
  238. {
  239. // Ipp8u
  240. {
  241. Image src(256,1);
  242. for(int i=0; i<src.width(); ++i)
  243. src(i,0) = i;
  244. ColorImage* result = grayToRGB(src);
  245. for(int i=0; i<src.width(); ++i)
  246. for(int c=0; c<3; ++c)
  247. CPPUNIT_ASSERT_EQUAL(i, static_cast<int>(result->getPixelQuick(i,0,c)));
  248. }
  249. // Ipp32f
  250. {
  251. FloatImage src(255*3,1);
  252. for(int i=0; i<src.width(); ++i)
  253. src.setPixelQuick(i,0,i/3.0);
  254. ColorImageT<Ipp32f>* result = grayToRGB(src);
  255. for(int i=0; i<result->width(); ++i)
  256. for(int c=0; c<3; ++c)
  257. CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<double>(i/3.0),
  258. static_cast<double>(result->getPixelQuick(i,0,c)), 0.0001);
  259. }
  260. }
  261. }
  262. void TestConvert::testGrayFloat()
  263. {
  264. // grayToFloat
  265. {
  266. // Ipp8u
  267. {
  268. Image src(256,1);
  269. for(int i=0; i<src.width(); ++i)
  270. src.setPixelQuick(i,0,i);
  271. FloatImage* result = grayToFloat(src);
  272. for(int i=0; i<src.width(); ++i)
  273. CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<double>(i),
  274. static_cast<double>(result->getPixelQuick(i,0)), 0.0001);
  275. }
  276. // Ipp8s
  277. {
  278. ImageT<Ipp8s> src(256,1);
  279. for(int i=0; i<src.width(); ++i)
  280. src.setPixelQuick(i,0,std::numeric_limits<Ipp8s>::min()+i);
  281. FloatImage* result = grayToFloat(src);
  282. for(int i=0; i<src.width(); ++i)
  283. CPPUNIT_ASSERT_EQUAL(std::numeric_limits<Ipp8s>::min()+i,
  284. static_cast<int>(result->getPixelQuick(i,0)));
  285. }
  286. // Ipp16s
  287. {
  288. ImageT<Ipp16s> src(2,1);
  289. src.setPixelQuick(0,0, std::numeric_limits<Ipp16s>::min());
  290. src.setPixelQuick(1,0, std::numeric_limits<Ipp16s>::max());
  291. FloatImage* result = grayToFloat(src);
  292. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::min()),
  293. static_cast<int>(result->getPixelQuick(0,0)));
  294. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::max()),
  295. static_cast<int>(result->getPixelQuick(1,0)));
  296. }
  297. }
  298. // floatToGray
  299. {
  300. FloatImage src(200,1);
  301. src(100,0) = 1.652312;
  302. for(int i=1; i<100; ++i) {
  303. src(100-i,0) = src(100,0)*src(100-i+1,0)*(src(100-i+1,0)<0?1:-1);
  304. src(100+i,0) = src(100,0)*src(100+i-1,0);
  305. }
  306. // Ipp8u
  307. {
  308. Image* result = new Image(src.width(), src.height());
  309. result = floatToGray(src, result);
  310. for(int i=1; i<=99; ++i)
  311. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(i,0)));
  312. CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(result->getPixelQuick(100,0)));
  313. CPPUNIT_ASSERT_EQUAL( 3, static_cast<int>(result->getPixelQuick(101,0)));
  314. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result->getPixelQuick(102,0)));
  315. CPPUNIT_ASSERT_EQUAL( 7, static_cast<int>(result->getPixelQuick(103,0)));
  316. CPPUNIT_ASSERT_EQUAL( 12, static_cast<int>(result->getPixelQuick(104,0)));
  317. CPPUNIT_ASSERT_EQUAL( 20, static_cast<int>(result->getPixelQuick(105,0)));
  318. CPPUNIT_ASSERT_EQUAL( 34, static_cast<int>(result->getPixelQuick(106,0)));
  319. CPPUNIT_ASSERT_EQUAL( 56, static_cast<int>(result->getPixelQuick(107,0)));
  320. CPPUNIT_ASSERT_EQUAL( 92, static_cast<int>(result->getPixelQuick(108,0)));
  321. CPPUNIT_ASSERT_EQUAL(152, static_cast<int>(result->getPixelQuick(109,0)));
  322. CPPUNIT_ASSERT_EQUAL(251, static_cast<int>(result->getPixelQuick(110,0)));
  323. for(int i=111; i<src.width(); ++i)
  324. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(i,0)));
  325. }
  326. // Ipp8s
  327. {
  328. ImageT<Ipp8s>* result = new ImageT<Ipp8s>(src.width(), src.height());
  329. result = floatToGray(src, result);
  330. for(int i=1; i<=91; ++i)
  331. CPPUNIT_ASSERT_EQUAL(-128, static_cast<int>(result->getPixelQuick(i,0)));
  332. CPPUNIT_ASSERT_EQUAL(-92, static_cast<int>(result->getPixelQuick( 92,0)));
  333. CPPUNIT_ASSERT_EQUAL(-34, static_cast<int>(result->getPixelQuick( 94,0)));
  334. CPPUNIT_ASSERT_EQUAL(-12, static_cast<int>(result->getPixelQuick( 96,0)));
  335. CPPUNIT_ASSERT_EQUAL(- 5, static_cast<int>(result->getPixelQuick( 98,0)));
  336. CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(result->getPixelQuick(100,0)));
  337. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result->getPixelQuick(102,0)));
  338. CPPUNIT_ASSERT_EQUAL( 12, static_cast<int>(result->getPixelQuick(104,0)));
  339. CPPUNIT_ASSERT_EQUAL( 34, static_cast<int>(result->getPixelQuick(106,0)));
  340. CPPUNIT_ASSERT_EQUAL( 92, static_cast<int>(result->getPixelQuick(108,0)));
  341. for(int i=109; i<src.width(); ++i)
  342. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(i,0)));
  343. }
  344. // Ipp16s
  345. {
  346. ImageT<Ipp16s>* result = new ImageT<Ipp16s>(src.width(), src.height());
  347. result = floatToGray(src, result);
  348. for(int i=1; i<=80; ++i)
  349. CPPUNIT_ASSERT_EQUAL(-32768, static_cast<int>(result->getPixelQuick(i,0)));
  350. CPPUNIT_ASSERT_EQUAL(-13924, static_cast<int>(result->getPixelQuick( 82,0)));
  351. CPPUNIT_ASSERT_EQUAL(- 5100, static_cast<int>(result->getPixelQuick( 84,0)));
  352. CPPUNIT_ASSERT_EQUAL(- 1868, static_cast<int>(result->getPixelQuick( 86,0)));
  353. CPPUNIT_ASSERT_EQUAL(- 684, static_cast<int>(result->getPixelQuick( 88,0)));
  354. CPPUNIT_ASSERT_EQUAL(- 251, static_cast<int>(result->getPixelQuick( 90,0)));
  355. CPPUNIT_ASSERT_EQUAL( 414, static_cast<int>(result->getPixelQuick(111,0)));
  356. CPPUNIT_ASSERT_EQUAL( 1131, static_cast<int>(result->getPixelQuick(113,0)));
  357. CPPUNIT_ASSERT_EQUAL( 3087, static_cast<int>(result->getPixelQuick(115,0)));
  358. CPPUNIT_ASSERT_EQUAL( 8427, static_cast<int>(result->getPixelQuick(117,0)));
  359. CPPUNIT_ASSERT_EQUAL( 23006, static_cast<int>(result->getPixelQuick(119,0)));
  360. for(int i=120; i<src.width(); ++i)
  361. CPPUNIT_ASSERT_EQUAL(+32767, static_cast<int>(result->getPixelQuick(i,0)));
  362. }
  363. }
  364. }
  365. void TestConvert::testRGBFloat()
  366. {
  367. ColorImage src(3,2);
  368. src.setPixelQuick(0,0, 1, 2, 3);
  369. src.setPixelQuick(1,0, 5, 10, 15);
  370. src.setPixelQuick(2,0,100,150,200);
  371. src.setPixelQuick(0,1,111,112,113);
  372. src.setPixelQuick(1,1, 0, 0, 0);
  373. src.setPixelQuick(2,1,255, 0,255);
  374. FloatImage* result = rgbToFloat(src);
  375. CPPUNIT_ASSERT_EQUAL( 1, static_cast<int>(result->getPixelQuick(0,0)));
  376. CPPUNIT_ASSERT_EQUAL( 2, static_cast<int>(result->getPixelQuick(1,0)));
  377. CPPUNIT_ASSERT_EQUAL( 3, static_cast<int>(result->getPixelQuick(2,0)));
  378. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result->getPixelQuick(3,0)));
  379. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result->getPixelQuick(4,0)));
  380. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result->getPixelQuick(5,0)));
  381. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result->getPixelQuick(6,0)));
  382. CPPUNIT_ASSERT_EQUAL(150, static_cast<int>(result->getPixelQuick(7,0)));
  383. CPPUNIT_ASSERT_EQUAL(200, static_cast<int>(result->getPixelQuick(8,0)));
  384. CPPUNIT_ASSERT_EQUAL(111, static_cast<int>(result->getPixelQuick(0,1)));
  385. CPPUNIT_ASSERT_EQUAL(112, static_cast<int>(result->getPixelQuick(1,1)));
  386. CPPUNIT_ASSERT_EQUAL(113, static_cast<int>(result->getPixelQuick(2,1)));
  387. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(3,1)));
  388. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(4,1)));
  389. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(5,1)));
  390. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(6,1)));
  391. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(7,1)));
  392. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(8,1)));
  393. }
  394. void TestConvert::testconvertBitDepth()
  395. {
  396. // gray images
  397. {
  398. // Ipp8u -> Ipp16u/Ipp16s/Ipp32s//32f
  399. {
  400. ImageT<Ipp8u> src(3,2);
  401. src(0,0) = 5; src(1,0) = 10; src(2,0) = 15;
  402. src(0,1) = 100; src(1,1) = 0; src(2,1) = 255;
  403. ImageT<Ipp16u>* result = new ImageT<Ipp16u>(src.width(), src.height());
  404. result = convertBitDepth(src, result);
  405. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result->getPixelQuick(0,0)));
  406. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result->getPixelQuick(1,0)));
  407. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result->getPixelQuick(2,0)));
  408. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result->getPixelQuick(0,1)));
  409. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(1,1)));
  410. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(2,1)));
  411. ImageT<Ipp16s>* result2 = new ImageT<Ipp16s>(src.width(), src.height());
  412. result2 = convertBitDepth(src, result2);
  413. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result2->getPixelQuick(0,0)));
  414. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result2->getPixelQuick(1,0)));
  415. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result2->getPixelQuick(2,0)));
  416. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result2->getPixelQuick(0,1)));
  417. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result2->getPixelQuick(1,1)));
  418. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result2->getPixelQuick(2,1)));
  419. ImageT<Ipp32s>* result3 = new ImageT<Ipp32s>(src.width(), src.height());
  420. result3 = convertBitDepth(src, result3);
  421. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result3->getPixelQuick(0,0)));
  422. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result3->getPixelQuick(1,0)));
  423. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result3->getPixelQuick(2,0)));
  424. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result3->getPixelQuick(0,1)));
  425. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result3->getPixelQuick(1,1)));
  426. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result3->getPixelQuick(2,1)));
  427. ImageT<Ipp32f>* result4 = new ImageT<Ipp32f>(src.width(), src.height());
  428. result4 = convertBitDepth(src, result4);
  429. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result4->getPixelQuick(0,0)));
  430. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result4->getPixelQuick(1,0)));
  431. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result4->getPixelQuick(2,0)));
  432. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result4->getPixelQuick(0,1)));
  433. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result4->getPixelQuick(1,1)));
  434. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result4->getPixelQuick(2,1)));
  435. }
  436. //8s to 32s//32f
  437. {
  438. ImageT<Ipp8s> src(3,1);
  439. src(0,0) = 0;
  440. src(1,0) = std::numeric_limits<Ipp8s>::min();
  441. src(2,0) = std::numeric_limits<Ipp8s>::max();
  442. ImageT<Ipp32s>* result = new ImageT<Ipp32s>(src.width(), src.height());
  443. result = convertBitDepth(src, result);
  444. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0)));
  445. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::min()),
  446. static_cast<int>(result->getPixelQuick(1,0)));
  447. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::max()),
  448. static_cast<int>(result->getPixelQuick(2,0)));
  449. ImageT<Ipp32f>* result2 = new ImageT<Ipp32f>(src.width(), src.height());
  450. result2 = convertBitDepth(src, result2);
  451. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result2->getPixelQuick(0,0)));
  452. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::min()),
  453. static_cast<int>(result2->getPixelQuick(1,0)));
  454. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::max()),
  455. static_cast<int>(result2->getPixelQuick(2,0)));
  456. }
  457. // Ipp16u -> Ipp32s//32f
  458. {
  459. ImageT<Ipp16u> src(3,2);
  460. src(0,0) = 500; src(1,0) = 1000; src(2,0) = 10000;
  461. src(0,1) = 15000; src(1,1) = std::numeric_limits<Ipp16u>::min(); src(2,1) = std::numeric_limits<Ipp16u>::max();
  462. ImageT<Ipp32s>* result = new ImageT<Ipp32s>(src.width(), src.height());
  463. result = convertBitDepth(src, result);
  464. CPPUNIT_ASSERT_EQUAL( 500, static_cast<int>(result->getPixelQuick(0,0)));
  465. CPPUNIT_ASSERT_EQUAL( 1000, static_cast<int>(result->getPixelQuick(1,0)));
  466. CPPUNIT_ASSERT_EQUAL(10000, static_cast<int>(result->getPixelQuick(2,0)));
  467. CPPUNIT_ASSERT_EQUAL(15000, static_cast<int>(result->getPixelQuick(0,1)));
  468. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16u>::min()),
  469. static_cast<int>(result->getPixelQuick(1,1)));
  470. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16u>::max()),
  471. static_cast<int>(result->getPixelQuick(2,1)));
  472. ImageT<Ipp32f>* result2 = new ImageT<Ipp32f>(src.width(), src.height());
  473. result2 = convertBitDepth(src, result2);
  474. CPPUNIT_ASSERT_EQUAL( 500, static_cast<int>(result2->getPixelQuick(0,0)));
  475. CPPUNIT_ASSERT_EQUAL( 1000, static_cast<int>(result2->getPixelQuick(1,0)));
  476. CPPUNIT_ASSERT_EQUAL(10000, static_cast<int>(result2->getPixelQuick(2,0)));
  477. CPPUNIT_ASSERT_EQUAL(15000, static_cast<int>(result2->getPixelQuick(0,1)));
  478. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16u>::min()),
  479. static_cast<int>(result2->getPixelQuick(1,1)));
  480. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16u>::max()),
  481. static_cast<int>(result2->getPixelQuick(2,1)));
  482. // decrease bitdepth to 8u
  483. ImageT<Ipp8u>* result3 = new ImageT<Ipp8u>(src.width(), src.height());
  484. result3 = convertBitDepth(src, result3);
  485. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result3->getPixelQuick(0,0)));
  486. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result3->getPixelQuick(1,0)));
  487. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result3->getPixelQuick(2,0)));
  488. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result3->getPixelQuick(0,1)));
  489. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result3->getPixelQuick(1,1)));
  490. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result3->getPixelQuick(2,1)));
  491. }
  492. // Ipp16s -> Ipp32f
  493. {
  494. ImageT<Ipp16s> src(3,2);
  495. src(0,0) = 0; src(1,0) = std::numeric_limits<Ipp16s>::min(); src(2,0) = std::numeric_limits<Ipp16s>::max();
  496. src(0,1) = std::numeric_limits<Ipp16s>::max()/2;
  497. src(1,1) = -std::numeric_limits<Ipp16s>::max()/2;
  498. src(2,1) = std::numeric_limits<Ipp16s>::max()/8;
  499. ImageT<Ipp32f>* result = new ImageT<Ipp32f>(src.width(), src.height());
  500. result = convertBitDepth(src, result);
  501. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0)));
  502. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::min()),
  503. static_cast<int>(result->getPixelQuick(1,0)));
  504. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::max()),
  505. static_cast<int>(result->getPixelQuick(2,0)));
  506. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::max()/2),
  507. static_cast<int>(result->getPixelQuick(0,1)));
  508. CPPUNIT_ASSERT_EQUAL(static_cast<int>(-std::numeric_limits<Ipp16s>::max()/2),
  509. static_cast<int>(result->getPixelQuick(1,1)));
  510. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::max()/8),
  511. static_cast<int>(result->getPixelQuick(2,1)));
  512. // decrease bitdepth to 8u
  513. ImageT<Ipp8u>* result2 = new ImageT<Ipp8u>(src.width(), src.height());
  514. result2 = convertBitDepth(src, result2);
  515. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result2->getPixelQuick(0,0)));
  516. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result2->getPixelQuick(1,0)));
  517. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result2->getPixelQuick(2,0)));
  518. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result2->getPixelQuick(0,1)));
  519. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result2->getPixelQuick(1,1)));
  520. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result2->getPixelQuick(2,1)));
  521. }
  522. // test specialization to decrease bitdepth from 32f to 8u/8s/16u/16s with ImageT
  523. {
  524. ImageT<Ipp32f> src(1,10);
  525. src(0,0) = -std::numeric_limits<float>::max();
  526. src(0,1) = std::numeric_limits<Ipp16s>::min();
  527. src(0,2) = std::numeric_limits<Ipp8s>::min();
  528. src(0,3) = std::numeric_limits<Ipp8u>::min();
  529. src(0,4) = std::numeric_limits<Ipp16u>::min();
  530. src(0,5) = std::numeric_limits<Ipp8s>::max();
  531. src(0,6) = std::numeric_limits<Ipp8u>::max();
  532. src(0,7) = std::numeric_limits<Ipp16s>::max();
  533. src(0,8) = std::numeric_limits<Ipp16u>::max();
  534. src(0,9) = std::numeric_limits<float>::max();
  535. // to Ipp16u
  536. {
  537. ImageT<Ipp16u>* result = new ImageT<Ipp16u>(src.width(), src.height());
  538. result = convertBitDepth(src, result);
  539. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0)));
  540. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,1)));
  541. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,2)));
  542. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3)));
  543. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4)));
  544. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,5)));
  545. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,6)));
  546. CPPUNIT_ASSERT_EQUAL(32767, static_cast<int>(result->getPixelQuick(0,7)));
  547. CPPUNIT_ASSERT_EQUAL(65535, static_cast<int>(result->getPixelQuick(0,8)));
  548. CPPUNIT_ASSERT_EQUAL(65535, static_cast<int>(result->getPixelQuick(0,9)));
  549. }
  550. // to Ipp16s
  551. {
  552. ImageT<Ipp16s>* result = new ImageT<Ipp16s>(src.width(), src.height());
  553. result = convertBitDepth(src, result);
  554. CPPUNIT_ASSERT_EQUAL(-32768, static_cast<int>(result->getPixelQuick(0,0)));
  555. CPPUNIT_ASSERT_EQUAL(-32768, static_cast<int>(result->getPixelQuick(0,1)));
  556. CPPUNIT_ASSERT_EQUAL( -128, static_cast<int>(result->getPixelQuick(0,2)));
  557. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3)));
  558. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4)));
  559. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,5)));
  560. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,6)));
  561. CPPUNIT_ASSERT_EQUAL( 32767, static_cast<int>(result->getPixelQuick(0,7)));
  562. CPPUNIT_ASSERT_EQUAL( 32767, static_cast<int>(result->getPixelQuick(0,8)));
  563. CPPUNIT_ASSERT_EQUAL( 32767, static_cast<int>(result->getPixelQuick(0,9)));
  564. }
  565. // to Ipp8u
  566. {
  567. ImageT<Ipp8u>* result = new ImageT<Ipp8u>(src.width(), src.height());
  568. result = convertBitDepth(src, result);
  569. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0)));
  570. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,1)));
  571. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,2)));
  572. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3)));
  573. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4)));
  574. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,5)));
  575. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,6)));
  576. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,7)));
  577. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,8)));
  578. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,9)));
  579. }
  580. // to Ipp8s
  581. {
  582. ImageT<Ipp8s>* result = new ImageT<Ipp8s>(src.width(), src.height());
  583. result = convertBitDepth(src, result);
  584. CPPUNIT_ASSERT_EQUAL(-128, static_cast<int>(result->getPixelQuick(0,0)));
  585. CPPUNIT_ASSERT_EQUAL(-128, static_cast<int>(result->getPixelQuick(0,1)));
  586. CPPUNIT_ASSERT_EQUAL(-128, static_cast<int>(result->getPixelQuick(0,2)));
  587. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3)));
  588. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4)));
  589. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,5)));
  590. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,6)));
  591. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,7)));
  592. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,8)));
  593. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,9)));
  594. }
  595. }
  596. }
  597. // color images
  598. {
  599. // Ipp8u -> Ipp16u/Ipp16s/Ipp32s//Ipp32f
  600. {
  601. ColorImageT<Ipp8u> src(3,2);
  602. src.setPixelQuick(0,0, 5, 5, 5);
  603. src.setPixelQuick(1,0, 10, 10, 10);
  604. src.setPixelQuick(2,0, 15, 15, 15);
  605. src.setPixelQuick(0,1,100,100,100);
  606. src.setPixelQuick(1,1, 0, 0, 0);
  607. src.setPixelQuick(2,1,255,255,255);
  608. ColorImageT<Ipp16u>* result = new ColorImageT<Ipp16u>(src.width(), src.height());
  609. result = convertBitDepth(src, result);
  610. for(int i=0; i<3; ++i) {
  611. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result->getPixelQuick(0,0,i)));
  612. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result->getPixelQuick(1,0,i)));
  613. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result->getPixelQuick(2,0,i)));
  614. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result->getPixelQuick(0,1,i)));
  615. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(1,1,i)));
  616. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(2,1,i)));
  617. }
  618. ColorImageT<Ipp16s>* result2 = new ColorImageT<Ipp16s>(src.width(), src.height());
  619. result2 = convertBitDepth(src, result2);
  620. for(int i=0; i<3; ++i) {
  621. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result2->getPixelQuick(0,0,i)));
  622. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result2->getPixelQuick(1,0,i)));
  623. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result2->getPixelQuick(2,0,i)));
  624. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result2->getPixelQuick(0,1,i)));
  625. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result2->getPixelQuick(1,1,i)));
  626. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result2->getPixelQuick(2,1,i)));
  627. }
  628. ColorImageT<Ipp32s>* result3 = new ColorImageT<Ipp32s>(src.width(), src.height());
  629. result3 = convertBitDepth(src, result3);
  630. for(int i=0; i<3; ++i) {
  631. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result3->getPixelQuick(0,0,i)));
  632. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result3->getPixelQuick(1,0,i)));
  633. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result3->getPixelQuick(2,0,i)));
  634. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result3->getPixelQuick(0,1,i)));
  635. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result3->getPixelQuick(1,1,i)));
  636. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result3->getPixelQuick(2,1,i)));
  637. }
  638. ColorImageT<Ipp32f>* result4 = new ColorImageT<Ipp32f>(src.width(), src.height());
  639. result4 = convertBitDepth(src, result4);
  640. for(int i=0; i<3; ++i) {
  641. CPPUNIT_ASSERT_EQUAL( 5, static_cast<int>(result4->getPixelQuick(0,0,i)));
  642. CPPUNIT_ASSERT_EQUAL( 10, static_cast<int>(result4->getPixelQuick(1,0,i)));
  643. CPPUNIT_ASSERT_EQUAL( 15, static_cast<int>(result4->getPixelQuick(2,0,i)));
  644. CPPUNIT_ASSERT_EQUAL(100, static_cast<int>(result4->getPixelQuick(0,1,i)));
  645. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result4->getPixelQuick(1,1,i)));
  646. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result4->getPixelQuick(2,1,i)));
  647. }
  648. }
  649. //8s to 32s//32f
  650. {
  651. ColorImageT<Ipp8s> src(3,1);
  652. src.setPixelQuick(0,0, 0,0,0);
  653. src.setPixelQuick(1,0, std::numeric_limits<Ipp8s>::min(),
  654. std::numeric_limits<Ipp8s>::min(),
  655. std::numeric_limits<Ipp8s>::min());
  656. src.setPixelQuick(2,0, std::numeric_limits<Ipp8s>::max(),
  657. std::numeric_limits<Ipp8s>::max(),
  658. std::numeric_limits<Ipp8s>::max());
  659. ColorImageT<Ipp32s>* result = new ColorImageT<Ipp32s>(src.width(), src.height());
  660. result = convertBitDepth(src, result);
  661. for(int i=0; i<3; ++i) {
  662. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0,i)));
  663. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::min()),
  664. static_cast<int>(result->getPixelQuick(1,0,i)));
  665. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::max()),
  666. static_cast<int>(result->getPixelQuick(2,0,i)));
  667. }
  668. ColorImageT<Ipp32f>* result2 = new ColorImageT<Ipp32f>(src.width(), src.height());
  669. result2 = convertBitDepth(src, result2);
  670. for(int i=0; i<3; ++i) {
  671. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result2->getPixelQuick(0,0,i)));
  672. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::min()),
  673. static_cast<int>(result2->getPixelQuick(1,0,i)));
  674. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp8s>::max()),
  675. static_cast<int>(result2->getPixelQuick(2,0,i)));
  676. }
  677. }
  678. // Ipp16u -> Ipp32s//32f
  679. {
  680. ColorImageT<Ipp16u> src(2,1);
  681. src.setPixelQuick(0,0, 500,500,500);
  682. src.setPixelQuick(1,0, std::numeric_limits<Ipp16u>::max(),
  683. std::numeric_limits<Ipp16u>::max(),
  684. std::numeric_limits<Ipp16u>::max());
  685. ColorImageT<Ipp32s>* result = new ColorImageT<Ipp32s>(src.width(), src.height());
  686. result = convertBitDepth(src, result);
  687. for(int i=0; i<3; ++i) {
  688. CPPUNIT_ASSERT_EQUAL(500, static_cast<int>(result->getPixelQuick(0,0,i)));
  689. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16u>::max()),
  690. static_cast<int>(result->getPixelQuick(1,0,i)));
  691. }
  692. ColorImageT<Ipp32f>* result2 = new ColorImageT<Ipp32f>(src.width(), src.height());
  693. result2 = convertBitDepth(src, result2);
  694. for(int i=0; i<3; ++i) {
  695. CPPUNIT_ASSERT_EQUAL( 500, static_cast<int>(result2->getPixelQuick(0,0,i)));
  696. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16u>::max()),
  697. static_cast<int>(result2->getPixelQuick(1,0,i)));
  698. }
  699. }
  700. // Ipp16s -> Ipp32f
  701. {
  702. ColorImageT<Ipp16s> src(3,2);
  703. src.setPixelQuick(0,0, 0,0,0);
  704. src.setPixelQuick(1,0, std::numeric_limits<Ipp16s>::min(),
  705. std::numeric_limits<Ipp16s>::min(),
  706. std::numeric_limits<Ipp16s>::min());
  707. src.setPixelQuick(2,0, std::numeric_limits<Ipp16s>::max(),
  708. std::numeric_limits<Ipp16s>::max(),
  709. std::numeric_limits<Ipp16s>::max());
  710. src.setPixelQuick(0,1, std::numeric_limits<Ipp16s>::max()/2,
  711. std::numeric_limits<Ipp16s>::max()/2,
  712. std::numeric_limits<Ipp16s>::max()/2);
  713. src.setPixelQuick(1,1,-std::numeric_limits<Ipp16s>::max()/2,
  714. -std::numeric_limits<Ipp16s>::max()/2,
  715. -std::numeric_limits<Ipp16s>::max()/2);
  716. src.setPixelQuick(2,1, std::numeric_limits<Ipp16s>::max()/8,
  717. std::numeric_limits<Ipp16s>::max()/8,
  718. std::numeric_limits<Ipp16s>::max()/8);
  719. ColorImageT<Ipp32f>* result = new ColorImageT<Ipp32f>(src.width(), src.height());
  720. result = convertBitDepth(src, result);
  721. for(int i=0; i<3; ++i) {
  722. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0,i)));
  723. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::min()),
  724. static_cast<int>(result->getPixelQuick(1,0,i)));
  725. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::max()),
  726. static_cast<int>(result->getPixelQuick(2,0,i)));
  727. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::max()/2),
  728. static_cast<int>(result->getPixelQuick(0,1,i)));
  729. CPPUNIT_ASSERT_EQUAL(static_cast<int>(-std::numeric_limits<Ipp16s>::max()/2),
  730. static_cast<int>(result->getPixelQuick(1,1,i)));
  731. CPPUNIT_ASSERT_EQUAL(static_cast<int>(std::numeric_limits<Ipp16s>::max()/8),
  732. static_cast<int>(result->getPixelQuick(2,1,i)));
  733. }
  734. }
  735. // 32s to 8u/8s
  736. {
  737. ColorImageT<Ipp32s> src(1,10);
  738. for(int i=0; i<3; ++i) {
  739. src(0,0,i) = std::numeric_limits<Ipp32s>::min();
  740. src(0,1,i) = std::numeric_limits<Ipp16s>::min();
  741. src(0,2,i) = std::numeric_limits<Ipp8s>::min();
  742. src(0,3,i) = std::numeric_limits<Ipp8u>::min();
  743. src(0,4,i) = std::numeric_limits<Ipp16u>::min();
  744. src(0,5,i) = std::numeric_limits<Ipp8s>::max();
  745. src(0,6,i) = std::numeric_limits<Ipp8u>::max();
  746. src(0,7,i) = std::numeric_limits<Ipp16s>::max();
  747. src(0,8,i) = std::numeric_limits<Ipp16u>::max();
  748. src(0,9,i) = std::numeric_limits<Ipp32s>::max();
  749. }
  750. // to 8u
  751. {
  752. ColorImageT<Ipp8u>* result = new ColorImageT<Ipp8u>(src.width(), src.height());
  753. result = convertBitDepth(src, result);
  754. for(int i=0; i<3; ++i) {
  755. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0,i)));
  756. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,1,i)));
  757. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,2,i)));
  758. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3,i)));
  759. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4,i)));
  760. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,5,i)));
  761. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,6,i)));
  762. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,7,i)));
  763. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,8,i)));
  764. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,9,i)));
  765. }
  766. }
  767. // to 8s
  768. {
  769. ColorImageT<Ipp8s>* result = new ColorImageT<Ipp8s>(src.width(), src.height());
  770. result = convertBitDepth(src, result);
  771. for(int i=0; i<3; ++i) {
  772. CPPUNIT_ASSERT_EQUAL( -128, static_cast<int>(result->getPixelQuick(0,0,i)));
  773. CPPUNIT_ASSERT_EQUAL( -128, static_cast<int>(result->getPixelQuick(0,1,i)));
  774. CPPUNIT_ASSERT_EQUAL( -128, static_cast<int>(result->getPixelQuick(0,2,i)));
  775. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3,i)));
  776. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4,i)));
  777. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,5,i)));
  778. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,6,i)));
  779. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,7,i)));
  780. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,8,i)));
  781. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,9,i)));
  782. }
  783. }
  784. }
  785. // test specialization to decrease bitdepth from 32f to 16u/16s/8u/8s ColorImageT
  786. {
  787. ColorImageT<Ipp32f> src(1,10);
  788. for(int i=0; i<3; ++i) {
  789. src(0,0,i) = -std::numeric_limits<float>::max();
  790. src(0,1,i) = std::numeric_limits<Ipp16s>::min();
  791. src(0,2,i) = std::numeric_limits<Ipp8s>::min();
  792. src(0,3,i) = std::numeric_limits<Ipp8u>::min();
  793. src(0,4,i) = std::numeric_limits<Ipp16u>::min();
  794. src(0,5,i) = std::numeric_limits<Ipp8s>::max();
  795. src(0,6,i) = std::numeric_limits<Ipp8u>::max();
  796. src(0,7,i) = std::numeric_limits<Ipp16s>::max();
  797. src(0,8,i) = std::numeric_limits<Ipp16u>::max();
  798. src(0,9,i) = std::numeric_limits<float>::max();
  799. }
  800. // to 16u
  801. {
  802. ColorImageT<Ipp16u>* result = new ColorImageT<Ipp16u>(src.width(), src.height());
  803. result = convertBitDepth(src, result);
  804. for(int i=0; i<3; ++i) {
  805. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0,i)));
  806. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,1,i)));
  807. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,2,i)));
  808. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3,i)));
  809. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4,i)));
  810. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,5,i)));
  811. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,6,i)));
  812. CPPUNIT_ASSERT_EQUAL(32767, static_cast<int>(result->getPixelQuick(0,7,i)));
  813. CPPUNIT_ASSERT_EQUAL(65535, static_cast<int>(result->getPixelQuick(0,8,i)));
  814. CPPUNIT_ASSERT_EQUAL(65535, static_cast<int>(result->getPixelQuick(0,9,i)));
  815. }
  816. }
  817. // to 16s
  818. {
  819. ColorImageT<Ipp16s>* result = new ColorImageT<Ipp16s>(src.width(), src.height());
  820. result = convertBitDepth(src, result);
  821. for(int i=0; i<3; ++i) {
  822. CPPUNIT_ASSERT_EQUAL(-32768, static_cast<int>(result->getPixelQuick(0,0,i)));
  823. CPPUNIT_ASSERT_EQUAL(-32768, static_cast<int>(result->getPixelQuick(0,1,i)));
  824. CPPUNIT_ASSERT_EQUAL( -128, static_cast<int>(result->getPixelQuick(0,2,i)));
  825. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3,i)));
  826. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4,i)));
  827. CPPUNIT_ASSERT_EQUAL( 127, static_cast<int>(result->getPixelQuick(0,5,i)));
  828. CPPUNIT_ASSERT_EQUAL( 255, static_cast<int>(result->getPixelQuick(0,6,i)));
  829. CPPUNIT_ASSERT_EQUAL( 32767, static_cast<int>(result->getPixelQuick(0,7,i)));
  830. CPPUNIT_ASSERT_EQUAL( 32767, static_cast<int>(result->getPixelQuick(0,8,i)));
  831. CPPUNIT_ASSERT_EQUAL( 32767, static_cast<int>(result->getPixelQuick(0,9,i)));
  832. }
  833. }
  834. // to 8u
  835. {
  836. ColorImageT<Ipp8u>* result = new ColorImageT<Ipp8u>(src.width(), src.height());
  837. result = convertBitDepth(src, result);
  838. for(int i=0; i<3; ++i) {
  839. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0,i)));
  840. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,1,i)));
  841. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,2,i)));
  842. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3,i)));
  843. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4,i)));
  844. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,5,i)));
  845. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,6,i)));
  846. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,7,i)));
  847. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,8,i)));
  848. CPPUNIT_ASSERT_EQUAL(255, static_cast<int>(result->getPixelQuick(0,9,i)));
  849. }
  850. }
  851. // to 8s
  852. {
  853. ColorImageT<Ipp8s>* result = new ColorImageT<Ipp8s>(src.width(), src.height());
  854. result = convertBitDepth(src, result);
  855. for(int i=0; i<3; ++i) {
  856. CPPUNIT_ASSERT_EQUAL(-128, static_cast<int>(result->getPixelQuick(0,0,i)));
  857. CPPUNIT_ASSERT_EQUAL(-128, static_cast<int>(result->getPixelQuick(0,1,i)));
  858. CPPUNIT_ASSERT_EQUAL(-128, static_cast<int>(result->getPixelQuick(0,2,i)));
  859. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,3,i)));
  860. CPPUNIT_ASSERT_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,4,i)));
  861. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,5,i)));
  862. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,6,i)));
  863. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,7,i)));
  864. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,8,i)));
  865. CPPUNIT_ASSERT_EQUAL(127, static_cast<int>(result->getPixelQuick(0,9,i)));
  866. }
  867. }
  868. }
  869. }
  870. }
  871. void TestConvert::testfloatToGrayScaled()
  872. {
  873. FloatImage src(7,1);
  874. src(0,0) = -255; src(1,0) = -128; src(2,0) = - 51;
  875. src(3,0) = 0;
  876. src(4,0) = 51; src(5,0) = 128; src(6,0) = 255;
  877. Image* result = new Image(src.width(), src.height());
  878. result = floatToGrayScaled(src, result);
  879. CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, static_cast<int>(result->getPixelQuick(0,0)), 1);
  880. CPPUNIT_ASSERT_DOUBLES_EQUAL( 64, static_cast<int>(result->getPixelQuick(1,0)), 1);
  881. CPPUNIT_ASSERT_DOUBLES_EQUAL( 102, static_cast<int>(result->getPixelQuick(2,0)), 1);
  882. CPPUNIT_ASSERT_DOUBLES_EQUAL( 128, static_cast<int>(result->getPixelQuick(3,0)), 1);
  883. CPPUNIT_ASSERT_DOUBLES_EQUAL( 153, static_cast<int>(result->getPixelQuick(4,0)), 1);
  884. CPPUNIT_ASSERT_DOUBLES_EQUAL( 192, static_cast<int>(result->getPixelQuick(5,0)), 1);
  885. CPPUNIT_ASSERT_DOUBLES_EQUAL( 255, static_cast<int>(result->getPixelQuick(6,0)), 1);
  886. }