First of all thanks for all this effort, I've been using Dcraw for a while, and it's nice to have a simple threaded implementation.
I'm trying to call Libraw through JNI. I can pass hundreds of images and decode perfectly fine with this snippet:
LibRaw RawProcessor; int result; jsize len = env->GetArrayLength(bufferBytes); jbyte* buffer = env->GetByteArrayElements(bufferBytes, 0); result = RawProcessor.open_buffer(buffer, len); if (LIBRAW_FATAL_ERROR(result)) return NULL; result = RawProcessor.unpack_thumb(); if (LIBRAW_FATAL_ERROR(result)) return NULL; libraw_processed_image_t *image = RawProcessor.dcraw_make_mem_thumb(&result); if (LIBRAW_FATAL_ERROR(result)) return NULL; jbyteArray thumb = env->NewByteArray(image->data_size); env->SetByteArrayRegion(thumb, 0, image->data_size, (jbyte *) image->data); env->ReleaseByteArrayElements(bufferBytes, buffer, 0); RawProcessor.dcraw_clear_mem(image); RawProcessor.recycle(); return thumb;
However when I send a non-image it crashes out with Fatal Signal 11 (SIGSEGV). So it appears I have a memory issue, but ONLY when it's not an image file. I thought I followed the examples for when there is a failure, but I guess I'm missing something. How should I be handling memory when the open_buffer throws an error?