fast_float_testbed.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516
  1. //---------------------------------------------------------------------------------
  2. //
  3. // Little Color Management System, fast floating point extensions
  4. // Copyright (c) 1998-2023 Marti Maria Saguer, all rights reserved
  5. //
  6. //
  7. // This program is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. //---------------------------------------------------------------------------------
  21. #include "fast_float_internal.h"
  22. #include <stdlib.h>
  23. #include <memory.h>
  24. // On Visual Studio, use debug CRT
  25. #ifdef _MSC_VER
  26. # include "crtdbg.h"
  27. #endif
  28. #ifndef PROFILES_DIR
  29. #define PROFILES_DIR "../../test_profiles/"
  30. #endif
  31. // Some pixel representations
  32. typedef struct { cmsUInt8Number r, g, b; } Scanline_rgb8bits;
  33. typedef struct { cmsUInt8Number r, g, b, a; } Scanline_rgba8bits;
  34. typedef struct { cmsUInt8Number c, m, y, k; } Scanline_cmyk8bits;
  35. typedef struct { cmsUInt16Number r, g, b; } Scanline_rgb16bits;
  36. typedef struct { cmsUInt16Number r, g, b, a; } Scanline_rgba16bits;
  37. typedef struct { cmsUInt16Number c, m, y, k; } Scanline_cmyk16bits;
  38. typedef struct { cmsUInt16Number r, g, b; } Scanline_rgb15bits;
  39. typedef struct { cmsUInt16Number r, g, b, a; } Scanline_rgba15bits;
  40. typedef struct { cmsUInt16Number r, g, b, a; } Scanline_cmyk15bits;
  41. typedef struct { cmsFloat32Number r, g, b; } Scanline_rgbFloat;
  42. typedef struct { cmsFloat32Number r, g, b, a; } Scanline_rgbaFloat;
  43. typedef struct { cmsFloat32Number c, m, y, k; } Scanline_cmykFloat;
  44. typedef struct { cmsFloat32Number L, a, b; } Scanline_LabFloat;
  45. // 15 bit mode. <=> 8 bits mode
  46. #define FROM_8_TO_15(x8) (cmsUInt16Number) ((((cmsUInt64Number)x8 << 15)) / 0xFF)
  47. #define FROM_15_TO_8(x15) (cmsUInt8Number) (((cmsUInt64Number) x15 * 0xFF + 0x4000) >> 15)
  48. // Floating point accuracy for tests
  49. #define EPSILON_FLOAT_TESTS 0.005
  50. // A flushed printf
  51. static
  52. void trace(const char* frm, ...)
  53. {
  54. va_list args;
  55. va_start(args, frm);
  56. vfprintf(stderr, frm, args);
  57. fflush(stderr);
  58. va_end(args);
  59. }
  60. // The callback function used by cmsSetLogErrorHandler()
  61. static
  62. void FatalErrorQuit(cmsContext ContextID, cmsUInt32Number ErrorCode, const char *Text)
  63. {
  64. UNUSED_PARAMETER(ContextID);
  65. UNUSED_PARAMETER(ErrorCode);
  66. trace("** Fatal error: %s\n", Text);
  67. exit(1);
  68. }
  69. // Rise an error and exit
  70. static
  71. void Fail(const char* frm, ...)
  72. {
  73. char ReasonToFailBuffer[1024];
  74. va_list args;
  75. va_start(args, frm);
  76. vsprintf(ReasonToFailBuffer, frm, args);
  77. FatalErrorQuit(0, 0, ReasonToFailBuffer);
  78. // unreachable va_end(args);
  79. }
  80. // Creates a fake profile that only has a curve. Used in several places
  81. static
  82. cmsHPROFILE CreateCurves(cmsContext ContextID)
  83. {
  84. cmsToneCurve* Gamma = cmsBuildGamma(ContextID, 1.1);
  85. cmsToneCurve* Transfer[3];
  86. cmsHPROFILE h;
  87. Transfer[0] = Transfer[1] = Transfer[2] = Gamma;
  88. h = cmsCreateLinearizationDeviceLink(ContextID, cmsSigRgbData, Transfer);
  89. cmsFreeToneCurve(ContextID, Gamma);
  90. return h;
  91. }
  92. // Check for a single 15 bit Photoshop-like formatter
  93. static
  94. void CheckSingleFormatter15(cmsContext id, cmsUInt32Number Type, const char* Text)
  95. {
  96. cmsUInt16Number Values[cmsMAXCHANNELS];
  97. cmsUInt8Number Buffer[1024];
  98. cmsFormatter f, b;
  99. cmsInt32Number i, j, nChannels, bytes;
  100. _xform_head info;
  101. UNUSED_PARAMETER(id);
  102. memset(&info, 0, sizeof(info));
  103. info.OutputFormat = info.InputFormat = Type;
  104. // Get functions to go forth and back
  105. f = Formatter_15Bit_Factory(id, Type, cmsFormatterInput, CMS_PACK_FLAGS_16BITS);
  106. b = Formatter_15Bit_Factory(id, Type, cmsFormatterOutput, CMS_PACK_FLAGS_16BITS);
  107. if (f.Fmt16 == NULL || b.Fmt16 == NULL) {
  108. Fail("no formatter for %s", Text);
  109. return;
  110. }
  111. nChannels = T_CHANNELS(Type);
  112. bytes = T_BYTES(Type);
  113. for (j = 0; j < 5; j++) {
  114. for (i = 0; i < nChannels; i++) {
  115. Values[i] = (cmsUInt16Number)(i + j) << 1;
  116. }
  117. b.Fmt16(id, (struct _cmstransform_struct*) &info, Values, Buffer, 1);
  118. memset(Values, 0, sizeof(Values));
  119. f.Fmt16(id, (struct _cmstransform_struct*) &info, Values, Buffer, 1);
  120. for (i = 0; i < nChannels; i++) {
  121. if (Values[i] != ((i + j) << 1)) {
  122. Fail("%s failed", Text);
  123. return;
  124. }
  125. }
  126. }
  127. }
  128. #define C(a) CheckSingleFormatter15(0, a, #a)
  129. // Check for all 15 bits formatters
  130. static
  131. void CheckFormatters15(void)
  132. {
  133. C(TYPE_GRAY_15);
  134. C(TYPE_GRAY_15_REV);
  135. C(TYPE_GRAY_15_SE);
  136. C(TYPE_GRAYA_15);
  137. C(TYPE_GRAYA_15_SE);
  138. C(TYPE_GRAYA_15_PLANAR);
  139. C(TYPE_RGB_15);
  140. C(TYPE_RGB_15_PLANAR);
  141. C(TYPE_RGB_15_SE);
  142. C(TYPE_BGR_15);
  143. C(TYPE_BGR_15_PLANAR);
  144. C(TYPE_BGR_15_SE);
  145. C(TYPE_RGBA_15);
  146. C(TYPE_RGBA_15_PLANAR);
  147. C(TYPE_RGBA_15_SE);
  148. C(TYPE_ARGB_15);
  149. C(TYPE_ABGR_15);
  150. C(TYPE_ABGR_15_PLANAR);
  151. C(TYPE_ABGR_15_SE);
  152. C(TYPE_BGRA_15);
  153. C(TYPE_BGRA_15_SE);
  154. C(TYPE_YMC_15);
  155. C(TYPE_CMY_15);
  156. C(TYPE_CMY_15_PLANAR);
  157. C(TYPE_CMY_15_SE);
  158. C(TYPE_CMYK_15);
  159. C(TYPE_CMYK_15_REV);
  160. C(TYPE_CMYK_15_PLANAR);
  161. C(TYPE_CMYK_15_SE);
  162. C(TYPE_KYMC_15);
  163. C(TYPE_KYMC_15_SE);
  164. C(TYPE_KCMY_15);
  165. C(TYPE_KCMY_15_REV);
  166. C(TYPE_KCMY_15_SE);
  167. }
  168. #undef C
  169. static
  170. cmsInt32Number checkSingleComputeIncrements(cmsUInt32Number Format, cmsUInt32Number planeStride, cmsUInt32Number ExpectedChannels, cmsUInt32Number ExpectedAlpha, ...)
  171. {
  172. cmsUInt32Number nChannels, nAlpha, nTotal, i, rc = 0 ;
  173. cmsUInt32Number ComponentStartingOrder[cmsMAXCHANNELS], ComponentPointerIncrements[cmsMAXCHANNELS];
  174. va_list args;
  175. va_start(args, ExpectedAlpha);
  176. _cmsComputeComponentIncrements(Format, planeStride, &nChannels, &nAlpha, ComponentStartingOrder, ComponentPointerIncrements);
  177. if (nChannels != ExpectedChannels)
  178. return 0;
  179. if (nAlpha != ExpectedAlpha)
  180. return 0;
  181. nTotal = nAlpha + nChannels;
  182. for (i = 0; i < nTotal; i++)
  183. {
  184. cmsUInt32Number so = va_arg(args, cmsUInt32Number);
  185. if (so != ComponentStartingOrder[i])
  186. goto Error;
  187. }
  188. for (i = 0; i < nTotal; i++)
  189. {
  190. cmsUInt32Number so = va_arg(args, cmsUInt32Number);
  191. if (so != ComponentPointerIncrements[i])
  192. goto Error;
  193. }
  194. // Success
  195. rc = 1;
  196. Error:
  197. va_end(args);
  198. return rc;
  199. }
  200. #define CHECK(frm, plane, chans, alpha, ...) if (!checkSingleComputeIncrements(frm, plane, chans, alpha, __VA_ARGS__)) { trace("Format failed!\n"); return 0; }
  201. // Validate the compute increments function
  202. cmsInt32Number CheckComputeIncrements(void)
  203. {
  204. CHECK(TYPE_GRAY_8, 0, 1, 0, /**/ 0, /**/ 1);
  205. CHECK(TYPE_GRAYA_8, 0, 1, 1, /**/ 0, 1, /**/ 2, 2);
  206. CHECK(TYPE_AGRAY_8, 0, 1, 1, /**/ 1, 0, /**/ 2, 2);
  207. CHECK(TYPE_GRAY_16, 0, 1, 0, /**/ 0, /**/ 2);
  208. CHECK(TYPE_GRAYA_16, 0, 1, 1, /**/ 0, 2, /**/ 4, 4);
  209. CHECK(TYPE_AGRAY_16, 0, 1, 1, /**/ 2, 0, /**/ 4, 4);
  210. CHECK(TYPE_GRAY_FLT, 0, 1, 0, /**/ 0, /**/ 4);
  211. CHECK(TYPE_GRAYA_FLT, 0, 1, 1, /**/ 0, 4, /**/ 8, 8);
  212. CHECK(TYPE_AGRAY_FLT, 0, 1, 1, /**/ 4, 0, /**/ 8, 8);
  213. CHECK(TYPE_GRAY_DBL, 0, 1, 0, /**/ 0, /**/ 8);
  214. CHECK(TYPE_AGRAY_DBL, 0, 1, 1, /**/ 8, 0, /**/ 16, 16);
  215. CHECK(TYPE_RGB_8, 0, 3, 0, /**/ 0, 1, 2, /**/ 3, 3, 3);
  216. CHECK(TYPE_RGBA_8, 0, 3, 1, /**/ 0, 1, 2, 3, /**/ 4, 4, 4, 4);
  217. CHECK(TYPE_ARGB_8, 0, 3, 1, /**/ 1, 2, 3, 0, /**/ 4, 4, 4, 4);
  218. CHECK(TYPE_RGB_16, 0, 3, 0, /**/ 0, 2, 4, /**/ 6, 6, 6);
  219. CHECK(TYPE_RGBA_16, 0, 3, 1, /**/ 0, 2, 4, 6, /**/ 8, 8, 8, 8);
  220. CHECK(TYPE_ARGB_16, 0, 3, 1, /**/ 2, 4, 6, 0, /**/ 8, 8, 8, 8);
  221. CHECK(TYPE_RGB_FLT, 0, 3, 0, /**/ 0, 4, 8, /**/ 12, 12, 12);
  222. CHECK(TYPE_RGBA_FLT, 0, 3, 1, /**/ 0, 4, 8, 12, /**/ 16, 16, 16, 16);
  223. CHECK(TYPE_ARGB_FLT, 0, 3, 1, /**/ 4, 8, 12, 0, /**/ 16, 16, 16, 16);
  224. CHECK(TYPE_BGR_8, 0, 3, 0, /**/ 2, 1, 0, /**/ 3, 3, 3);
  225. CHECK(TYPE_BGRA_8, 0, 3, 1, /**/ 2, 1, 0, 3, /**/ 4, 4, 4, 4);
  226. CHECK(TYPE_ABGR_8, 0, 3, 1, /**/ 3, 2, 1, 0, /**/ 4, 4, 4, 4);
  227. CHECK(TYPE_BGR_16, 0, 3, 0, /**/ 4, 2, 0, /**/ 6, 6, 6);
  228. CHECK(TYPE_BGRA_16, 0, 3, 1, /**/ 4, 2, 0, 6, /**/ 8, 8, 8, 8);
  229. CHECK(TYPE_ABGR_16, 0, 3, 1, /**/ 6, 4, 2, 0, /**/ 8, 8, 8, 8);
  230. CHECK(TYPE_BGR_FLT, 0, 3, 0, /**/ 8, 4, 0, /**/ 12, 12, 12);
  231. CHECK(TYPE_BGRA_FLT, 0, 3, 1, /**/ 8, 4, 0, 12, /**/ 16, 16, 16, 16);
  232. CHECK(TYPE_ABGR_FLT, 0, 3, 1, /**/ 12, 8, 4, 0, /**/ 16, 16, 16, 16);
  233. CHECK(TYPE_CMYK_8, 0, 4, 0, /**/ 0, 1, 2, 3, /**/ 4, 4, 4, 4);
  234. CHECK(TYPE_CMYKA_8, 0, 4, 1, /**/ 0, 1, 2, 3, 4, /**/ 5, 5, 5, 5, 5);
  235. CHECK(TYPE_ACMYK_8, 0, 4, 1, /**/ 1, 2, 3, 4, 0, /**/ 5, 5, 5, 5, 5);
  236. CHECK(TYPE_KYMC_8, 0, 4, 0, /**/ 3, 2, 1, 0, /**/ 4, 4, 4, 4);
  237. CHECK(TYPE_KYMCA_8, 0, 4, 1, /**/ 3, 2, 1, 0, 4, /**/ 5, 5, 5, 5, 5);
  238. CHECK(TYPE_AKYMC_8, 0, 4, 1, /**/ 4, 3, 2, 1, 0, /**/ 5, 5, 5, 5, 5);
  239. CHECK(TYPE_KCMY_8, 0, 4, 0, /**/ 1, 2, 3, 0, /**/ 4, 4, 4, 4);
  240. CHECK(TYPE_CMYK_16, 0, 4, 0, /**/ 0, 2, 4, 6, /**/ 8, 8, 8, 8);
  241. CHECK(TYPE_CMYKA_16, 0, 4, 1, /**/ 0, 2, 4, 6, 8, /**/ 10, 10, 10, 10, 10);
  242. CHECK(TYPE_ACMYK_16, 0, 4, 1, /**/ 2, 4, 6, 8, 0, /**/ 10, 10, 10, 10, 10);
  243. CHECK(TYPE_KYMC_16, 0, 4, 0, /**/ 6, 4, 2, 0, /**/ 8, 8, 8, 8);
  244. CHECK(TYPE_KYMCA_16, 0, 4, 1, /**/ 6, 4, 2, 0, 8, /**/ 10, 10, 10, 10, 10);
  245. CHECK(TYPE_AKYMC_16, 0, 4, 1, /**/ 8, 6, 4, 2, 0, /**/ 10, 10, 10, 10, 10);
  246. CHECK(TYPE_KCMY_16, 0, 4, 0, /**/ 2, 4, 6, 0, /**/ 8, 8, 8, 8);
  247. // Planar
  248. CHECK(TYPE_GRAYA_8_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 1, 1);
  249. CHECK(TYPE_AGRAY_8_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 1, 1);
  250. CHECK(TYPE_GRAYA_16_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 2, 2);
  251. CHECK(TYPE_AGRAY_16_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 2, 2);
  252. CHECK(TYPE_GRAYA_FLT_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 4, 4);
  253. CHECK(TYPE_AGRAY_FLT_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 4, 4);
  254. CHECK(TYPE_GRAYA_DBL_PLANAR, 100, 1, 1, /**/ 0, 100, /**/ 8, 8);
  255. CHECK(TYPE_AGRAY_DBL_PLANAR, 100, 1, 1, /**/ 100, 0, /**/ 8, 8);
  256. CHECK(TYPE_RGB_8_PLANAR, 100, 3, 0, /**/ 0, 100, 200, /**/ 1, 1, 1);
  257. CHECK(TYPE_RGBA_8_PLANAR, 100, 3, 1, /**/ 0, 100, 200, 300, /**/ 1, 1, 1, 1);
  258. CHECK(TYPE_ARGB_8_PLANAR, 100, 3, 1, /**/ 100, 200, 300, 0, /**/ 1, 1, 1, 1);
  259. CHECK(TYPE_BGR_8_PLANAR, 100, 3, 0, /**/ 200, 100, 0, /**/ 1, 1, 1);
  260. CHECK(TYPE_BGRA_8_PLANAR, 100, 3, 1, /**/ 200, 100, 0, 300, /**/ 1, 1, 1, 1);
  261. CHECK(TYPE_ABGR_8_PLANAR, 100, 3, 1, /**/ 300, 200, 100, 0, /**/ 1, 1, 1, 1);
  262. CHECK(TYPE_RGB_16_PLANAR, 100, 3, 0, /**/ 0, 100, 200, /**/ 2, 2, 2);
  263. CHECK(TYPE_RGBA_16_PLANAR, 100, 3, 1, /**/ 0, 100, 200, 300, /**/ 2, 2, 2, 2);
  264. CHECK(TYPE_ARGB_16_PLANAR, 100, 3, 1, /**/ 100, 200, 300, 0, /**/ 2, 2, 2, 2);
  265. CHECK(TYPE_BGR_16_PLANAR, 100, 3, 0, /**/ 200, 100, 0, /**/ 2, 2, 2);
  266. CHECK(TYPE_BGRA_16_PLANAR, 100, 3, 1, /**/ 200, 100, 0, 300, /**/ 2, 2, 2, 2);
  267. CHECK(TYPE_ABGR_16_PLANAR, 100, 3, 1, /**/ 300, 200, 100, 0, /**/ 2, 2, 2, 2);
  268. return 1;
  269. }
  270. // Check 15 bit mode accuracy
  271. static
  272. cmsBool Valid15(cmsUInt16Number a, cmsUInt8Number b)
  273. {
  274. return abs(FROM_15_TO_8(a) - b) <= 2;
  275. }
  276. // Check the test macros itselves
  277. static
  278. void Check15bitMacros(void)
  279. {
  280. int i;
  281. trace("Checking 15 bit <=> 8 bit macros...");
  282. for (i = 0; i < 256; i++)
  283. {
  284. cmsUInt16Number n = FROM_8_TO_15(i);
  285. cmsUInt8Number m = FROM_15_TO_8(n);
  286. if (m != i)
  287. Fail("Failed on %d (->%d->%d)", i, n, m);
  288. }
  289. trace("ok\n");
  290. }
  291. // Do an in-depth test by checking all RGB cube of 8 bits, going from profilein to profileout.
  292. // Results should be same except for 2 contone levels allowed for roundoff. Note 15 bits is more
  293. // precise than 8 bits and this is a source of discrepancies. Cache is disabled
  294. static
  295. void TryAllValues15(cmsContext ContextID, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
  296. {
  297. Scanline_rgb8bits* buffer8in;
  298. Scanline_rgb15bits* buffer15in;
  299. Scanline_rgb8bits* buffer8out;
  300. Scanline_rgb15bits* buffer15out;
  301. int r, g, b, j;
  302. cmsUInt32Number npixels = 256 * 256 * 256; // All RGB cube in 8 bits
  303. cmsHTRANSFORM xform15 = cmsCreateTransform(ContextID, hlcmsProfileIn, TYPE_RGB_15, hlcmsProfileOut, TYPE_RGB_15, Intent, cmsFLAGS_NOCACHE);
  304. cmsHTRANSFORM xform8 = cmsCreateTransform(ContextID, hlcmsProfileIn, TYPE_RGB_8, hlcmsProfileOut, TYPE_RGB_8, Intent, cmsFLAGS_NOCACHE); // Transforms already created
  305. cmsCloseProfile(ContextID, hlcmsProfileIn);
  306. cmsCloseProfile(ContextID, hlcmsProfileOut);
  307. if (xform15 == NULL || xform8 == NULL) {
  308. Fail("NULL transforms on check for 15 bit conversions");
  309. }
  310. // Since this is just a test, I will not check memory allocation...
  311. buffer8in = (Scanline_rgb8bits*)malloc(npixels * sizeof(Scanline_rgb8bits));
  312. buffer15in = (Scanline_rgb15bits*)malloc(npixels * sizeof(Scanline_rgb15bits));
  313. buffer8out = (Scanline_rgb8bits*)malloc(npixels * sizeof(Scanline_rgb8bits));
  314. buffer15out = (Scanline_rgb15bits*)malloc(npixels * sizeof(Scanline_rgb15bits));
  315. // Fill input values for 8 and 15 bits
  316. j = 0;
  317. for (r = 0; r < 256; r++)
  318. for (g = 0; g < 256; g++)
  319. for (b = 0; b < 256; b++) {
  320. buffer8in[j].r = (cmsUInt8Number)r;
  321. buffer8in[j].g = (cmsUInt8Number)g;
  322. buffer8in[j].b = (cmsUInt8Number)b;
  323. buffer15in[j].r = FROM_8_TO_15(r);
  324. buffer15in[j].g = FROM_8_TO_15(g);
  325. buffer15in[j].b = FROM_8_TO_15(b);
  326. j++;
  327. }
  328. cmsDoTransform(ContextID, xform15, buffer15in, buffer15out, npixels);
  329. cmsDoTransform(ContextID, xform8, buffer8in, buffer8out, npixels);
  330. j = 0;
  331. for (r = 0; r < 256; r++)
  332. for (g = 0; g < 256; g++)
  333. for (b = 0; b < 256; b++) {
  334. // Check the results
  335. if (!Valid15(buffer15out[j].r, buffer8out[j].r) ||
  336. !Valid15(buffer15out[j].g, buffer8out[j].g) ||
  337. !Valid15(buffer15out[j].b, buffer8out[j].b))
  338. Fail("Conversion failed at (%d %d %d) != (%d %d %d)", buffer8out[j].r, buffer8out[j].g, buffer8out[j].b,
  339. FROM_15_TO_8(buffer15out[j].r), FROM_15_TO_8(buffer15out[j].g), FROM_15_TO_8(buffer15out[j].b));
  340. j++;
  341. }
  342. free(buffer8in); free(buffer15in);
  343. free(buffer8out); free(buffer15out);
  344. cmsDeleteTransform(ContextID, xform15);
  345. cmsDeleteTransform(ContextID, xform8);
  346. }
  347. // Convert some known values
  348. static
  349. void Check15bitsConversions(cmsContext ContextID)
  350. {
  351. Check15bitMacros();
  352. trace("Checking accuracy of 15 bits on CLUT...");
  353. TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(ContextID, PROFILES_DIR "test3.icc", "r"), INTENT_PERCEPTUAL);
  354. trace("Ok\n");
  355. trace("Checking accuracy of 15 bits on same profile ...");
  356. TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, PROFILES_DIR "test0.icc", "r"), cmsOpenProfileFromFile(ContextID, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL);
  357. trace("Ok\n");
  358. trace("Checking accuracy of 15 bits on Matrix...");
  359. TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(ContextID, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL);
  360. trace("Ok\n");
  361. trace("All 15 bits tests passed OK\n\n");
  362. }
  363. // Next test checks results of optimized 16 bits versus raw 16 bits.
  364. static
  365. void TryAllValues16bits(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
  366. {
  367. Scanline_rgba16bits* bufferIn;
  368. Scanline_rgba16bits* bufferRawOut;
  369. Scanline_rgba16bits* bufferPluginOut;
  370. int r, g, b;
  371. int j;
  372. cmsUInt32Number npixels = 256 * 256 * 256;
  373. cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGBA_16, hlcmsProfileOut, TYPE_RGBA_16, Intent, cmsFLAGS_NOCACHE| cmsFLAGS_COPY_ALPHA);
  374. cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGBA_16, hlcmsProfileOut, TYPE_RGBA_16, Intent, cmsFLAGS_NOCACHE| cmsFLAGS_COPY_ALPHA);
  375. cmsCloseProfile(Raw, hlcmsProfileIn);
  376. cmsCloseProfile(Raw, hlcmsProfileOut);
  377. if (xformRaw == NULL || xformPlugin == NULL) {
  378. Fail("NULL transforms on check float conversions");
  379. }
  380. // Again, no checking on mem alloc because this is just a test
  381. bufferIn = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
  382. bufferRawOut = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
  383. bufferPluginOut = (Scanline_rgba16bits*)malloc(npixels * sizeof(Scanline_rgba16bits));
  384. // Same input to both transforms
  385. j = 0;
  386. for (r = 0; r < 256; r++)
  387. for (g = 0; g < 256; g++)
  388. for (b = 0; b < 256; b++) {
  389. bufferIn[j].r = FROM_8_TO_16(0xf8);
  390. bufferIn[j].g = FROM_8_TO_16(0xf8);
  391. bufferIn[j].b = FROM_8_TO_16(0xf8);
  392. bufferIn[j].a = 0xffff;
  393. j++;
  394. }
  395. // Different transforms, different output buffers
  396. cmsDoTransform(Raw, xformRaw, bufferIn, bufferRawOut, npixels);
  397. cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferPluginOut, npixels);
  398. // Lets compare results
  399. j = 0;
  400. for (r = 0; r < 256; r++)
  401. for (g = 0; g < 256; g++)
  402. for (b = 0; b < 256; b++) {
  403. if (bufferRawOut[j].r != bufferPluginOut[j].r ||
  404. bufferRawOut[j].g != bufferPluginOut[j].g ||
  405. bufferRawOut[j].b != bufferPluginOut[j].b ||
  406. bufferRawOut[j].a != bufferPluginOut[j].a)
  407. Fail(
  408. "Conversion failed at [%x %x %x %x] (%x %x %x %x) != (%x %x %x %x)",
  409. bufferIn[j].r, bufferIn[j].g, bufferIn[j].b, bufferIn[j].a,
  410. bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b, bufferRawOut[j].a,
  411. bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b, bufferPluginOut[j].a);
  412. j++;
  413. }
  414. free(bufferIn); free(bufferRawOut);
  415. free(bufferPluginOut);
  416. cmsDeleteTransform(Raw, xformRaw);
  417. cmsDeleteTransform(Plugin, xformPlugin);
  418. }
  419. static
  420. void CheckAccuracy16Bits(cmsContext Raw, cmsContext Plugin)
  421. {
  422. // CLUT should be as 16 bits or better
  423. trace("Checking accuracy of 16 bits CLUT...");
  424. TryAllValues16bits(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test3.icc", "r"), INTENT_PERCEPTUAL);
  425. trace("All 16 bits tests passed OK\n\n");
  426. }
  427. // Try values that are denormalized, not-a-number and out of range
  428. static
  429. void CheckUncommonValues(cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
  430. {
  431. union
  432. {
  433. cmsFloat32Number subnormal;
  434. cmsUInt32Number Int;
  435. } sub_pos, sub_neg;
  436. Scanline_rgbFloat* bufferIn;
  437. Scanline_rgbFloat* bufferPluginOut;
  438. cmsUInt32Number i, npixels = 100;
  439. cmsContext Plugin = cmsCreateContext(cmsFastFloatExtensions(), NULL);
  440. cmsHTRANSFORM xformPlugin = cmsCreateTransformTHR(Plugin, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, 0);
  441. sub_pos.Int = 0x00000002;
  442. sub_neg.Int = 0x80000002;
  443. cmsCloseProfile(hlcmsProfileIn);
  444. cmsCloseProfile(hlcmsProfileOut);
  445. if (xformPlugin == NULL) {
  446. Fail("NULL transform on check uncommon values");
  447. }
  448. bufferIn = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
  449. bufferPluginOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
  450. for (i = 0; i < npixels; i++)
  451. {
  452. bufferIn[i].r = i / 40.0f - 0.5f;
  453. bufferIn[i].g = i / 20.0f - 0.5f;
  454. bufferIn[i].b = i / 60.0f - 0.5f;
  455. }
  456. cmsDoTransform(xformPlugin, bufferIn, bufferPluginOut, npixels);
  457. bufferIn[0].r = NAN;
  458. bufferIn[0].g = NAN;
  459. bufferIn[0].b = NAN;
  460. bufferIn[1].r = INFINITY;
  461. bufferIn[1].g = INFINITY;
  462. bufferIn[1].b = INFINITY;
  463. bufferIn[2].r = sub_pos.subnormal;
  464. bufferIn[2].g = sub_pos.subnormal;
  465. bufferIn[2].b = sub_pos.subnormal;
  466. bufferIn[3].r = sub_neg.subnormal;
  467. bufferIn[3].g = sub_neg.subnormal;
  468. bufferIn[3].b = sub_neg.subnormal;
  469. cmsDoTransform(xformPlugin, bufferIn, bufferPluginOut, 4);
  470. free(bufferIn);
  471. free(bufferPluginOut);
  472. cmsDeleteTransform(xformPlugin);
  473. cmsDeleteContext(Plugin);
  474. }
  475. static
  476. void lab8toLab(cmsUInt8Number lab8[3], cmsCIELab* Lab)
  477. {
  478. cmsUInt16Number lab16[3];
  479. lab16[0] = FROM_8_TO_16(lab8[0]);
  480. lab16[1] = FROM_8_TO_16(lab8[1]);
  481. lab16[2] = FROM_8_TO_16(lab8[2]);
  482. cmsLabEncoded2Float(Lab, lab16);
  483. }
  484. static
  485. void CheckToEncodedLab(void)
  486. {
  487. cmsContext Plugin = cmsCreateContext(cmsFastFloatExtensions(), NULL);
  488. cmsContext Raw = cmsCreateContext(NULL, NULL);
  489. cmsHPROFILE hsRGB = cmsCreate_sRGBProfile();
  490. cmsHPROFILE hLab = cmsCreateLab4Profile(NULL);
  491. cmsHTRANSFORM xform_plugin = cmsCreateTransformTHR(Plugin, hsRGB, TYPE_RGB_8, hLab, TYPE_Lab_8, INTENT_PERCEPTUAL, 0);
  492. cmsHTRANSFORM xform = cmsCreateTransformTHR(Raw, hsRGB, TYPE_RGB_8, hLab, TYPE_Lab_8, INTENT_PERCEPTUAL, 0);
  493. int r, g, b;
  494. cmsCIELab Lab1, Lab2;
  495. cmsUInt8Number rgb[3], lab1[3], lab2[3];
  496. double err;
  497. for (r=0; r < 256; r += 5)
  498. for (g = 0; g < 256; g += 5)
  499. for (b = 0; b < 256; b += 5)
  500. {
  501. rgb[0] = (cmsUInt8Number) r; rgb[1] = (cmsUInt8Number) g; rgb[2] = (cmsUInt8Number) b;
  502. cmsDoTransform(xform_plugin, rgb, lab1, 1);
  503. cmsDoTransform(xform, rgb, lab2, 1);
  504. lab8toLab(lab1, &Lab1);
  505. lab8toLab(lab2, &Lab2);
  506. err = cmsDeltaE(&Lab1, &Lab2);
  507. if (err > 0.1)
  508. {
  509. trace("Error on lab encoded (%f, %f, %f) <> (% f, % f, % f)\n",
  510. Lab1.L, Lab1.a, Lab1.b, Lab2.L, Lab2.a, Lab2.b);
  511. }
  512. }
  513. cmsDeleteTransform(xform); cmsDeleteTransform(xform_plugin);
  514. cmsCloseProfile(hsRGB); cmsCloseProfile(hLab);
  515. cmsDeleteContext(Raw);
  516. cmsDeleteContext(Plugin);
  517. }
  518. static
  519. void CheckToFloatLab(void)
  520. {
  521. cmsContext Plugin = cmsCreateContext(cmsFastFloatExtensions(), NULL);
  522. cmsContext Raw = cmsCreateContext(NULL, NULL);
  523. cmsHPROFILE hsRGB = cmsCreate_sRGBProfile();
  524. cmsHPROFILE hLab = cmsCreateLab4Profile(NULL);
  525. cmsHTRANSFORM xform_plugin = cmsCreateTransformTHR(Plugin, hsRGB, TYPE_RGB_8, hLab, TYPE_Lab_DBL, INTENT_PERCEPTUAL, 0);
  526. cmsHTRANSFORM xform = cmsCreateTransformTHR(Raw, hsRGB, TYPE_RGB_8, hLab, TYPE_Lab_DBL, INTENT_PERCEPTUAL, 0);
  527. int r, g, b;
  528. cmsCIELab Lab1, Lab2;
  529. cmsUInt8Number rgb[3];
  530. double err;
  531. for (r = 0; r < 256; r += 10)
  532. for (g = 0; g < 256; g += 10)
  533. for (b = 0; b < 256; b += 10)
  534. {
  535. rgb[0] = (cmsUInt8Number)r; rgb[1] = (cmsUInt8Number)g; rgb[2] = (cmsUInt8Number)b;
  536. cmsDoTransform(xform_plugin, rgb, &Lab1, 1);
  537. cmsDoTransform(xform, rgb, &Lab2, 1);
  538. err = cmsDeltaE(&Lab1, &Lab2);
  539. if (err > 0.1)
  540. {
  541. trace("Error on lab encoded (%f, %f, %f) <> (% f, % f, % f)\n",
  542. Lab1.L, Lab1.a, Lab1.b, Lab2.L, Lab2.a, Lab2.b);
  543. }
  544. }
  545. cmsDeleteTransform(xform); cmsDeleteTransform(xform_plugin);
  546. cmsCloseProfile(hsRGB); cmsCloseProfile(hLab);
  547. cmsDeleteContext(Raw);
  548. cmsDeleteContext(Plugin);
  549. }
  550. static
  551. void CheckFloatToFloatLab(void)
  552. {
  553. cmsContext Plugin = cmsCreateContext(cmsFastFloatExtensions(), NULL);
  554. cmsContext Raw = cmsCreateContext(NULL, NULL);
  555. cmsHPROFILE hsRGB = cmsCreate_sRGBProfile();
  556. cmsHPROFILE hLab = cmsCreateLab4Profile(NULL);
  557. cmsHTRANSFORM xform_plugin = cmsCreateTransformTHR(Plugin, hsRGB, TYPE_RGB_FLT, hLab, TYPE_Lab_FLT, INTENT_PERCEPTUAL, 0);
  558. cmsHTRANSFORM xform = cmsCreateTransformTHR(Raw, hsRGB, TYPE_RGB_FLT, hLab, TYPE_Lab_FLT, INTENT_PERCEPTUAL, 0);
  559. int r, g, b;
  560. cmsCIELab Lab1, Lab2;
  561. cmsFloat32Number rgb[3];
  562. cmsFloat32Number Lab[3];
  563. double err;
  564. for (r = 0; r < 256; r += 10)
  565. for (g = 0; g < 256; g += 10)
  566. for (b = 0; b < 256; b += 10)
  567. {
  568. rgb[0] = (cmsFloat32Number)r / 255.0f;
  569. rgb[1] = (cmsFloat32Number)g / 255.0f;
  570. rgb[2] = (cmsFloat32Number)b / 255.0f;
  571. cmsDoTransform(xform_plugin, rgb, Lab, 1);
  572. Lab1.L = Lab[0]; Lab1.a = Lab[1]; Lab1.b = Lab[2];
  573. cmsDoTransform(xform, rgb, Lab, 1);
  574. Lab2.L = Lab[0]; Lab2.a = Lab[1]; Lab2.b = Lab[2];
  575. err = cmsDeltaE(&Lab1, &Lab2);
  576. if (err > 0.5)
  577. {
  578. trace("Error on lab encoded (%f, %f, %f) <> (% f, % f, % f)\n",
  579. Lab1.L, Lab1.a, Lab1.b, Lab2.L, Lab2.a, Lab2.b);
  580. }
  581. }
  582. cmsDeleteTransform(xform); cmsDeleteTransform(xform_plugin);
  583. cmsCloseProfile(hsRGB); cmsCloseProfile(hLab);
  584. cmsDeleteContext(Raw);
  585. cmsDeleteContext(Plugin);
  586. }
  587. // --------------------------------------------------------------------------------------------------
  588. // A C C U R A C Y C H E C K S
  589. // --------------------------------------------------------------------------------------------------
  590. // Check result accuracy
  591. static
  592. cmsBool ValidFloat(cmsFloat32Number a, cmsFloat32Number b)
  593. {
  594. return fabsf(a-b) < EPSILON_FLOAT_TESTS;
  595. }
  596. // Do an in-depth test by checking all RGB cube of 8 bits, going from profilein to profileout.
  597. // Values with and without optimization are checked (different contexts, one with the plugin and another without)
  598. // Results should be same except for EPSILON_FLOAT_TESTS allowed for accuracy/speed tradeoff. Cache is disabled
  599. static
  600. void TryAllValuesFloat(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
  601. {
  602. Scanline_rgbFloat* bufferIn;
  603. Scanline_rgbFloat* bufferRawOut;
  604. Scanline_rgbFloat* bufferPluginOut;
  605. int r, g, b;
  606. int j;
  607. cmsUInt32Number npixels = 256 * 256 * 256;
  608. cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, cmsFLAGS_NOCACHE);
  609. cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, cmsFLAGS_NOCACHE);
  610. cmsCloseProfile(Raw, hlcmsProfileIn);
  611. cmsCloseProfile(Raw, hlcmsProfileOut);
  612. if (xformRaw == NULL || xformPlugin == NULL) {
  613. Fail("NULL transforms on check float conversions");
  614. }
  615. // Again, no checking on mem alloc because this is just a test
  616. bufferIn = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
  617. bufferRawOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
  618. bufferPluginOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
  619. // Same input to both transforms
  620. j = 0;
  621. for (r = 0; r < 256; r++)
  622. for (g = 0; g < 256; g++)
  623. for (b = 0; b < 256; b++) {
  624. bufferIn[j].r = (cmsFloat32Number)r / 255.0f;
  625. bufferIn[j].g = (cmsFloat32Number)g / 255.0f;
  626. bufferIn[j].b = (cmsFloat32Number)b / 255.0f;
  627. j++;
  628. }
  629. // Different transforms, different output buffers
  630. cmsDoTransform(Raw, xformRaw, bufferIn, bufferRawOut, npixels);
  631. cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferPluginOut, npixels);
  632. // Lets compare results
  633. j = 0;
  634. for (r = 0; r < 256; r++)
  635. for (g = 0; g < 256; g++)
  636. for (b = 0; b < 256; b++) {
  637. if (!ValidFloat(bufferRawOut[j].r, bufferPluginOut[j].r) ||
  638. !ValidFloat(bufferRawOut[j].g, bufferPluginOut[j].g) ||
  639. !ValidFloat(bufferRawOut[j].b, bufferPluginOut[j].b))
  640. Fail("Conversion failed at (%f %f %f) != (%f %f %f)", bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b,
  641. bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b);
  642. j++;
  643. }
  644. free(bufferIn); free(bufferRawOut);
  645. free(bufferPluginOut);
  646. cmsDeleteTransform(Raw, xformRaw);
  647. cmsDeleteTransform(Plugin, xformPlugin);
  648. }
  649. static
  650. void TryAllValuesFloatAlpha(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent, cmsBool copyAlpha)
  651. {
  652. Scanline_rgbaFloat* bufferIn;
  653. Scanline_rgbaFloat* bufferRawOut;
  654. Scanline_rgbaFloat* bufferPluginOut;
  655. int r, g, b;
  656. int j;
  657. cmsUInt32Number npixels = 256 * 256 * 256;
  658. cmsUInt32Number flags = cmsFLAGS_NOCACHE | ( copyAlpha? cmsFLAGS_COPY_ALPHA : 0);
  659. cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGBA_FLT, hlcmsProfileOut, TYPE_RGBA_FLT, Intent, flags);
  660. cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGBA_FLT, hlcmsProfileOut, TYPE_RGBA_FLT, Intent, flags);
  661. cmsCloseProfile(Raw, hlcmsProfileIn);
  662. cmsCloseProfile(Plugin, hlcmsProfileOut);
  663. if (xformRaw == NULL || xformPlugin == NULL) {
  664. Fail("NULL transforms on check float conversions");
  665. }
  666. // Again, no checking on mem alloc because this is just a test
  667. bufferIn = (Scanline_rgbaFloat*)malloc(npixels * sizeof(Scanline_rgbaFloat));
  668. bufferRawOut = (Scanline_rgbaFloat*)malloc(npixels * sizeof(Scanline_rgbaFloat));
  669. bufferPluginOut = (Scanline_rgbaFloat*)malloc(npixels * sizeof(Scanline_rgbaFloat));
  670. memset(bufferRawOut, 0, npixels * sizeof(Scanline_rgbaFloat));
  671. memset(bufferPluginOut, 0, npixels * sizeof(Scanline_rgbaFloat));
  672. // Same input to both transforms
  673. j = 0;
  674. for (r = 0; r < 256; r++)
  675. for (g = 0; g < 256; g++)
  676. for (b = 0; b < 256; b++) {
  677. bufferIn[j].r = (cmsFloat32Number)r / 255.0f;
  678. bufferIn[j].g = (cmsFloat32Number)g / 255.0f;
  679. bufferIn[j].b = (cmsFloat32Number)b / 255.0f;
  680. bufferIn[j].a = (cmsFloat32Number) 1.0f;
  681. j++;
  682. }
  683. // Different transforms, different output buffers
  684. cmsDoTransform(Raw, xformRaw, bufferIn, bufferRawOut, npixels);
  685. cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferPluginOut, npixels);
  686. // Lets compare results
  687. j = 0;
  688. for (r = 0; r < 256; r++)
  689. for (g = 0; g < 256; g++)
  690. for (b = 0; b < 256; b++) {
  691. if (!ValidFloat(bufferRawOut[j].r, bufferPluginOut[j].r) ||
  692. !ValidFloat(bufferRawOut[j].g, bufferPluginOut[j].g) ||
  693. !ValidFloat(bufferRawOut[j].b, bufferPluginOut[j].b) ||
  694. !ValidFloat(bufferRawOut[j].a, bufferPluginOut[j].a))
  695. Fail("Conversion failed at (%f %f %f %f) != (%f %f %f %f)", bufferRawOut[j].r, bufferRawOut[j].g, bufferRawOut[j].b, bufferRawOut[j].a,
  696. bufferPluginOut[j].r, bufferPluginOut[j].g, bufferPluginOut[j].b, bufferPluginOut[j].a);
  697. j++;
  698. }
  699. free(bufferIn); free(bufferRawOut);
  700. free(bufferPluginOut);
  701. cmsDeleteTransform(Raw, xformRaw);
  702. cmsDeleteTransform(Plugin, xformPlugin);
  703. }
  704. // Next test checks results of optimized floating point versus 16 bits. That is, converting the float to 16 bits, operating
  705. // in 16 bits and back to float. Results again should be in range of epsilon
  706. static
  707. cmsBool Valid16Float(cmsUInt16Number a, cmsFloat32Number b)
  708. {
  709. return fabs(((cmsFloat32Number)a / (cmsFloat32Number) 0xFFFF) - b) < EPSILON_FLOAT_TESTS;
  710. }
  711. // Do an in-depth test by checking all RGB cube of 8 bits, going from profilein to profileout. 16 bits temporary is used as reference
  712. static
  713. void TryAllValuesFloatVs16(cmsContext Raw, cmsContext Plugin, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
  714. {
  715. Scanline_rgbFloat* bufferIn;
  716. Scanline_rgb16bits* bufferIn16;
  717. Scanline_rgbFloat* bufferFloatOut;
  718. Scanline_rgb16bits* buffer16Out;
  719. int r, g, b;
  720. int j;
  721. cmsUInt32Number npixels = 256 * 256 * 256;
  722. cmsHTRANSFORM xformRaw = cmsCreateTransform(Raw, hlcmsProfileIn, TYPE_RGB_16, hlcmsProfileOut, TYPE_RGB_16, Intent, cmsFLAGS_NOCACHE);
  723. cmsHTRANSFORM xformPlugin = cmsCreateTransform(Plugin, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, cmsFLAGS_NOCACHE);
  724. cmsCloseProfile(Raw, hlcmsProfileIn);
  725. cmsCloseProfile(Raw, hlcmsProfileOut);
  726. if (xformRaw == NULL || xformPlugin == NULL) {
  727. Fail("NULL transforms on check float vs 16 conversions");
  728. }
  729. // Again, no checking on mem alloc because this is just a test
  730. bufferIn = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
  731. bufferIn16 = (Scanline_rgb16bits*)malloc(npixels * sizeof(Scanline_rgb16bits));
  732. bufferFloatOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
  733. buffer16Out = (Scanline_rgb16bits*)malloc(npixels * sizeof(Scanline_rgb16bits));
  734. // Fill two equivalent input buffers
  735. j = 0;
  736. for (r = 0; r < 256; r++)
  737. for (g = 0; g < 256; g++)
  738. for (b = 0; b < 256; b++) {
  739. bufferIn[j].r = (cmsFloat32Number)r / 255.0f;
  740. bufferIn[j].g = (cmsFloat32Number)g / 255.0f;
  741. bufferIn[j].b = (cmsFloat32Number)b / 255.0f;
  742. bufferIn16[j].r = FROM_8_TO_16(r);
  743. bufferIn16[j].g = FROM_8_TO_16(g);
  744. bufferIn16[j].b = FROM_8_TO_16(b);
  745. j++;
  746. }
  747. // Convert
  748. cmsDoTransform(Raw, xformRaw, bufferIn16, buffer16Out, npixels);
  749. cmsDoTransform(Plugin, xformPlugin, bufferIn, bufferFloatOut, npixels);
  750. j = 0;
  751. for (r = 0; r < 256; r++)
  752. for (g = 0; g < 256; g++)
  753. for (b = 0; b < 256; b++) {
  754. // Check for same values
  755. if (!Valid16Float(buffer16Out[j].r, bufferFloatOut[j].r) ||
  756. !Valid16Float(buffer16Out[j].g, bufferFloatOut[j].g) ||
  757. !Valid16Float(buffer16Out[j].b, bufferFloatOut[j].b))
  758. Fail("Conversion failed at (%f %f %f) != (%f %f %f)", buffer16Out[j].r / 65535.0, buffer16Out[j].g / 65535.0, buffer16Out[j].b / 65535.0,
  759. bufferFloatOut[j].r, bufferFloatOut[j].g, bufferFloatOut[j].b);
  760. j++;
  761. }
  762. free(bufferIn16); free(buffer16Out);
  763. free(bufferIn); free(bufferFloatOut);
  764. cmsDeleteTransform(Raw, xformRaw);
  765. cmsDeleteTransform(Plugin, xformPlugin);
  766. }
  767. // Check change format feature
  768. static
  769. void CheckChangeFormat(cmsContext ContextID)
  770. {
  771. cmsHPROFILE hsRGB, hLab;
  772. cmsHTRANSFORM xform, xform2;
  773. cmsUInt8Number rgb8[3] = { 10, 120, 40 };
  774. cmsUInt16Number rgb16[3] = { 10* 257, 120*257, 40*257 };
  775. cmsUInt16Number lab16_1[3], lab16_2[3];
  776. trace("Checking change format feature...");
  777. hsRGB = cmsCreate_sRGBProfile(ContextID);
  778. hLab = cmsCreateLab4Profile(ContextID, NULL);
  779. xform = cmsCreateTransform(ContextID, hsRGB, TYPE_RGB_16, hLab, TYPE_Lab_16, INTENT_PERCEPTUAL, 0);
  780. cmsDoTransform(ContextID, xform, rgb16, lab16_1, 1);
  781. xform2 = cmsCloneTransformChangingFormats(ContextID, xform, TYPE_RGB_8, TYPE_Lab_16);
  782. cmsDoTransform(ContextID, xform2, rgb8, lab16_2, 1);
  783. cmsDeleteTransform(ContextID, xform);
  784. cmsDeleteTransform(ContextID, xform2);
  785. if (memcmp(lab16_1, lab16_2, sizeof(lab16_1)) != 0)
  786. Fail("Change format failed!");
  787. trace("Ok\n");
  788. }
  789. static
  790. cmsBool ValidInt(cmsUInt16Number a, cmsUInt16Number b)
  791. {
  792. return abs(a - b) <= 32;
  793. }
  794. static
  795. void CheckLab2Roundtrip(cmsContext ContextID)
  796. {
  797. cmsHPROFILE hsRGB, hLab;
  798. cmsHTRANSFORM xform, xform2;
  799. cmsInt8Number* lab;
  800. cmsInt32Number Mb, j;
  801. cmsInt32Number r, g, b;
  802. Scanline_rgb8bits* In;
  803. Scanline_rgb8bits* Out;
  804. trace("Checking lab2 roundtrip...");
  805. hsRGB = cmsCreate_sRGBProfile(ContextID);
  806. hLab = cmsCreateLab2Profile(ContextID, NULL);
  807. xform = cmsCreateTransform(ContextID, hsRGB, TYPE_RGB_8, hLab, TYPE_Lab_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE|cmsFLAGS_BLACKPOINTCOMPENSATION);
  808. xform2 = cmsCreateTransform(ContextID, hLab, TYPE_Lab_8, hsRGB, TYPE_RGB_8, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_BLACKPOINTCOMPENSATION);
  809. cmsCloseProfile(ContextID, hsRGB);
  810. cmsCloseProfile(ContextID, hLab);
  811. Mb = 256 * 256 * 256 * sizeof(Scanline_rgb8bits);
  812. In = (Scanline_rgb8bits*)malloc(Mb);
  813. Out = (Scanline_rgb8bits*)malloc(Mb);
  814. lab = (cmsInt8Number*)malloc(256 * 256 * 256 * 3 * sizeof(cmsInt8Number));
  815. j = 0;
  816. for (r = 0; r < 256; r++)
  817. for (g = 0; g < 256; g++)
  818. for (b = 0; b < 256; b++)
  819. {
  820. In[j].r = (cmsUInt8Number)r;
  821. In[j].g = (cmsUInt8Number)g;
  822. In[j].b = (cmsUInt8Number)b;
  823. j++;
  824. }
  825. cmsDoTransform(ContextID, xform, In, lab, 256 * 256 * 256);
  826. cmsDoTransform(ContextID, xform2, lab, Out, 256 * 256 * 256);
  827. cmsDeleteTransform(ContextID, xform);
  828. cmsDeleteTransform(ContextID, xform2);
  829. j = 0;
  830. for (r = 0; r < 256; r++)
  831. for (g = 0; g < 256; g++)
  832. for (b = 0; b < 256; b++) {
  833. // Check for same values
  834. if (!ValidInt(In[j].r, Out[j].r) ||
  835. !ValidInt(In[j].g, Out[j].g) ||
  836. !ValidInt(In[j].b, Out[j].b))
  837. Fail("Conversion failed at (%d %d %d) != (%d %d %d)", In[j].r, In[j].g, In[j].b,
  838. Out[j].r, Out[j].g, Out[j].b);
  839. j++;
  840. }
  841. free(In);
  842. free(Out);
  843. free(lab);
  844. trace("Ok\n");
  845. }
  846. static
  847. void CheckAlphaDetect(void)
  848. {
  849. cmsHPROFILE hsRGB;
  850. cmsHTRANSFORM xform;
  851. cmsSetLogErrorHandler(NULL);
  852. hsRGB = cmsCreate_sRGBProfile();
  853. xform = cmsCreateTransform(hsRGB, TYPE_RGB_FLT, hsRGB, TYPE_RGBA_FLT, INTENT_PERCEPTUAL, cmsFLAGS_COPY_ALPHA);
  854. cmsCloseProfile(hsRGB);
  855. if (xform != NULL)
  856. Fail("Copy alpha with mismatched channels should not succeed");
  857. cmsSetLogErrorHandler(FatalErrorQuit);
  858. }
  859. // Convert some known values
  860. static
  861. void CheckConversionFloat(cmsContext Raw, cmsContext Plugin)
  862. {
  863. trace("Check alpha detection.");
  864. CheckAlphaDetect();
  865. trace("Ok\n");
  866. trace("Crash test.");
  867. TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL, FALSE);
  868. trace("..");
  869. TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL, TRUE);
  870. trace("Ok\n");
  871. trace("Crash (II) test.");
  872. TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL, FALSE);
  873. trace("..");
  874. TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL, TRUE);
  875. trace("Ok\n");
  876. trace("Crash (III) test.");
  877. CheckUncommonValues(cmsOpenProfileFromFile(PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(PROFILES_DIR "test3.icc", "r"), INTENT_PERCEPTUAL);
  878. trace("..");
  879. CheckUncommonValues(cmsOpenProfileFromFile(PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL);
  880. trace("Ok\n");
  881. trace("Checking conversion to Lab...");
  882. CheckToEncodedLab();
  883. CheckToFloatLab();
  884. CheckFloatToFloatLab();
  885. trace("Ok\n");
  886. // Matrix-shaper should be accurate
  887. trace("Checking accuracy on Matrix-shaper...");
  888. TryAllValuesFloat(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL);
  889. trace("Ok\n");
  890. // CLUT should be as 16 bits or better
  891. trace("Checking accuracy of CLUT...");
  892. TryAllValuesFloatVs16(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test5.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test3.icc", "r"), INTENT_PERCEPTUAL);
  893. trace("Ok\n");
  894. // Same profile should give same values (we test both methods)
  895. trace("Checking accuracy on same profile ...");
  896. TryAllValuesFloatVs16(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL);
  897. TryAllValuesFloat(Raw, Plugin, cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), cmsOpenProfileFromFile(Raw, PROFILES_DIR "test0.icc", "r"), INTENT_PERCEPTUAL);
  898. trace("Ok\n");
  899. }
  900. static
  901. cmsBool ValidFloat2(cmsFloat32Number a, cmsFloat32Number b)
  902. {
  903. return fabsf(a - b) < 0.007;
  904. }
  905. static
  906. cmsFloat32Number distance(cmsFloat32Number rgb1[], cmsFloat32Number rgb2[])
  907. {
  908. cmsFloat32Number dr = rgb2[0] - rgb1[0];
  909. cmsFloat32Number dg = rgb2[1] - rgb1[1];
  910. cmsFloat32Number db = rgb2[2] - rgb1[2];
  911. return dr * dr + dg * dg + db * db;
  912. }
  913. static
  914. void CheckLab2RGB(cmsContext plugin)
  915. {
  916. cmsHPROFILE hLab = cmsCreateLab4Profile(plugin);
  917. cmsHPROFILE hRGB = cmsOpenProfileFromFile(plugin, PROFILES_DIR "test3.icc", "r");
  918. cmsContext noPlugin = cmsCreateContext(0, 0);
  919. cmsHTRANSFORM hXformNoPlugin = cmsCreateTransform(noPlugin, hLab, TYPE_Lab_FLT, hRGB, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOCACHE);
  920. cmsHTRANSFORM hXformPlugin = cmsCreateTransform(plugin, hLab, TYPE_Lab_FLT, hRGB, TYPE_RGB_FLT, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_NOCACHE);
  921. cmsFloat32Number Lab[3], RGB[3], RGB2[3];
  922. cmsFloat32Number maxInside = 0, maxOutside = 0, L, a, b;
  923. trace("Checking Lab -> RGB...");
  924. cmsCloseProfile(hLab);
  925. cmsCloseProfile(hRGB);
  926. for (L = 4; L <= 100; L++)
  927. {
  928. for (a = -30; a < +30; a++)
  929. for (b = -30; b < +30; b++)
  930. {
  931. cmsFloat32Number d;
  932. Lab[0] = L; Lab[1] = a; Lab[2] = b;
  933. cmsDoTransform(hXformNoPlugin, Lab, RGB, 1);
  934. cmsDoTransform(hXformPlugin, Lab, RGB2, 1);
  935. d = distance(RGB, RGB2);
  936. if (d > maxInside)
  937. maxInside = d;
  938. }
  939. }
  940. for (L = 1; L <= 100; L += 5)
  941. {
  942. for (a = -100; a < +100; a += 5)
  943. for (b = -100; b < +100; b += 5)
  944. {
  945. cmsFloat32Number d;
  946. Lab[0] = L; Lab[1] = a; Lab[2] = b;
  947. cmsDoTransform(hXformNoPlugin, Lab, RGB, 1);
  948. cmsDoTransform(hXformPlugin, Lab, RGB2, 1);
  949. d = distance(RGB, RGB2);
  950. if (d > maxOutside)
  951. maxOutside = d;
  952. }
  953. }
  954. trace("Max distance: Inside gamut %f, Outside gamut %f\n", sqrtf(maxInside), sqrtf(maxOutside));
  955. cmsDeleteTransform(hXformNoPlugin);
  956. cmsDeleteTransform(hXformPlugin);
  957. cmsDeleteContext(noPlugin);
  958. }
  959. static
  960. void CheckSoftProofing(void)
  961. {
  962. cmsHPROFILE hRGB1 = cmsOpenProfileFromFile(PROFILES_DIR "test5.icc", "r");
  963. cmsHPROFILE hRGB2 = cmsOpenProfileFromFile(PROFILES_DIR "test3.icc", "r");
  964. cmsContext noPlugin = cmsCreateContext(0, 0);
  965. cmsHTRANSFORM hXformNoPlugin = cmsCreateProofingTransformTHR(noPlugin, hRGB1, TYPE_RGB_FLT, hRGB1, TYPE_RGB_FLT, hRGB2, INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_GAMUTCHECK | cmsFLAGS_SOFTPROOFING);
  966. cmsHTRANSFORM hXformPlugin = cmsCreateProofingTransformTHR(0, hRGB1, TYPE_RGB_FLT, hRGB1, TYPE_RGB_FLT, hRGB2, INTENT_RELATIVE_COLORIMETRIC, INTENT_RELATIVE_COLORIMETRIC, cmsFLAGS_GAMUTCHECK | cmsFLAGS_SOFTPROOFING);
  967. cmsUInt32Number Mb, j, r, g, b;
  968. Scanline_rgbFloat* In;
  969. Scanline_rgbFloat* Out1, *Out2;
  970. trace("Checking soft proofing and gamut check ...");
  971. cmsCloseProfile(hRGB1);
  972. cmsCloseProfile(hRGB2);
  973. Mb = 256 * 256 * 256 * sizeof(Scanline_rgbFloat);
  974. In = (Scanline_rgbFloat*)malloc(Mb);
  975. Out1 = (Scanline_rgbFloat*)malloc(Mb);
  976. Out2 = (Scanline_rgbFloat*)malloc(Mb);
  977. j = 0;
  978. for (r = 0; r < 256; r++)
  979. for (g = 0; g < 256; g++)
  980. for (b = 0; b < 256; b++)
  981. {
  982. In[j].r = (cmsFloat32Number)r / 255.0f;
  983. In[j].g = (cmsFloat32Number)g / 255.0f;
  984. In[j].b = (cmsFloat32Number)b / 255.0f;
  985. j++;
  986. }
  987. cmsDoTransform(hXformNoPlugin, In, Out1, 256 * 256 * 256);
  988. cmsDoTransform(hXformPlugin, In, Out2, 256 * 256 * 256);
  989. j = 0;
  990. for (r = 0; r < 256; r++)
  991. for (g = 0; g < 256; g++)
  992. for (b = 0; b < 256; b++) {
  993. // Check for same values
  994. if (!ValidFloat(Out1[j].r, Out2[j].r) ||
  995. !ValidFloat(Out1[j].g, Out2[j].g) ||
  996. !ValidFloat(Out1[j].b, Out2[j].b))
  997. Fail("Conversion failed at (%f %f %f) != (%f %f %f)", Out1[j].r, Out1[j].g, Out1[j].b,
  998. Out2[j].r, Out2[j].g, Out2[j].b);
  999. j++;
  1000. }
  1001. free(In); free(Out1); free(Out2);
  1002. cmsDeleteTransform(hXformNoPlugin);
  1003. cmsDeleteTransform(hXformPlugin);
  1004. cmsDeleteContext(noPlugin);
  1005. trace("Ok\n");
  1006. }
  1007. // --------------------------------------------------------------------------------------------------
  1008. // P E R F O R M A N C E C H E C K S
  1009. // --------------------------------------------------------------------------------------------------
  1010. static
  1011. cmsFloat64Number MPixSec(cmsFloat64Number diff)
  1012. {
  1013. cmsFloat64Number seconds = (cmsFloat64Number)diff / (cmsFloat64Number)CLOCKS_PER_SEC;
  1014. return (256.0 * 256.0 * 256.0) / (1024.0*1024.0*seconds);
  1015. }
  1016. typedef cmsFloat64Number(*perf_fn)(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut);
  1017. static
  1018. void PerformanceHeader(void)
  1019. {
  1020. trace(" MPixel/sec. MByte/sec.\n");
  1021. }
  1022. static
  1023. cmsHPROFILE loadProfile(const char* name)
  1024. {
  1025. if (*name == '*')
  1026. {
  1027. if (strcmp(name, "*lab") == 0)
  1028. {
  1029. return cmsCreateLab4Profile(ct);
  1030. }
  1031. else
  1032. if (strcmp(name, "*xyz") == 0)
  1033. {
  1034. return cmsCreateXYZProfile(ct);
  1035. }
  1036. else
  1037. if (strcmp(name, "*curves") == 0)
  1038. {
  1039. return CreateCurves(ct);
  1040. }
  1041. else
  1042. Fail("Unknown builtin '%s'", name);
  1043. }
  1044. return cmsOpenProfileFromFile(ct, name, "r");
  1045. }
  1046. static
  1047. cmsFloat64Number Performance(const char* Title, perf_fn fn, cmsContext ct, const char* inICC, const char* outICC, size_t sz, cmsFloat64Number prev)
  1048. {
  1049. cmsHPROFILE hlcmsProfileIn = loadProfile(inICC);
  1050. cmsHPROFILE hlcmsProfileOut = loadProfile(outICC);
  1051. cmsFloat64Number n = fn(ct, hlcmsProfileIn, hlcmsProfileOut);
  1052. trace("%-30s: ", Title); fflush(stdout);
  1053. trace("%-12.2f %-12.2f", n, n * sz);
  1054. if (prev > 0.0) {
  1055. cmsFloat64Number imp = n / prev;
  1056. if (imp > 1)
  1057. trace(" (x %-2.1f)", imp);
  1058. }
  1059. trace("\n"); fflush(stdout);
  1060. return n;
  1061. }
  1062. static
  1063. void ComparativeCt(cmsContext ct1, cmsContext ct2, const char* Title, perf_fn fn1, perf_fn fn2, const char* inICC, const char* outICC)
  1064. {
  1065. cmsHPROFILE hlcmsProfileIn;
  1066. cmsHPROFILE hlcmsProfileOut;
  1067. if (inICC == NULL)
  1068. hlcmsProfileIn = CreateCurves(ct1);
  1069. else
  1070. hlcmsProfileIn = cmsOpenProfileFromFile(ct1, inICC, "r");
  1071. if (outICC == NULL)
  1072. hlcmsProfileOut = CreateCurves(ct1);
  1073. else
  1074. hlcmsProfileOut = cmsOpenProfileFromFile(ct1, outICC, "r");
  1075. cmsFloat64Number n1 = fn1(ct1, hlcmsProfileIn, hlcmsProfileOut);
  1076. if (inICC == NULL)
  1077. hlcmsProfileIn = CreateCurves(ct2);
  1078. else
  1079. hlcmsProfileIn = cmsOpenProfileFromFile(ct2, inICC, "r");
  1080. if (outICC == NULL)
  1081. hlcmsProfileOut = CreateCurves(ct2);
  1082. else
  1083. hlcmsProfileOut = cmsOpenProfileFromFile(ct2, outICC, "r");
  1084. cmsFloat64Number n2 = fn2(ct2, hlcmsProfileIn, hlcmsProfileOut);
  1085. trace("%-30s: ", Title); fflush(stdout);
  1086. trace("%-12.2f %-12.2f\n", n1, n2);
  1087. }
  1088. static
  1089. void Comparative(cmsContext Raw, cmsContext Plugin, const char* Title, perf_fn fn1, perf_fn fn2, const char* inICC, const char* outICC)
  1090. {
  1091. ComparativeCt(Raw, Plugin, Title, fn1, fn2, inICC, outICC);
  1092. }
  1093. // The worst case is used, no cache and all rgb combinations
  1094. static
  1095. cmsFloat64Number SpeedTest8bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1096. {
  1097. cmsInt32Number r, g, b, j;
  1098. clock_t atime;
  1099. cmsFloat64Number diff;
  1100. cmsHTRANSFORM hlcmsxform;
  1101. Scanline_rgb8bits *In;
  1102. cmsUInt32Number Mb;
  1103. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1104. Fail("Unable to open profiles");
  1105. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_8, hlcmsProfileOut, TYPE_RGB_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1106. cmsCloseProfile(ct, hlcmsProfileIn);
  1107. cmsCloseProfile(ct, hlcmsProfileOut);
  1108. Mb = 256 * 256 * 256 * sizeof(Scanline_rgb8bits);
  1109. In = (Scanline_rgb8bits*)malloc(Mb);
  1110. j = 0;
  1111. for (r = 0; r < 256; r++)
  1112. for (g = 0; g < 256; g++)
  1113. for (b = 0; b < 256; b++) {
  1114. In[j].r = (cmsUInt8Number)r;
  1115. In[j].g = (cmsUInt8Number)g;
  1116. In[j].b = (cmsUInt8Number)b;
  1117. j++;
  1118. }
  1119. atime = clock();
  1120. cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
  1121. diff = clock() - atime;
  1122. free(In);
  1123. cmsDeleteTransform(ct, hlcmsxform);
  1124. return MPixSec(diff);
  1125. }
  1126. static
  1127. cmsFloat64Number SpeedTest8bitsRGBA(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1128. {
  1129. cmsInt32Number r, g, b, j;
  1130. clock_t atime;
  1131. cmsFloat64Number diff;
  1132. cmsHTRANSFORM hlcmsxform;
  1133. Scanline_rgba8bits *In;
  1134. cmsUInt32Number Mb;
  1135. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1136. Fail("Unable to open profiles");
  1137. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1138. cmsCloseProfile(ct, hlcmsProfileIn);
  1139. cmsCloseProfile(ct, hlcmsProfileOut);
  1140. Mb = 256 * 256 * 256 * sizeof(Scanline_rgba8bits);
  1141. In = (Scanline_rgba8bits*)malloc(Mb);
  1142. j = 0;
  1143. for (r = 0; r < 256; r++)
  1144. for (g = 0; g < 256; g++)
  1145. for (b = 0; b < 256; b++) {
  1146. In[j].r = (cmsUInt8Number)r;
  1147. In[j].g = (cmsUInt8Number)g;
  1148. In[j].b = (cmsUInt8Number)b;
  1149. In[j].a = 0;
  1150. j++;
  1151. }
  1152. atime = clock();
  1153. cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
  1154. diff = clock() - atime;
  1155. free(In);
  1156. cmsDeleteTransform(ct, hlcmsxform);
  1157. return MPixSec(diff);
  1158. }
  1159. // The worst case is used, no cache and all rgb combinations
  1160. static
  1161. cmsFloat64Number SpeedTest15bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1162. {
  1163. cmsInt32Number r, g, b, j;
  1164. clock_t atime;
  1165. cmsFloat64Number diff;
  1166. cmsHTRANSFORM hlcmsxform;
  1167. Scanline_rgb15bits *In;
  1168. cmsUInt32Number Mb;
  1169. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1170. Fail("Unable to open profiles");
  1171. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_15, hlcmsProfileOut, TYPE_RGB_15, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1172. cmsCloseProfile(ct, hlcmsProfileIn);
  1173. cmsCloseProfile(ct, hlcmsProfileOut);
  1174. Mb = 256 * 256 * 256 * sizeof(Scanline_rgb15bits);
  1175. In = (Scanline_rgb15bits*)malloc(Mb);
  1176. j = 0;
  1177. for (r = 0; r < 256; r++)
  1178. for (g = 0; g < 256; g++)
  1179. for (b = 0; b < 256; b++) {
  1180. In[j].r = (cmsUInt16Number)r;
  1181. In[j].g = (cmsUInt16Number)g;
  1182. In[j].b = (cmsUInt16Number)b;
  1183. j++;
  1184. }
  1185. atime = clock();
  1186. cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
  1187. diff = clock() - atime;
  1188. free(In);
  1189. cmsDeleteTransform(ct, hlcmsxform);
  1190. return MPixSec(diff);
  1191. }
  1192. static
  1193. cmsFloat64Number SpeedTest15bitsRGBA(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1194. {
  1195. cmsInt32Number r, g, b, j;
  1196. clock_t atime;
  1197. cmsFloat64Number diff;
  1198. cmsHTRANSFORM hlcmsxform;
  1199. Scanline_rgba15bits *In;
  1200. cmsUInt32Number Mb;
  1201. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1202. Fail("Unable to open profiles");
  1203. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_15, hlcmsProfileOut, TYPE_RGBA_15, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1204. cmsCloseProfile(ct, hlcmsProfileIn);
  1205. cmsCloseProfile(ct, hlcmsProfileOut);
  1206. Mb = 256 * 256 * 256 * sizeof(Scanline_rgba15bits);
  1207. In = (Scanline_rgba15bits*)malloc(Mb);
  1208. j = 0;
  1209. for (r = 0; r < 256; r++)
  1210. for (g = 0; g < 256; g++)
  1211. for (b = 0; b < 256; b++) {
  1212. In[j].r = (cmsUInt16Number)r;
  1213. In[j].g = (cmsUInt16Number)g;
  1214. In[j].b = (cmsUInt16Number)b;
  1215. In[j].a = 0;
  1216. j++;
  1217. }
  1218. atime = clock();
  1219. cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
  1220. diff = clock() - atime;
  1221. free(In);
  1222. cmsDeleteTransform(ct, hlcmsxform);
  1223. return MPixSec(diff);
  1224. }
  1225. static
  1226. cmsFloat64Number SpeedTest15bitsCMYK(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1227. {
  1228. cmsInt32Number r, g, b, j;
  1229. clock_t atime;
  1230. cmsFloat64Number diff;
  1231. cmsHTRANSFORM hlcmsxform;
  1232. Scanline_cmyk15bits *In;
  1233. cmsUInt32Number Mb;
  1234. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1235. Fail("Unable to open profiles");
  1236. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_CMYK_15, hlcmsProfileOut, TYPE_CMYK_15, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1237. cmsCloseProfile(ct, hlcmsProfileIn);
  1238. cmsCloseProfile(ct, hlcmsProfileOut);
  1239. Mb = 256 * 256 * 256 * sizeof(Scanline_cmyk15bits);
  1240. In = (Scanline_cmyk15bits*)malloc(Mb);
  1241. j = 0;
  1242. for (r = 0; r < 256; r++)
  1243. for (g = 0; g < 256; g++)
  1244. for (b = 0; b < 256; b++) {
  1245. In[j].r = (cmsUInt16Number)r;
  1246. In[j].g = (cmsUInt16Number)g;
  1247. In[j].b = (cmsUInt16Number)b;
  1248. In[j].a = (cmsUInt16Number)0;
  1249. j++;
  1250. }
  1251. atime = clock();
  1252. cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
  1253. diff = clock() - atime;
  1254. free(In);
  1255. cmsDeleteTransform(ct, hlcmsxform);
  1256. return MPixSec(diff);
  1257. }
  1258. // The worst case is used, no cache and all rgb combinations
  1259. static
  1260. cmsFloat64Number SpeedTest16bitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1261. {
  1262. cmsInt32Number r, g, b, j;
  1263. clock_t atime;
  1264. cmsFloat64Number diff;
  1265. cmsHTRANSFORM hlcmsxform;
  1266. Scanline_rgb16bits *In;
  1267. cmsUInt32Number Mb;
  1268. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1269. Fail("Unable to open profiles");
  1270. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_16, hlcmsProfileOut, TYPE_RGB_16, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1271. cmsCloseProfile(ct, hlcmsProfileIn);
  1272. cmsCloseProfile(ct, hlcmsProfileOut);
  1273. Mb = 256 * 256 * 256 * sizeof(Scanline_rgb16bits);
  1274. In = (Scanline_rgb16bits*)malloc(Mb);
  1275. j = 0;
  1276. for (r = 0; r < 256; r++)
  1277. for (g = 0; g < 256; g++)
  1278. for (b = 0; b < 256; b++) {
  1279. In[j].r = (cmsUInt16Number)FROM_8_TO_16(r);
  1280. In[j].g = (cmsUInt16Number)FROM_8_TO_16(g);
  1281. In[j].b = (cmsUInt16Number)FROM_8_TO_16(b);
  1282. j++;
  1283. }
  1284. atime = clock();
  1285. cmsDoTransform(ct, hlcmsxform, In, In, 256 * 256 * 256);
  1286. diff = clock() - atime;
  1287. free(In);
  1288. cmsDeleteTransform(ct, hlcmsxform);
  1289. return MPixSec(diff);
  1290. }
  1291. static
  1292. cmsFloat64Number SpeedTest16bitsCMYK(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1293. {
  1294. cmsInt32Number r, g, b, j;
  1295. clock_t atime;
  1296. cmsFloat64Number diff;
  1297. cmsHTRANSFORM hlcmsxform;
  1298. Scanline_cmyk16bits* In;
  1299. cmsUInt32Number Mb;
  1300. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1301. Fail("Unable to open profiles");
  1302. hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_CMYK_16, hlcmsProfileOut, TYPE_CMYK_16, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1303. cmsCloseProfile(hlcmsProfileIn);
  1304. cmsCloseProfile(hlcmsProfileOut);
  1305. Mb = 256 * 256 * 256 * sizeof(Scanline_cmyk16bits);
  1306. In = (Scanline_cmyk16bits*)malloc(Mb);
  1307. j = 0;
  1308. for (r = 0; r < 256; r++)
  1309. for (g = 0; g < 256; g++)
  1310. for (b = 0; b < 256; b++) {
  1311. In[j].c = (cmsUInt16Number)r;
  1312. In[j].m = (cmsUInt16Number)g;
  1313. In[j].y = (cmsUInt16Number)b;
  1314. In[j].k = (cmsUInt16Number)r;
  1315. j++;
  1316. }
  1317. atime = clock();
  1318. cmsDoTransform(hlcmsxform, In, In, 256 * 256 * 256);
  1319. diff = clock() - atime;
  1320. free(In);
  1321. cmsDeleteTransform(hlcmsxform);
  1322. return MPixSec(diff);
  1323. }
  1324. static
  1325. void SpeedTest8(void)
  1326. {
  1327. cmsContext noPlugin = cmsCreateContext(0, 0);
  1328. cmsFloat64Number t[10];
  1329. trace("\n\n");
  1330. trace("P E R F O R M A N C E T E S T S 8 B I T S (D E F A U L T)\n");
  1331. trace("==============================================================\n\n");
  1332. fflush(stdout);
  1333. PerformanceHeader();
  1334. t[0] = Performance("8 bits on CLUT profiles ", SpeedTest8bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb8bits), 0);
  1335. t[1] = Performance("8 bits on Matrix-Shaper ", SpeedTest8bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), 0);
  1336. t[2] = Performance("8 bits on same MatrixSh ", SpeedTest8bitsRGB, noPlugin, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), 0);
  1337. t[3] = Performance("8 bits on curves ", SpeedTest8bitsRGB, noPlugin, "*curves", "*curves", sizeof(Scanline_rgb8bits), 0);
  1338. // Note that context 0 has the plug-in installed
  1339. trace("\n\n");
  1340. trace("P E R F O R M A N C E T E S T S 8 B I T S (P L U G I N)\n");
  1341. trace("===========================================================\n\n");
  1342. fflush(stdout);
  1343. PerformanceHeader();
  1344. Performance("8 bits on CLUT profiles ", SpeedTest8bitsRGB, 0, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb8bits), t[0]);
  1345. Performance("8 bits on Matrix-Shaper ", SpeedTest8bitsRGB, 0, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), t[1]);
  1346. Performance("8 bits on same MatrixSh ", SpeedTest8bitsRGB, 0, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb8bits), t[2]);
  1347. Performance("8 bits on curves ", SpeedTest8bitsRGB, 0, "*curves", "*curves", sizeof(Scanline_rgb8bits), t[3]);
  1348. cmsDeleteContext(noPlugin);
  1349. }
  1350. static
  1351. void SpeedTest15(cmsContext ct)
  1352. {
  1353. trace("\n\nP E R F O R M A N C E T E S T S 1 5 B I T S (P L U G I N)\n");
  1354. trace( "===============================================================\n\n");
  1355. PerformanceHeader();
  1356. Performance("15 bits on CLUT profiles ", SpeedTest15bitsRGB, ct, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb15bits), 0);
  1357. Performance("15 bits on Matrix-Shaper profiles", SpeedTest15bitsRGB, ct, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb15bits), 0);
  1358. Performance("15 bits on same Matrix-Shaper ", SpeedTest15bitsRGB, ct, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb15bits), 0);
  1359. Performance("15 bits on curves ", SpeedTest15bitsRGB, ct, "*curves", "*curves", sizeof(Scanline_rgb15bits), 0);
  1360. Performance("15 bits on CMYK CLUT profiles ", SpeedTest15bitsCMYK, ct,PROFILES_DIR "test1.icc", PROFILES_DIR "test2.icc", sizeof(Scanline_rgba15bits), 0);
  1361. }
  1362. static
  1363. void SpeedTest16(cmsContext ct)
  1364. {
  1365. cmsContext noPlugin = cmsCreateContext(0, 0);
  1366. trace("\n\n");
  1367. trace("P E R F O R M A N C E T E S T S 1 6 B I T S (D E F A U L T)\n");
  1368. trace("=================================================================\n\n");
  1369. PerformanceHeader();
  1370. Performance("16 bits on CLUT profiles ", SpeedTest16bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb16bits), 0);
  1371. Performance("16 bits on Matrix-Shaper profiles", SpeedTest16bitsRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), 0);
  1372. Performance("16 bits on same Matrix-Shaper ", SpeedTest16bitsRGB, noPlugin, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), 0);
  1373. Performance("16 bits on curves ", SpeedTest16bitsRGB, noPlugin, "*curves", "*curves", sizeof(Scanline_rgb16bits), 0);
  1374. Performance("16 bits on CMYK CLUT profiles ", SpeedTest16bitsCMYK, noPlugin, PROFILES_DIR "test1.icc", PROFILES_DIR "test2.icc", sizeof(Scanline_cmyk16bits), 0);
  1375. trace("\n\n");
  1376. trace("P E R F O R M A N C E T E S T S 1 6 B I T S (P L U G I N)\n");
  1377. trace("===============================================================\n\n");
  1378. PerformanceHeader();
  1379. Performance("16 bits on CLUT profiles ", SpeedTest16bitsRGB, ct, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgb16bits), 0);
  1380. Performance("16 bits on Matrix-Shaper profiles", SpeedTest16bitsRGB, ct, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), 0);
  1381. Performance("16 bits on same Matrix-Shaper ", SpeedTest16bitsRGB, ct, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgb16bits), 0);
  1382. Performance("16 bits on curves ", SpeedTest16bitsRGB, ct, "*curves", "*curves", sizeof(Scanline_rgb16bits), 0);
  1383. Performance("16 bits on CMYK CLUT profiles ", SpeedTest16bitsCMYK, ct, PROFILES_DIR "test1.icc", PROFILES_DIR "test2.icc", sizeof(Scanline_cmyk16bits), 0);
  1384. cmsDeleteContext(noPlugin);
  1385. }
  1386. // The worst case is used, no cache and all rgb combinations
  1387. static
  1388. cmsFloat64Number SpeedTestFloatRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1389. {
  1390. cmsInt32Number j;
  1391. clock_t atime;
  1392. cmsFloat64Number diff;
  1393. cmsHTRANSFORM hlcmsxform;
  1394. void *In;
  1395. cmsUInt32Number size, Mb;
  1396. cmsUInt32Number inFormatter=0, outFormatter=0;
  1397. cmsFloat64Number seconds;
  1398. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1399. Fail("Unable to open profiles");
  1400. switch (cmsGetColorSpace(hlcmsProfileIn))
  1401. {
  1402. case cmsSigRgbData: inFormatter = TYPE_RGB_FLT; break;
  1403. case cmsSigLabData: inFormatter = TYPE_Lab_FLT; break;
  1404. default:
  1405. Fail("Invalid colorspace");
  1406. }
  1407. switch (cmsGetColorSpace(hlcmsProfileOut))
  1408. {
  1409. case cmsSigRgbData: outFormatter = TYPE_RGB_FLT; break;
  1410. case cmsSigLabData: outFormatter = TYPE_Lab_FLT; break;
  1411. case cmsSigXYZData: outFormatter = TYPE_XYZ_FLT; break;
  1412. default:
  1413. Fail("Invalid colorspace");
  1414. }
  1415. hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, inFormatter, hlcmsProfileOut, outFormatter, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1416. cmsCloseProfile(ct, hlcmsProfileIn);
  1417. cmsCloseProfile(ct, hlcmsProfileOut);
  1418. j = 0;
  1419. if (inFormatter == TYPE_RGB_FLT)
  1420. {
  1421. cmsInt32Number r, g, b;
  1422. Scanline_rgbFloat* fill;
  1423. size = 256 * 256 * 256;
  1424. Mb = size * sizeof(Scanline_rgbFloat);
  1425. In = malloc(Mb);
  1426. fill = (Scanline_rgbFloat*)In;
  1427. for (r = 0; r < 256; r++)
  1428. for (g = 0; g < 256; g++)
  1429. for (b = 0; b < 256; b++) {
  1430. fill[j].r = (cmsFloat32Number)r / 255.0f;
  1431. fill[j].g = (cmsFloat32Number)g / 255.0f;
  1432. fill[j].b = (cmsFloat32Number)b / 255.0f;
  1433. j++;
  1434. }
  1435. }
  1436. else
  1437. {
  1438. cmsFloat32Number L, a, b;
  1439. Scanline_LabFloat* fill;
  1440. size = 100 * 256 * 256;
  1441. Mb = size * sizeof(Scanline_LabFloat);
  1442. In = malloc(Mb);
  1443. fill = (Scanline_LabFloat*)In;
  1444. for (L = 0; L < 100; L++)
  1445. for (a = -127.0; a < 127.0; a++)
  1446. for (b = -127.0; b < +127.0; b++) {
  1447. fill[j].L = L;
  1448. fill[j].a = a;
  1449. fill[j].b = b;
  1450. j++;
  1451. }
  1452. }
  1453. atime = clock();
  1454. cmsDoTransform(ct, hlcmsxform, In, In, size);
  1455. diff = clock() - atime;
  1456. free(In);
  1457. cmsDeleteTransform(ct, hlcmsxform);
  1458. seconds = (cmsFloat64Number)diff / (cmsFloat64Number)CLOCKS_PER_SEC;
  1459. return ((cmsFloat64Number)size) / (1024.0 * 1024.0 * seconds);
  1460. }
  1461. static
  1462. cmsFloat64Number SpeedTestFloatCMYK(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1463. {
  1464. cmsInt32Number c, m, y, k, j;
  1465. clock_t atime;
  1466. cmsFloat64Number diff;
  1467. cmsHTRANSFORM hlcmsxform;
  1468. Scanline_cmykFloat* In;
  1469. cmsUInt32Number Mb;
  1470. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1471. Fail("Unable to open profiles");
  1472. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_CMYK_FLT, hlcmsProfileOut, TYPE_CMYK_FLT, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1473. cmsCloseProfile(ct, hlcmsProfileIn);
  1474. cmsCloseProfile(ct, hlcmsProfileOut);
  1475. Mb = 64 * 64 * 64 * 64 * sizeof(Scanline_cmykFloat);
  1476. In = (Scanline_cmykFloat*)malloc(Mb);
  1477. j = 0;
  1478. for (c = 0; c < 256; c += 4)
  1479. for (m = 0; m < 256; m += 4)
  1480. for (y = 0; y < 256; y += 4)
  1481. for (k = 0; k < 256; k += 4) {
  1482. In[j].c = (cmsFloat32Number)c / 255.0f;
  1483. In[j].m = (cmsFloat32Number)m / 255.0f;
  1484. In[j].y = (cmsFloat32Number)y / 255.0f;
  1485. In[j].k = (cmsFloat32Number)k / 255.0f;
  1486. j++;
  1487. }
  1488. atime = clock();
  1489. cmsDoTransform(ct, hlcmsxform, In, In, 64 * 64 * 64 * 64);
  1490. diff = clock() - atime;
  1491. free(In);
  1492. cmsDeleteTransform(ct, hlcmsxform);
  1493. return MPixSec(diff);
  1494. }
  1495. static
  1496. cmsFloat64Number SpeedTestFloatLab(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1497. {
  1498. cmsInt32Number j;
  1499. clock_t atime;
  1500. cmsFloat64Number diff;
  1501. cmsHTRANSFORM hlcmsxform;
  1502. void* In;
  1503. cmsUInt32Number size, Mb;
  1504. cmsUInt32Number outFormatter = 0;
  1505. cmsFloat64Number seconds;
  1506. cmsFloat32Number L, a, b;
  1507. Scanline_LabFloat* fill;
  1508. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1509. Fail("Unable to open profiles");
  1510. if (cmsGetColorSpace(hlcmsProfileIn) != cmsSigLabData)
  1511. {
  1512. Fail("Invalid colorspace");
  1513. }
  1514. switch (cmsGetColorSpace(hlcmsProfileOut))
  1515. {
  1516. case cmsSigRgbData: outFormatter = TYPE_RGB_FLT; break;
  1517. case cmsSigLabData: outFormatter = TYPE_Lab_FLT; break;
  1518. case cmsSigXYZData: outFormatter = TYPE_XYZ_FLT; break;
  1519. default:
  1520. Fail("Invalid colorspace");
  1521. }
  1522. hlcmsxform = cmsCreateTransformTHR(ct, hlcmsProfileIn, TYPE_Lab_FLT, hlcmsProfileOut, outFormatter, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1523. cmsCloseProfile(hlcmsProfileIn);
  1524. cmsCloseProfile(hlcmsProfileOut);
  1525. j = 0;
  1526. size = 100 * 256 * 256;
  1527. Mb = size * sizeof(Scanline_LabFloat);
  1528. In = malloc(Mb);
  1529. fill = (Scanline_LabFloat*)In;
  1530. for (L = 0; L < 100; L++)
  1531. for (a = -127.0; a < 127.0; a++)
  1532. for (b = -127.0; b < +127.0; b++) {
  1533. fill[j].L = L;
  1534. fill[j].a = a;
  1535. fill[j].b = b;
  1536. j++;
  1537. }
  1538. atime = clock();
  1539. cmsDoTransform(hlcmsxform, In, In, size);
  1540. diff = clock() - atime;
  1541. free(In);
  1542. cmsDeleteTransform(hlcmsxform);
  1543. seconds = (cmsFloat64Number)diff / (cmsFloat64Number)CLOCKS_PER_SEC;
  1544. return ((cmsFloat64Number)size) / (1024.0 * 1024.0 * seconds);
  1545. }
  1546. static
  1547. void SpeedTestFloat(cmsContext noPlugin, cmsContext plugin)
  1548. {
  1549. cmsContext noPlugin = cmsCreateContext(0, 0);
  1550. cmsFloat64Number t[10] = { 0 };
  1551. trace("\n\n");
  1552. trace("P E R F O R M A N C E T E S T S F L O A T (D E F A U L T)\n");
  1553. trace("==============================================================\n\n");
  1554. fflush(stdout);
  1555. PerformanceHeader();
  1556. t[0] = Performance("Floating point on CLUT profiles ", SpeedTestFloatRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgbFloat), 0);
  1557. t[1] = Performance("Floating point on Matrix-Shaper ", SpeedTestFloatRGB, noPlugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgbFloat), 0);
  1558. t[2] = Performance("Floating point on same MatrixSh ", SpeedTestFloatRGB, noPlugin, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgbFloat), 0);
  1559. t[3] = Performance("Floating point on curves ", SpeedTestFloatRGB, noPlugin, "*curves", "*curves", sizeof(Scanline_rgbFloat), 0);
  1560. t[4] = Performance("Floating point on RGB->Lab ", SpeedTestFloatRGB, noPlugin, PROFILES_DIR "test5.icc", "*lab", sizeof(Scanline_rgbFloat), 0);
  1561. t[5] = Performance("Floating point on RGB->XYZ ", SpeedTestFloatRGB, noPlugin, PROFILES_DIR "test3.icc", "*xyz", sizeof(Scanline_rgbFloat), 0);
  1562. t[6] = Performance("Floating point on CMYK->CMYK ", SpeedTestFloatCMYK, noPlugin, PROFILES_DIR "test1.icc", PROFILES_DIR "test2.icc",sizeof(Scanline_cmykFloat), 0);
  1563. t[7] = Performance("Floating point on Lab->RGB ", SpeedTestFloatLab, noPlugin, "*lab", PROFILES_DIR "test3.icc", sizeof(Scanline_LabFloat), 0);
  1564. // Note that context 0 has the plug-in installed
  1565. trace("\n\n");
  1566. trace("P E R F O R M A N C E T E S T S F L O A T (P L U G I N)\n");
  1567. trace("===========================================================\n\n");
  1568. fflush(stdout);
  1569. PerformanceHeader();
  1570. Performance("Floating point on CLUT profiles ", SpeedTestFloatRGB, plugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc", sizeof(Scanline_rgbFloat), t[0]);
  1571. Performance("Floating point on Matrix-Shaper ", SpeedTestFloatRGB, plugin, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgbFloat), t[1]);
  1572. Performance("Floating point on same MatrixSh ", SpeedTestFloatRGB, plugin, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc", sizeof(Scanline_rgbFloat), t[2]);
  1573. Performance("Floating point on curves ", SpeedTestFloatRGB, plugin, "*curves", "*curves", sizeof(Scanline_rgbFloat), t[3]);
  1574. Performance("Floating point on RGB->Lab ", SpeedTestFloatRGB, plugin, PROFILES_DIR "test5.icc", "*lab", sizeof(Scanline_rgbFloat), t[4]);
  1575. Performance("Floating point on RGB->XYZ ", SpeedTestFloatRGB, plugin, PROFILES_DIR "test3.icc", "*xyz", sizeof(Scanline_rgbFloat), t[5]);
  1576. Performance("Floating point on CMYK->CMYK ", SpeedTestFloatCMYK, plugin, PROFILES_DIR "test1.icc", PROFILES_DIR "test2.icc", sizeof(Scanline_cmykFloat), t[6]);
  1577. Performance("Floating point on Lab->RGB ", SpeedTestFloatLab, plugin, "*lab", "test3.icc", sizeof(Scanline_LabFloat), t[7]);
  1578. cmsDeleteContext(noPlugin);
  1579. }
  1580. static
  1581. cmsFloat64Number SpeedTestFloatByUsing16BitsRGB(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1582. {
  1583. cmsInt32Number r, g, b, j;
  1584. clock_t atime;
  1585. cmsFloat64Number diff;
  1586. cmsHTRANSFORM xform16;
  1587. Scanline_rgbFloat *In;
  1588. Scanline_rgb16bits *tmp16;
  1589. cmsUInt32Number MbFloat, Mb16;
  1590. UNUSED_PARAMETER(ct);
  1591. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1592. Fail("Unable to open profiles");
  1593. xform16 = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGB_16, hlcmsProfileOut, TYPE_RGB_16, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1594. cmsCloseProfile(ct, hlcmsProfileIn);
  1595. cmsCloseProfile(ct, hlcmsProfileOut);
  1596. MbFloat = 256 * 256 * 256 * sizeof(Scanline_rgbFloat);
  1597. Mb16 = 256 * 256 * 256 * sizeof(Scanline_rgb16bits);
  1598. In = (Scanline_rgbFloat*)malloc(MbFloat);
  1599. tmp16 = (Scanline_rgb16bits*)malloc(Mb16);
  1600. j = 0;
  1601. for (r = 0; r < 256; r++)
  1602. for (g = 0; g < 256; g++)
  1603. for (b = 0; b < 256; b++) {
  1604. In[j].r = (cmsFloat32Number)r / 255.0f;
  1605. In[j].g = (cmsFloat32Number)g / 255.0f;
  1606. In[j].b = (cmsFloat32Number)b / 255.0f;
  1607. j++;
  1608. }
  1609. atime = clock();
  1610. for (j = 0; j < 256 * 256 * 256; j++) {
  1611. tmp16[j].r = (cmsUInt16Number)floor(In[j].r * 65535.0 + 0.5);
  1612. tmp16[j].g = (cmsUInt16Number)floor(In[j].g * 65535.0 + 0.5);
  1613. tmp16[j].b = (cmsUInt16Number)floor(In[j].b * 65535.0 + 0.5);
  1614. j++;
  1615. }
  1616. cmsDoTransform(ct, xform16, tmp16, tmp16, 256 * 256 * 256);
  1617. for (j = 0; j < 256 * 256 * 256; j++) {
  1618. In[j].r = (cmsFloat32Number) (tmp16[j].r / 65535.0 );
  1619. In[j].g = (cmsFloat32Number) (tmp16[j].g / 65535.0);
  1620. In[j].b = (cmsFloat32Number) (tmp16[j].b / 65535.0);
  1621. j++;
  1622. }
  1623. diff = clock() - atime;
  1624. free(In); free(tmp16);
  1625. cmsDeleteTransform(ct, xform16);
  1626. return MPixSec(diff);
  1627. }
  1628. static
  1629. void ComparativeFloatVs16bits(cmsContext Raw, cmsContext Plugin)
  1630. {
  1631. trace("\n\n");
  1632. trace("C O M P A R A T I V E converting to 16 bit vs. using float plug-in.\n");
  1633. trace(" values given in MegaPixels per second.\n");
  1634. trace("====================================================================\n");
  1635. trace(" 16 bits tmp. Float plugin\n");
  1636. fflush(stdout);
  1637. Comparative(Raw, Plugin, "Floating point on CLUT profiles ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc");
  1638. Comparative(Raw, Plugin, "Floating point on Matrix-Shaper ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc");
  1639. Comparative(Raw, Plugin, "Floating point on same MatrixSh ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc");
  1640. Comparative(Raw, Plugin, "Floating point on curves ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, NULL, NULL);
  1641. }
  1642. typedef struct
  1643. {
  1644. Scanline_rgba8bits pixels[256][256];
  1645. cmsUInt8Number padding[4];
  1646. } padded_line;
  1647. typedef struct
  1648. {
  1649. padded_line line[256];
  1650. } big_bitmap;
  1651. static
  1652. cmsFloat64Number SpeedTest8bitDoTransform(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1653. {
  1654. cmsInt32Number r, g, b, j;
  1655. clock_t atime;
  1656. cmsFloat64Number diff;
  1657. cmsHTRANSFORM hlcmsxform;
  1658. big_bitmap* In;
  1659. big_bitmap* Out;
  1660. cmsUInt32Number Mb;
  1661. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1662. Fail("Unable to open profiles");
  1663. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1664. cmsCloseProfile(ct, hlcmsProfileIn);
  1665. cmsCloseProfile(ct, hlcmsProfileOut);
  1666. // Our test bitmap is 256 x 256 padded lines
  1667. Mb = sizeof(big_bitmap);
  1668. In = (big_bitmap*)malloc(Mb);
  1669. Out = (big_bitmap*)malloc(Mb);
  1670. for (r = 0; r < 256; r++)
  1671. for (g = 0; g < 256; g++)
  1672. for (b = 0; b < 256; b++) {
  1673. In->line[r].pixels[g][b].r = (cmsUInt8Number)r;
  1674. In->line[r].pixels[g][b].g = (cmsUInt8Number)g;
  1675. In->line[r].pixels[g][b].b = (cmsUInt8Number)b;
  1676. In->line[r].pixels[g][b].a = 0;
  1677. }
  1678. atime = clock();
  1679. for (j = 0; j < 256; j++) {
  1680. cmsDoTransform(ct, hlcmsxform, In->line[j].pixels, Out->line[j].pixels, 256 * 256);
  1681. }
  1682. diff = clock() - atime;
  1683. free(In); free(Out);
  1684. cmsDeleteTransform(ct, hlcmsxform);
  1685. return MPixSec(diff);
  1686. }
  1687. static
  1688. cmsFloat64Number SpeedTest8bitLineStride(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut)
  1689. {
  1690. cmsInt32Number r, g, b;
  1691. clock_t atime;
  1692. cmsFloat64Number diff;
  1693. cmsHTRANSFORM hlcmsxform;
  1694. big_bitmap* In;
  1695. big_bitmap* Out;
  1696. cmsUInt32Number Mb;
  1697. if (hlcmsProfileIn == NULL || hlcmsProfileOut == NULL)
  1698. Fail("Unable to open profiles");
  1699. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_RGBA_8, hlcmsProfileOut, TYPE_RGBA_8, INTENT_PERCEPTUAL, cmsFLAGS_NOCACHE);
  1700. cmsCloseProfile(ct, hlcmsProfileIn);
  1701. cmsCloseProfile(ct, hlcmsProfileOut);
  1702. // Our test bitmap is 256 x 256 padded lines
  1703. Mb = sizeof(big_bitmap);
  1704. In = (big_bitmap*)malloc(Mb);
  1705. Out = (big_bitmap*)malloc(Mb);
  1706. for (r = 0; r < 256; r++)
  1707. for (g = 0; g < 256; g++)
  1708. for (b = 0; b < 256; b++) {
  1709. In->line[r].pixels[g][b].r = (cmsUInt8Number)r;
  1710. In->line[r].pixels[g][b].g = (cmsUInt8Number)g;
  1711. In->line[r].pixels[g][b].b = (cmsUInt8Number)b;
  1712. In->line[r].pixels[g][b].a = 0;
  1713. }
  1714. atime = clock();
  1715. cmsDoTransformLineStride(ct, hlcmsxform, In, Out, 256*256, 256, sizeof(padded_line), sizeof(padded_line), 0, 0);
  1716. diff = clock() - atime;
  1717. free(In); free(Out);
  1718. cmsDeleteTransform(ct, hlcmsxform);
  1719. return MPixSec(diff);
  1720. }
  1721. static
  1722. void ComparativeLineStride8bits(cmsContext NoPlugin, cmsContext Plugin)
  1723. {
  1724. trace("\n\n");
  1725. trace("C O M P A R A T I V E cmsDoTransform() vs. cmsDoTransformLineStride()\n");
  1726. trace(" values given in MegaPixels per second.\n");
  1727. trace("====================================================================\n");
  1728. fflush(stdout);
  1729. ComparativeCt(NoPlugin, Plugin, "CLUT profiles ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc");
  1730. ComparativeCt(NoPlugin, Plugin, "CLUT 16 bits ", SpeedTest16bitsRGB, SpeedTest16bitsRGB, PROFILES_DIR "test5.icc", PROFILES_DIR "test3.icc");
  1731. ComparativeCt(NoPlugin, Plugin, "Matrix-Shaper ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, PROFILES_DIR "test5.icc", PROFILES_DIR "test0.icc");
  1732. ComparativeCt(NoPlugin, Plugin, "same MatrixSh ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, PROFILES_DIR "test0.icc", PROFILES_DIR "test0.icc");
  1733. ComparativeCt(NoPlugin, Plugin, "curves ", SpeedTest8bitDoTransform, SpeedTest8bitLineStride, NULL, NULL);
  1734. }
  1735. static
  1736. void TestGrayTransformPerformance(cmsContext ct)
  1737. {
  1738. cmsInt32Number j;
  1739. clock_t atime;
  1740. cmsFloat64Number diff;
  1741. cmsHTRANSFORM hlcmsxform;
  1742. float *In;
  1743. cmsInt32Number pixels;
  1744. cmsUInt32Number Mb;
  1745. cmsToneCurve* gamma18;
  1746. cmsToneCurve* gamma22;
  1747. cmsHPROFILE hlcmsProfileIn;
  1748. cmsHPROFILE hlcmsProfileOut;
  1749. gamma18 = cmsBuildGamma(ct, 1.8);
  1750. gamma22 = cmsBuildGamma(ct, 2.2);
  1751. hlcmsProfileIn = cmsCreateGrayProfile(ct, NULL, gamma18);
  1752. hlcmsProfileOut = cmsCreateGrayProfile(ct, NULL, gamma22);
  1753. cmsFreeToneCurve(ct, gamma18);
  1754. cmsFreeToneCurve(ct, gamma22);
  1755. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_GRAY_FLT | EXTRA_SH(1), hlcmsProfileOut, TYPE_GRAY_FLT|EXTRA_SH(1), INTENT_PERCEPTUAL, 0);
  1756. cmsCloseProfile(ct, hlcmsProfileIn);
  1757. cmsCloseProfile(ct, hlcmsProfileOut);
  1758. pixels = 256 * 256 * 256;
  1759. Mb = pixels* 2*sizeof(float);
  1760. In = (float*) malloc(Mb);
  1761. for (j = 0; j < pixels*2; j++)
  1762. In[j] = (j % 256) / 255.0f;
  1763. atime = clock();
  1764. cmsDoTransform(ct, hlcmsxform, In, In, pixels);
  1765. diff = clock() - atime;
  1766. free(In);
  1767. cmsDeleteTransform(ct, hlcmsxform);
  1768. trace("Gray conversion using two gray profiles\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
  1769. }
  1770. static
  1771. void TestGrayTransformPerformance1(cmsContext ct)
  1772. {
  1773. cmsInt32Number j;
  1774. clock_t atime;
  1775. cmsFloat64Number diff;
  1776. cmsHTRANSFORM hlcmsxform;
  1777. float *In;
  1778. cmsInt32Number pixels;
  1779. cmsUInt32Number Mb;
  1780. cmsToneCurve* gamma18;
  1781. cmsToneCurve* gamma22;
  1782. cmsHPROFILE hlcmsProfileIn;
  1783. cmsHPROFILE hlcmsProfileOut;
  1784. gamma18 = cmsBuildGamma(ct, 1.8);
  1785. gamma22 = cmsBuildGamma(ct, 1./2.2);
  1786. hlcmsProfileIn = cmsCreateLinearizationDeviceLink(ct, cmsSigGrayData, &gamma18);
  1787. hlcmsProfileOut = cmsCreateLinearizationDeviceLink(ct, cmsSigGrayData, &gamma22);
  1788. cmsFreeToneCurve(ct, gamma18);
  1789. cmsFreeToneCurve(ct, gamma22);
  1790. hlcmsxform = cmsCreateTransform(ct, hlcmsProfileIn, TYPE_GRAY_FLT, hlcmsProfileOut, TYPE_GRAY_FLT, INTENT_PERCEPTUAL, 0);
  1791. cmsCloseProfile(ct, hlcmsProfileIn);
  1792. cmsCloseProfile(ct, hlcmsProfileOut);
  1793. pixels = 256 * 256 * 256;
  1794. Mb = pixels* sizeof(float);
  1795. In = (float*) malloc(Mb);
  1796. for (j = 0; j < pixels; j++)
  1797. In[j] = (j % 256) / 255.0f;
  1798. atime = clock();
  1799. cmsDoTransform(ct, hlcmsxform, In, In, pixels);
  1800. diff = clock() - atime;
  1801. free(In);
  1802. cmsDeleteTransform(ct, hlcmsxform);
  1803. trace("Gray conversion using two devicelinks\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
  1804. }
  1805. // The harness test
  1806. int main()
  1807. {
  1808. #ifdef _MSC_VER
  1809. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  1810. #endif
  1811. cmsContext raw = cmsCreateContext(NULL, NULL);
  1812. cmsContext plugin = cmsCreateContext(NULL, NULL);
  1813. trace("FastFloating point extensions testbed - 1.6\n");
  1814. trace("Copyright (c) 1998-2023 Marti Maria Saguer, all rights reserved\n");
  1815. trace("\nInstalling error logger ... ");
  1816. cmsSetLogErrorHandler(raw, FatalErrorQuit);
  1817. cmsSetLogErrorHandler(plugin, FatalErrorQuit);
  1818. trace("done.\n");
  1819. trace("Installing plug-in ... ");
  1820. cmsPlugin(plugin, cmsFastFloatExtensions());
  1821. trace("done.\n\n");
  1822. CheckComputeIncrements();
  1823. // 15 bit functionality
  1824. CheckFormatters15();
  1825. Check15bitsConversions(plugin);
  1826. // 16 bits functionality
  1827. CheckAccuracy16Bits(raw, plugin);
  1828. // Lab to whatever
  1829. CheckLab2RGB(plugin);
  1830. // Change format
  1831. CheckChangeFormat();
  1832. // Soft proofing
  1833. CheckSoftProofing();
  1834. // Floating point functionality
  1835. CheckConversionFloat(raw, plugin);
  1836. trace("All floating point tests passed OK\n");
  1837. SpeedTest8(plugin);
  1838. SpeedTest16(plugin);
  1839. SpeedTest15(plugin);
  1840. SpeedTestFloat(raw, plugin);
  1841. ComparativeFloatVs16bits(raw, plugin);
  1842. ComparativeLineStride8bits(raw, plugin);
  1843. // Test gray performance
  1844. trace("\n\n");
  1845. trace("F L O A T G R A Y conversions performance.\n");
  1846. trace("====================================================================\n");
  1847. TestGrayTransformPerformance(plugin);
  1848. TestGrayTransformPerformance1(plugin);
  1849. trace("\nAll tests passed OK\n");
  1850. cmsDeleteContext(0);
  1851. return 0;
  1852. }