views:

559

answers:

4

Canon/Nikon/other cameras save raw output of their sensor in some of their proprietary formats (.CR2, whatever). Is there any Java library designed to read them and convert into manageable BufferedImages?

I don't reqlly care here about fully customizable conversion similar to ufraw or imagemagick, rather something simple that "just works" for rendering simple previews of such images.

+1  A: 

Unless you want to write you own file parser/loader (sounds fun imho ;) ), perhaps JMagick will help you. I haven't tried it and it might not work given your target platform since JMagick uses JNI.

UPDATE: dcraw looks like a good resource/reference

basszero
Thanks for references to JMagick, which is cool piece of software. I'm happy to upvote this answer, though I don't quite like JNI.
Marcin
+2  A: 

jrawio is a plugin for Java Image I/O. With it you can read the raster data, the thumbnails and the metadata from the raw image file.

D. Wroblewski
jrawio is pretty cool, though it has its quirks -- it won't make it in my case (has trouble with Canon 5dmkii images) but it might for others.
Marcin
+1  A: 

I've been where you are, and I feel for you. Your best bet is to use an Adobe or dcraw-based program to create thumbnails automatically. Temporary DNG files using Adobe's converter may be easier to use.

IF you insist on doing it in Java, you're about to run into a mountain of pain. RAW formats change often, have all sorts of crazy nuances and are intentionally hard to work with. Camera makers want you to use THEIR RAW conversion software, to show the camera's abilities at its best and screw Adobe. The guy behind dcraw found that some are camera manufacturers even use encryption now!

The existing Java libraries are poor -- JRawIO has improved since I last looked at it, but it supports only a fraction of the formats that dcraw does. In addition to the listed libraries, the imagero library may provide the ability to display a thumbnail for your image.

From personal experience, don't even think about writing your own RAW file reader. I tried to do this with a very simple RAW format once (just a solid array of sensor data, 12 bits per pixel). The dcraw source translates badly to Java. You haven't seen such a nightmare of bit-fiddling ever. Took me days to debug problems with byte alignment and endian-ness.

BobMcGee
Sadly, you are right. I have tried jmagick which is probably closest to what I need, but still pain to use. Jrawio didn't make it for Canon 5dMkII photos.
Marcin
I still say to try converting to DNG if possible, since that does not change as much and is better supported by jrawio and other programs. Adobe Lightroom has a build-in viewer (with thumbs) for the DNG format, as do Mac OS and a number of programs.If you have a 5DMkII then you have my infinite envy, and I can't blame you for wanting to manage your RAW files in Java. That's a sweet camera, you should *really* look at Lightroom for managing your workflow. I couldn't be happier with it.
BobMcGee
+1  A: 

nef and cr2 already contains preview images in jpeg. just find the right offset and the right length to extract it... Laurent Clevy @ lclevy.free.fr/raw

Laurent