All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.parser.image.OneBitImage Maven / Gradle / Ivy

There is a newer version: 7.15.25
Show newest version
/*
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info:  http://www.idrsolutions.com
* Help section for developers at http://www.idrsolutions.com/support/
*
* (C) Copyright 1997-2017 IDRsolutions and Contributors.
*
* This file is part of JPedal/JPDF2HTML5
*
@LICENSE@
*
* ---------------
* OneBitImage.java
* ---------------
*/

package org.jpedal.parser.image;

import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;

import org.jpedal.io.ColorSpaceConvertor;
import org.jpedal.utils.LogWriter;

/**
 * @author markee
 */
class OneBitImage {


    static BufferedImage make(final int d, final int w, final int h, byte[] data) throws RuntimeException {

        LogWriter.writeLog("comp=1 and d= " + d);

        final BufferedImage image;

        data = ColorSpaceConvertor.normaliseTo8Bit(d, w, h, data);

        // create an image from the raw data
        final DataBuffer db = new DataBufferByte(data, data.length);
        final int[] bands = {0};
        image = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY);
        final Raster raster = Raster.createInterleavedRaster(db, w, h, w, 1, bands, null);
        image.setData(raster);

        return image;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy