Lambdacrash
Lambdacrash

Reputation: 201

Read 14 and 16 bits image

I try to read (in a BufferedImage) a 14 or 16 bits image over 1 or 3 channels (grayscale or RGB). I precise, each color component of this image is stored on 14 or 16 bits.

My code (using Apache Sanselan / Imaging) read the image but each color component is truncated to 8 bits.

File f = new File("/tmp/a.tiff");
Map<String, ManagedImageBufferedImageFactory> params = 
    new HashMap<String, ManagedImageBufferedImageFactory>();
params.put(ImagingConstants.BUFFERED_IMAGE_FACTORY, 
    new ManagedImageBufferedImageFactory());
BufferedImage image = Imaging.getBufferedImage(file, params);

Could you provide me a code snippet ? I'm stuck for 6 hours and Google does not want to help me :-p

Upvotes: 0

Views: 820

Answers (1)

Lambdacrash
Lambdacrash

Reputation: 201

Okay ! I close my question by myself :-P

I finally found a jar of Java Advanced Imaging. JAI solved my problem.

The following code is able to load TIFF or BMP image of any numbers of components with any depth for each.

        RenderedOp op = JAI.create("fileload", filename);
        // gets the number of channels (R / RGB / RGBA)
        channels =  op.getColorModel().getNumColorComponents();
        // gets the depth of each component (16 16 16)
        depth = new int[channels];
        for(int i=0; i<op.getColorModel().getNumColorComponents(); i++)
        {
            depth[i] = op.getColorModel().getComponentSize(i);
        }
        // gets the BufferedImage
        image = op.getAsBufferedImage();

Thanks !!

Upvotes: 1

Related Questions