类sun.awt.image.ByteComponentRaster源码实例Demo

下面列出了怎么用sun.awt.image.ByteComponentRaster的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: LCMSImageLayout.java
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;
}
 
源代码2 项目: dragonwell8_jdk   文件: PSPathGraphics.java
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* 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) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.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,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
源代码3 项目: dragonwell8_jdk   文件: ImageRepresentation.java
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;
}
 
源代码4 项目: dragonwell8_jdk   文件: ImageRepresentation.java
private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
int transPix, int numLut, IndexColorModel icm,
byte[] pix, int off, int scansize,
ByteComponentRaster bct, int chanOff);
 
源代码5 项目: dragonwell8_jdk   文件: WPathGraphics.java
/**
 * Have the printing application redraw everything that falls
 * within the page bounds defined by <code>region</code>.
 */
@Override
public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)
        throws PrinterException {

    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, wPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(wPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(wPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);

    proxy.translate(
        -wPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / wPrinterJob.getXRes() * DEFAULT_USER_RES,
        -wPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / wPrinterJob.getYRes() * DEFAULT_USER_RES);
    /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));
    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* We need to set the device clip using saved information.
     * savedClip intersects the user clip with a clip that restricts
     * the GDI rendered area of our BufferedImage to that which
     * may correspond to a rotate or shear.
     * The saved device transform is needed as the current transform
     * is not likely to be the same.
     */
    if (savedClip != null) {
        deviceClip(savedClip.getPathIterator(savedTransform));
    }

    /* Scale the bounding rectangle by the scale transform.
     * Because the scaling transform has only x and y
     * scaling components it is equivalent to multiplying
     * the x components of the bounding rectangle by
     * the x scaling factor and to multiplying the y components
     * by the y scaling factor.
     */
    Rectangle2D.Float scaledBounds
            = new Rectangle2D.Float(
                    (float) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.getHeight() * scaleY));

    /* Pull the raster data from the buffered image
     * and pass it along to GDI.
     */
   ByteComponentRaster tile
            = (ByteComponentRaster)deepImage.getRaster();

    wPrinterJob.drawImage3ByteBGR(tile.getDataStorage(),
                scaledBounds.x, scaledBounds.y,
                scaledBounds.width,
                scaledBounds.height,
                0f, 0f,
                deepImage.getWidth(), deepImage.getHeight());

}
 
源代码6 项目: TencentKona-8   文件: LCMSImageLayout.java
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;
}
 
源代码7 项目: TencentKona-8   文件: PSPathGraphics.java
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* 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) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.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,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
源代码8 项目: TencentKona-8   文件: ImageRepresentation.java
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;
}
 
源代码9 项目: TencentKona-8   文件: ImageRepresentation.java
private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
int transPix, int numLut, IndexColorModel icm,
byte[] pix, int off, int scansize,
ByteComponentRaster bct, int chanOff);
 
源代码10 项目: TencentKona-8   文件: WPathGraphics.java
/**
 * Have the printing application redraw everything that falls
 * within the page bounds defined by <code>region</code>.
 */
@Override
public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)
        throws PrinterException {

    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, wPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(wPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(wPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);

    proxy.translate(
        -wPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / wPrinterJob.getXRes() * DEFAULT_USER_RES,
        -wPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / wPrinterJob.getYRes() * DEFAULT_USER_RES);
    /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));
    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* We need to set the device clip using saved information.
     * savedClip intersects the user clip with a clip that restricts
     * the GDI rendered area of our BufferedImage to that which
     * may correspond to a rotate or shear.
     * The saved device transform is needed as the current transform
     * is not likely to be the same.
     */
    if (savedClip != null) {
        deviceClip(savedClip.getPathIterator(savedTransform));
    }

    /* Scale the bounding rectangle by the scale transform.
     * Because the scaling transform has only x and y
     * scaling components it is equivalent to multiplying
     * the x components of the bounding rectangle by
     * the x scaling factor and to multiplying the y components
     * by the y scaling factor.
     */
    Rectangle2D.Float scaledBounds
            = new Rectangle2D.Float(
                    (float) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.getHeight() * scaleY));

    /* Pull the raster data from the buffered image
     * and pass it along to GDI.
     */
   ByteComponentRaster tile
            = (ByteComponentRaster)deepImage.getRaster();

    wPrinterJob.drawImage3ByteBGR(tile.getDataStorage(),
                scaledBounds.x, scaledBounds.y,
                scaledBounds.width,
                scaledBounds.height,
                0f, 0f,
                deepImage.getWidth(), deepImage.getHeight());

}
 
源代码11 项目: jdk8u60   文件: LCMSImageLayout.java
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;
}
 
源代码12 项目: jdk8u60   文件: PSPathGraphics.java
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* 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) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.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,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
源代码13 项目: jdk8u60   文件: ImageRepresentation.java
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;
}
 
源代码14 项目: jdk8u60   文件: ImageRepresentation.java
private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
int transPix, int numLut, IndexColorModel icm,
byte[] pix, int off, int scansize,
ByteComponentRaster bct, int chanOff);
 
源代码15 项目: jdk8u60   文件: WPathGraphics.java
/**
 * Have the printing application redraw everything that falls
 * within the page bounds defined by <code>region</code>.
 */
@Override
public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)
        throws PrinterException {

    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, wPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(wPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(wPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);

    proxy.translate(
        -wPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / wPrinterJob.getXRes() * DEFAULT_USER_RES,
        -wPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / wPrinterJob.getYRes() * DEFAULT_USER_RES);
    /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));
    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* We need to set the device clip using saved information.
     * savedClip intersects the user clip with a clip that restricts
     * the GDI rendered area of our BufferedImage to that which
     * may correspond to a rotate or shear.
     * The saved device transform is needed as the current transform
     * is not likely to be the same.
     */
    if (savedClip != null) {
        deviceClip(savedClip.getPathIterator(savedTransform));
    }

    /* Scale the bounding rectangle by the scale transform.
     * Because the scaling transform has only x and y
     * scaling components it is equivalent to multiplying
     * the x components of the bounding rectangle by
     * the x scaling factor and to multiplying the y components
     * by the y scaling factor.
     */
    Rectangle2D.Float scaledBounds
            = new Rectangle2D.Float(
                    (float) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.getHeight() * scaleY));

    /* Pull the raster data from the buffered image
     * and pass it along to GDI.
     */
   ByteComponentRaster tile
            = (ByteComponentRaster)deepImage.getRaster();

    wPrinterJob.drawImage3ByteBGR(tile.getDataStorage(),
                scaledBounds.x, scaledBounds.y,
                scaledBounds.width,
                scaledBounds.height,
                0f, 0f,
                deepImage.getWidth(), deepImage.getHeight());

}
 
源代码16 项目: openjdk-jdk8u   文件: LCMSImageLayout.java
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;
}
 
源代码17 项目: openjdk-jdk8u   文件: PSPathGraphics.java
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* 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) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.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,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
源代码18 项目: openjdk-jdk8u   文件: ImageRepresentation.java
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;
}
 
源代码19 项目: openjdk-jdk8u   文件: ImageRepresentation.java
private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
int transPix, int numLut, IndexColorModel icm,
byte[] pix, int off, int scansize,
ByteComponentRaster bct, int chanOff);
 
源代码20 项目: openjdk-jdk8u   文件: WPathGraphics.java
/**
 * Have the printing application redraw everything that falls
 * within the page bounds defined by <code>region</code>.
 */
@Override
public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)
        throws PrinterException {

    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, wPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(wPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(wPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);

    proxy.translate(
        -wPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / wPrinterJob.getXRes() * DEFAULT_USER_RES,
        -wPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / wPrinterJob.getYRes() * DEFAULT_USER_RES);
    /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));
    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* We need to set the device clip using saved information.
     * savedClip intersects the user clip with a clip that restricts
     * the GDI rendered area of our BufferedImage to that which
     * may correspond to a rotate or shear.
     * The saved device transform is needed as the current transform
     * is not likely to be the same.
     */
    if (savedClip != null) {
        deviceClip(savedClip.getPathIterator(savedTransform));
    }

    /* Scale the bounding rectangle by the scale transform.
     * Because the scaling transform has only x and y
     * scaling components it is equivalent to multiplying
     * the x components of the bounding rectangle by
     * the x scaling factor and to multiplying the y components
     * by the y scaling factor.
     */
    Rectangle2D.Float scaledBounds
            = new Rectangle2D.Float(
                    (float) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.getHeight() * scaleY));

    /* Pull the raster data from the buffered image
     * and pass it along to GDI.
     */
   ByteComponentRaster tile
            = (ByteComponentRaster)deepImage.getRaster();

    wPrinterJob.drawImage3ByteBGR(tile.getDataStorage(),
                scaledBounds.x, scaledBounds.y,
                scaledBounds.width,
                scaledBounds.height,
                0f, 0f,
                deepImage.getWidth(), deepImage.getHeight());

}
 
源代码21 项目: openjdk-jdk8u-backup   文件: LCMSImageLayout.java
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;
}
 
源代码22 项目: openjdk-jdk8u-backup   文件: PSPathGraphics.java
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* 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) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.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,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
源代码23 项目: openjdk-jdk8u-backup   文件: ImageRepresentation.java
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;
}
 
源代码24 项目: openjdk-jdk8u-backup   文件: ImageRepresentation.java
private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
int transPix, int numLut, IndexColorModel icm,
byte[] pix, int off, int scansize,
ByteComponentRaster bct, int chanOff);
 
源代码25 项目: openjdk-jdk8u-backup   文件: WPathGraphics.java
/**
 * Have the printing application redraw everything that falls
 * within the page bounds defined by <code>region</code>.
 */
@Override
public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)
        throws PrinterException {

    WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, wPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(wPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(wPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);

    proxy.translate(
        -wPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / wPrinterJob.getXRes() * DEFAULT_USER_RES,
        -wPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / wPrinterJob.getYRes() * DEFAULT_USER_RES);
    /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));
    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* We need to set the device clip using saved information.
     * savedClip intersects the user clip with a clip that restricts
     * the GDI rendered area of our BufferedImage to that which
     * may correspond to a rotate or shear.
     * The saved device transform is needed as the current transform
     * is not likely to be the same.
     */
    if (savedClip != null) {
        deviceClip(savedClip.getPathIterator(savedTransform));
    }

    /* Scale the bounding rectangle by the scale transform.
     * Because the scaling transform has only x and y
     * scaling components it is equivalent to multiplying
     * the x components of the bounding rectangle by
     * the x scaling factor and to multiplying the y components
     * by the y scaling factor.
     */
    Rectangle2D.Float scaledBounds
            = new Rectangle2D.Float(
                    (float) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.getHeight() * scaleY));

    /* Pull the raster data from the buffered image
     * and pass it along to GDI.
     */
   ByteComponentRaster tile
            = (ByteComponentRaster)deepImage.getRaster();

    wPrinterJob.drawImage3ByteBGR(tile.getDataStorage(),
                scaledBounds.x, scaledBounds.y,
                scaledBounds.width,
                scaledBounds.height,
                0f, 0f,
                deepImage.getWidth(), deepImage.getHeight());

}
 
源代码26 项目: Bytecoder   文件: LCMSImageLayout.java
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;
}
 
源代码27 项目: Bytecoder   文件: PSPathGraphics.java
/** Redraw a rectanglular area using a proxy graphics
  * To do this we need to know the rectangular area to redraw and
  * the transform & clip in effect at the time of the original drawImage
  *
  */

public void redrawRegion(Rectangle2D region, double scaleX, double scaleY,
                         Shape savedClip, AffineTransform savedTransform)

        throws PrinterException {

    PSPrinterJob psPrinterJob = (PSPrinterJob)getPrinterJob();
    Printable painter = getPrintable();
    PageFormat pageFormat = getPageFormat();
    int pageIndex = getPageIndex();

    /* Create a buffered image big enough to hold the portion
     * of the source image being printed.
     */
    BufferedImage deepImage = new BufferedImage(
                                    (int) region.getWidth(),
                                    (int) region.getHeight(),
                                    BufferedImage.TYPE_3BYTE_BGR);

    /* Get a graphics for the application to render into.
     * We initialize the buffer to white in order to
     * match the paper and then we shift the BufferedImage
     * so that it covers the area on the page where the
     * caller's Image will be drawn.
     */
    Graphics2D g = deepImage.createGraphics();
    ProxyGraphics2D proxy = new ProxyGraphics2D(g, psPrinterJob);
    proxy.setColor(Color.white);
    proxy.fillRect(0, 0, deepImage.getWidth(), deepImage.getHeight());
    proxy.clipRect(0, 0, deepImage.getWidth(), deepImage.getHeight());

    proxy.translate(-region.getX(), -region.getY());

    /* Calculate the resolution of the source image.
     */
    float sourceResX = (float)(psPrinterJob.getXRes() / scaleX);
    float sourceResY = (float)(psPrinterJob.getYRes() / scaleY);

    /* The application expects to see user space at 72 dpi.
     * so change user space from image source resolution to
     *  72 dpi.
     */
    proxy.scale(sourceResX / DEFAULT_USER_RES,
                sourceResY / DEFAULT_USER_RES);
   proxy.translate(
        -psPrinterJob.getPhysicalPrintableX(pageFormat.getPaper())
           / psPrinterJob.getXRes() * DEFAULT_USER_RES,
        -psPrinterJob.getPhysicalPrintableY(pageFormat.getPaper())
           / psPrinterJob.getYRes() * DEFAULT_USER_RES);
   /* NB User space now has to be at 72 dpi for this calc to be correct */
    proxy.transform(new AffineTransform(getPageFormat().getMatrix()));

    proxy.setPaint(Color.black);

    painter.print(proxy, pageFormat, pageIndex);

    g.dispose();

    /* In PSPrinterJob images are printed in device space
     * and therefore we need to set a device space clip.
     */
    psPrinterJob.setClip(savedTransform.createTransformedShape(savedClip));


    /* 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) (region.getX() * scaleX),
                    (float) (region.getY() * scaleY),
                    (float) (region.getWidth() * scaleX),
                    (float) (region.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,
                        scaledBounds.width,
                        scaledBounds.height,
                        0f, 0f,
                        deepImage.getWidth(), deepImage.getHeight(),
                        deepImage.getWidth(), deepImage.getHeight());


}
 
源代码28 项目: Bytecoder   文件: ImageRepresentation.java
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;
}
 
源代码29 项目: Bytecoder   文件: ImageRepresentation.java
private native boolean setDiffICM(int x, int y, int w, int h, int[] lut,
int transPix, int numLut, IndexColorModel icm,
byte[] pix, int off, int scansize,
ByteComponentRaster bct, int chanOff);
 
源代码30 项目: openjdk-jdk9   文件: LCMSImageLayout.java
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;
}
 
 类所在包
 类方法
 同包方法