Example usage for java.awt.image DataBuffer TYPE_BYTE

List of usage examples for java.awt.image DataBuffer TYPE_BYTE

Introduction

In this page you can find the example usage for java.awt.image DataBuffer TYPE_BYTE.

Prototype

int TYPE_BYTE

To view the source code for java.awt.image DataBuffer TYPE_BYTE.

Click Source Link

Document

Tag for unsigned byte data.

Usage

From source file:PngEncoder.java

/**
 * Creates a PNG encoder for an image.//from   w  ww.  j  a v a2s. c  om
 *
 * @param image the image to be encoded
 * @param encodeAlpha true if the image's alpha channel should be encoded
 * @param filter The filter to be applied to the image data, one of the 
 *        following values:
 *        <ul>
 *        <li>SUB_FILTER</li>
 *        <li>UP_FILTER</li>
 *        <li>AVERAGE_FILTER</li>
 *        <li>PAETH_FILTER</li>
 *        </ul>
 *        If a null value is specified, no filtering will be performed.
 * @param compressionLevel the deflater compression level that will be used
 *        for compressing the image data:  Valid values range from 0 to 9.
 *        Higher values result in smaller files and therefore decrease
 *        network traffic, but require more CPU time to encode.  The normal
 *        compromise value is 3.
 */
public PngEncoder(Image image, boolean encodeAlpha, Filter filter, int compressionLevel) {
    super();

    this.image = ImageToBufferedImage.toBufferedImage(image);
    this.filter = filter;
    this.compressionLevel = compressionLevel;

    width = this.image.getWidth(null);
    height = this.image.getHeight(null);
    raster = this.image.getRaster();
    transferType = raster.getTransferType();

    // Establish storage information
    int dataBytes = raster.getNumDataElements();
    if (transferType == DataBuffer.TYPE_BYTE && dataBytes == 4) {
        outputBpp = encodeAlpha ? 4 : 3;
        inputBpp = 4;
        translator = new ByteTranslator();
    } else if (transferType == DataBuffer.TYPE_BYTE && dataBytes == 3) {
        outputBpp = 3;
        inputBpp = 3;
        encodeAlpha = false;
        translator = new ByteTranslator();
    } else if (transferType == DataBuffer.TYPE_INT && dataBytes == 1) {
        outputBpp = encodeAlpha ? 4 : 3;
        inputBpp = 4;
        translator = new IntTranslator();
    } else if (transferType == DataBuffer.TYPE_BYTE && dataBytes == 1) {
        throw new UnsupportedOperationException("Encoding indexed-color images not yet supported.");
    } else {
        throw new IllegalArgumentException("Cannot determine appropriate bits-per-pixel for provided image.");
    }
}

From source file:GraphicsUtil.java

public static boolean is_BYTE_COMP_Data(SampleModel sm) {
    // Check ColorModel is of type DirectColorModel
    if (!(sm instanceof ComponentSampleModel))
        return false;

    // Check transfer type
    if (sm.getDataType() != DataBuffer.TYPE_BYTE)
        return false;

    return true;/*from   ww w  .  j  a va2 s  . c o  m*/
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testRangeTimeByte1or2Points() {
    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testRangeTimeByte(rangeB2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_SHORT:
            testRangeTimeShort(rangeS2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_INT:
            testRangeTimeInteger(rangeI2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_FLOAT:
            testRangeTimeFloat(rangeF2bounds, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testRangeTimeDouble(rangeD2bounds, SINGLE_POINT);
            break;
        default://from   w w  w  .ja va2 s.c  om
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testRangeTimeByte(rangeBpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_SHORT:
            testRangeTimeShort(rangeSpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_INT:
            testRangeTimeInteger(rangeIpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_FLOAT:
            testRangeTimeFloat(rangeFpoint, SINGLE_POINT);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testRangeTimeDouble(rangeDpoint, SINGLE_POINT);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:org.photovault.dcraw.RawImage.java

/**
 *     Get a 8 bit gamma corrected version of the image.
 * @param minWidth Minimum width for the image that will be rendered
 * @param minHeight Minimum height for the image that will be rendered
 * @param isLowQualityAcceptable If true, renderer may use optimizations that
 * trade off image quality for speed./*  w  w  w  .  j a va  2s . c om*/
 * @return The corrected image
 */
public RenderableOp getCorrectedImage(int minWidth, int minHeight, boolean isLowQualityAcceptable) {

    int maxSubsample = 1;
    if (minWidth > 0 && minHeight > 0) {
        while (width >= minWidth * 2 * maxSubsample && height >= minHeight * 2 * maxSubsample) {
            maxSubsample *= 2;
        }
    }
    if (rawImage == null || maxSubsample < subsample) {
        // dcraw.setHalfSize( isHalfSizeEnough );
        if (maxSubsample == 1 && subsample > 1) {
            // The image has been loaded with 1/2 resolution so reloading
            // cannot be avoided
            closeRaw();
        }
        subsample = maxSubsample;
        loadRawImage();
        correctedImage = null;
    }
    if (correctedImage == null) {
        RenderingHints nonCachedHints = new RenderingHints(JAI.KEY_TILE_CACHE, null);

        // TODO: Why setting color model as a rendering hint produces black image???
        RawConvDescriptor.register();
        ParameterBlock pb = new ParameterBlockJAI("RawConv");
        pb.setSource(wbAdjustedRawImage, 0);
        pb.set(white, 0);
        pb.set(black, 1);
        pb.set(highlightCompression, 2);
        rawConverter = JAI.createRenderable("RawConv", pb, nonCachedHints);
        rawConverter.setProperty("org.photovault.opname", "raw_toneadj_image");
        applyExposureSettings();

        // Convert from linear to gamma corrected
        createGammaLut();
        LookupTableJAI jailut = new LookupTableJAI(gammaLut);
        correctedImage = LookupDescriptor.createRenderable(rawConverter, jailut, null);
        correctedImage.setProperty("org.photovault.opname", "gamma_lut_image");
        // Store the color model of the image
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        cm = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, Transparency.OPAQUE,
                DataBuffer.TYPE_BYTE);

    }
    return correctedImage;
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testJaiToolsRangeTimeByte1or2Points() {
    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJaiToolsRangeTime(rangeJTB, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJaiToolsRangeTime(rangeJTS, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJaiToolsRangeTime(rangeJTI, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJaiToolsRangeTime(rangeJTF, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJaiToolsRangeTime(rangeJTD, SINGLE_POINT, arrayDtest);
            break;
        default:/*from www  .  ja  v  a 2s  .co  m*/
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJaiToolsRangeTime(rangeJTBpoint, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJaiToolsRangeTime(rangeJTSpoint, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJaiToolsRangeTime(rangeJTIpoint, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJaiToolsRangeTime(rangeJTFpoint, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJaiToolsRangeTime(rangeJTDpoint, SINGLE_POINT, arrayDtest);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:org.geoserver.catalog.CoverageViewReader.java

private ColorModel getColorModelWithAlpha(int currentBandCount) {
    if (currentBandCount == 3) {
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        int[] nBits = { 8, 8, 8, 8 };
        return new ComponentColorModel(cs, nBits, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    } else if (currentBandCount == 1) {
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
        int[] nBits = { 8, 8 };
        return new ComponentColorModel(cs, nBits, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    } else {//from   w ww. j av  a  2  s  .  c  o m
        throw new IllegalArgumentException("Cannot create a color model with alpha" + "support starting with "
                + currentBandCount + " bands");
    }
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testJAIRangeTimeByte1or2Points() {
    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJAIRangeTime(rangeJAIB, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJAIRangeTime(rangeJAIS, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJAIRangeTime(rangeJAII, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJAIRangeTime(rangeJAIF, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJAIRangeTime(rangeJAID, SINGLE_POINT, arrayDtest);
            break;
        default://  w ww  .j  av a  2 s  .  c  o  m
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testJAIRangeTime(rangeJAIBpoint, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testJAIRangeTime(rangeJAISpoint, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testJAIRangeTime(rangeJAIIpoint, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testJAIRangeTime(rangeJAIFpoint, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testJAIRangeTime(rangeJAIDpoint, SINGLE_POINT, arrayDtest);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:com.celements.photo.image.GenerateThumbnail.java

private String getHashOfImage(BufferedImage img) throws NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance(ImageLibStrings.HASHING_ALGORITHM);

    PixelAccessor pa = new PixelAccessor(img);
    UnpackedImageData uid = pa.getPixels(img.getData(), img.getData().getBounds(), DataBuffer.TYPE_BYTE, false);
    byte[][] pixels = uid.getByteData();
    for (int i = 0; i < pixels.length; i++) {
        digest.update(pixels[i]);//from  w ww.  jav  a2s  . c o m
    }

    return new String(digest.digest());
}

From source file:it.geosolutions.jaiext.range.RangeTest.java

@Test
public void testApacheCommonRangeTimeByte1or2Points() {

    if (!SINGLE_POINT) {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testApacheCommonsRangeTime(rangeCommonsB, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testApacheCommonsRangeTime(rangeCommonsS, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testApacheCommonsRangeTime(rangeCommonsI, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testApacheCommonsRangeTime(rangeCommonsF, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testApacheCommonsRangeTime(rangeCommonsD, SINGLE_POINT, arrayDtest);
            break;
        default://from   ww  w. ja v  a  2  s  .c o  m
            throw new IllegalArgumentException("Wrong data type");
        }
    } else {
        switch (TEST_SELECTOR) {
        case DataBuffer.TYPE_BYTE:
            testApacheCommonsRangeTime(rangeCommonsBpoint, SINGLE_POINT, arrayBtest);
            break;
        case DataBuffer.TYPE_SHORT:
            testApacheCommonsRangeTime(rangeCommonsSpoint, SINGLE_POINT, arrayStest);
            break;
        case DataBuffer.TYPE_INT:
            testApacheCommonsRangeTime(rangeCommonsIpoint, SINGLE_POINT, arrayItest);
            break;
        case DataBuffer.TYPE_FLOAT:
            testApacheCommonsRangeTime(rangeCommonsFpoint, SINGLE_POINT, arrayFtest);
            break;
        case DataBuffer.TYPE_DOUBLE:
            testApacheCommonsRangeTime(rangeCommonsDpoint, SINGLE_POINT, arrayDtest);
            break;
        default:
            throw new IllegalArgumentException("Wrong data type");
        }
    }
}

From source file:org.apache.xmlgraphics.ps.PSImageUtils.java

/**
 * Extracts a packed RGB integer array of a RenderedImage.
 * @param img the image//  w  ww . j a  v a2s .c  om
 * @param startX the starting X coordinate
 * @param startY the starting Y coordinate
 * @param w the width of the cropped image
 * @param h the height of the cropped image
 * @param rgbArray the prepared integer array to write to
 * @param offset offset in the target array
 * @param scansize width of a row in the target array
 * @return the populated integer array previously passed in as rgbArray parameter
 */
public static int[] getRGB(RenderedImage img, int startX, int startY, int w, int h, int[] rgbArray, int offset,
        int scansize) {
    Raster raster = img.getData();
    int yoff = offset;
    int off;
    Object data;
    int nbands = raster.getNumBands();
    int dataType = raster.getDataBuffer().getDataType();
    switch (dataType) {
    case DataBuffer.TYPE_BYTE:
        data = new byte[nbands];
        break;
    case DataBuffer.TYPE_USHORT:
        data = new short[nbands];
        break;
    case DataBuffer.TYPE_INT:
        data = new int[nbands];
        break;
    case DataBuffer.TYPE_FLOAT:
        data = new float[nbands];
        break;
    case DataBuffer.TYPE_DOUBLE:
        data = new double[nbands];
        break;
    default:
        throw new IllegalArgumentException("Unknown data buffer type: " + dataType);
    }

    if (rgbArray == null) {
        rgbArray = new int[offset + h * scansize];
    }

    ColorModel colorModel = img.getColorModel();
    for (int y = startY; y < startY + h; y++, yoff += scansize) {
        off = yoff;
        for (int x = startX; x < startX + w; x++) {
            rgbArray[off++] = colorModel.getRGB(raster.getDataElements(x, y, data));
        }
    }

    return rgbArray;
}