Search in sources :

Example 1 with ByteComponentRaster

use of sun.awt.image.ByteComponentRaster in project jdk8u_jdk by JetBrains.

the class PSPathGraphics method drawImageToPlatform.

/**
     * The various <code>drawImage()</code> methods for
     * <code>WPathGraphics</code> are all decomposed
     * into an invocation of <code>drawImageToPlatform</code>.
     * The portion of the passed in image defined by
     * <code>srcX, srcY, srcWidth, and srcHeight</code>
     * is transformed by the supplied AffineTransform and
     * drawn using PS to the printer context.
     *
     * @param   img     The image to be drawn.
     *                  This method does nothing if <code>img</code> is null.
     * @param   xform   Used to transform the image before drawing.
     *                  This can be null.
     * @param   bgcolor This color is drawn where the image has transparent
     *                  pixels. If this parameter is null then the
     *                  pixels already in the destination should show
     *                  through.
     * @param   srcX    With srcY this defines the upper-left corner
     *                  of the portion of the image to be drawn.
     *
     * @param   srcY    With srcX this defines the upper-left corner
     *                  of the portion of the image to be drawn.
     * @param   srcWidth    The width of the portion of the image to
     *                      be drawn.
     * @param   srcHeight   The height of the portion of the image to
     *                      be drawn.
     * @param   handlingTransparency if being recursively called to
     *                    print opaque region of transparent image
     */
protected boolean drawImageToPlatform(Image image, AffineTransform xform, Color bgcolor, int srcX, int srcY, int srcWidth, int srcHeight, boolean handlingTransparency) {
    BufferedImage img = getBufferedImage(image);
    if (img == null) {
        return true;
    }
    PSPrinterJob psPrinterJob = (PSPrinterJob) getPrinterJob();
    /* The full transform to be applied to the image is the
         * caller's transform concatenated on to the transform
         * from user space to device space. If the caller didn't
         * supply a transform then we just act as if they passed
         * in the identify transform.
         */
    AffineTransform fullTransform = getTransform();
    if (xform == null) {
        xform = new AffineTransform();
    }
    fullTransform.concatenate(xform);
    /* Split the full transform into a pair of
         * transforms. The first transform holds effects
         * such as rotation and shearing. The second transform
         * is setup to hold only the scaling effects.
         * These transforms are created such that a point,
         * p, in user space, when transformed by 'fullTransform'
         * lands in the same place as when it is transformed
         * by 'rotTransform' and then 'scaleTransform'.
         *
         * The entire image transformation is not in Java in order
         * to minimize the amount of memory needed in the VM. By
         * dividing the transform in two, we rotate and shear
         * the source image in its own space and only go to
         * the, usually, larger, device space when we ask
         * PostScript to perform the final scaling.
         */
    double[] fullMatrix = new double[6];
    fullTransform.getMatrix(fullMatrix);
    /* Calculate the amount of scaling in the x
         * and y directions. This scaling is computed by
         * transforming a unit vector along each axis
         * and computing the resulting magnitude.
         * The computed values 'scaleX' and 'scaleY'
         * represent the amount of scaling PS will be asked
         * to perform.
         * Clamp this to the device scale for better quality printing.
         */
    Point2D.Float unitVectorX = new Point2D.Float(1, 0);
    Point2D.Float unitVectorY = new Point2D.Float(0, 1);
    fullTransform.deltaTransform(unitVectorX, unitVectorX);
    fullTransform.deltaTransform(unitVectorY, unitVectorY);
    Point2D.Float origin = new Point2D.Float(0, 0);
    double scaleX = unitVectorX.distance(origin);
    double scaleY = unitVectorY.distance(origin);
    double devResX = psPrinterJob.getXRes();
    double devResY = psPrinterJob.getYRes();
    double devScaleX = devResX / DEFAULT_USER_RES;
    double devScaleY = devResY / DEFAULT_USER_RES;
    /* check if rotated or sheared */
    int transformType = fullTransform.getType();
    boolean clampScale = ((transformType & (AffineTransform.TYPE_GENERAL_ROTATION | AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);
    if (clampScale) {
        if (scaleX > devScaleX)
            scaleX = devScaleX;
        if (scaleY > devScaleY)
            scaleY = devScaleY;
    }
    /* We do not need to draw anything if either scaling
         * factor is zero.
         */
    if (scaleX != 0 && scaleY != 0) {
        /* Here's the transformation we will do with Java2D,
            */
        AffineTransform rotTransform = new AffineTransform(//m00
        fullMatrix[0] / scaleX, //m10
        fullMatrix[1] / scaleY, //m01
        fullMatrix[2] / scaleX, //m11
        fullMatrix[3] / scaleY, //m02
        fullMatrix[4] / scaleX, //m12
        fullMatrix[5] / scaleY);
        /* The scale transform is not used directly: we instead
             * directly multiply by scaleX and scaleY.
             *
             * Conceptually here is what the scaleTransform is:
             *
             * AffineTransform scaleTransform = new AffineTransform(
             *                      scaleX,                     //m00
             *                      0,                          //m10
             *                      0,                          //m01
             *                      scaleY,                     //m11
             *                      0,                          //m02
             *                      0);                         //m12
             */
        /* Convert the image source's rectangle into the rotated
             * and sheared space. Once there, we calculate a rectangle
             * that encloses the resulting shape. It is this rectangle
             * which defines the size of the BufferedImage we need to
             * create to hold the transformed image.
             */
        Rectangle2D.Float srcRect = new Rectangle2D.Float(srcX, srcY, srcWidth, srcHeight);
        Shape rotShape = rotTransform.createTransformedShape(srcRect);
        Rectangle2D rotBounds = rotShape.getBounds2D();
        /* add a fudge factor as some fp precision problems have
             * been observed which caused pixels to be rounded down and
             * out of the image.
             */
        rotBounds.setRect(rotBounds.getX(), rotBounds.getY(), rotBounds.getWidth() + 0.001, rotBounds.getHeight() + 0.001);
        int boundsWidth = (int) rotBounds.getWidth();
        int boundsHeight = (int) rotBounds.getHeight();
        if (boundsWidth > 0 && boundsHeight > 0) {
            /* If the image has transparent or semi-transparent
                 * pixels then we'll have the application re-render
                 * the portion of the page covered by the image.
                 * This will be done in a later call to print using the
                 * saved graphics state.
                 * However several special cases can be handled otherwise:
                 * - bitmask transparency with a solid background colour
                 * - images which have transparency color models but no
                 * transparent pixels
                 * - images with bitmask transparency and an IndexColorModel
                 * (the common transparent GIF case) can be handled by
                 * rendering just the opaque pixels.
                 */
            boolean drawOpaque = true;
            if (!handlingTransparency && hasTransparentPixels(img)) {
                drawOpaque = false;
                if (isBitmaskTransparency(img)) {
                    if (bgcolor == null) {
                        if (drawBitmaskImage(img, xform, bgcolor, srcX, srcY, srcWidth, srcHeight)) {
                            // image drawn, just return.
                            return true;
                        }
                    } else if (bgcolor.getTransparency() == Transparency.OPAQUE) {
                        drawOpaque = true;
                    }
                }
                if (!canDoRedraws()) {
                    drawOpaque = true;
                }
            } else {
                // if there's no transparent pixels there's no need
                // for a background colour. This can avoid edge artifacts
                // in rotation cases.
                bgcolor = null;
            }
            // may blit b/g colour (including white) where it shoudn't.
            if ((srcX + srcWidth > img.getWidth(null) || srcY + srcHeight > img.getHeight(null)) && canDoRedraws()) {
                drawOpaque = false;
            }
            if (drawOpaque == false) {
                fullTransform.getMatrix(fullMatrix);
                AffineTransform tx = new AffineTransform(//m00
                fullMatrix[0] / devScaleX, //m10
                fullMatrix[1] / devScaleY, //m01
                fullMatrix[2] / devScaleX, //m11
                fullMatrix[3] / devScaleY, //m02
                fullMatrix[4] / devScaleX, //m12
                fullMatrix[5] / devScaleY);
                Rectangle2D.Float rect = new Rectangle2D.Float(srcX, srcY, srcWidth, srcHeight);
                Shape shape = fullTransform.createTransformedShape(rect);
                // Region isn't user space because its potentially
                // been rotated for landscape.
                Rectangle2D region = shape.getBounds2D();
                region.setRect(region.getX(), region.getY(), region.getWidth() + 0.001, region.getHeight() + 0.001);
                // Try to limit the amount of memory used to 8Mb, so
                // if at device resolution this exceeds a certain
                // image size then scale down the region to fit in
                // that memory, but never to less than 72 dpi.
                int w = (int) region.getWidth();
                int h = (int) region.getHeight();
                int nbytes = w * h * 3;
                int maxBytes = 8 * 1024 * 1024;
                double origDpi = (devResX < devResY) ? devResX : devResY;
                int dpi = (int) origDpi;
                double scaleFactor = 1;
                double maxSFX = w / (double) boundsWidth;
                double maxSFY = h / (double) boundsHeight;
                double maxSF = (maxSFX > maxSFY) ? maxSFY : maxSFX;
                int minDpi = (int) (dpi / maxSF);
                if (minDpi < DEFAULT_USER_RES)
                    minDpi = DEFAULT_USER_RES;
                while (nbytes > maxBytes && dpi > minDpi) {
                    scaleFactor *= 2;
                    dpi /= 2;
                    nbytes /= 4;
                }
                if (dpi < minDpi) {
                    scaleFactor = (origDpi / minDpi);
                }
                region.setRect(region.getX() / scaleFactor, region.getY() / scaleFactor, region.getWidth() / scaleFactor, region.getHeight() / scaleFactor);
                /*
                     * We need to have the clip as part of the saved state,
                     * either directly, or all the components that are
                     * needed to reconstitute it (image source area,
                     * image transform and current graphics transform).
                     * The clip is described in user space, so we need to
                     * save the current graphics transform anyway so just
                     * save these two.
                     */
                psPrinterJob.saveState(getTransform(), getClip(), region, scaleFactor, scaleFactor);
                return true;
            /* The image can be rendered directly by PS so we
                 * copy it into a BufferedImage (this takes care of
                 * ColorSpace and BufferedImageOp issues) and then
                 * send that to PS.
                 */
            } else {
                /* Create a buffered image big enough to hold the portion
                     * of the source image being printed.
                     */
                BufferedImage deepImage = new BufferedImage((int) rotBounds.getWidth(), (int) rotBounds.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
                /* Setup a Graphics2D on to the BufferedImage so that the
                     * source image when copied, lands within the image buffer.
                     */
                Graphics2D imageGraphics = deepImage.createGraphics();
                imageGraphics.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
                imageGraphics.translate(-rotBounds.getX(), -rotBounds.getY());
                imageGraphics.transform(rotTransform);
                /* Fill the BufferedImage either with the caller supplied
                     * color, 'bgColor' or, if null, with white.
                     */
                if (bgcolor == null) {
                    bgcolor = Color.white;
                }
                /* REMIND: no need to use scaling here. */
                imageGraphics.drawImage(img, srcX, srcY, srcX + srcWidth, srcY + srcHeight, srcX, srcY, srcX + srcWidth, srcY + srcHeight, bgcolor, null);
                /* In PSPrinterJob images are printed in device space
                     * and therefore we need to set a device space clip.
                     * FIX: this is an overly tight coupling of these
                     * two classes.
                     * The temporary clip set needs to be an intersection
                     * with the previous user clip.
                     * REMIND: two xfms may lose accuracy in clip path.
                     */
                Shape holdClip = getClip();
                Shape oldClip = getTransform().createTransformedShape(holdClip);
                AffineTransform sat = AffineTransform.getScaleInstance(scaleX, scaleY);
                Shape imgClip = sat.createTransformedShape(rotShape);
                Area imgArea = new Area(imgClip);
                Area oldArea = new Area(oldClip);
                imgArea.intersect(oldArea);
                psPrinterJob.setClip(imgArea);
                /* Scale the bounding rectangle by the scale transform.
                     * Because the scaling transform has only x and y
                     * scaling components it is equivalent to multiply
                     * the x components of the bounding rectangle by
                     * the x scaling factor and to multiply the y components
                     * by the y scaling factor.
                     */
                Rectangle2D.Float scaledBounds = new Rectangle2D.Float((float) (rotBounds.getX() * scaleX), (float) (rotBounds.getY() * scaleY), (float) (rotBounds.getWidth() * scaleX), (float) (rotBounds.getHeight() * scaleY));
                /* Pull the raster data from the buffered image
                     * and pass it along to PS.
                     */
                ByteComponentRaster tile = (ByteComponentRaster) deepImage.getRaster();
                psPrinterJob.drawImageBGR(tile.getDataStorage(), scaledBounds.x, scaledBounds.y, (float) Math.rint(scaledBounds.width + 0.5), (float) Math.rint(scaledBounds.height + 0.5), 0f, 0f, deepImage.getWidth(), deepImage.getHeight(), deepImage.getWidth(), deepImage.getHeight());
                /* Reset the device clip to match user clip */
                psPrinterJob.setClip(getTransform().createTransformedShape(holdClip));
                imageGraphics.dispose();
            }
        }
    }
    return true;
}
Also used : Shape(java.awt.Shape) Rectangle2D(java.awt.geom.Rectangle2D) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Area(java.awt.geom.Area) Point2D(java.awt.geom.Point2D) ByteComponentRaster(sun.awt.image.ByteComponentRaster) AffineTransform(java.awt.geom.AffineTransform)

Example 2 with ByteComponentRaster

use of sun.awt.image.ByteComponentRaster 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 3 with ByteComponentRaster

use of sun.awt.image.ByteComponentRaster 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 4 with ByteComponentRaster

use of sun.awt.image.ByteComponentRaster in project jdk8u_jdk by JetBrains.

the class GIFImageWriteParam method writeRasterData.

private void writeRasterData(RenderedImage image, Rectangle sourceBounds, Dimension destSize, ImageWriteParam param, boolean interlaceFlag) throws IOException {
    int sourceXOffset = sourceBounds.x;
    int sourceYOffset = sourceBounds.y;
    int sourceWidth = sourceBounds.width;
    int sourceHeight = sourceBounds.height;
    int destWidth = destSize.width;
    int destHeight = destSize.height;
    int periodX;
    int periodY;
    if (param == null) {
        periodX = 1;
        periodY = 1;
    } else {
        periodX = param.getSourceXSubsampling();
        periodY = param.getSourceYSubsampling();
    }
    SampleModel sampleModel = image.getSampleModel();
    int bitsPerPixel = sampleModel.getSampleSize()[0];
    int initCodeSize = bitsPerPixel;
    if (initCodeSize == 1) {
        initCodeSize++;
    }
    stream.write(initCodeSize);
    LZWCompressor compressor = new LZWCompressor(stream, initCodeSize, false);
    /* At this moment we know that input image is indexed image.
         * We can directly copy data iff:
         *   - no subsampling required (periodX = 1, periodY = 0)
         *   - we can access data directly (image is non-tiled,
         *     i.e. image data are in single block)
         *   - we can calculate offset in data buffer (next 3 lines)
         */
    boolean isOptimizedCase = periodX == 1 && periodY == 1 && image.getNumXTiles() == 1 && image.getNumYTiles() == 1 && sampleModel instanceof ComponentSampleModel && image.getTile(0, 0) instanceof ByteComponentRaster && image.getTile(0, 0).getDataBuffer() instanceof DataBufferByte;
    int numRowsWritten = 0;
    int progressReportRowPeriod = Math.max(destHeight / 20, 1);
    processImageStarted(imageIndex);
    if (interlaceFlag) {
        if (DEBUG)
            System.out.println("Writing interlaced");
        if (isOptimizedCase) {
            ByteComponentRaster tile = (ByteComponentRaster) image.getTile(0, 0);
            byte[] data = ((DataBufferByte) tile.getDataBuffer()).getData();
            ComponentSampleModel csm = (ComponentSampleModel) tile.getSampleModel();
            int offset = csm.getOffset(sourceXOffset, sourceYOffset, 0);
            // take into account the raster data offset
            offset += tile.getDataOffset(0);
            int lineStride = csm.getScanlineStride();
            writeRowsOpt(data, offset, lineStride, compressor, 0, 8, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
            if (abortRequested()) {
                return;
            }
            numRowsWritten += destHeight / 8;
            writeRowsOpt(data, offset, lineStride, compressor, 4, 8, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
            if (abortRequested()) {
                return;
            }
            numRowsWritten += (destHeight - 4) / 8;
            writeRowsOpt(data, offset, lineStride, compressor, 2, 4, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
            if (abortRequested()) {
                return;
            }
            numRowsWritten += (destHeight - 2) / 4;
            writeRowsOpt(data, offset, lineStride, compressor, 1, 2, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
        } else {
            writeRows(image, compressor, sourceXOffset, periodX, sourceYOffset, 8 * periodY, sourceWidth, 0, 8, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
            if (abortRequested()) {
                return;
            }
            numRowsWritten += destHeight / 8;
            writeRows(image, compressor, sourceXOffset, periodX, sourceYOffset + 4 * periodY, 8 * periodY, sourceWidth, 4, 8, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
            if (abortRequested()) {
                return;
            }
            numRowsWritten += (destHeight - 4) / 8;
            writeRows(image, compressor, sourceXOffset, periodX, sourceYOffset + 2 * periodY, 4 * periodY, sourceWidth, 2, 4, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
            if (abortRequested()) {
                return;
            }
            numRowsWritten += (destHeight - 2) / 4;
            writeRows(image, compressor, sourceXOffset, periodX, sourceYOffset + periodY, 2 * periodY, sourceWidth, 1, 2, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
        }
    } else {
        if (DEBUG)
            System.out.println("Writing non-interlaced");
        if (isOptimizedCase) {
            Raster tile = image.getTile(0, 0);
            byte[] data = ((DataBufferByte) tile.getDataBuffer()).getData();
            ComponentSampleModel csm = (ComponentSampleModel) tile.getSampleModel();
            int offset = csm.getOffset(sourceXOffset, sourceYOffset, 0);
            int lineStride = csm.getScanlineStride();
            writeRowsOpt(data, offset, lineStride, compressor, 0, 1, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
        } else {
            writeRows(image, compressor, sourceXOffset, periodX, sourceYOffset, periodY, sourceWidth, 0, 1, destWidth, destHeight, numRowsWritten, progressReportRowPeriod);
        }
    }
    if (abortRequested()) {
        return;
    }
    processImageProgress(100.0F);
    compressor.flush();
    stream.write(0x00);
    processImageComplete();
}
Also used : LZWCompressor(com.sun.imageio.plugins.common.LZWCompressor) ComponentSampleModel(java.awt.image.ComponentSampleModel) SampleModel(java.awt.image.SampleModel) ByteComponentRaster(sun.awt.image.ByteComponentRaster) Raster(java.awt.image.Raster) ByteComponentRaster(sun.awt.image.ByteComponentRaster) WritableRaster(java.awt.image.WritableRaster) ComponentSampleModel(java.awt.image.ComponentSampleModel) DataBufferByte(java.awt.image.DataBufferByte)

Example 5 with ByteComponentRaster

use of sun.awt.image.ByteComponentRaster in project jdk8u_jdk by JetBrains.

the class ImageRepresentation method convertToRGB.

private void convertToRGB() {
    int w = bimage.getWidth();
    int h = bimage.getHeight();
    int size = w * h;
    DataBufferInt dbi = new DataBufferInt(size);
    // Note that stealData() requires a markDirty() afterwards
    // since we modify the data in it.
    int[] newpixels = SunWritableRaster.stealData(dbi, 0);
    if (cmodel instanceof IndexColorModel && biRaster instanceof ByteComponentRaster && biRaster.getNumDataElements() == 1) {
        ByteComponentRaster bct = (ByteComponentRaster) biRaster;
        byte[] data = bct.getDataStorage();
        int coff = bct.getDataOffset(0);
        for (int i = 0; i < size; i++) {
            newpixels[i] = srcLUT[data[coff + i] & 0xff];
        }
    } else {
        Object srcpixels = null;
        int off = 0;
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                srcpixels = biRaster.getDataElements(x, y, srcpixels);
                newpixels[off++] = cmodel.getRGB(srcpixels);
            }
        }
    }
    // We modified the data array directly above so mark it as dirty now...
    SunWritableRaster.markDirty(dbi);
    isSameCM = false;
    cmodel = ColorModel.getRGBdefault();
    int[] bandMasks = { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
    biRaster = Raster.createPackedRaster(dbi, w, h, w, bandMasks, null);
    bimage = createImage(cmodel, biRaster, cmodel.isAlphaPremultiplied(), null);
    srcLUT = null;
    isDefaultBI = true;
}
Also used : ByteComponentRaster(sun.awt.image.ByteComponentRaster) DataBufferInt(java.awt.image.DataBufferInt) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

ByteComponentRaster (sun.awt.image.ByteComponentRaster)9 Graphics2D (java.awt.Graphics2D)4 AffineTransform (java.awt.geom.AffineTransform)4 Rectangle2D (java.awt.geom.Rectangle2D)4 BufferedImage (java.awt.image.BufferedImage)4 ComponentSampleModel (java.awt.image.ComponentSampleModel)3 IndexColorModel (java.awt.image.IndexColorModel)3 Shape (java.awt.Shape)2 Point2D (java.awt.geom.Point2D)2 ColorModel (java.awt.image.ColorModel)2 SampleModel (java.awt.image.SampleModel)2 WritableRaster (java.awt.image.WritableRaster)2 PageFormat (java.awt.print.PageFormat)2 Printable (java.awt.print.Printable)2 IntegerComponentRaster (sun.awt.image.IntegerComponentRaster)2 ProxyGraphics2D (sun.print.ProxyGraphics2D)2 LZWCompressor (com.sun.imageio.plugins.common.LZWCompressor)1 Area (java.awt.geom.Area)1 ComponentColorModel (java.awt.image.ComponentColorModel)1 DataBufferByte (java.awt.image.DataBufferByte)1