@@ -231,10 +231,57 @@ jbyteArray encodeBitmap(JNIEnv *env, jobject thiz,
231231 });
232232 options->version = 5 ;
233233 options->image_orientation = heif_orientation_normal;
234+
234235 result = heif_context_encode_image (ctx.get (), image, encoder.get (), options.get (), &handle);
235236 options.reset ();
236237 if (handle && result.code == heif_error_Ok) {
237238 heif_context_set_primary_image (ctx.get (), handle);
239+ //
240+ // std::time_t currentTime = std::time(nullptr);
241+ // std::tm *timeInfo = std::localtime(¤tTime);
242+ //
243+ // // Format the date and time
244+ // char formattedTime[20]; // Buffer for the formatted time
245+ // std::strftime(formattedTime, sizeof(formattedTime), "%Y:%m:%d %H:%M:%S", timeInfo);
246+ // std::string dateTime(formattedTime);
247+ //
248+ // std::string format(heifCompressionFormat == heif_compression_AV1 ? "AVIF" : "HEIC");
249+ //
250+ // std::string xmpMetadata = "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?>"
251+ // "<x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP Core 5.5.0'>"
252+ // "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>"
253+ // "<rdf:Description rdf:about='' xmlns:dc='http://purl.org/dc/elements/1.1/'>"
254+ // "<dc:title>Generated image by avif-coder</dc:title>"
255+ // "<dc:creator>avif-coder</dc:creator>"
256+ // "<dc:description>A image was created by avif-coder (https://github.com/awxkee/avif-coder)</dc:description>"
257+ // "<dc:date>" + dateTime + "</dc:date>\n"
258+ // "<dc:publisher>https://github.com/awxkee/avif-coder>"
259+ // "<dc:format>" + format + "</dc:format>"
260+ // "</rdf:Description>"
261+ // "<rdf:Description rdf:about='' xmlns:exif='http://ns.adobe.com/exif/1.0/'>\n"
262+ // "<exif:ColorSpace>sRGB</exif:ColorSpace>\n"
263+ // "<exif:ColorProfile>sRGB IEC61966-2.1</exif:ColorProfile>\n"
264+ // "</rdf:Description>\n"
265+ // "<rdf:Description rdf:about='' xmlns:xmp='http://ns.adobe.com/xap/1.0/'>\n"
266+ // "<xmp:CreatorTool>avif-coder (https://github.com/awxkee/avif-coder)</xmp:CreatorTool>\n"
267+ // "<xmp:ModifyDate>" +
268+ // dateTime +
269+ // "</xmp:ModifyDate>\n"
270+ // "</rdf:Description>\n"
271+ // "</rdf:RDF>"
272+ // "</x:xmpmeta>"
273+ // "<?xpacket end='w'?>";
274+ //
275+ // result = heif_context_add_XMP_metadata(ctx.get(), handle,
276+ // reinterpret_cast<const void *>(xmpMetadata.data()),
277+ // static_cast<int>(xmpMetadata.size()));
278+ // if (result.code != heif_error_Ok) {
279+ // heif_image_handle_release(handle);
280+ // heif_image_release(image);
281+ // throwCantEncodeImageException(env, result.message);
282+ // return static_cast<jbyteArray>(nullptr);
283+ // }
284+
238285 heif_image_handle_release (handle);
239286 }
240287 heif_image_release (image);
@@ -379,10 +426,6 @@ Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_getSizeImpl(JNIEnv *env, jobjec
379426 return sizeObject;
380427}
381428
382- uint16_t convert12to16 (uint16_t value12) {
383- return (value12 << (16 - 12 )); // Left-shift the 12-bit value to fill 16 bits.
384- }
385-
386429extern " C"
387430JNIEXPORT jobject JNICALL
388431Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_decodeImpl (JNIEnv *env, jobject thiz,
@@ -639,34 +682,37 @@ Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_decodeImpl(JNIEnv *env, jobject
639682 heif_image_handle_release (handle);
640683
641684 if (hasICC) {
642- convertUseDefinedColorSpace (dstARGB, stride, imageHeight, profile.data (), profile.size (),
685+ convertUseDefinedColorSpace (dstARGB, stride, imageWidth, imageHeight, profile.data (),
686+ profile.size (),
643687 useBitmapHalf16Floats);
644688 colorSpaceName = " SRGB" ;
645689 } else if (colorSpaceName && strcmp (colorSpaceName, " BT2020_PQ" ) == 0 &&
646690 osVersion < colorSpaceRequiredVersion) {
647- convertUseDefinedColorSpace (dstARGB, stride, imageHeight, &bt2020PQ[0 ],
691+ convertUseDefinedColorSpace (dstARGB, stride, imageWidth, imageHeight, &bt2020PQ[0 ],
648692 sizeof (bt2020PQ),
649693 useBitmapHalf16Floats);
650694 colorSpaceName = " SRGB" ;
651695 colorSpaceRequiredVersion = 29 ;
652696 } else if (colorSpaceName && strcmp (colorSpaceName, " BT2020" ) == 0 &&
653697 osVersion < colorSpaceRequiredVersion) {
654- convertUseDefinedColorSpace (dstARGB, stride, imageHeight, &bt2020[0 ], sizeof (bt2020),
698+ convertUseDefinedColorSpace (dstARGB, stride, imageWidth, imageHeight, &bt2020[0 ],
699+ sizeof (bt2020),
655700 useBitmapHalf16Floats);
656701 colorSpaceName = " SRGB" ;
657702 } else if (colorSpaceName && strcmp (colorSpaceName, " DISPLAY_P3" ) == 0 &&
658703 osVersion < colorSpaceRequiredVersion) {
659- convertUseDefinedColorSpace (dstARGB, stride, imageHeight, &displayP3[0 ], sizeof (displayP3),
704+ convertUseDefinedColorSpace (dstARGB, stride, imageWidth, imageHeight, &displayP3[0 ],
705+ sizeof (displayP3),
660706 useBitmapHalf16Floats);
661707 colorSpaceName = " SRGB" ;
662708 } else if (colorSpaceName && strcmp (colorSpaceName, " LINEAR_SRGB" ) == 0 &&
663709 osVersion < colorSpaceRequiredVersion) {
664- convertUseDefinedColorSpace (dstARGB, stride, imageHeight, &linearSRGB[0 ],
710+ convertUseDefinedColorSpace (dstARGB, stride, imageWidth, imageHeight, &linearSRGB[0 ],
665711 sizeof (linearSRGB), useBitmapHalf16Floats);
666712 colorSpaceName = " SRGB" ;
667713 } else if (colorSpaceName && strcmp (colorSpaceName, " BT709" ) == 0 &&
668714 osVersion < colorSpaceRequiredVersion) {
669- convertUseDefinedColorSpace (dstARGB, stride, imageHeight, &bt709[0 ],
715+ convertUseDefinedColorSpace (dstARGB, stride, imageWidth, imageHeight, &bt709[0 ],
670716 sizeof (bt709), useBitmapHalf16Floats);
671717 colorSpaceName = " SRGB" ;
672718 }
0 commit comments