Search in sources :

Example 26 with ComponentColorModel

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

the class LCMSImageLayout method createImageLayout.

/* This method creates a layout object for given image.
     * Returns null if the image is not supported by current implementation.
     */
public static LCMSImageLayout createImageLayout(BufferedImage image) throws ImageLayoutException {
    LCMSImageLayout l = new LCMSImageLayout();
    switch(image.getType()) {
        case BufferedImage.TYPE_INT_RGB:
            l.pixelType = PT_ARGB_8;
            l.isIntPacked = true;
            break;
        case BufferedImage.TYPE_INT_ARGB:
            l.pixelType = PT_ARGB_8;
            l.isIntPacked = true;
            break;
        case BufferedImage.TYPE_INT_BGR:
            l.pixelType = PT_ABGR_8;
            l.isIntPacked = true;
            break;
        case BufferedImage.TYPE_3BYTE_BGR:
            l.pixelType = PT_BGR_8;
            break;
        case BufferedImage.TYPE_4BYTE_ABGR:
            l.pixelType = PT_ABGR_8;
            break;
        case BufferedImage.TYPE_BYTE_GRAY:
            l.pixelType = PT_GRAY_8;
            break;
        case BufferedImage.TYPE_USHORT_GRAY:
            l.pixelType = PT_GRAY_16;
            break;
        default:
            /* ColorConvertOp creates component images as
                 * default destination, so this kind of images
                 * has to be supported.
                 */
            ColorModel cm = image.getColorModel();
            if (cm instanceof ComponentColorModel) {
                ComponentColorModel ccm = (ComponentColorModel) cm;
                // verify whether the component size is fine
                int[] cs = ccm.getComponentSize();
                for (int s : cs) {
                    if (s != 8) {
                        return null;
                    }
                }
                return createImageLayout(image.getRaster());
            }
            return null;
    }
    l.width = image.getWidth();
    l.height = image.getHeight();
    switch(image.getType()) {
        case BufferedImage.TYPE_INT_RGB:
        case BufferedImage.TYPE_INT_ARGB:
        case BufferedImage.TYPE_INT_BGR:
            do {
                IntegerComponentRaster intRaster = (IntegerComponentRaster) image.getRaster();
                l.nextRowOffset = safeMult(4, intRaster.getScanlineStride());
                l.nextPixelOffset = safeMult(4, intRaster.getPixelStride());
                l.offset = safeMult(4, intRaster.getDataOffset(0));
                l.dataArray = intRaster.getDataStorage();
                l.dataArrayLength = 4 * intRaster.getDataStorage().length;
                l.dataType = DT_INT;
                if (l.nextRowOffset == l.width * 4 * intRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        case BufferedImage.TYPE_3BYTE_BGR:
        case BufferedImage.TYPE_4BYTE_ABGR:
            do {
                ByteComponentRaster byteRaster = (ByteComponentRaster) image.getRaster();
                l.nextRowOffset = byteRaster.getScanlineStride();
                l.nextPixelOffset = byteRaster.getPixelStride();
                int firstBand = image.getSampleModel().getNumBands() - 1;
                l.offset = byteRaster.getDataOffset(firstBand);
                l.dataArray = byteRaster.getDataStorage();
                l.dataArrayLength = byteRaster.getDataStorage().length;
                l.dataType = DT_BYTE;
                if (l.nextRowOffset == l.width * byteRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        case BufferedImage.TYPE_BYTE_GRAY:
            do {
                ByteComponentRaster byteRaster = (ByteComponentRaster) image.getRaster();
                l.nextRowOffset = byteRaster.getScanlineStride();
                l.nextPixelOffset = byteRaster.getPixelStride();
                l.dataArrayLength = byteRaster.getDataStorage().length;
                l.offset = byteRaster.getDataOffset(0);
                l.dataArray = byteRaster.getDataStorage();
                l.dataType = DT_BYTE;
                if (l.nextRowOffset == l.width * byteRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        case BufferedImage.TYPE_USHORT_GRAY:
            do {
                ShortComponentRaster shortRaster = (ShortComponentRaster) image.getRaster();
                l.nextRowOffset = safeMult(2, shortRaster.getScanlineStride());
                l.nextPixelOffset = safeMult(2, shortRaster.getPixelStride());
                l.offset = safeMult(2, shortRaster.getDataOffset(0));
                l.dataArray = shortRaster.getDataStorage();
                l.dataArrayLength = 2 * shortRaster.getDataStorage().length;
                l.dataType = DT_SHORT;
                if (l.nextRowOffset == l.width * 2 * shortRaster.getPixelStride()) {
                    l.imageAtOnce = true;
                }
            } while (false);
            break;
        default:
            return null;
    }
    l.verify();
    return l;
}
Also used : ShortComponentRaster(sun.awt.image.ShortComponentRaster) ColorModel(java.awt.image.ColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ByteComponentRaster(sun.awt.image.ByteComponentRaster) IntegerComponentRaster(sun.awt.image.IntegerComponentRaster)

Example 27 with ComponentColorModel

use of java.awt.image.ComponentColorModel in project Lucee by lucee.

the class Image method info.

public Struct info() throws PageException {
    if (sctInfo != null)
        return sctInfo;
    Struct sctInfo = new StructImpl(), sct;
    ImageMetaDrew.addInfo(format, source, sctInfo);
    sctInfo = ImageGetEXIFMetadata.flatten(sctInfo);
    sctInfo.setEL(KeyConstants._height, new Double(getHeight()));
    sctInfo.setEL(KeyConstants._width, new Double(getWidth()));
    sctInfo.setEL(KeyConstants._source, source == null ? "" : source.getAbsolutePath());
    // sct.setEL("mime_type",getMimeType());
    ColorModel cm = image().getColorModel();
    sct = new StructImpl();
    sctInfo.setEL("colormodel", sct);
    sct.setEL("alpha_channel_support", Caster.toBoolean(cm.hasAlpha()));
    sct.setEL("alpha_premultiplied", Caster.toBoolean(cm.isAlphaPremultiplied()));
    sct.setEL("transparency", toStringTransparency(cm.getTransparency()));
    sct.setEL("pixel_size", Caster.toDouble(cm.getPixelSize()));
    sct.setEL("num_components", Caster.toDouble(cm.getNumComponents()));
    sct.setEL("num_color_components", Caster.toDouble(cm.getNumColorComponents()));
    sct.setEL("colorspace", toStringColorSpace(cm.getColorSpace()));
    // bits_component
    int[] bitspercomponent = cm.getComponentSize();
    Array arr = new ArrayImpl();
    Double value;
    for (int i = 0; i < bitspercomponent.length; i++) {
        sct.setEL("bits_component_" + (i + 1), value = new Double(bitspercomponent[i]));
        arr.appendEL(value);
    }
    sct.setEL("bits_component", arr);
    // colormodel_type
    if (cm instanceof ComponentColorModel)
        sct.setEL("colormodel_type", "ComponentColorModel");
    else if (cm instanceof IndexColorModel)
        sct.setEL("colormodel_type", "IndexColorModel");
    else if (cm instanceof PackedColorModel)
        sct.setEL("colormodel_type", "PackedColorModel");
    else
        sct.setEL("colormodel_type", ListUtil.last(cm.getClass().getName(), '.'));
    getMetaData(sctInfo);
    // Metadata.addInfo(format,source,sctInfo);
    Metadata.addExifInfo(format, source, sctInfo);
    this.sctInfo = sctInfo;
    return sctInfo;
}
Also used : Array(lucee.runtime.type.Array) PackedColorModel(java.awt.image.PackedColorModel) StructImpl(lucee.runtime.type.StructImpl) IndexColorModel(java.awt.image.IndexColorModel) DirectColorModel(java.awt.image.DirectColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) PackedColorModel(java.awt.image.PackedColorModel) ColorModel(java.awt.image.ColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) ArrayImpl(lucee.runtime.type.ArrayImpl) Point(java.awt.Point) Struct(lucee.runtime.type.Struct) IndexColorModel(java.awt.image.IndexColorModel)

Example 28 with ComponentColorModel

use of java.awt.image.ComponentColorModel in project artisynth_core by artisynth.

the class GLSupport method getImageRGBA.

public static BufferedImage getImageRGBA(ByteBuffer buff, int width, int height) {
    final ComponentColorModel RGBA_COLOR = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 8 }, true, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    // sRGBA color model
    WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, 4, null);
    BufferedImage image = new BufferedImage(RGBA_COLOR, raster, false, null);
    // flip vertically
    int scanline = 4 * width;
    int pos = width * height * 4 - scanline;
    for (int i = 0; i < height; ++i) {
        for (int j = 0; j < scanline; ++j) {
            byte bb = buff.get();
            raster.getDataBuffer().setElem(pos + j, bb);
        }
        pos -= scanline;
    }
    return image;
}
Also used : ComponentColorModel(java.awt.image.ComponentColorModel) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage)

Example 29 with ComponentColorModel

use of java.awt.image.ComponentColorModel in project artisynth_core by artisynth.

the class DicomTextureContent method createImage.

public BufferedImage createImage() {
    ComponentColorModel colorModel = null;
    colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 8 }, true, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
    switch(internalStorage) {
        case UBYTE:
            colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] { 8 }, false, false, ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
            break;
        case UBYTE_RGB:
            colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] { 8, 8, 8, 0 }, false, false, ComponentColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
            break;
        case USHORT:
            colorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] { 16 }, false, false, ComponentColorModel.OPAQUE, DataBuffer.TYPE_USHORT);
            break;
        default:
    }
    // sRGBA color model
    WritableRaster raster = Raster.createInterleavedRaster(colorModel.getTransferType(), textureWidth, textureHeight, colorModel.getNumComponents(), null);
    BufferedImage image = new BufferedImage(colorModel, raster, false, null);
    synchronized (textureImage) {
        textureImage.position(0);
        textureImage.limit(textureImage.capacity());
        // flip vertically
        int scanline = textureWidth;
        int pos = textureWidth * textureHeight - scanline;
        for (int i = 0; i < textureHeight; ++i) {
            for (int j = 0; j < textureWidth; ++j) {
                switch(internalStorage) {
                    case UBYTE:
                        raster.getDataBuffer().setElem(pos + j, textureImage.get());
                        break;
                    case UBYTE_RGB:
                        raster.getDataBuffer().setElem(0, pos + j, textureImage.get());
                        raster.getDataBuffer().setElem(1, pos + j, textureImage.get());
                        raster.getDataBuffer().setElem(2, pos + j, textureImage.get());
                        break;
                    case USHORT:
                        raster.getDataBuffer().setElem(pos + j, textureImage.getShort());
                        break;
                    default:
                }
            }
            pos -= scanline;
        }
        textureImage.rewind();
    }
    return image;
}
Also used : ComponentColorModel(java.awt.image.ComponentColorModel) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage)

Example 30 with ComponentColorModel

use of java.awt.image.ComponentColorModel in project imageio-ext by geosolutions-it.

the class JP2KKakaduWriteTest method testReducedMemory.

public static void testReducedMemory() throws IOException {
    if (!isKakaduAvailable) {
        LOGGER.warning("Kakadu libs not found: test are skipped ");
        return;
    }
    System.setProperty(JP2KKakaduImageWriter.MAX_BUFFER_SIZE_KEY, "64K");
    final ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorModel cm = new ComponentColorModel(cs, new int[] { 16 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_USHORT);
    final int w = 512;
    final int h = 512;
    SampleModel sm = cm.createCompatibleSampleModel(w, h);
    final int bufferSize = w * h;
    final short[] bufferValues = new short[bufferSize];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) // bufferValues[j + (i * h)] = (short) ((j + i) * (65536 /
        // 1024));
        bufferValues[j + (i * h)] = (short) (Math.random() * 65535);
    }
    DataBuffer imageBuffer = new DataBufferUShort(bufferValues, bufferSize);
    BufferedImage bi = new BufferedImage(cm, Raster.createWritableRaster(sm, imageBuffer, null), false, null);
    write(outputFileName + "_RM", bi, true, lossLessQuality);
    write(outputFileName + "_RM", bi, false, lossLessQuality);
    write(outputFileName + "_RM", bi, true, lossyQuality);
    write(outputFileName + "_RM", bi, false, lossyQuality);
    LOGGER.info(writeOperations + " write operations performed");
}
Also used : SampleModel(java.awt.image.SampleModel) ColorSpace(java.awt.color.ColorSpace) ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) ComponentColorModel(java.awt.image.ComponentColorModel) DataBufferUShort(java.awt.image.DataBufferUShort) BufferedImage(java.awt.image.BufferedImage) DataBuffer(java.awt.image.DataBuffer)

Aggregations

ComponentColorModel (java.awt.image.ComponentColorModel)44 ColorModel (java.awt.image.ColorModel)28 BufferedImage (java.awt.image.BufferedImage)26 ColorSpace (java.awt.color.ColorSpace)22 WritableRaster (java.awt.image.WritableRaster)17 IndexColorModel (java.awt.image.IndexColorModel)11 SampleModel (java.awt.image.SampleModel)11 Point (java.awt.Point)9 DirectColorModel (java.awt.image.DirectColorModel)9 DataBufferByte (java.awt.image.DataBufferByte)8 DataBuffer (java.awt.image.DataBuffer)7 Graphics2D (java.awt.Graphics2D)5 ComponentSampleModel (java.awt.image.ComponentSampleModel)5 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)5 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)4 ByteBuffer (java.nio.ByteBuffer)4 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)3 DataBufferUShort (java.awt.image.DataBufferUShort)3 PixelInterleavedSampleModel (java.awt.image.PixelInterleavedSampleModel)3 File (java.io.File)3