haraldk / TwelveMonkeys

TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO
https://haraldk.github.io/TwelveMonkeys/
BSD 3-Clause "New" or "Revised" License
1.9k stars 314 forks source link

Camera RAW support #370

Open amigax opened 7 years ago

amigax commented 7 years ago

Sorry couldnt work out how to email author, will there be .raw support ever added?

haraldk commented 7 years ago

Hi Gareth,

Depends on what you mean by ".raw".

I've started working on support for camera RAW formats, like Canon CR2, Nikon NEF and Adobe DNG, some time ago. It's in a separate branch, but I haven't had time to finish them yet. They can be used for extracting thumbnails and preview images, but no support for decoding, normalisation and demosaicing etc. of the RAW data yet.

For "pixel dump" type RAW files, you can use JAI ImageIO I think. Adding support for reading this is quite trivial, but you would need to to supply dimensions, pixel layout, bit depth etc., as these things are not stored in the file. So I'm not sure how useful it would be. No plans to add this.

What exactly are your requirements?

-- Harald K

ckovorodkin commented 6 years ago

At that point, in my branch ckovorodkin:camera-raw-cr2-slice there is ability to decode "regular" Canon CR2 RAW as mixed one-channel grayscale bitmap.

Todo:

ckovorodkin commented 6 years ago

Please note, that the current implementation suggests TIFFImageReader for processing the CR2 file (this is due to the fact that CR2 is based on TIFF). But TIFFImageReader is unable to decode CR2 in correct way and must be rejected from list of readers:

final BufferedImage sourceImage;
try (final ImageInputStream stream = ImageIO.createImageInputStream(new File(parent, name))) {
    final Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(stream);
    ImageReader reader;
    // skip TIFFImageReader
    //noinspection StatementWithEmptyBody
    while (!((reader = imageReaders.next()) instanceof CR2ImageReader)) {
    }
    final ImageReadParam param = reader.getDefaultReadParam();
    reader.setInput(stream, false, false);
    try {
        sourceImage = reader.read(2, param);
    } finally {
        reader.dispose();
    }
}