Search in sources :

Example 6 with ComponentSampleModel

use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.

the class LCMSImageLayout method createImageLayout.

public static LCMSImageLayout createImageLayout(Raster r) {
    LCMSImageLayout l = new LCMSImageLayout();
    if (r instanceof ByteComponentRaster && r.getSampleModel() instanceof ComponentSampleModel) {
        ByteComponentRaster br = (ByteComponentRaster) r;
        ComponentSampleModel csm = (ComponentSampleModel) r.getSampleModel();
        l.pixelType = CHANNELS_SH(br.getNumBands()) | BYTES_SH(1);
        int[] bandOffsets = csm.getBandOffsets();
        BandOrder order = BandOrder.getBandOrder(bandOffsets);
        int firstBand = 0;
        switch(order) {
            case INVERTED:
                l.pixelType |= DOSWAP;
                firstBand = csm.getNumBands() - 1;
                break;
            case DIRECT:
                // do nothing
                break;
            default:
                // unable to create the image layout;
                return null;
        }
        l.nextRowOffset = br.getScanlineStride();
        l.nextPixelOffset = br.getPixelStride();
        l.offset = br.getDataOffset(firstBand);
        l.dataArray = br.getDataStorage();
        l.dataType = DT_BYTE;
        l.width = br.getWidth();
        l.height = br.getHeight();
        if (l.nextRowOffset == l.width * br.getPixelStride()) {
            l.imageAtOnce = true;
        }
        return l;
    }
    return null;
}
Also used : ByteComponentRaster(sun.awt.image.ByteComponentRaster) ComponentSampleModel(java.awt.image.ComponentSampleModel)

Example 7 with ComponentSampleModel

use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.

the class ImageUtil method getBandSize.

public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());
    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel) sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);
        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
Also used : ComponentSampleModel(java.awt.image.ComponentSampleModel) Point(java.awt.Point)

Example 8 with ComponentSampleModel

use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.

the class BMPImageReader method read8Bit.

// Method to read 8 bit BMP image data
private void read8Bit(byte[] bdata) throws IOException {
    // Padding bytes at the end of each scanline
    int padding = width % 4;
    if (padding != 0) {
        padding = 4 - padding;
    }
    int lineLength = width + padding;
    if (noTransform) {
        int j = isBottomUp ? (height - 1) * width : 0;
        for (int i = 0; i < height; i++) {
            if (abortRequested()) {
                break;
            }
            iis.readFully(bdata, j, width);
            iis.skipBytes(padding);
            j += isBottomUp ? -width : width;
            processImageUpdate(bi, 0, i, destinationRegion.width, 1, 1, 1, new int[] { 0 });
            processImageProgress(100.0F * i / destinationRegion.height);
        }
    } else {
        byte[] buf = new byte[lineLength];
        int lineStride = ((ComponentSampleModel) sampleModel).getScanlineStride();
        if (isBottomUp) {
            int lastLine = sourceRegion.y + (destinationRegion.height - 1) * scaleY;
            iis.skipBytes(lineLength * (height - 1 - lastLine));
        } else
            iis.skipBytes(lineLength * sourceRegion.y);
        int skipLength = lineLength * (scaleY - 1);
        int k = destinationRegion.y * lineStride;
        if (isBottomUp)
            k += (destinationRegion.height - 1) * lineStride;
        k += destinationRegion.x;
        for (int j = 0, y = sourceRegion.y; j < destinationRegion.height; j++, y += scaleY) {
            if (abortRequested())
                break;
            iis.read(buf, 0, lineLength);
            for (int i = 0, m = sourceRegion.x; i < destinationRegion.width; i++, m += scaleX) {
                //get the bit and assign to the data buffer of the raster
                bdata[k + i] = buf[m];
            }
            k += isBottomUp ? -lineStride : lineStride;
            iis.skipBytes(skipLength);
            processImageUpdate(bi, 0, j, destinationRegion.width, 1, 1, 1, new int[] { 0 });
            processImageProgress(100.0F * j / destinationRegion.height);
        }
    }
}
Also used : ComponentSampleModel(java.awt.image.ComponentSampleModel) Point(java.awt.Point)

Example 9 with ComponentSampleModel

use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.

the class BMPImageReader method decodeRLE8.

private void decodeRLE8(int imSize, int padding, byte[] values, byte[] bdata) throws IOException {
    byte[] val = new byte[width * height];
    int count = 0, l = 0;
    int value;
    boolean flag = false;
    int lineNo = isBottomUp ? height - 1 : 0;
    int lineStride = ((ComponentSampleModel) sampleModel).getScanlineStride();
    int finished = 0;
    while (count != imSize) {
        value = values[count++] & 0xff;
        if (value == 0) {
            switch(values[count++] & 0xff) {
                case 0:
                    // End-of-scanline marker
                    if (lineNo >= sourceRegion.y && lineNo < sourceRegion.y + sourceRegion.height) {
                        if (noTransform) {
                            int pos = lineNo * width;
                            for (int i = 0; i < width; i++) bdata[pos++] = val[i];
                            processImageUpdate(bi, 0, lineNo, destinationRegion.width, 1, 1, 1, new int[] { 0 });
                            finished++;
                        } else if ((lineNo - sourceRegion.y) % scaleY == 0) {
                            int currentLine = (lineNo - sourceRegion.y) / scaleY + destinationRegion.y;
                            int pos = currentLine * lineStride;
                            pos += destinationRegion.x;
                            for (int i = sourceRegion.x; i < sourceRegion.x + sourceRegion.width; i += scaleX) bdata[pos++] = val[i];
                            processImageUpdate(bi, 0, currentLine, destinationRegion.width, 1, 1, 1, new int[] { 0 });
                            finished++;
                        }
                    }
                    processImageProgress(100.0F * finished / destinationRegion.height);
                    lineNo += isBottomUp ? -1 : 1;
                    l = 0;
                    if (abortRequested()) {
                        flag = true;
                    }
                    break;
                case 1:
                    // End-of-RLE marker
                    flag = true;
                    break;
                case 2:
                    // delta or vector marker
                    int xoff = values[count++] & 0xff;
                    int yoff = values[count] & 0xff;
                    // Move to the position xoff, yoff down
                    l += xoff + yoff * width;
                    break;
                default:
                    int end = values[count - 1] & 0xff;
                    for (int i = 0; i < end; i++) {
                        val[l++] = (byte) (values[count++] & 0xff);
                    }
                    // an extra padding byte will be present, so skip that.
                    if ((end & 1) == 1) {
                        count++;
                    }
            }
        } else {
            for (int i = 0; i < value; i++) {
                val[l++] = (byte) (values[count] & 0xff);
            }
            count++;
        }
        // If End-of-RLE data, then exit the while loop
        if (flag) {
            break;
        }
    }
}
Also used : ComponentSampleModel(java.awt.image.ComponentSampleModel) Point(java.awt.Point)

Example 10 with ComponentSampleModel

use of java.awt.image.ComponentSampleModel in project jdk8u_jdk by JetBrains.

the class ImageUtil method imageIsContiguous.

/**
     * Returns whether the image has contiguous data across rows.
     */
public static final boolean imageIsContiguous(RenderedImage image) {
    SampleModel sm;
    if (image instanceof BufferedImage) {
        WritableRaster ras = ((BufferedImage) image).getRaster();
        sm = ras.getSampleModel();
    } else {
        sm = image.getSampleModel();
    }
    if (sm instanceof ComponentSampleModel) {
        // Ensure image rows samples are stored contiguously
        // in a single bank.
        ComponentSampleModel csm = (ComponentSampleModel) sm;
        if (csm.getPixelStride() != csm.getNumBands()) {
            return false;
        }
        int[] bandOffsets = csm.getBandOffsets();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] != i) {
                return false;
            }
        }
        int[] bankIndices = csm.getBankIndices();
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bankIndices[i] != 0) {
                return false;
            }
        }
        return true;
    }
    // pixel stride.
    return ImageUtil.isBinary(sm);
}
Also used : ComponentSampleModel(java.awt.image.ComponentSampleModel) SampleModel(java.awt.image.SampleModel) MultiPixelPackedSampleModel(java.awt.image.MultiPixelPackedSampleModel) SinglePixelPackedSampleModel(java.awt.image.SinglePixelPackedSampleModel) WritableRaster(java.awt.image.WritableRaster) ComponentSampleModel(java.awt.image.ComponentSampleModel) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point)

Aggregations

ComponentSampleModel (java.awt.image.ComponentSampleModel)12 Point (java.awt.Point)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)6 SampleModel (java.awt.image.SampleModel)5 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)5 ColorModel (java.awt.image.ColorModel)4 IndexColorModel (java.awt.image.IndexColorModel)4 DirectColorModel (java.awt.image.DirectColorModel)3 WritableRaster (java.awt.image.WritableRaster)3 ByteComponentRaster (sun.awt.image.ByteComponentRaster)3 BufferedImage (java.awt.image.BufferedImage)2 ComponentColorModel (java.awt.image.ComponentColorModel)2 DataBufferByte (java.awt.image.DataBufferByte)2 Raster (java.awt.image.Raster)2 LZWCompressor (com.sun.imageio.plugins.common.LZWCompressor)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 ColorSpace (java.awt.color.ColorSpace)1 AffineTransform (java.awt.geom.AffineTransform)1