JXRGluePFC.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338
  1. //*@@@+++@@@@******************************************************************
  2. //
  3. // Copyright © Microsoft Corp.
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // • Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. // • Redistributions in binary form must reproduce the above copyright notice,
  12. // this list of conditions and the following disclaimer in the documentation
  13. // and/or other materials provided with the distribution.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  19. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. // POSSIBILITY OF SUCH DAMAGE.
  26. //
  27. //*@@@---@@@@******************************************************************
  28. #include <stdlib.h>
  29. #include <JXRGlue.h>
  30. #include <math.h>
  31. //================================================================
  32. // PKFormatConverter
  33. //================================================================
  34. #define HLF_MIN 0.00006103515625f
  35. #define HLF_MAX 65504.0f
  36. #define HLF_MIN_BITS 0x0400
  37. #define HLF_MAX_BITS 0x7bff
  38. #define HLF_MIN_BITS_NEG (HLF_MIN_BITS | 0x8000)
  39. #define HLF_MAX_BITS_NEG (HLF_MAX_BITS | 0x8000)
  40. #define HLF_QNaN_BITZS 0x7fff
  41. // simple and slow implementation of half <-> float conversion
  42. static U32 Convert_Half_To_Float(U16 u16)
  43. {
  44. // 1s5e10m -> 1s8e23m
  45. const U32 s = (u16 >> 15) & 0x0001;
  46. const U32 e = (u16 >> 10) & 0x001f;
  47. const U32 m = (u16 >> 0) & 0x03ff;
  48. if (0 == e) // 0, denorm
  49. {
  50. return s << 31;
  51. }
  52. else if (~(~0 << 5) == e) // inf, snan, qnan
  53. {
  54. return (s << 31) | ~(~0 << 8) << 23| (m << 13);
  55. }
  56. return (s << 31) | ((e - 15 + 127) << 23) | (m << 13); // norm
  57. }
  58. static U16 Convert_Float_To_Half(float f)
  59. {
  60. // 1s5e10m -> 1s8e23m
  61. const U32 iFloat = *(U32*)&f; // Convert float to U32
  62. if (f != f)
  63. {
  64. return (U16)(iFloat | HLF_QNaN_BITZS); // +QNaN, -QNaN
  65. }
  66. else if (f < -HLF_MAX)
  67. {
  68. return HLF_MAX_BITS_NEG;
  69. }
  70. else if (HLF_MAX < f)
  71. {
  72. return HLF_MAX_BITS;
  73. }
  74. else if (-HLF_MIN < f && f < HLF_MIN)
  75. {
  76. return (U16)((iFloat >> 16) & 0x8000); // +0, -0
  77. }
  78. // Cut-and-paste from C++, introduce scope so we can decl more vars
  79. {
  80. const U32 s = (iFloat >> 31) & 0x00000001;
  81. const U32 e = (iFloat >> 23) & 0x000000ff;
  82. const U32 m = (iFloat >> 0) & 0x007fffff;
  83. return (U16) ((s << 15) | ((e - 127 + 15) << 10) | (m >> 13));
  84. }
  85. }
  86. static U8 Convert_Float_To_U8(float f)
  87. {
  88. // convert from linear scRGB to non-linear sRGB
  89. if (f <= 0)
  90. {
  91. return 0;
  92. }
  93. else if (f <= 0.0031308f)
  94. {
  95. return (U8)((255.0f * f * 12.92f) + 0.5f);
  96. }
  97. else if (f < 1.0f)
  98. {
  99. return (U8)((255.0f * ((1.055f * (float)pow(f, 1.0 / 2.4)) - 0.055f)) + 0.5f);
  100. }
  101. else
  102. {
  103. return 255;
  104. }
  105. }
  106. static U8 Convert_AlphaFloat_To_U8(float f)
  107. {
  108. // alpha is converted differently than RGB in scRGB
  109. if (f <= 0)
  110. {
  111. return 0;
  112. }
  113. else if (f < 1.0f)
  114. {
  115. return (U8)((255.0f * f) + 0.5f);
  116. }
  117. else
  118. {
  119. return 255;
  120. }
  121. }
  122. ERR RGB24_BGR24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  123. {
  124. I32 i = 0, j = 0;
  125. UNREFERENCED_PARAMETER( pFC );
  126. for (i = 0; i < pRect->Height; ++i)
  127. {
  128. for (j = 0; j < pRect->Width * 3; j += 3)
  129. {
  130. // swap red with blue
  131. U8 t = pb[j];
  132. pb[j] = pb[j + 2];
  133. pb[j + 2] = t;
  134. }
  135. pb += cbStride;
  136. }
  137. return WMP_errSuccess;
  138. }
  139. ERR BGR24_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  140. {
  141. return RGB24_BGR24(pFC, pRect, pb, cbStride);
  142. }
  143. ERR RGB24_BGR32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  144. {
  145. I32 i = 0, j = 0;
  146. UNREFERENCED_PARAMETER( pFC );
  147. for (i = 0; i < pRect->Height; ++i)
  148. {
  149. for (j = 0; j < pRect->Width; j++)
  150. {
  151. // swap red with blue
  152. U8 t = pb[3*j];
  153. pb[4*j] = pb[3*j + 2];
  154. pb[4*j + 1] = pb[3*j + 1];
  155. pb[4*j + 2] = t;
  156. }
  157. pb += cbStride;
  158. }
  159. return WMP_errSuccess;
  160. }
  161. ERR BGR32_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  162. {
  163. I32 i = 0, j = 0;
  164. UNREFERENCED_PARAMETER( pFC );
  165. for (i = 0; i < pRect->Height; ++i)
  166. {
  167. for (j = 0; j < pRect->Width; j++)
  168. {
  169. // swap red with blue
  170. U8 t = pb[4*j];
  171. pb[3*j] = pb[4*j + 2];
  172. pb[3*j + 1] = pb[4*j + 1];
  173. pb[3*j + 2] = t;
  174. }
  175. pb += cbStride;
  176. }
  177. return WMP_errSuccess;
  178. }
  179. ERR RGB24_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  180. {
  181. I32 i = 0, j = 0, k = 0;
  182. UNREFERENCED_PARAMETER( pFC );
  183. for (i = 0; i < pRect->Height; ++i)
  184. {
  185. for (j = 0, k = 0; j < pRect->Width * 3; j += 3, ++k)
  186. {
  187. U8 r = pb[j];
  188. U8 g = pb[j + 1];
  189. U8 b = pb[j + 2];
  190. pb[k] = r / 4 + g / 2 + b / 8 + 16;
  191. }
  192. pb += cbStride;
  193. }
  194. return WMP_errSuccess;
  195. }
  196. ERR BGR24_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  197. {
  198. ERR err = WMP_errSuccess;
  199. Call(BGR24_RGB24(pFC, pRect, pb, cbStride));
  200. Call(RGB24_Gray8(pFC, pRect, pb, cbStride));
  201. Cleanup:
  202. return err;
  203. }
  204. ERR Gray8_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  205. {
  206. I32 i = 0, j = 0, k = 0;
  207. UNREFERENCED_PARAMETER( pFC );
  208. for (i = 0; i < pRect->Height; ++i)
  209. {
  210. for (j = pRect->Width - 1, k = 3 * j; 0 <= j; j--, k -= 3)
  211. {
  212. U8 v = pb[j];
  213. pb[k] = v;
  214. pb[k + 1] = v;
  215. pb[k + 2] = v;
  216. }
  217. pb += cbStride;
  218. }
  219. return WMP_errSuccess;
  220. }
  221. ERR Gray8_BGR24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  222. {
  223. return Gray8_RGB24(pFC, pRect, pb, cbStride);
  224. }
  225. #if 0
  226. ERR RGB48_BGR48(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  227. {
  228. ERR err = WMP_errSuccess;
  229. I32 i = 0, j = 0;
  230. UNREFERENCED_PARAMETER( pFC );
  231. Call(PKFormatConverter_Copy(pFC, pRect, pb, cbStride));
  232. for (i = 0; i < pRect->Height; ++i)
  233. {
  234. for (j = 0; j < pRect->Width; j += 3)
  235. {
  236. U16* ps = (U16*)pb;
  237. // swap red with blue
  238. U16 t = ps[j];
  239. ps[j] = ps[j + 2];
  240. ps[j + 2] = t;
  241. }
  242. pb += cbStride;
  243. }
  244. Cleanup:
  245. return err;
  246. }
  247. ERR BGR48_RGB48(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  248. {
  249. return RGB48_BGR48(pFC, pRect, pb, cbStride);
  250. }
  251. ERR RGB48_Gray16(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  252. {
  253. ERR err = WMP_errSuccess;
  254. I32 i = 0, j = 0, k = 0;
  255. UNREFERENCED_PARAMETER( pFC );
  256. Call(PKFormatConverter_Copy(pFC, pRect, pb, cbStride));
  257. for (i = 0; i < pRect->Height; ++i)
  258. {
  259. for (j = 0, k = 0; j < pRect->Width; j += 3, ++k)
  260. {
  261. U16* ps = (U16*)pb;
  262. // Y = r / 4 + g / 2 + b / 8 + 16
  263. U16 r = ps[j];
  264. U16 g = ps[j + 1];
  265. U16 b = ps[j + 2];
  266. ps[k] = r / 4 + g / 2 + b / 8 + 16;
  267. }
  268. pb += cbStride;
  269. }
  270. Cleanup:
  271. return err;
  272. }
  273. #endif
  274. ERR RGBA128Fixed_RGBA128Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  275. {
  276. const I32 iHeight = pRect->Height;
  277. const I32 iWidthX4 = 4 * pRect->Width; // 4 == R, G, B, A
  278. const float fltCvtFactor = 1.0F / (1 << 24);
  279. I32 y;
  280. UNREFERENCED_PARAMETER( pFC );
  281. for (y = 0; y < iHeight; y++)
  282. {
  283. I32 x;
  284. float *pfltDstPixel = (float*)(pb + cbStride*y);
  285. const I32 *piSrcPixel = (I32*)pfltDstPixel;
  286. for (x = 0; x < iWidthX4; x++)
  287. pfltDstPixel[x] = piSrcPixel[x] * fltCvtFactor;
  288. }
  289. return WMP_errSuccess;
  290. }
  291. ERR RGBA128Float_RGBA128Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  292. {
  293. const I32 iHeight = pRect->Height;
  294. const I32 iWidthX4 = 4 * pRect->Width; // 4 == R, G, B, A
  295. const float fltCvtFactor = (float)(1 << 24);
  296. I32 y;
  297. UNREFERENCED_PARAMETER( pFC );
  298. for (y = 0; y < iHeight; y++)
  299. {
  300. I32 x;
  301. I32 *piDstPixel = (I32*)(pb + cbStride*y);
  302. const float *pfltSrcPixel = (float*)piDstPixel;
  303. for (x = 0; x < iWidthX4; x++)
  304. piDstPixel[x] = (I32) (pfltSrcPixel[x] * fltCvtFactor + 0.5F);
  305. }
  306. return WMP_errSuccess;
  307. }
  308. ERR RGB96Fixed_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  309. {
  310. const I32 iHeight = pRect->Height;
  311. const I32 iWidthX3 = 3 * pRect->Width; // 3 == R, G, B
  312. const float fltCvtFactor = 1.0F / (1 << 24);
  313. I32 y;
  314. UNREFERENCED_PARAMETER( pFC );
  315. for (y = 0; y < iHeight; y++)
  316. {
  317. I32 x;
  318. float *pfltDstPixel = (float*)(pb + cbStride*y);
  319. const I32 *piSrcPixel = (I32*)pfltDstPixel;
  320. for (x = 0; x < iWidthX3; x++)
  321. pfltDstPixel[x] = piSrcPixel[x] * fltCvtFactor;
  322. }
  323. return WMP_errSuccess;
  324. }
  325. ERR RGB128Fixed_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  326. {
  327. const I32 iHeight = pRect->Height;
  328. const I32 iWidth = pRect->Width;
  329. const float fltCvtFactor = 1.0F / (1 << 24);
  330. I32 y;
  331. UNREFERENCED_PARAMETER( pFC );
  332. for (y = 0; y < iHeight; y++)
  333. {
  334. I32 x;
  335. float *pfltDstPixel = (float*)(pb + cbStride*y);
  336. const I32 *piSrcPixel = (I32*)pfltDstPixel;
  337. for (x = 0; x < iWidth; x++)
  338. {
  339. pfltDstPixel[3*x] = piSrcPixel[4*x] * fltCvtFactor;
  340. pfltDstPixel[3*x+1] = piSrcPixel[4*x+1] * fltCvtFactor;
  341. pfltDstPixel[3*x+2] = piSrcPixel[4*x+2] * fltCvtFactor;
  342. }
  343. }
  344. return WMP_errSuccess;
  345. }
  346. ERR RGB96Float_RGB96Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  347. {
  348. const I32 iHeight = pRect->Height;
  349. const I32 iWidthX3 = 3 * pRect->Width; // 3 == R, G, B
  350. const float fltCvtFactor = (float) (1 << 24);
  351. I32 y;
  352. UNREFERENCED_PARAMETER( pFC );
  353. for (y = 0; y < iHeight; y++)
  354. {
  355. I32 x;
  356. I32 *piDstPixel = (I32*)(pb + cbStride*y);
  357. const float *pfltSrcPixel = (float*)piDstPixel;
  358. for (x = 0; x < iWidthX3; x++)
  359. piDstPixel[x] = (I32)(pfltSrcPixel[x] * fltCvtFactor + 0.5F);
  360. }
  361. return WMP_errSuccess;
  362. }
  363. ERR RGB96Float_RGB128Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  364. {
  365. const I32 iHeight = pRect->Height;
  366. const I32 iWidth = pRect->Width;
  367. const float fltCvtFactor = (float) (1 << 24);
  368. I32 y;
  369. UNREFERENCED_PARAMETER( pFC );
  370. assert(iWidth > 2); // Otherwise, we corrupt source data in inner loop
  371. for (y = iHeight - 1; y >= 0; y--)
  372. {
  373. I32 x;
  374. I32 *piDstPixel = (I32*)(pb + cbStride*y);
  375. const float *pfltSrcPixel = (float*)piDstPixel;
  376. for (x = iWidth - 1; x >= 0; x--)
  377. {
  378. piDstPixel[4*x] = (I32)(pfltSrcPixel[3*x] * fltCvtFactor + 0.5F);
  379. piDstPixel[4*x+1] = (I32)(pfltSrcPixel[3*x+1] * fltCvtFactor + 0.5F);
  380. piDstPixel[4*x+2] = (I32)(pfltSrcPixel[3*x+2] * fltCvtFactor + 0.5F);
  381. piDstPixel[4*x+3] = 0; // Zero out the alpha channel
  382. }
  383. }
  384. return WMP_errSuccess;
  385. }
  386. ERR RGB96Float_RGB128Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  387. {
  388. const I32 iHeight = pRect->Height;
  389. const I32 iWidth = pRect->Width;
  390. I32 y;
  391. UNREFERENCED_PARAMETER( pFC );
  392. assert(iWidth > 2); // Otherwise, we corrupt source data in inner loop
  393. for (y = iHeight - 1; y >= 0; y--)
  394. {
  395. I32 x;
  396. float *pfltDstPixel = (float*)(pb + cbStride*y);
  397. const float *pfltSrcPixel = (float*)pfltDstPixel;
  398. for (x = iWidth - 1; x >= 0; x--)
  399. {
  400. pfltDstPixel[4*x] = pfltSrcPixel[3*x];
  401. pfltDstPixel[4*x+1] = pfltSrcPixel[3*x+1];
  402. pfltDstPixel[4*x+2] = pfltSrcPixel[3*x+2];
  403. pfltDstPixel[4*x+3] = 0.0F; // Zero out the alpha channel
  404. }
  405. }
  406. return WMP_errSuccess;
  407. }
  408. ERR RGB128Float_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  409. {
  410. const I32 iHeight = pRect->Height;
  411. const I32 iWidth = pRect->Width;
  412. I32 y;
  413. UNREFERENCED_PARAMETER( pFC );
  414. for (y = 0; y < iHeight; y++)
  415. {
  416. I32 x;
  417. float *pfltDstPixel = (float*)(pb + cbStride*y);
  418. const float *pfltSrcPixel = (float*)pfltDstPixel;
  419. for (x = 0; x < iWidth; x++)
  420. {
  421. pfltDstPixel[3*x] = pfltSrcPixel[4*x];
  422. pfltDstPixel[3*x+1] = pfltSrcPixel[4*x+1];
  423. pfltDstPixel[3*x+2] = pfltSrcPixel[4*x+2];
  424. }
  425. }
  426. return WMP_errSuccess;
  427. }
  428. ERR RGB48Half_RGB64Half(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  429. {
  430. const I32 iHeight = pRect->Height;
  431. const I32 iWidth = pRect->Width;
  432. I32 y;
  433. UNREFERENCED_PARAMETER( pFC );
  434. assert(iWidth > 2); // Otherwise, we corrupt source data in inner loop
  435. for (y = iHeight - 1; y >= 0; y--)
  436. {
  437. I32 x;
  438. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  439. const I16 *piSrcPixel = (I16*)piDstPixel;
  440. for (x = iWidth - 1; x >= 0; x--)
  441. {
  442. piDstPixel[4*x] = piSrcPixel[3*x];
  443. piDstPixel[4*x+1] = piSrcPixel[3*x+1];
  444. piDstPixel[4*x+2] = piSrcPixel[3*x+2];
  445. piDstPixel[4*x+3] = 0; // Zero out the alpha channel
  446. }
  447. }
  448. return WMP_errSuccess;
  449. }
  450. ERR RGB64Half_RGB48Half(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  451. {
  452. const I32 iHeight = pRect->Height;
  453. const I32 iWidth = pRect->Width;
  454. I32 y;
  455. UNREFERENCED_PARAMETER( pFC );
  456. for (y = 0; y < iHeight; y++)
  457. {
  458. I32 x;
  459. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  460. const short *piSrcPixel = (I16*)piDstPixel;
  461. for (x = 0; x < iWidth; x++)
  462. {
  463. piDstPixel[3*x] = piSrcPixel[4*x];
  464. piDstPixel[3*x+1] = piSrcPixel[4*x+1];
  465. piDstPixel[3*x+2] = piSrcPixel[4*x+2];
  466. }
  467. }
  468. return WMP_errSuccess;
  469. }
  470. ERR BGR24_BGR32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  471. {
  472. const I32 iHeight = pRect->Height;
  473. const I32 iWidth = pRect->Width;
  474. I32 y;
  475. UNREFERENCED_PARAMETER( pFC );
  476. assert(iWidth > 2); // Otherwise, we corrupt source data in inner loop
  477. for (y = iHeight - 1; y >= 0; y--)
  478. {
  479. I32 x;
  480. U8 *piDstPixel = pb + cbStride*y;
  481. const U8 *piSrcPixel = piDstPixel;
  482. for (x = iWidth - 1; x >= 0; x--)
  483. {
  484. piDstPixel[4*x] = piSrcPixel[3*x];
  485. piDstPixel[4*x+1] = piSrcPixel[3*x+1];
  486. piDstPixel[4*x+2] = piSrcPixel[3*x+2];
  487. piDstPixel[4*x+3] = 0; // Zero out the alpha channel
  488. }
  489. }
  490. return WMP_errSuccess;
  491. }
  492. ERR BGR32_BGR24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  493. {
  494. const I32 iHeight = pRect->Height;
  495. const I32 iWidth = pRect->Width;
  496. I32 y;
  497. UNREFERENCED_PARAMETER( pFC );
  498. for (y = 0; y < iHeight; y++)
  499. {
  500. I32 x;
  501. U8 *piDstPixel = pb + cbStride*y;
  502. const U8 *piSrcPixel = piDstPixel;
  503. for (x = 0; x < iWidth; x++)
  504. {
  505. piDstPixel[3*x] = piSrcPixel[4*x];
  506. piDstPixel[3*x+1] = piSrcPixel[4*x+1];
  507. piDstPixel[3*x+2] = piSrcPixel[4*x+2];
  508. }
  509. }
  510. return WMP_errSuccess;
  511. }
  512. ERR Gray32Fixed_Gray32Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  513. {
  514. const I32 iHeight = pRect->Height;
  515. const I32 iWidth = pRect->Width;
  516. const float fltCvtFactor = 1.0F / (1 << 24);
  517. I32 y;
  518. UNREFERENCED_PARAMETER( pFC );
  519. for (y = 0; y < iHeight; y++)
  520. {
  521. I32 x;
  522. float *pfltDstPixel = (float*)(pb + cbStride*y);
  523. const I32 *piSrcPixel = (I32*)pfltDstPixel;
  524. for (x = 0; x < iWidth; x++)
  525. pfltDstPixel[x] = piSrcPixel[x] * fltCvtFactor;
  526. }
  527. return WMP_errSuccess;
  528. }
  529. ERR Gray32Float_Gray32Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  530. {
  531. const I32 iHeight = pRect->Height;
  532. const I32 iWidth = pRect->Width;
  533. const float fltCvtFactor = (float) (1 << 24);
  534. I32 y;
  535. UNREFERENCED_PARAMETER( pFC );
  536. for (y = 0; y < iHeight; y++)
  537. {
  538. I32 x;
  539. I32 *piDstPixel = (I32*)(pb + cbStride*y);
  540. const float *pfltSrcPixel = (float*)piDstPixel;
  541. for (x = 0; x < iWidth; x++)
  542. piDstPixel[x] = (I32)(pfltSrcPixel[x] * fltCvtFactor + 0.5F);
  543. }
  544. return WMP_errSuccess;
  545. }
  546. ERR Gray16Fixed_Gray32Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  547. {
  548. const I32 iHeight = pRect->Height;
  549. const I32 iWidth = pRect->Width;
  550. const float fltCvtFactor = 1.0F / (1 << 13);
  551. I32 y;
  552. UNREFERENCED_PARAMETER( pFC );
  553. // Stride is assumed to be same for src/dst
  554. for (y = iHeight - 1; y >= 0; y--)
  555. {
  556. I32 x;
  557. float *pfltDstPixel = (float*)(pb + cbStride*y);
  558. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  559. for (x = iWidth - 1; x >= 0; x--)
  560. pfltDstPixel[x] = piSrcPixel[x] * fltCvtFactor;
  561. }
  562. return WMP_errSuccess;
  563. }
  564. ERR Gray32Float_Gray16Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  565. {
  566. const I32 iHeight = pRect->Height;
  567. const I32 iWidth = pRect->Width;
  568. const float fltCvtFactor = (float) (1 << 13);
  569. I32 y;
  570. UNREFERENCED_PARAMETER( pFC );
  571. // Stride is assumed to be same for src/dst
  572. for (y = 0; y < iHeight; y++)
  573. {
  574. I32 x;
  575. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  576. const float *pfltSrcPixel = (float*)piDstPixel;
  577. for (x = 0; x < iWidth; x++)
  578. piDstPixel[x] = (I16)(pfltSrcPixel[x] * fltCvtFactor + 0.5F);
  579. }
  580. return WMP_errSuccess;
  581. }
  582. ERR RGB48Fixed_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  583. {
  584. const I32 iHeight = pRect->Height;
  585. const I32 iWidthX3 = 3 * pRect->Width;
  586. const float fltCvtFactor = 1.0F / (1 << 13);
  587. I32 y;
  588. UNREFERENCED_PARAMETER( pFC );
  589. // Stride is assumed to be same for src/dst
  590. for (y = iHeight - 1; y >= 0; y--)
  591. {
  592. I32 x;
  593. float *pfltDstPixel = (float*)(pb + cbStride*y);
  594. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  595. for (x = iWidthX3 - 1; x >= 0; x--)
  596. pfltDstPixel[x] = piSrcPixel[x] * fltCvtFactor;
  597. }
  598. return WMP_errSuccess;
  599. }
  600. ERR RGB96Float_RGB48Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  601. {
  602. const I32 iHeight = pRect->Height;
  603. const I32 iWidthX3 = 3 * pRect->Width;
  604. const float fltCvtFactor = (float)(1 << 13);
  605. I32 y;
  606. UNREFERENCED_PARAMETER( pFC );
  607. // Stride is assumed to be same for src/dst
  608. for (y = 0; y < iHeight; y++)
  609. {
  610. I32 x;
  611. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  612. const float *pfltSrcPixel = (float*)piDstPixel;
  613. for (x = 0; x < iWidthX3; x++)
  614. piDstPixel[x] = (I16)(pfltSrcPixel[x] * fltCvtFactor + 0.5F);
  615. }
  616. return WMP_errSuccess;
  617. }
  618. ERR RGB64Fixed_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  619. {
  620. const I32 iHeight = pRect->Height;
  621. const I32 iWidth = pRect->Width;
  622. const float fltCvtFactor = 1.0F / (1 << 13);
  623. I32 y;
  624. UNREFERENCED_PARAMETER( pFC );
  625. // Stride is assumed to be same for src/dst
  626. for (y = iHeight - 1; y >= 0; y--)
  627. {
  628. I32 x;
  629. float *pfltDstPixel = (float*)(pb + cbStride*y);
  630. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  631. for (x = iWidth - 1; x >= 0; x--)
  632. {
  633. pfltDstPixel[3*x] = piSrcPixel[4*x] * fltCvtFactor;
  634. pfltDstPixel[3*x+1] = piSrcPixel[4*x+1] * fltCvtFactor;
  635. pfltDstPixel[3*x+2] = piSrcPixel[4*x+2] * fltCvtFactor;
  636. }
  637. }
  638. return WMP_errSuccess;
  639. }
  640. ERR RGB96Float_RGB64Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  641. {
  642. const I32 iHeight = pRect->Height;
  643. const I32 iWidth = pRect->Width;
  644. const float fltCvtFactor = (float)(1 << 13);
  645. I32 y;
  646. UNREFERENCED_PARAMETER( pFC );
  647. // Stride is assumed to be same for src/dst
  648. for (y = 0; y < iHeight; y++)
  649. {
  650. I32 x;
  651. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  652. const float *pfltSrcPixel = (float*)piDstPixel;
  653. for (x = 0; x < iWidth; x++)
  654. {
  655. piDstPixel[4*x] = (I16)(pfltSrcPixel[3*x] * fltCvtFactor + 0.5F);
  656. piDstPixel[4*x+1] = (I16)(pfltSrcPixel[3*x+1] * fltCvtFactor + 0.5F);
  657. piDstPixel[4*x+2] = (I16)(pfltSrcPixel[3*x+2] * fltCvtFactor + 0.5F);
  658. piDstPixel[4*x+3] = 0; // Zero out the alpha channel
  659. }
  660. }
  661. return WMP_errSuccess;
  662. }
  663. ERR RGBA64Fixed_RGBA128Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  664. {
  665. const I32 iHeight = pRect->Height;
  666. const I32 iWidthX4 = 4 * pRect->Width;
  667. const float fltCvtFactor = 1.0F / (1 << 13);
  668. I32 y;
  669. UNREFERENCED_PARAMETER( pFC );
  670. // Stride is assumed to be same for src/dst
  671. for (y = iHeight - 1; y >= 0; y--)
  672. {
  673. I32 x;
  674. float *pfltDstPixel = (float*)(pb + cbStride*y);
  675. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  676. for (x = iWidthX4 - 1; x >= 0; x--)
  677. pfltDstPixel[x] = piSrcPixel[x] * fltCvtFactor;
  678. }
  679. return WMP_errSuccess;
  680. }
  681. ERR RGBA128Float_RGBA64Fixed(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  682. {
  683. const I32 iHeight = pRect->Height;
  684. const I32 iWidthX4 = 4 * pRect->Width;
  685. const float fltCvtFactor = (float)(1 << 13);
  686. I32 y;
  687. UNREFERENCED_PARAMETER( pFC );
  688. // Stride is assumed to be same for src/dst
  689. for (y = 0; y < iHeight; y++)
  690. {
  691. I32 x;
  692. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  693. const float *pfltSrcPixel = (float*)piDstPixel;
  694. for (x = 0; x < iWidthX4; x++)
  695. piDstPixel[x] = (I16)(pfltSrcPixel[x] * fltCvtFactor + 0.5F);
  696. }
  697. return WMP_errSuccess;
  698. }
  699. ERR RGBE_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  700. {
  701. const I32 iHeight = pRect->Height;
  702. const I32 iWidth = pRect->Width;
  703. I32 y;
  704. UNREFERENCED_PARAMETER( pFC );
  705. // Stride is assumed to be same for src/dst
  706. for (y = iHeight - 1; y >= 0; y--)
  707. {
  708. I32 x;
  709. float *pfltDstPixel = (float*)(pb + cbStride*y);
  710. const U8 *piSrcPixel = (U8*)pfltDstPixel;
  711. for (x = iWidth - 1; x >= 0; x--)
  712. {
  713. // First read the exponent
  714. const U8 rawExp = piSrcPixel[4*x+3];
  715. if (0 == rawExp)
  716. {
  717. pfltDstPixel[3*x] = 0.0F;
  718. pfltDstPixel[3*x+1] = 0.0F;
  719. pfltDstPixel[3*x+2] = 0.0F;
  720. }
  721. else
  722. {
  723. const I32 adjExp = (I32)rawExp - 128 - 8; // Can be negative
  724. float fltExp;
  725. if (adjExp > -32 && adjExp < 32)
  726. {
  727. fltExp = (float) (((U32)1) << abs(adjExp));
  728. if (adjExp < 0)
  729. fltExp = 1.0F / fltExp;
  730. }
  731. else
  732. {
  733. fltExp = (float)ldexp(1.0F, adjExp);
  734. }
  735. pfltDstPixel[3*x] = piSrcPixel[4*x] * fltExp;
  736. pfltDstPixel[3*x + 1] = piSrcPixel[4*x + 1] * fltExp;
  737. pfltDstPixel[3*x + 2] = piSrcPixel[4*x + 2] * fltExp;
  738. }
  739. }
  740. }
  741. return WMP_errSuccess;
  742. }
  743. ERR RGB96Float_RGBE(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  744. {
  745. const I32 iHeight = pRect->Height;
  746. const I32 iWidth = pRect->Width;
  747. I32 y;
  748. UNREFERENCED_PARAMETER( pFC );
  749. assert(iWidth > 2); // Otherwise, we corrupt source data in inner loop
  750. // Stride is assumed to be same for src/dst
  751. for (y = 0; y < iHeight; y++)
  752. {
  753. I32 x;
  754. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  755. const float *pfltSrcPixel = (float*)piDstPixel;
  756. for (x = 0; x < iWidth; x++)
  757. {
  758. // We clamp source RGB values at zero (don't allow negative numbers)
  759. const float fltRed = max(pfltSrcPixel[3*x], 0.0F);
  760. const float fltGreen = max(pfltSrcPixel[3*x+1], 0.0F);
  761. const float fltBlue = max(pfltSrcPixel[3*x+2], 0.0F);
  762. float fltMaxPos = fltRed;
  763. if (fltGreen > fltMaxPos)
  764. fltMaxPos = fltGreen;
  765. if (fltBlue > fltMaxPos)
  766. fltMaxPos = fltBlue;
  767. if (fltMaxPos < 1e-32)
  768. {
  769. piDstPixel[4*x] = 0; // R
  770. piDstPixel[4*x+1] = 0; // G
  771. piDstPixel[4*x+2] = 0; // B
  772. piDstPixel[4*x+3] = 0; // E
  773. }
  774. else
  775. {
  776. int e;
  777. const float fltScale = (float)frexp(fltMaxPos, &e) * 256 / fltMaxPos;
  778. // rounding SHOULD NOT be added - it has the potential to roll over to zero (and yes, 256 is the correct multiplier above)
  779. piDstPixel[4*x] = (U8)(fltRed * fltScale); // R
  780. piDstPixel[4*x+1] = (U8)(fltGreen * fltScale); // G
  781. piDstPixel[4*x+2] = (U8)(fltBlue * fltScale); // B
  782. piDstPixel[4*x+3] = (U8)(e + 128); // E
  783. }
  784. }
  785. }
  786. return WMP_errSuccess;
  787. }
  788. ERR RGBA64Half_RGBA128Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  789. {
  790. const I32 iHeight = pRect->Height;
  791. const I32 iWidthX4 = 4 * pRect->Width;
  792. I32 y;
  793. UNREFERENCED_PARAMETER( pFC );
  794. // Stride is assumed to be same for src/dst
  795. for (y = iHeight - 1; y >= 0; y--)
  796. {
  797. I32 x;
  798. U32 *pfltDstPixel = (U32*)(pb + cbStride*y); // It's really float, but use U32 ptr
  799. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  800. for (x = iWidthX4 - 1; x >= 0; x--)
  801. pfltDstPixel[x] = Convert_Half_To_Float(piSrcPixel[x]);
  802. }
  803. return WMP_errSuccess;
  804. }
  805. ERR RGBA128Float_RGBA64Half(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  806. {
  807. const I32 iHeight = pRect->Height;
  808. const I32 iWidthX4 = 4 * pRect->Width;
  809. I32 y;
  810. UNREFERENCED_PARAMETER( pFC );
  811. // Stride is assumed to be same for src/dst
  812. for (y = 0; y < iHeight; y++)
  813. {
  814. I32 x;
  815. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  816. const float *pfltSrcPixel = (float*)piDstPixel;
  817. for (x = 0; x < iWidthX4; x++)
  818. piDstPixel[x] = Convert_Float_To_Half(pfltSrcPixel[x]);
  819. }
  820. return WMP_errSuccess;
  821. }
  822. ERR RGB64Half_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  823. {
  824. const I32 iHeight = pRect->Height;
  825. const I32 iWidth = pRect->Width;
  826. I32 y;
  827. UNREFERENCED_PARAMETER( pFC );
  828. // Stride is assumed to be same for src/dst
  829. for (y = iHeight - 1; y >= 0; y--)
  830. {
  831. I32 x;
  832. U32 *pfltDstPixel = (U32*)(pb + cbStride*y); // It's really float, but use U32 ptr
  833. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  834. for (x = iWidth - 1; x >= 0; x--)
  835. {
  836. pfltDstPixel[3*x] = Convert_Half_To_Float(piSrcPixel[4*x]);
  837. pfltDstPixel[3*x+1] = Convert_Half_To_Float(piSrcPixel[4*x+1]);
  838. pfltDstPixel[3*x+2] = Convert_Half_To_Float(piSrcPixel[4*x+2]);
  839. }
  840. }
  841. return WMP_errSuccess;
  842. }
  843. ERR RGB96Float_RGB64Half(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  844. {
  845. const I32 iHeight = pRect->Height;
  846. const I32 iWidth = pRect->Width;
  847. I32 y;
  848. UNREFERENCED_PARAMETER( pFC );
  849. // Stride is assumed to be same for src/dst
  850. for (y = 0; y < iHeight; y++)
  851. {
  852. I32 x;
  853. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  854. const float *pfltSrcPixel = (float*)piDstPixel;
  855. for (x = 0; x < iWidth; x++)
  856. {
  857. piDstPixel[4*x] = Convert_Float_To_Half(pfltSrcPixel[3*x]);
  858. piDstPixel[4*x+1] = Convert_Float_To_Half(pfltSrcPixel[3*x+1]);
  859. piDstPixel[4*x+2] = Convert_Float_To_Half(pfltSrcPixel[3*x+2]);
  860. piDstPixel[4*x+3] = 0; // Zero out the alpha channel
  861. }
  862. }
  863. return WMP_errSuccess;
  864. }
  865. ERR RGB48Half_RGB96Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  866. {
  867. const I32 iHeight = pRect->Height;
  868. const I32 iWidthX3 = 3*pRect->Width;
  869. I32 y;
  870. UNREFERENCED_PARAMETER( pFC );
  871. // Stride is assumed to be same for src/dst
  872. for (y = iHeight - 1; y >= 0; y--)
  873. {
  874. I32 x;
  875. U32 *pfltDstPixel = (U32*)(pb + cbStride*y); // It's really float, but use U32 ptr
  876. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  877. for (x = iWidthX3 - 1; x >= 0; x--)
  878. pfltDstPixel[x] = Convert_Half_To_Float(piSrcPixel[x]);
  879. }
  880. return WMP_errSuccess;
  881. }
  882. ERR RGB96Float_RGB48Half(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  883. {
  884. const I32 iHeight = pRect->Height;
  885. const I32 iWidthX3 = 3*pRect->Width;
  886. I32 y;
  887. UNREFERENCED_PARAMETER( pFC );
  888. // Stride is assumed to be same for src/dst
  889. for (y = 0; y < iHeight; y++)
  890. {
  891. I32 x;
  892. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  893. const float *pfltSrcPixel = (float*)piDstPixel;
  894. for (x = 0; x < iWidthX3; x++)
  895. piDstPixel[x] = Convert_Float_To_Half(pfltSrcPixel[x]);
  896. }
  897. return WMP_errSuccess;
  898. }
  899. ERR Gray16Half_Gray32Float(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  900. {
  901. const I32 iHeight = pRect->Height;
  902. const I32 iWidth = pRect->Width;
  903. I32 y;
  904. UNREFERENCED_PARAMETER( pFC );
  905. // Stride is assumed to be same for src/dst
  906. for (y = iHeight - 1; y >= 0; y--)
  907. {
  908. I32 x;
  909. U32 *pfltDstPixel = (U32*)(pb + cbStride*y); // It's really float, but use U32 ptr
  910. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  911. for (x = iWidth - 1; x >= 0; x--)
  912. pfltDstPixel[x] = Convert_Half_To_Float(piSrcPixel[x]);
  913. }
  914. return WMP_errSuccess;
  915. }
  916. ERR Gray32Float_Gray16Half(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  917. {
  918. const I32 iHeight = pRect->Height;
  919. const I32 iWidth = pRect->Width;
  920. I32 y;
  921. UNREFERENCED_PARAMETER( pFC );
  922. // Stride is assumed to be same for src/dst
  923. for (y = 0; y < iHeight; y++)
  924. {
  925. I32 x;
  926. I16 *piDstPixel = (I16*)(pb + cbStride*y);
  927. const float *pfltSrcPixel = (float*)piDstPixel;
  928. for (x = 0; x < iWidth; x++)
  929. piDstPixel[x] = Convert_Float_To_Half(pfltSrcPixel[x]);
  930. }
  931. return WMP_errSuccess;
  932. }
  933. ERR RGB555_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  934. {
  935. const I32 iHeight = pRect->Height;
  936. const I32 iWidth = pRect->Width;
  937. I32 y;
  938. UNREFERENCED_PARAMETER( pFC );
  939. // Stride is assumed to be same for src/dst
  940. for (y = iHeight - 1; y >= 0; y--)
  941. {
  942. I32 x;
  943. U8 *piDstPixel = (pb + cbStride*y);
  944. const U16 *piSrcPixel = (U16*)piDstPixel;
  945. for (x = iWidth - 1; x >= 0; x--)
  946. {
  947. const U16 v = piSrcPixel[x];
  948. const unsigned int r = ((v >> 10) & 0x1f);
  949. const unsigned int g = ((v >> 5) & 0x1f);
  950. const unsigned int b = (v & 0x1f);
  951. piDstPixel[3*x] = (U8)(r << 3); // R
  952. piDstPixel[3*x+1] = (U8)(g << 3); // G
  953. piDstPixel[3*x+2] = (U8)(b << 3); // B
  954. }
  955. }
  956. return WMP_errSuccess;
  957. }
  958. ERR RGB101010_RGB48(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  959. {
  960. const I32 iHeight = pRect->Height;
  961. const I32 iWidth = pRect->Width;
  962. I32 y;
  963. UNREFERENCED_PARAMETER( pFC );
  964. // Stride is assumed to be same for src/dst
  965. for (y = iHeight - 1; y >= 0; y--)
  966. {
  967. I32 x;
  968. U16 *piDstPixel = (U16*)(pb + cbStride*y);
  969. const U32 *piSrcPixel = (U32*)piDstPixel;
  970. for (x = iWidth - 1; x >= 0; x--)
  971. {
  972. const U32 v = piSrcPixel[x];
  973. const unsigned int r = ((v >> 20) & 0x3FF);
  974. const unsigned int g = ((v >> 10) & 0x3FF);
  975. const unsigned int b = (v & 0x3FF);
  976. piDstPixel[3*x] = (U16)(r << 6); // R
  977. piDstPixel[3*x+1] = (U16)(g << 6); // G
  978. piDstPixel[3*x+2] = (U16)(b << 6); // B
  979. }
  980. }
  981. return WMP_errSuccess;
  982. }
  983. ERR RGB24_RGB555(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  984. {
  985. const I32 iHeight = pRect->Height;
  986. const I32 iWidth = pRect->Width;
  987. I32 y;
  988. UNREFERENCED_PARAMETER( pFC );
  989. // Stride is assumed to be same for src/dst
  990. for (y = 0; y < iHeight; y++)
  991. {
  992. I32 x;
  993. U16 *piDstPixel = (U16*)(pb + cbStride*y);
  994. const U8 *piSrcPixel = (U8*)piDstPixel;
  995. for (x = 0; x < iWidth; x++)
  996. {
  997. const unsigned int r = piSrcPixel[3*x];
  998. const unsigned int g = piSrcPixel[3*x+1];
  999. const unsigned int b = piSrcPixel[3*x+2];
  1000. piDstPixel[x] = (U16) (
  1001. ((r & 0xF8) << 7) |
  1002. ((g & 0xF8) << 2) |
  1003. (b >> 3));
  1004. }
  1005. }
  1006. return WMP_errSuccess;
  1007. }
  1008. ERR RGB48_RGB101010(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1009. {
  1010. const I32 iHeight = pRect->Height;
  1011. const I32 iWidth = pRect->Width;
  1012. I32 y;
  1013. UNREFERENCED_PARAMETER( pFC );
  1014. // Stride is assumed to be same for src/dst
  1015. for (y = 0; y < iHeight; y++)
  1016. {
  1017. I32 x;
  1018. U32 *piDstPixel = (U32*)(pb + cbStride*y);
  1019. const U16 *piSrcPixel = (U16*)piDstPixel;
  1020. for (x = 0; x < iWidth; x++)
  1021. {
  1022. const unsigned int r = piSrcPixel[3*x];
  1023. const unsigned int g = piSrcPixel[3*x+1];
  1024. const unsigned int b = piSrcPixel[3*x+2];
  1025. piDstPixel[x] = (3 << 30) | // For compatibility with D3D's 2-10-10-10 format.
  1026. ((r & 0x0000FFC0) << 14) |
  1027. ((g & 0x0000FFC0) << 4) |
  1028. (b >> 6);
  1029. }
  1030. }
  1031. return WMP_errSuccess;
  1032. }
  1033. ERR RGB565_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1034. {
  1035. const I32 iHeight = pRect->Height;
  1036. const I32 iWidth = pRect->Width;
  1037. I32 y;
  1038. UNREFERENCED_PARAMETER( pFC );
  1039. // Stride is assumed to be same for src/dst
  1040. for (y = iHeight - 1; y >= 0; y--)
  1041. {
  1042. I32 x;
  1043. U8 *piDstPixel = (pb + cbStride*y);
  1044. const U16 *piSrcPixel = (U16*)piDstPixel;
  1045. for (x = iWidth - 1; x >= 0; x--)
  1046. {
  1047. const U16 v = piSrcPixel[x];
  1048. const unsigned int r = ((v >> 11) & 0x1f);
  1049. const unsigned int g = ((v >> 5) & 0x3f);
  1050. const unsigned int b = (v & 0x1f);
  1051. piDstPixel[3*x] = (U8)(r << 3); // R
  1052. piDstPixel[3*x+1] = (U8)(g << 2); // G
  1053. piDstPixel[3*x+2] = (U8)(b << 3); // B
  1054. }
  1055. }
  1056. return WMP_errSuccess;
  1057. }
  1058. ERR RGB24_RGB565(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1059. {
  1060. const I32 iHeight = pRect->Height;
  1061. const I32 iWidth = pRect->Width;
  1062. I32 y;
  1063. UNREFERENCED_PARAMETER( pFC );
  1064. // Stride is assumed to be same for src/dst
  1065. for (y = 0; y < iHeight; y++)
  1066. {
  1067. I32 x;
  1068. U16 *piDstPixel = (U16*)(pb + cbStride*y);
  1069. const U8 *piSrcPixel = (U8*)piDstPixel;
  1070. for (x = 0; x < iWidth; x++)
  1071. {
  1072. const unsigned int r = piSrcPixel[3*x];
  1073. const unsigned int g = piSrcPixel[3*x+1];
  1074. const unsigned int b = piSrcPixel[3*x+2];
  1075. piDstPixel[x] = (U16) (
  1076. ((r & 0xF8) << 8) |
  1077. ((g & 0xFC) << 3) |
  1078. (b >> 3));
  1079. }
  1080. }
  1081. return WMP_errSuccess;
  1082. }
  1083. ERR RGBA32_BGRA32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1084. {
  1085. const I32 iHeight = pRect->Height;
  1086. const I32 iWidthX4 = 4 * pRect->Width; // 4 == R, G, B, A
  1087. I32 y;
  1088. UNREFERENCED_PARAMETER( pFC );
  1089. for (y = 0; y < iHeight; y++)
  1090. {
  1091. I32 x;
  1092. U8 *piPixel = (U8*)(pb + cbStride*y);
  1093. for (x = 0; x < iWidthX4; x += 4)
  1094. {
  1095. // Swap R and B
  1096. U8 bTemp = piPixel[x];
  1097. piPixel[x] = piPixel[x+2];
  1098. piPixel[x+2] = bTemp;
  1099. }
  1100. }
  1101. return WMP_errSuccess;
  1102. }
  1103. ERR BGRA32_RGBA32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1104. {
  1105. return RGBA32_BGRA32(pFC, pRect, pb, cbStride);
  1106. }
  1107. ERR BlackWhite_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1108. {
  1109. const I32 iHeight = pRect->Height;
  1110. const I32 iWidth = pRect->Width;
  1111. Bool bBlackWhite = pFC->pDecoder->WMP.wmiSCP.bBlackWhite;
  1112. I32 y;
  1113. // Stride is assumed to be same for src/dst
  1114. for (y = iHeight - 1; y >= 0; y--)
  1115. {
  1116. I32 x;
  1117. I32 n;
  1118. U8 *piDstPixel = (pb + cbStride*y);
  1119. const U8 *piSrcPixel = (U8*)piDstPixel;
  1120. if (iWidth % 8 != 0)
  1121. {
  1122. const U8 v = piSrcPixel[iWidth / 8];
  1123. for (n = 0; n < iWidth % 8; n++)
  1124. {
  1125. piDstPixel[iWidth/8*8+n] = (((v >> (7 - n)) & 0x1) != 0) ^ bBlackWhite ? 0xFF : 0x00;
  1126. }
  1127. }
  1128. for (x = iWidth / 8 - 1; x >= 0; x--)
  1129. {
  1130. const U8 v = piSrcPixel[x];
  1131. for (n = 0; n < 8; n++)
  1132. {
  1133. piDstPixel[8*x+n] = (((v >> (7 - n)) & 0x1) != 0) ^ bBlackWhite ? 0xFF : 0x00;
  1134. }
  1135. }
  1136. }
  1137. return WMP_errSuccess;
  1138. }
  1139. ERR Gray16_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1140. {
  1141. I32 i = 0, j = 0;
  1142. UNREFERENCED_PARAMETER( pFC );
  1143. for (i = 0; i < pRect->Height; ++i)
  1144. {
  1145. for (j = 0; j < pRect->Width; ++j)
  1146. {
  1147. U16 v = ((U16*)pb)[j];
  1148. pb[j] = v >> 8;
  1149. }
  1150. pb += cbStride;
  1151. }
  1152. return WMP_errSuccess;
  1153. }
  1154. ERR RGB48_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1155. {
  1156. const I32 iHeight = pRect->Height;
  1157. const I32 iWidth = pRect->Width;
  1158. I32 y;
  1159. UNREFERENCED_PARAMETER( pFC );
  1160. // Stride is assumed to be same for src/dst
  1161. for (y = 0; y < iHeight; y++)
  1162. {
  1163. I32 x;
  1164. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1165. const U16 *piSrcPixel = (U16*)piDstPixel;
  1166. for (x = 0; x < iWidth; x++)
  1167. {
  1168. const U16 r = piSrcPixel[3*x];
  1169. const U16 g = piSrcPixel[3*x+1];
  1170. const U16 b = piSrcPixel[3*x+2];
  1171. piDstPixel[3*x] = r >> 8;
  1172. piDstPixel[3*x+1] = g >> 8;
  1173. piDstPixel[3*x+2] = b >> 8;
  1174. }
  1175. }
  1176. return WMP_errSuccess;
  1177. }
  1178. ERR RGBA64_RGBA32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1179. {
  1180. const I32 iHeight = pRect->Height;
  1181. const I32 iWidth = pRect->Width;
  1182. I32 y;
  1183. UNREFERENCED_PARAMETER( pFC );
  1184. // Stride is assumed to be same for src/dst
  1185. for (y = 0; y < iHeight; y++)
  1186. {
  1187. I32 x;
  1188. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1189. const U16 *piSrcPixel = (U16*)piDstPixel;
  1190. for (x = 0; x < iWidth; x++)
  1191. {
  1192. const U16 r = piSrcPixel[4*x];
  1193. const U16 g = piSrcPixel[4*x+1];
  1194. const U16 b = piSrcPixel[4*x+2];
  1195. const U16 a = piSrcPixel[4*x+3];
  1196. piDstPixel[4*x] = r >> 8;
  1197. piDstPixel[4*x+1] = g >> 8;
  1198. piDstPixel[4*x+2] = b >> 8;
  1199. piDstPixel[4*x+3] = a >> 8;
  1200. }
  1201. }
  1202. return WMP_errSuccess;
  1203. }
  1204. ERR Gray32Float_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1205. {
  1206. const I32 iHeight = pRect->Height;
  1207. const I32 iWidth = pRect->Width;
  1208. I32 y;
  1209. UNREFERENCED_PARAMETER( pFC );
  1210. // Stride is assumed to be same for src/dst
  1211. for (y = 0; y < iHeight; y++)
  1212. {
  1213. I32 x;
  1214. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1215. const float *piSrcPixel = (float*)piDstPixel;
  1216. for (x = 0; x < iWidth; x++)
  1217. {
  1218. const float v = piSrcPixel[x];
  1219. piDstPixel[x] = Convert_Float_To_U8(v);
  1220. }
  1221. }
  1222. return WMP_errSuccess;
  1223. }
  1224. ERR RGB96Float_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1225. {
  1226. const I32 iHeight = pRect->Height;
  1227. const I32 iWidth = pRect->Width;
  1228. I32 y;
  1229. UNREFERENCED_PARAMETER( pFC );
  1230. // Stride is assumed to be same for src/dst
  1231. for (y = 0; y < iHeight; y++)
  1232. {
  1233. I32 x;
  1234. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1235. const float *piSrcPixel = (float*)piDstPixel;
  1236. for (x = 0; x < iWidth; x++)
  1237. {
  1238. const float r = piSrcPixel[3*x];
  1239. const float g = piSrcPixel[3*x+1];
  1240. const float b = piSrcPixel[3*x+2];
  1241. piDstPixel[3*x] = Convert_Float_To_U8(r);
  1242. piDstPixel[3*x+1] = Convert_Float_To_U8(g);
  1243. piDstPixel[3*x+2] = Convert_Float_To_U8(b);
  1244. }
  1245. }
  1246. return WMP_errSuccess;
  1247. }
  1248. ERR RGB128Float_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1249. {
  1250. const I32 iHeight = pRect->Height;
  1251. const I32 iWidth = pRect->Width;
  1252. I32 y;
  1253. UNREFERENCED_PARAMETER( pFC );
  1254. // Stride is assumed to be same for src/dst
  1255. for (y = 0; y < iHeight; y++)
  1256. {
  1257. I32 x;
  1258. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1259. const float *piSrcPixel = (float*)piDstPixel;
  1260. for (x = 0; x < iWidth; x++)
  1261. {
  1262. const float r = piSrcPixel[4*x];
  1263. const float g = piSrcPixel[4*x+1];
  1264. const float b = piSrcPixel[4*x+2];
  1265. piDstPixel[3*x] = Convert_Float_To_U8(r);
  1266. piDstPixel[3*x+1] = Convert_Float_To_U8(g);
  1267. piDstPixel[3*x+2] = Convert_Float_To_U8(b);
  1268. }
  1269. }
  1270. return WMP_errSuccess;
  1271. }
  1272. ERR RGBA128Float_RGBA32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1273. {
  1274. const I32 iHeight = pRect->Height;
  1275. const I32 iWidth = pRect->Width;
  1276. I32 y;
  1277. UNREFERENCED_PARAMETER( pFC );
  1278. // Stride is assumed to be same for src/dst
  1279. for (y = 0; y < iHeight; y++)
  1280. {
  1281. I32 x;
  1282. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1283. const float *piSrcPixel = (float*)piDstPixel;
  1284. for (x = 0; x < iWidth; x++)
  1285. {
  1286. const float r = piSrcPixel[4*x];
  1287. const float g = piSrcPixel[4*x+1];
  1288. const float b = piSrcPixel[4*x+2];
  1289. const float a = piSrcPixel[4*x+3];
  1290. piDstPixel[4*x] = Convert_Float_To_U8(r);
  1291. piDstPixel[4*x+1] = Convert_Float_To_U8(g);
  1292. piDstPixel[4*x+2] = Convert_Float_To_U8(b);
  1293. piDstPixel[4*x+3] = Convert_AlphaFloat_To_U8(a);
  1294. }
  1295. }
  1296. return WMP_errSuccess;
  1297. }
  1298. ERR Gray16Fixed_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1299. {
  1300. const I32 iHeight = pRect->Height;
  1301. const I32 iWidth = pRect->Width;
  1302. const float fltCvtFactor = 1.0F / (1 << 13);
  1303. I32 y;
  1304. UNREFERENCED_PARAMETER( pFC );
  1305. // Stride is assumed to be same for src/dst
  1306. for (y = 0; y < iHeight; y++)
  1307. {
  1308. I32 x;
  1309. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1310. const I16 *piSrcPixel = (I16*)piDstPixel;
  1311. for (x = 0; x < iWidth; x++)
  1312. {
  1313. piDstPixel[x] = Convert_Float_To_U8(piSrcPixel[x] * fltCvtFactor);
  1314. }
  1315. }
  1316. return WMP_errSuccess;
  1317. }
  1318. ERR Gray32Fixed_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1319. {
  1320. const I32 iHeight = pRect->Height;
  1321. const I32 iWidth = pRect->Width;
  1322. const float fltCvtFactor = 1.0F / (1 << 24);
  1323. I32 y;
  1324. UNREFERENCED_PARAMETER( pFC );
  1325. // Stride is assumed to be same for src/dst
  1326. for (y = 0; y < iHeight; y++)
  1327. {
  1328. I32 x;
  1329. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1330. const I32 *piSrcPixel = (I32*)piDstPixel;
  1331. for (x = 0; x < iWidth; x++)
  1332. {
  1333. piDstPixel[x] = Convert_Float_To_U8(piSrcPixel[x] * fltCvtFactor);
  1334. }
  1335. }
  1336. return WMP_errSuccess;
  1337. }
  1338. ERR RGB48Fixed_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1339. {
  1340. const I32 iHeight = pRect->Height;
  1341. const I32 iWidth = pRect->Width;
  1342. const float fltCvtFactor = 1.0F / (1 << 13);
  1343. I32 y;
  1344. UNREFERENCED_PARAMETER( pFC );
  1345. for (y = 0; y < iHeight; y++)
  1346. {
  1347. I32 x;
  1348. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1349. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  1350. for (x = 0; x < iWidth; x++)
  1351. {
  1352. pfltDstPixel[3*x] = Convert_Float_To_U8(piSrcPixel[3*x] * fltCvtFactor);
  1353. pfltDstPixel[3*x+1] = Convert_Float_To_U8(piSrcPixel[3*x+1] * fltCvtFactor);
  1354. pfltDstPixel[3*x+2] = Convert_Float_To_U8(piSrcPixel[3*x+2] * fltCvtFactor);
  1355. }
  1356. }
  1357. return WMP_errSuccess;
  1358. }
  1359. ERR RGB64Fixed_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1360. {
  1361. const I32 iHeight = pRect->Height;
  1362. const I32 iWidth = pRect->Width;
  1363. const float fltCvtFactor = 1.0F / (1 << 13);
  1364. I32 y;
  1365. UNREFERENCED_PARAMETER( pFC );
  1366. for (y = 0; y < iHeight; y++)
  1367. {
  1368. I32 x;
  1369. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1370. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  1371. for (x = 0; x < iWidth; x++)
  1372. {
  1373. pfltDstPixel[3*x] = Convert_Float_To_U8(piSrcPixel[4*x] * fltCvtFactor);
  1374. pfltDstPixel[3*x+1] = Convert_Float_To_U8(piSrcPixel[4*x+1] * fltCvtFactor);
  1375. pfltDstPixel[3*x+2] = Convert_Float_To_U8(piSrcPixel[4*x+2] * fltCvtFactor);
  1376. }
  1377. }
  1378. return WMP_errSuccess;
  1379. }
  1380. ERR RGB96Fixed_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1381. {
  1382. const I32 iHeight = pRect->Height;
  1383. const I32 iWidth = pRect->Width;
  1384. const float fltCvtFactor = 1.0F / (1 << 24);
  1385. I32 y;
  1386. UNREFERENCED_PARAMETER( pFC );
  1387. for (y = 0; y < iHeight; y++)
  1388. {
  1389. I32 x;
  1390. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1391. const I32 *piSrcPixel = (I32*)pfltDstPixel;
  1392. for (x = 0; x < iWidth; x++)
  1393. {
  1394. pfltDstPixel[3*x] = Convert_Float_To_U8(piSrcPixel[3*x] * fltCvtFactor);
  1395. pfltDstPixel[3*x+1] = Convert_Float_To_U8(piSrcPixel[3*x+1] * fltCvtFactor);
  1396. pfltDstPixel[3*x+2] = Convert_Float_To_U8(piSrcPixel[3*x+2] * fltCvtFactor);
  1397. }
  1398. }
  1399. return WMP_errSuccess;
  1400. }
  1401. ERR RGB128Fixed_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1402. {
  1403. const I32 iHeight = pRect->Height;
  1404. const I32 iWidth = pRect->Width;
  1405. const float fltCvtFactor = 1.0F / (1 << 24);
  1406. I32 y;
  1407. UNREFERENCED_PARAMETER( pFC );
  1408. for (y = 0; y < iHeight; y++)
  1409. {
  1410. I32 x;
  1411. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1412. const I32 *piSrcPixel = (I32*)pfltDstPixel;
  1413. for (x = 0; x < iWidth; x++)
  1414. {
  1415. pfltDstPixel[3*x] = Convert_Float_To_U8(piSrcPixel[4*x] * fltCvtFactor);
  1416. pfltDstPixel[3*x+1] = Convert_Float_To_U8(piSrcPixel[4*x+1] * fltCvtFactor);
  1417. pfltDstPixel[3*x+2] = Convert_Float_To_U8(piSrcPixel[4*x+2] * fltCvtFactor);
  1418. }
  1419. }
  1420. return WMP_errSuccess;
  1421. }
  1422. ERR RGBA64Fixed_RGBA32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1423. {
  1424. const I32 iHeight = pRect->Height;
  1425. const I32 iWidth = pRect->Width;
  1426. const float fltCvtFactor = 1.0F / (1 << 13);
  1427. I32 y;
  1428. UNREFERENCED_PARAMETER( pFC );
  1429. for (y = 0; y < iHeight; y++)
  1430. {
  1431. I32 x;
  1432. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1433. const I16 *piSrcPixel = (I16*)pfltDstPixel;
  1434. for (x = 0; x < iWidth; x++)
  1435. {
  1436. pfltDstPixel[4*x] = Convert_Float_To_U8(piSrcPixel[4*x] * fltCvtFactor);
  1437. pfltDstPixel[4*x+1] = Convert_Float_To_U8(piSrcPixel[4*x+1] * fltCvtFactor);
  1438. pfltDstPixel[4*x+2] = Convert_Float_To_U8(piSrcPixel[4*x+2] * fltCvtFactor);
  1439. pfltDstPixel[4*x+3] = Convert_AlphaFloat_To_U8(piSrcPixel[4*x+3] * fltCvtFactor);
  1440. }
  1441. }
  1442. return WMP_errSuccess;
  1443. }
  1444. ERR RGBA128Fixed_RGBA32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1445. {
  1446. const I32 iHeight = pRect->Height;
  1447. const I32 iWidth = pRect->Width;
  1448. const float fltCvtFactor = 1.0F / (1 << 24);
  1449. I32 y;
  1450. UNREFERENCED_PARAMETER( pFC );
  1451. for (y = 0; y < iHeight; y++)
  1452. {
  1453. I32 x;
  1454. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1455. const I32 *piSrcPixel = (I32*)pfltDstPixel;
  1456. for (x = 0; x < iWidth; x++)
  1457. {
  1458. pfltDstPixel[4*x] = Convert_Float_To_U8(piSrcPixel[4*x] * fltCvtFactor);
  1459. pfltDstPixel[4*x+1] = Convert_Float_To_U8(piSrcPixel[4*x+1] * fltCvtFactor);
  1460. pfltDstPixel[4*x+2] = Convert_Float_To_U8(piSrcPixel[4*x+2] * fltCvtFactor);
  1461. pfltDstPixel[4*x+3] = Convert_AlphaFloat_To_U8(piSrcPixel[4*x+3] * fltCvtFactor);
  1462. }
  1463. }
  1464. return WMP_errSuccess;
  1465. }
  1466. ERR Gray16Half_Gray8(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1467. {
  1468. const I32 iHeight = pRect->Height;
  1469. const I32 iWidth = pRect->Width;
  1470. I32 y;
  1471. UNREFERENCED_PARAMETER( pFC );
  1472. // Stride is assumed to be same for src/dst
  1473. for (y = 0; y < iHeight; y++)
  1474. {
  1475. I32 x;
  1476. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1477. const U16 *piSrcPixel = (U16*)piDstPixel;
  1478. for (x = 0; x < iWidth; x++)
  1479. {
  1480. const U32 v = Convert_Half_To_Float(piSrcPixel[x]);
  1481. piDstPixel[x] = Convert_Float_To_U8(*(float*)&v);
  1482. }
  1483. }
  1484. return WMP_errSuccess;
  1485. }
  1486. ERR RGB48Half_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1487. {
  1488. const I32 iHeight = pRect->Height;
  1489. const I32 iWidth = pRect->Width;
  1490. I32 y;
  1491. UNREFERENCED_PARAMETER( pFC );
  1492. for (y = 0; y < iHeight; y++)
  1493. {
  1494. I32 x;
  1495. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1496. const U16 *piSrcPixel = (U16*)pfltDstPixel;
  1497. for (x = 0; x < iWidth; x++)
  1498. {
  1499. const U32 r = Convert_Half_To_Float(piSrcPixel[3*x]);
  1500. const U32 g = Convert_Half_To_Float(piSrcPixel[3*x+1]);
  1501. const U32 b = Convert_Half_To_Float(piSrcPixel[3*x+2]);
  1502. pfltDstPixel[3*x] = Convert_Float_To_U8(*(float*)&r);
  1503. pfltDstPixel[3*x+1] = Convert_Float_To_U8(*(float*)&g);
  1504. pfltDstPixel[3*x+2] = Convert_Float_To_U8(*(float*)&b);
  1505. }
  1506. }
  1507. return WMP_errSuccess;
  1508. }
  1509. ERR RGB64Half_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1510. {
  1511. const I32 iHeight = pRect->Height;
  1512. const I32 iWidth = pRect->Width;
  1513. I32 y;
  1514. UNREFERENCED_PARAMETER( pFC );
  1515. for (y = 0; y < iHeight; y++)
  1516. {
  1517. I32 x;
  1518. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1519. const U16 *piSrcPixel = (U16*)pfltDstPixel;
  1520. for (x = 0; x < iWidth; x++)
  1521. {
  1522. const U32 r = Convert_Half_To_Float(piSrcPixel[4*x]);
  1523. const U32 g = Convert_Half_To_Float(piSrcPixel[4*x+1]);
  1524. const U32 b = Convert_Half_To_Float(piSrcPixel[4*x+2]);
  1525. pfltDstPixel[3*x] = Convert_Float_To_U8(*(float*)&r);
  1526. pfltDstPixel[3*x+1] = Convert_Float_To_U8(*(float*)&g);
  1527. pfltDstPixel[3*x+2] = Convert_Float_To_U8(*(float*)&b);
  1528. }
  1529. }
  1530. return WMP_errSuccess;
  1531. }
  1532. ERR RGBA64Half_RGBA32(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1533. {
  1534. const I32 iHeight = pRect->Height;
  1535. const I32 iWidth = pRect->Width;
  1536. I32 y;
  1537. UNREFERENCED_PARAMETER( pFC );
  1538. for (y = 0; y < iHeight; y++)
  1539. {
  1540. I32 x;
  1541. U8 *pfltDstPixel = (U8*)(pb + cbStride*y);
  1542. const U16 *piSrcPixel = (U16*)pfltDstPixel;
  1543. for (x = 0; x < iWidth; x++)
  1544. {
  1545. const U32 r = Convert_Half_To_Float(piSrcPixel[4*x]);
  1546. const U32 g = Convert_Half_To_Float(piSrcPixel[4*x+1]);
  1547. const U32 b = Convert_Half_To_Float(piSrcPixel[4*x+2]);
  1548. const U32 a = Convert_Half_To_Float(piSrcPixel[4*x+3]);
  1549. pfltDstPixel[4*x] = Convert_Float_To_U8(*(float*)&r);
  1550. pfltDstPixel[4*x+1] = Convert_Float_To_U8(*(float*)&g);
  1551. pfltDstPixel[4*x+2] = Convert_Float_To_U8(*(float*)&b);
  1552. pfltDstPixel[4*x+3] = Convert_AlphaFloat_To_U8(*(float*)&a);
  1553. }
  1554. }
  1555. return WMP_errSuccess;
  1556. }
  1557. ERR RGB101010_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1558. {
  1559. const I32 iHeight = pRect->Height;
  1560. const I32 iWidth = pRect->Width;
  1561. I32 y;
  1562. UNREFERENCED_PARAMETER( pFC );
  1563. // Stride is assumed to be same for src/dst
  1564. for (y = 0; y < iHeight; y++)
  1565. {
  1566. I32 x;
  1567. U8 *piDstPixel = (U8*)(pb + cbStride*y);
  1568. const U32 *piSrcPixel = (U32*)piDstPixel;
  1569. for (x = 0; x < iWidth; x++)
  1570. {
  1571. const U32 v = piSrcPixel[x];
  1572. const unsigned int r = ((v >> 20) & 0x3FF);
  1573. const unsigned int g = ((v >> 10) & 0x3FF);
  1574. const unsigned int b = (v & 0x3FF);
  1575. piDstPixel[3*x] = (U8) (r >> 2);
  1576. piDstPixel[3*x+1] = (U8) (g >> 2);
  1577. piDstPixel[3*x+2] = (U8) (b >> 2);
  1578. }
  1579. }
  1580. return WMP_errSuccess;
  1581. }
  1582. ERR RGBE_RGB24(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1583. {
  1584. I32 i = 0, j = 0;
  1585. UNREFERENCED_PARAMETER( pFC );
  1586. for (i = 0; i < pRect->Height; ++i)
  1587. {
  1588. for (j = 0; j < pRect->Width; j++)
  1589. {
  1590. // First read the exponent
  1591. const U8 rawExp = pb[4*j+3];
  1592. if (0 == rawExp)
  1593. {
  1594. pb[3*j] = 0;
  1595. pb[3*j+1] = 0;
  1596. pb[3*j+2] = 0;
  1597. }
  1598. else
  1599. {
  1600. const I32 adjExp = (I32)rawExp - 128 - 8; // Can be negative
  1601. float fltExp;
  1602. if (adjExp > -32 && adjExp < 32)
  1603. {
  1604. fltExp = (float) (((U32)1) << abs(adjExp));
  1605. if (adjExp < 0)
  1606. fltExp = 1.0F / fltExp;
  1607. }
  1608. else
  1609. {
  1610. fltExp = (float)ldexp(1.0F, adjExp);
  1611. }
  1612. pb[3*j] = Convert_Float_To_U8(pb[4*j] * fltExp);
  1613. pb[3*j + 1] = Convert_Float_To_U8(pb[4*j + 1] * fltExp);
  1614. pb[3*j + 2] = Convert_Float_To_U8(pb[4*j + 2] * fltExp);
  1615. }
  1616. }
  1617. pb += cbStride;
  1618. }
  1619. return WMP_errSuccess;
  1620. }
  1621. //================================================================
  1622. typedef struct tagPKPixelConverterInfo
  1623. {
  1624. const PKPixelFormatGUID* pGUIDPixFmtFrom;
  1625. const PKPixelFormatGUID* pGUIDPixFmtTo;
  1626. ERR (*Convert)(PKFormatConverter*, const PKRect*, U8*, U32);
  1627. } PKPixelConverterInfo;
  1628. static PKPixelConverterInfo s_pcInfo[] = {
  1629. {&GUID_PKPixelFormat24bppRGB, &GUID_PKPixelFormat24bppBGR, RGB24_BGR24}, // Fwd
  1630. {&GUID_PKPixelFormat24bppBGR, &GUID_PKPixelFormat24bppRGB, BGR24_RGB24}, // Rev
  1631. {&GUID_PKPixelFormat24bppRGB, &GUID_PKPixelFormat32bppBGR, RGB24_BGR32}, // Fwd
  1632. {&GUID_PKPixelFormat32bppBGR, &GUID_PKPixelFormat24bppRGB, BGR32_RGB24}, // Rev
  1633. // The following are not to be exposed when building the Adobe Photoshop plugin
  1634. #ifndef ADOBE_PS_PLUGIN
  1635. {&GUID_PKPixelFormat24bppRGB, &GUID_PKPixelFormat8bppGray, RGB24_Gray8}, // Fwd
  1636. {&GUID_PKPixelFormat8bppGray, &GUID_PKPixelFormat24bppRGB, Gray8_RGB24}, // Rev
  1637. {&GUID_PKPixelFormat24bppBGR, &GUID_PKPixelFormat8bppGray, BGR24_Gray8}, // Fwd
  1638. {&GUID_PKPixelFormat8bppGray, &GUID_PKPixelFormat24bppBGR, Gray8_BGR24}, // Rev
  1639. #endif // ADOBE_PS_PLUGIN
  1640. {&GUID_PKPixelFormat128bppRGBAFixedPoint, &GUID_PKPixelFormat128bppRGBAFloat, RGBA128Fixed_RGBA128Float}, // Fwd
  1641. {&GUID_PKPixelFormat128bppRGBAFloat, &GUID_PKPixelFormat128bppRGBAFixedPoint, RGBA128Float_RGBA128Fixed}, // Rev
  1642. {&GUID_PKPixelFormat96bppRGBFixedPoint, &GUID_PKPixelFormat96bppRGBFloat, RGB96Fixed_RGB96Float}, // Fwd
  1643. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat96bppRGBFixedPoint, RGB96Float_RGB96Fixed}, // Rev
  1644. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat128bppRGBFloat, RGB96Float_RGB128Float}, // Fwd
  1645. {&GUID_PKPixelFormat128bppRGBFloat, &GUID_PKPixelFormat96bppRGBFloat, RGB128Float_RGB96Float}, // Rev
  1646. {&GUID_PKPixelFormat96bppRGBFixedPoint, &GUID_PKPixelFormat128bppRGBFixedPoint, RGB96Float_RGB128Float}, // Fwd
  1647. {&GUID_PKPixelFormat128bppRGBFixedPoint, &GUID_PKPixelFormat96bppRGBFixedPoint, RGB128Float_RGB96Float}, // Rev
  1648. {&GUID_PKPixelFormat64bppRGBHalf, &GUID_PKPixelFormat48bppRGBHalf, RGB64Half_RGB48Half}, // Fwd
  1649. {&GUID_PKPixelFormat48bppRGBHalf, &GUID_PKPixelFormat64bppRGBHalf, RGB48Half_RGB64Half}, // Rev
  1650. {&GUID_PKPixelFormat64bppRGBFixedPoint, &GUID_PKPixelFormat48bppRGBFixedPoint, RGB64Half_RGB48Half}, // Fwd
  1651. {&GUID_PKPixelFormat48bppRGBFixedPoint, &GUID_PKPixelFormat64bppRGBFixedPoint, RGB48Half_RGB64Half}, // Rev
  1652. {&GUID_PKPixelFormat32bppBGR, &GUID_PKPixelFormat24bppBGR, BGR32_BGR24}, // Fwd
  1653. {&GUID_PKPixelFormat24bppBGR, &GUID_PKPixelFormat32bppBGR, BGR24_BGR32}, // Rev
  1654. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat128bppRGBFixedPoint, RGB96Float_RGB128Fixed}, // Fwd
  1655. {&GUID_PKPixelFormat128bppRGBFixedPoint, &GUID_PKPixelFormat96bppRGBFloat, RGB128Fixed_RGB96Float}, // Rev
  1656. {&GUID_PKPixelFormat32bppGrayFixedPoint, &GUID_PKPixelFormat32bppGrayFloat, Gray32Fixed_Gray32Float}, // Fwd
  1657. {&GUID_PKPixelFormat32bppGrayFloat, &GUID_PKPixelFormat32bppGrayFixedPoint, Gray32Float_Gray32Fixed}, // Rev
  1658. {&GUID_PKPixelFormat16bppGrayFixedPoint, &GUID_PKPixelFormat32bppGrayFloat, Gray16Fixed_Gray32Float}, // Fwd
  1659. {&GUID_PKPixelFormat32bppGrayFloat, &GUID_PKPixelFormat16bppGrayFixedPoint, Gray32Float_Gray16Fixed}, // Rev
  1660. {&GUID_PKPixelFormat48bppRGBFixedPoint, &GUID_PKPixelFormat96bppRGBFloat, RGB48Fixed_RGB96Float}, // Fwd
  1661. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat48bppRGBFixedPoint, RGB96Float_RGB48Fixed}, // Rev
  1662. {&GUID_PKPixelFormat64bppRGBFixedPoint, &GUID_PKPixelFormat96bppRGBFloat, RGB64Fixed_RGB96Float}, // Fwd
  1663. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat64bppRGBFixedPoint, RGB96Float_RGB64Fixed}, // Rev
  1664. {&GUID_PKPixelFormat64bppRGBAFixedPoint, &GUID_PKPixelFormat128bppRGBAFloat, RGBA64Fixed_RGBA128Float}, // Fwd
  1665. {&GUID_PKPixelFormat128bppRGBAFloat, &GUID_PKPixelFormat64bppRGBAFixedPoint, RGBA128Float_RGBA64Fixed}, // Rev
  1666. {&GUID_PKPixelFormat32bppRGBE, &GUID_PKPixelFormat96bppRGBFloat, RGBE_RGB96Float}, // Fwd
  1667. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat32bppRGBE, RGB96Float_RGBE}, // Rev
  1668. {&GUID_PKPixelFormat64bppRGBAHalf, &GUID_PKPixelFormat128bppRGBAFloat, RGBA64Half_RGBA128Float}, // Fwd
  1669. {&GUID_PKPixelFormat128bppRGBAFloat, &GUID_PKPixelFormat64bppRGBAHalf, RGBA128Float_RGBA64Half}, // Rev
  1670. {&GUID_PKPixelFormat64bppRGBHalf, &GUID_PKPixelFormat96bppRGBFloat, RGB64Half_RGB96Float}, // Fwd
  1671. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat64bppRGBHalf, RGB96Float_RGB64Half}, // Rev
  1672. {&GUID_PKPixelFormat48bppRGBHalf, &GUID_PKPixelFormat96bppRGBFloat, RGB48Half_RGB96Float}, // Fwd
  1673. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat48bppRGBHalf, RGB96Float_RGB48Half}, // Rev
  1674. {&GUID_PKPixelFormat16bppGrayHalf, &GUID_PKPixelFormat32bppGrayFloat, Gray16Half_Gray32Float}, // Fwd
  1675. {&GUID_PKPixelFormat32bppGrayFloat, &GUID_PKPixelFormat16bppGrayHalf, Gray32Float_Gray16Half}, // Rev
  1676. {&GUID_PKPixelFormat16bppRGB555, &GUID_PKPixelFormat24bppRGB, RGB555_RGB24}, // Fwd
  1677. {&GUID_PKPixelFormat24bppRGB, &GUID_PKPixelFormat16bppRGB555, RGB24_RGB555}, // Rev
  1678. {&GUID_PKPixelFormat16bppRGB565, &GUID_PKPixelFormat24bppRGB, RGB565_RGB24}, // Fwd
  1679. {&GUID_PKPixelFormat24bppRGB, &GUID_PKPixelFormat16bppRGB565, RGB24_RGB565}, // Rev
  1680. {&GUID_PKPixelFormat32bppRGB101010, &GUID_PKPixelFormat48bppRGB, RGB101010_RGB48}, // Fwd
  1681. {&GUID_PKPixelFormat48bppRGB, &GUID_PKPixelFormat32bppRGB101010, RGB48_RGB101010}, // Rev
  1682. {&GUID_PKPixelFormat32bppRGBA, &GUID_PKPixelFormat32bppBGRA, RGBA32_BGRA32}, // Fwd
  1683. {&GUID_PKPixelFormat32bppBGRA, &GUID_PKPixelFormat32bppRGBA, BGRA32_RGBA32}, // Rev
  1684. {&GUID_PKPixelFormat32bppPRGBA, &GUID_PKPixelFormat32bppPBGRA, RGBA32_BGRA32}, // Fwd
  1685. {&GUID_PKPixelFormat32bppPBGRA, &GUID_PKPixelFormat32bppPRGBA, BGRA32_RGBA32}, // Rev
  1686. // conversions to 8bppGray / 24bppRGB / 32bppRGBA
  1687. {&GUID_PKPixelFormatBlackWhite, &GUID_PKPixelFormat8bppGray, BlackWhite_Gray8},
  1688. {&GUID_PKPixelFormat16bppGray, &GUID_PKPixelFormat8bppGray, Gray16_Gray8},
  1689. {&GUID_PKPixelFormat48bppRGB, &GUID_PKPixelFormat24bppRGB, RGB48_RGB24},
  1690. {&GUID_PKPixelFormat64bppRGBA, &GUID_PKPixelFormat32bppRGBA, RGBA64_RGBA32},
  1691. {&GUID_PKPixelFormat32bppGrayFloat, &GUID_PKPixelFormat8bppGray, Gray32Float_Gray8},
  1692. {&GUID_PKPixelFormat96bppRGBFloat, &GUID_PKPixelFormat24bppRGB, RGB96Float_RGB24},
  1693. {&GUID_PKPixelFormat128bppRGBFloat, &GUID_PKPixelFormat24bppRGB, RGB128Float_RGB24},
  1694. {&GUID_PKPixelFormat128bppRGBAFloat, &GUID_PKPixelFormat32bppRGBA, RGBA128Float_RGBA32},
  1695. {&GUID_PKPixelFormat16bppGrayFixedPoint, &GUID_PKPixelFormat8bppGray, Gray16Fixed_Gray8},
  1696. {&GUID_PKPixelFormat32bppGrayFixedPoint, &GUID_PKPixelFormat8bppGray, Gray32Fixed_Gray8},
  1697. {&GUID_PKPixelFormat48bppRGBFixedPoint, &GUID_PKPixelFormat24bppRGB, RGB48Fixed_RGB24},
  1698. {&GUID_PKPixelFormat64bppRGBFixedPoint, &GUID_PKPixelFormat24bppRGB, RGB64Fixed_RGB24},
  1699. {&GUID_PKPixelFormat96bppRGBFixedPoint, &GUID_PKPixelFormat24bppRGB, RGB96Fixed_RGB24},
  1700. {&GUID_PKPixelFormat128bppRGBFixedPoint, &GUID_PKPixelFormat24bppRGB, RGB128Fixed_RGB24},
  1701. {&GUID_PKPixelFormat64bppRGBAFixedPoint, &GUID_PKPixelFormat32bppRGBA, RGBA64Fixed_RGBA32},
  1702. {&GUID_PKPixelFormat128bppRGBAFixedPoint, &GUID_PKPixelFormat32bppRGBA, RGBA128Fixed_RGBA32},
  1703. {&GUID_PKPixelFormat16bppGrayHalf, &GUID_PKPixelFormat8bppGray, Gray16Half_Gray8},
  1704. {&GUID_PKPixelFormat48bppRGBHalf, &GUID_PKPixelFormat24bppRGB, RGB48Half_RGB24},
  1705. {&GUID_PKPixelFormat64bppRGBHalf, &GUID_PKPixelFormat24bppRGB, RGB64Half_RGB24},
  1706. {&GUID_PKPixelFormat64bppRGBAHalf, &GUID_PKPixelFormat32bppRGBA, RGBA64Half_RGBA32},
  1707. {&GUID_PKPixelFormat32bppRGB101010, &GUID_PKPixelFormat24bppRGB, RGB101010_RGB24},
  1708. {&GUID_PKPixelFormat32bppRGBE, &GUID_PKPixelFormat24bppRGB, RGBE_RGB24}
  1709. };
  1710. /* auxiliary data structure and hack to support valid encoding from/to configurations that
  1711. // don't actually require any color conversion. This is a conservative approach, where we
  1712. // include as few formats as necessary to encode situations that we're currently aware of.
  1713. */
  1714. typedef struct tagPKPixelConverter2Info
  1715. {
  1716. const PKPixelFormatGUID* pGUIDPixFmtFrom;
  1717. const PKPixelFormatGUID* pGUIDPixFmtTo;
  1718. } PKPixelConverter2Info;
  1719. static PKPixelConverter2Info s_pcInfo2[] = {
  1720. // This allows us to view an RGBA input file as RGB, for when we create a planar alpha file
  1721. {&GUID_PKPixelFormat128bppRGBFloat, &GUID_PKPixelFormat128bppRGBAFloat},
  1722. // 16- and 32-bpp RGB input files are given the "DontCare" GUID, so the next three
  1723. // from/to combinations are ok, and allowed on encoding:
  1724. {&GUID_PKPixelFormatDontCare, &GUID_PKPixelFormat16bppRGB555},
  1725. {&GUID_PKPixelFormatDontCare, &GUID_PKPixelFormat16bppRGB565},
  1726. {&GUID_PKPixelFormatDontCare, &GUID_PKPixelFormat32bppBGRA}
  1727. };
  1728. ERR PKFormatConverter_Initialize(PKFormatConverter* pFC, PKImageDecode* pID, char *pExt, PKPixelFormatGUID enPF)
  1729. {
  1730. ERR err;
  1731. PKPixelFormatGUID enPFFrom;
  1732. Call(pID->GetPixelFormat(pID, &enPFFrom));
  1733. Call(PKFormatConverter_InitializeConvert(pFC, enPFFrom, pExt, enPF));
  1734. pFC->pDecoder = pID;
  1735. Cleanup:
  1736. return err;
  1737. }
  1738. extern int PKStrnicmp(const char* s1, const char* s2, size_t c);
  1739. ERR PKFormatConverter_InitializeConvert(PKFormatConverter* pFC, const PKPixelFormatGUID enPFFrom,
  1740. char *pExt, PKPixelFormatGUID enPFTo)
  1741. {
  1742. ERR err = WMP_errSuccess;
  1743. //================================
  1744. pFC->enPixelFormat = enPFTo;
  1745. if (pExt != NULL && IsEqualGUID(&enPFTo, &GUID_PKPixelFormat24bppRGB) &&
  1746. 0 == PKStrnicmp(pExt, ".bmp", strlen(pExt)))
  1747. enPFTo = GUID_PKPixelFormat24bppBGR;
  1748. if (pExt != NULL && (0 == PKStrnicmp(pExt, ".tif", strlen(pExt)) || 0 == PKStrnicmp(pExt, ".tiff", strlen(pExt))))
  1749. {
  1750. if (IsEqualGUID(&enPFTo, &GUID_PKPixelFormat32bppBGRA))
  1751. enPFTo = GUID_PKPixelFormat32bppRGBA;
  1752. if (IsEqualGUID(&enPFTo, &GUID_PKPixelFormat32bppPBGRA))
  1753. enPFTo = GUID_PKPixelFormat32bppPRGBA;
  1754. }
  1755. //================================
  1756. if (!IsEqualGUID(&enPFFrom, &enPFTo))
  1757. {
  1758. size_t i = 0;
  1759. for (i = 0; i < sizeof2(s_pcInfo); ++i)
  1760. {
  1761. PKPixelConverterInfo* pPCI = s_pcInfo + i;
  1762. if (IsEqualGUID(&enPFFrom, pPCI->pGUIDPixFmtFrom) && IsEqualGUID(&enPFTo, pPCI->pGUIDPixFmtTo))
  1763. {
  1764. pFC->Convert= pPCI->Convert;
  1765. goto Cleanup;
  1766. }
  1767. }
  1768. // Bugfix to allow legitimate encoding from/to combinations that don't actually
  1769. // involve color conversions.
  1770. for (i = 0; i < sizeof2(s_pcInfo2); ++i)
  1771. {
  1772. PKPixelConverter2Info* pPCI = s_pcInfo2 + i;
  1773. if (IsEqualGUID(&enPFFrom, pPCI->pGUIDPixFmtFrom) && IsEqualGUID(&enPFTo, pPCI->pGUIDPixFmtTo))
  1774. {
  1775. goto Cleanup;
  1776. }
  1777. }
  1778. // If we failed the original check, and this bugfix check, then exit with error
  1779. Call(WMP_errUnsupportedFormat);
  1780. }
  1781. Cleanup:
  1782. return err;
  1783. }
  1784. ERR PKFormatConverter_EnumConversions(const PKPixelFormatGUID *pguidSourcePF,
  1785. const U32 iIndex,
  1786. const PKPixelFormatGUID **ppguidTargetPF)
  1787. {
  1788. U32 iCurrIdx = 0;
  1789. U32 i;
  1790. ERR errResult = WMP_errIndexNotFound;
  1791. *ppguidTargetPF = &GUID_PKPixelFormatDontCare; // Init return value
  1792. for (i = 0; i < sizeof2(s_pcInfo); i++)
  1793. {
  1794. if (IsEqualGUID(s_pcInfo[i].pGUIDPixFmtFrom, pguidSourcePF))
  1795. {
  1796. if (iCurrIdx == iIndex)
  1797. {
  1798. // Found our target
  1799. errResult = WMP_errSuccess;
  1800. *ppguidTargetPF = s_pcInfo[i].pGUIDPixFmtTo;
  1801. break;
  1802. }
  1803. iCurrIdx += 1;
  1804. }
  1805. }
  1806. return errResult;
  1807. }
  1808. ERR PKFormatConverter_GetPixelFormat(PKFormatConverter* pFC, PKPixelFormatGUID* pPF)
  1809. {
  1810. *pPF = pFC->enPixelFormat;
  1811. return WMP_errSuccess;
  1812. }
  1813. ERR PKFormatConverter_GetSourcePixelFormat(PKFormatConverter* pFC, PKPixelFormatGUID* pPF)
  1814. {
  1815. return pFC->pDecoder->GetPixelFormat(pFC->pDecoder, pPF);
  1816. }
  1817. ERR PKFormatConverter_GetSize(PKFormatConverter* pFC, I32* piWidth, I32* piHeight)
  1818. {
  1819. return pFC->pDecoder->GetSize(pFC->pDecoder, piWidth, piHeight);
  1820. }
  1821. ERR PKFormatConverter_GetResolution(PKFormatConverter* pFC, Float* pfrX, Float* pfrY)
  1822. {
  1823. return pFC->pDecoder->GetResolution(pFC->pDecoder, pfrX, pfrY);
  1824. }
  1825. ERR PKFormatConverter_Copy(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1826. {
  1827. ERR err = WMP_errSuccess;
  1828. Call(pFC->pDecoder->Copy(pFC->pDecoder, pRect, pb, cbStride));
  1829. Call(pFC->Convert(pFC, pRect, pb, cbStride));
  1830. Cleanup:
  1831. return err;
  1832. }
  1833. ERR PKFormatConverter_Convert(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride)
  1834. {
  1835. UNREFERENCED_PARAMETER( pFC );
  1836. UNREFERENCED_PARAMETER( pRect );
  1837. UNREFERENCED_PARAMETER( pb );
  1838. UNREFERENCED_PARAMETER( cbStride );
  1839. return WMP_errSuccess;
  1840. }
  1841. ERR PKFormatConverter_Release(PKFormatConverter** ppFC)
  1842. {
  1843. ERR err = WMP_errSuccess;
  1844. Call(PKFree((void **) ppFC));
  1845. Cleanup:
  1846. return err;
  1847. }