I have a really simple question, but no matter how much I looked, I couldn't find it anywhere.
How can I connect libraw and libjpeg-turbo? Specifically, how do I get RGB data after:
ret = RawProcessor.dcraw_process();
so that I can pass it as
JSAMPLE* image_buffer; /* Points to large array of R,G,B-order data */
which will be fed to libjpeg.
Thank you very much!
use
use
libraw_processed_image_t *image = RawProcessor.dcraw_make_mem_image(&ret);
to make 3-channel RGB image (output_bps should be set to 8 for JPEG)
and
LibRaw::dcraw_clear_mem(image);
to clean (deallocate) libraw_processed_image_t after JPEG creation is done.
-- Alex Tutubalin @LibRaw LLC
Thank you very much for your
Thank you very much for your help! I feel like I am close, but I am still getting an exception at
write_JPEG_file(outfn, 10);
This is the same function as in libjpeg-turbo example. (https://github.com/libjpeg-turbo/libjpeg-turbo/blob/master/example.txt)
Do you see any glaring errors? Thanks a lot in advance!
int main(int ac, char* av[])
{
int ret;
char outfn[1024];
LibRaw RawProcessor;
_putenv((char*)"TZ=UTC"); // dcraw compatibility, affects TIFF datestamp field
#define P1 RawProcessor.imgdata.idata
#define S RawProcessor.imgdata.sizes
#define C RawProcessor.imgdata.color
#define T RawProcessor.imgdata.thumbnail
#define P2 RawProcessor.imgdata.other
#define OUT RawProcessor.imgdata.params
OUT.output_bps = 8;
if ((ret = RawProcessor.open_file(av[1])) != LIBRAW_SUCCESS)
return 1;
if ((ret = RawProcessor.unpack()) != LIBRAW_SUCCESS)
return 1;
ret = RawProcessor.dcraw_process();
if (LIBRAW_SUCCESS != ret)
if (LIBRAW_FATAL_ERROR(ret))
return 1;
libraw_processed_image_t* image = RawProcessor.dcraw_make_mem_image(&ret);
if (LIBRAW_SUCCESS != ret)
if (LIBRAW_FATAL_ERROR(ret))
return 1;
_snprintf_s(outfn, sizeof(outfn), "%s.jpeg", av[1]);
image_height = image->height;
image_width = image->width;
image_buffer = (JSAMPLE*)image->data;
write_JPEG_file(outfn, 10);
LibRaw::dcraw_clear_mem(image);
RawProcessor.recycle(); // just for show this call
return 0;
}
baris
I could not see what
I could not see what exceptions you get.
This snippet, created from your code (removed _putenv, _snprintf_s replaced w/ simple sprintf) compiles and converts single ARW file to jpeg: https://www.dropbox.com/s/1lq7npmuip2xne5/raw2jpeg.zip?dl=0
example.txt cut to write function only (JPEG read complains about put_scanline_someplace, so entire JPEG reading code removed).
Needed #includes added to example.txt and main (stdlib.h)
Compiled/tested under FreeBSD (under Linux is should be the same) using this command line:
clang -I/usr/local/include -I../LibRaw -o raw2jpeg main.cpp example.cpp -L/usr/local/lib -ljpeg -L../LibRaw/lib -lraw -lcxxrt
libjpeg-turbo 2.0.2 is installed in /usr/local
LibRaw is compiled in ../LibRaw
-- Alex Tutubalin @LibRaw LLC
Thanks a lot for your support
Thanks a lot for your support! This works. Somehow my code didn't work with release-DLL version, VCRT kept giving errors. However, it works nice with static lib or debug build. Go figure! :)
Again, thanks for your help. It gave me the assurance that I was on the right path.
baris
Under Windows:
Under Windows:
The problem may relate to FILE* pointer:
- you create one in your code (using runtime you specify on linking your code)
- and pass it to libjpeg.dll
You need to make sure that libjpeg.dll uses same runtime version with same FILE* structure layout.
(the problem is windows-specific, on Linux/Unix and Mac FILE* is handled by the single system runtime)
-- Alex Tutubalin @LibRaw LLC
It looks like it is simpler
It looks like it is simpler to implement it for one time in one of libraw samples: https://github.com/LibRaw/LibRaw/commit/52b7066b3ed285ed84c20a2442c59331...
-- Alex Tutubalin @LibRaw LLC