@@ -174,32 +174,18 @@ jobject decodeImplementationNative(JNIEnv *env, jobject thiz,
174174 convertUseICC (dstARGB, stride, imageWidth, imageHeight, profile.data (),
175175 profile.size (),
176176 useBitmapHalf16Floats, &stride);
177- } else if (colorProfile == " SMPTE_428" && hasNCLX) {
178- float primaries[3 ][2 ] = {{static_cast <float >(nclx->color_primary_red_x ),
179- static_cast <float >(nclx->color_primary_red_y )},
180- {static_cast <float >(nclx->color_primary_green_x ),
181- static_cast <float >(nclx->color_primary_green_y )},
182- {static_cast <float >(nclx->color_primary_blue_x ),
183- static_cast <float >(nclx->color_primary_blue_y )}};
184- float whitePoint[2 ] = {static_cast <float >(nclx->color_primary_white_x ),
185- static_cast <float >(nclx->color_primary_white_y )};
186- ColorSpaceProfile srcProfile (primaries, whitePoint, Rec2020LumaPrimaries,
187- DisplayP3WhitePointNits);
188- HDRTransferAdapter hdrTransferAdapter (
189- reinterpret_cast <uint8_t *>(dstARGB.data ()),
190- stride, imageWidth, imageHeight, useBitmapHalf16Floats,
191- useBitmapHalf16Floats ? 16 : 8 , Rec709, SMPTE428, toneMapper, &srcProfile,
192- rec709Profile, 2 .2f );
193- hdrTransferAdapter.transfer ();
194- } else if (colorProfile == " BT2020_PQ" || colorProfile == " DISPLAY_P3_PQ" ||
195- colorProfile == " BT2020_HLG" || colorProfile == " DISPLAY_P3_HLG" ) {
177+ } else if ((colorProfile == " BT2020_PQ" || colorProfile == " DISPLAY_P3_PQ" ||
178+ colorProfile == " BT2020_HLG" || colorProfile == " DISPLAY_P3_HLG" ||
179+ colorProfile.find (" SMPTE_428" ) != std::string::npos) && hasNCLX && (nclx)) {
196180 bool isVulkanLoaded = loadVulkanRunner ();
197181 bool vulkanWorkerDone = false ;
198182 if (assetManager != nullptr && isVulkanLoaded) {
199183 std::string kernel = " SMPTE2084.comp.spv" ;
200184
201185 if (colorProfile.find (" HLG" ) != std::string::npos) {
202186 kernel = " HLG.comp.spv" ;
187+ } else if (colorProfile.find (" SMPTE_428" ) != std::string::npos) {
188+ kernel = " SMPTE428.comp.spv" ;
203189 }
204190
205191 float primaries[3 ][2 ] = {{static_cast <float >(nclx->color_primary_red_x ),
@@ -214,13 +200,13 @@ jobject decodeImplementationNative(JNIEnv *env, jobject thiz,
214200 float lumaPrimaries[3 ];
215201
216202 if (colorProfile.find (" BT2020" ) != std::string::npos) {
217- memcpy (lumaPrimaries, Rec2020LumaPrimaries, sizeof (float ) * 3 );
203+ memcpy (lumaPrimaries, Rec2020LumaPrimaries, sizeof (float ) * 3 );
218204 } else {
219- memcpy (lumaPrimaries, DisplayP3LumaPrimaries, sizeof (float ) * 3 );
205+ memcpy (lumaPrimaries, DisplayP3LumaPrimaries, sizeof (float ) * 3 );
220206 }
221207
222208 ColorSpaceProfile srcProfile (primaries, whitePoint, Rec2020LumaPrimaries,
223- DisplayP3WhitePointNits );
209+ Rec2020WhitePointNits );
224210 CmsMatrix dstMatrix = CmsMatrix (rec709Profile->primaries , rec709Profile->illuminant );
225211 CmsMatrix srcMatrix = CmsMatrix (srcProfile.primaries , srcProfile.illuminant );
226212 CmsMatrix trns = dstMatrix.inverted () * srcMatrix;
@@ -230,9 +216,10 @@ jobject decodeImplementationNative(JNIEnv *env, jobject thiz,
230216 .oetfCurve = 1 ,
231217 };
232218
233- memcpy (shaderData.lumaPrimaries , lumaPrimaries, sizeof (float ) * 3 );
219+ memcpy (shaderData.lumaPrimaries , lumaPrimaries, sizeof (float ) * 3 );
234220
235- if (colorProfile == " DISPLAY_P3_PQ" || colorProfile == " DISPLAY_P3_HLG" ) {
221+ if (colorProfile == " DISPLAY_P3_PQ" || colorProfile == " DISPLAY_P3_HLG" ||
222+ colorProfile.find (" BT2020" ) != std::string::npos) {
236223 shaderData.oetfCurve = 2 ;
237224 }
238225
@@ -262,6 +249,9 @@ jobject decodeImplementationNative(JNIEnv *env, jobject thiz,
262249
263250 if (colorProfile.find (" HLG" ) != std::string::npos) {
264251 function = HLG;
252+ } else if (colorProfile.find (" SMPTE_428" ) != std::string::npos) {
253+ function = SMPTE428;
254+ gammaCurve = DCIP3;
265255 }
266256 HDRTransferAdapter hdrTransferAdapter (
267257 reinterpret_cast <uint8_t *>(dstARGB.data ()),
@@ -270,20 +260,76 @@ jobject decodeImplementationNative(JNIEnv *env, jobject thiz,
270260 rec709Profile, 2 .2f );
271261 hdrTransferAdapter.transfer ();
272262 }
273- } else if (colorProfile == " BT2020" ) {
274- convertUseICC (dstARGB, stride, imageWidth, imageHeight, &bt2020[0 ],
275- sizeof (bt2020),
276- useBitmapHalf16Floats, &stride);
277- } else if (colorProfile == " DISPLAY_P3" ) {
278- convertUseICC (dstARGB, stride, imageWidth, imageHeight, &displayP3[0 ],
279- sizeof (displayP3),
280- useBitmapHalf16Floats, &stride);
263+ } else if (colorProfile == " BT2020" || colorProfile == " BT709" ||
264+ colorProfile == " DISPLAY_P3" ) {
265+ bool isVulkanLoaded = loadVulkanRunner ();
266+ bool vulkanWorkerDone = false ;
267+
268+ ColorSpaceProfile *srcProfile = rec2020Profile;
269+ if (colorProfile == " BT709" ) {
270+ srcProfile = rec709Profile;
271+ }
272+ CmsMatrix dstMatrix = CmsMatrix (rec709Profile->primaries , rec709Profile->illuminant );
273+ CmsMatrix srcMatrix = CmsMatrix (srcProfile->primaries , srcProfile->illuminant );
274+ CmsMatrix trns = dstMatrix.inverted () * srcMatrix;
275+
276+ float lumaPrimaries[3 ];
277+
278+ if (colorProfile.find (" BT2020" ) != std::string::npos) {
279+ memcpy (lumaPrimaries, Rec2020LumaPrimaries, sizeof (float ) * 3 );
280+ } else if (colorProfile.find (" BT709" ) != std::string::npos) {
281+ memcpy (lumaPrimaries, Rec709LumaPrimaries, sizeof (float ) * 3 );
282+ } else {
283+ memcpy (lumaPrimaries, DisplayP3LumaPrimaries, sizeof (float ) * 3 );
284+ }
285+
286+ if (isVulkanLoaded) {
287+ ShaderGammaData shaderData = {
288+ .oetfCurve = 3 ,
289+ .gamma = 2.4 ,
290+ };
291+
292+ if (colorProfile.find (" P3" ) != std::string::npos) {
293+ shaderData.gamma = 2 .6f ;
294+ } else if (colorProfile.find (" 709" ) != std::string::npos) {
295+ shaderData.gamma = 2 .0f ;
296+ }
297+
298+ memcpy (shaderData.lumaPrimaries , lumaPrimaries, sizeof (float ) * 3 );
299+
300+ for (int i = 0 ; i < 3 ; ++i) {
301+ for (int j = 0 ; j < 3 ; ++j) {
302+ shaderData.colorMatrix [i][j] = trns.getMatrix ()[i * 3 + j];
303+ }
304+ }
305+ string kernel = " GammaOetf.comp.spv" ;
306+ vulkanWorkerDone = VulkanRunnerWithData (kernel, assetManager,
307+ reinterpret_cast <uint8_t *>(dstARGB.data ()),
308+ imageWidth,
309+ imageHeight, stride,
310+ useBitmapHalf16Floats ? RgbaF16 : RgbaU8,
311+ reinterpret_cast <void *>(&shaderData),
312+ sizeof (ShaderGammaData));
313+ }
314+ if (!vulkanWorkerDone) {
315+ HDRTransferFunction function = GAMMA_TRANSFER;
316+ float gamma = 2 .4f ;
317+ if (colorProfile.find (" P3" ) != std::string::npos) {
318+ gamma = 2 .6f ;
319+ } else if (colorProfile.find (" 709" ) != std::string::npos) {
320+ gamma = 2 .0f ;
321+ }
322+
323+ HDRTransferAdapter hdrTransferAdapter (
324+ reinterpret_cast <uint8_t *>(dstARGB.data ()),
325+ stride, imageWidth, imageHeight, useBitmapHalf16Floats,
326+ useBitmapHalf16Floats ? 16 : 8 , sRGB , function, toneMapper, srcProfile,
327+ rec709Profile, gamma);
328+ hdrTransferAdapter.transfer ();
329+ }
281330 } else if (colorProfile == " LINEAR_SRGB" ) {
282331 convertUseICC (dstARGB, stride, imageWidth, imageHeight, &linearSRGB[0 ],
283332 sizeof (linearSRGB), useBitmapHalf16Floats, &stride);
284- } else if (colorProfile == " BT709" ) {
285- convertUseICC (dstARGB, stride, imageWidth, imageHeight, &bt709[0 ],
286- sizeof (bt709), useBitmapHalf16Floats, &stride);
287333 }
288334
289335 string imageConfig = useBitmapHalf16Floats ? " RGBA_F16" : " ARGB_8888" ;
0 commit comments