@@ -387,30 +387,34 @@ Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_getSizeImpl(JNIEnv *env, jobjec
387387 throwBitDepthException (env);
388388 return static_cast <jobject>(nullptr );
389389 }
390- heif_image *img;
391- std::shared_ptr<heif_decoding_options> options (heif_decoding_options_alloc (),
392- [](heif_decoding_options *deo) {
393- heif_decoding_options_free (deo);
394- });
395- options->convert_hdr_to_8bit = true ;
396- result = heif_decode_image (handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_RGBA,
397- options.get ());
398- options.reset ();
399- if (result.code != heif_error_Ok) {
400- heif_image_handle_release (handle);
401- std::string exception = " Decode an image has failed" ;
402- throwException (env, exception);
403- return static_cast <jobject>(nullptr );
404- }
405-
406- auto width = heif_image_get_primary_width (img);
407- auto height = heif_image_get_primary_height (img);
408-
409- heif_image_release (img);
390+ auto width = heif_image_handle_get_width (handle);
391+ auto height = heif_image_handle_get_height (handle);
410392 heif_image_handle_release (handle);
411393
412394 jclass sizeClass = env->FindClass (" android/util/Size" );
413395 jmethodID methodID = env->GetMethodID (sizeClass, " <init>" , " (II)V" );
414396 auto sizeObject = env->NewObject (sizeClass, methodID, width, height);
415397 return sizeObject;
398+ }
399+
400+
401+ extern " C"
402+ JNIEXPORT jboolean JNICALL
403+ Java_com_radzivon_bartoshyk_avif_coder_HeifCoder_isSupportedImageImplBB (JNIEnv *env, jobject thiz,
404+ jobject byteBuffer) {
405+ auto bufferAddress = reinterpret_cast <uint8_t *>(env->GetDirectBufferAddress (byteBuffer));
406+ int length = (int ) env->GetDirectBufferCapacity (byteBuffer);
407+ if (!bufferAddress || length <= 0 ) {
408+ std::string errorString = " Only direct byte buffers are supported" ;
409+ throwException (env, errorString);
410+ return (jboolean) false ;
411+ }
412+ std::vector<uint8_t > srcBuffer (length);
413+ std::copy (bufferAddress, bufferAddress + length, srcBuffer.begin ());
414+ auto cMime = heif_get_file_mime_type (reinterpret_cast <const uint8_t *>(srcBuffer.data ()),
415+ (int )srcBuffer.size ());
416+ std::string mime (cMime);
417+ return mime == " image/heic" || mime == " image/heif" ||
418+ mime == " image/heic-sequence" || mime == " image/heif-sequence" ||
419+ mime == " image/avif" || mime == " image/avif-sequence" ;
416420}
0 commit comments