java.awt.image.Raster#createChild()源码实例Demo

下面列出了java.awt.image.Raster#createChild() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码2 项目: TencentKona-8   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码3 项目: jdk8u60   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码4 项目: openjdk-jdk8u   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码6 项目: Bytecoder   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int[] span = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码7 项目: openjdk-jdk9   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码8 项目: jdk8u-jdk   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码9 项目: hottub   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码10 项目: openjdk-8-source   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码11 项目: openjdk-8   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码12 项目: jdk8u_jdk   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码13 项目: jdk8u-jdk   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码14 项目: jdk8u-dev-jdk   文件: Blit.java
public void Blit(SurfaceData srcData,
                 SurfaceData dstData,
                 Composite comp,
                 Region clip,
                 int srcx, int srcy,
                 int dstx, int dsty,
                 int width, int height)
{
    ColorModel srcCM = srcData.getColorModel();
    ColorModel dstCM = dstData.getColorModel();
    // REMIND: Should get RenderingHints from sg2d
    CompositeContext ctx = comp.createContext(srcCM, dstCM,
                                              new RenderingHints(null));
    Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
    WritableRaster dstRas =
        (WritableRaster) dstData.getRaster(dstx, dsty, width, height);

    if (clip == null) {
        clip = Region.getInstanceXYWH(dstx, dsty, width, height);
    }
    int span[] = {dstx, dsty, dstx+width, dsty+height};
    SpanIterator si = clip.getSpanIterator(span);
    srcx -= dstx;
    srcy -= dsty;
    while (si.nextSpan(span)) {
        int w = span[2] - span[0];
        int h = span[3] - span[1];
        Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
                                              w, h, 0, 0, null);
        WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
                                                              w, h, 0, 0, null);
        ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
    }
    ctx.dispose();
}
 
源代码15 项目: ganttproject   文件: SimpleRenderedImage.java
/**
 * Returns an arbitrary rectangular region of the RenderedImage in a Raster.
 * The rectangle of interest will be clipped against the image bounds.
 * 
 * <p>
 * The returned Raster is semantically a copy. This means that updates to the
 * source image will not be reflected in the returned Raster. For non-writable
 * (immutable) source images, the returned value may be a reference to the
 * image's internal data. The returned Raster should be considered
 * non-writable; any attempt to alter its pixel data (such as by casting it to
 * WritableRaster or obtaining and modifying its DataBuffer) may result in
 * undefined behavior. The copyData method should be used if the returned
 * Raster is to be modified.
 * 
 * @param bounds
 *          the region of the RenderedImage to be returned.
 */
@Override
public Raster getData(Rectangle bounds) {
  int startX = XToTileX(bounds.x);
  int startY = YToTileY(bounds.y);
  int endX = XToTileX(bounds.x + bounds.width - 1);
  int endY = YToTileY(bounds.y + bounds.height - 1);
  Raster tile;

  if ((startX == endX) && (startY == endY)) {
    tile = getTile(startX, startY);
    return tile.createChild(bounds.x, bounds.y, bounds.width, bounds.height, bounds.x, bounds.y, null);
  } else {
    // Create a WritableRaster of the desired size
    SampleModel sm = sampleModel.createCompatibleSampleModel(bounds.width, bounds.height);

    // Translate it
    WritableRaster dest = Raster.createWritableRaster(sm, bounds.getLocation());

    for (int j = startY; j <= endY; j++) {
      for (int i = startX; i <= endX; i++) {
        tile = getTile(i, j);
        Rectangle intersectRect = bounds.intersection(tile.getBounds());
        Raster liveRaster = tile.createChild(intersectRect.x, intersectRect.y, intersectRect.width,
            intersectRect.height, intersectRect.x, intersectRect.y, null);
        dest.setDataElements(0, 0, liveRaster);
      }
    }
    return dest;
  }
}
 
源代码16 项目: ganttproject   文件: SimpleRenderedImage.java
/**
 * Copies an arbitrary rectangular region of the RenderedImage into a
 * caller-supplied WritableRaster. The region to be computed is determined by
 * clipping the bounds of the supplied WritableRaster against the bounds of
 * the image. The supplied WritableRaster must have a SampleModel that is
 * compatible with that of the image.
 * 
 * <p>
 * If the raster argument is null, the entire image will be copied into a
 * newly-created WritableRaster with a SampleModel that is compatible with
 * that of the image.
 * 
 * @param dest
 *          a WritableRaster to hold the returned portion of the image.
 * @return a reference to the supplied WritableRaster, or to a new
 *         WritableRaster if the supplied one was null.
 */
@Override
public WritableRaster copyData(WritableRaster dest) {
  Rectangle bounds;
  Raster tile;

  if (dest == null) {
    bounds = getBounds();
    Point p = new Point(minX, minY);
    /* A SampleModel to hold the entire image. */
    SampleModel sm = sampleModel.createCompatibleSampleModel(width, height);
    dest = Raster.createWritableRaster(sm, p);
  } else {
    bounds = dest.getBounds();
  }

  int startX = XToTileX(bounds.x);
  int startY = YToTileY(bounds.y);
  int endX = XToTileX(bounds.x + bounds.width - 1);
  int endY = YToTileY(bounds.y + bounds.height - 1);

  for (int j = startY; j <= endY; j++) {
    for (int i = startX; i <= endX; i++) {
      tile = getTile(i, j);
      Rectangle intersectRect = bounds.intersection(tile.getBounds());
      Raster liveRaster = tile.createChild(intersectRect.x, intersectRect.y, intersectRect.width,
          intersectRect.height, intersectRect.x, intersectRect.y, null);

      /*
       * WritableRaster.setDataElements takes into account of inRaster's minX
       * and minY and add these to x and y. Since liveRaster has the origin at
       * the correct location, the following call should not again give these
       * coordinates in places of x and y.
       */
      dest.setDataElements(0, 0, liveRaster);
    }
  }
  return dest;
}
 
源代码17 项目: blog-codes   文件: mxPngImageEncoder.java
private void writeIDAT() throws IOException
{
	IDATOutputStream ios = new IDATOutputStream(dataOutput, 8192);
	DeflaterOutputStream dos = new DeflaterOutputStream(ios,
			new Deflater(9));

	// Future work - don't convert entire image to a Raster It
	// might seem that you could just call image.getData() but
	// 'BufferedImage.subImage' doesn't appear to set the Width
	// and height properly of the Child Raster, so the Raster
	// you get back here appears larger than it should.
	// This solves that problem by bounding the raster to the
	// image's bounds...
	Raster ras = image.getData(new Rectangle(image.getMinX(), image
			.getMinY(), image.getWidth(), image.getHeight()));
	// log.fine("Image: [" +
	//                    image.getMinY()  + ", " +
	//                    image.getMinX()  + ", " +
	//                    image.getWidth()  + ", " +
	//                    image.getHeight() + "]");
	// log.fine("Ras: [" +
	//                    ras.getMinX()  + ", " +
	//                    ras.getMinY()  + ", " +
	//                    ras.getWidth()  + ", " +
	//                    ras.getHeight() + "]");

	if (skipAlpha)
	{
		int numBands = ras.getNumBands() - 1;
		int[] bandList = new int[numBands];
		for (int i = 0; i < numBands; i++)
		{
			bandList[i] = i;
		}
		ras = ras.createChild(0, 0, ras.getWidth(), ras.getHeight(), 0, 0,
				bandList);
	}

	if (interlace)
	{
		// Interlacing pass 1
		encodePass(dos, ras, 0, 0, 8, 8);
		// Interlacing pass 2
		encodePass(dos, ras, 4, 0, 8, 8);
		// Interlacing pass 3
		encodePass(dos, ras, 0, 4, 4, 8);
		// Interlacing pass 4
		encodePass(dos, ras, 2, 0, 4, 4);
		// Interlacing pass 5
		encodePass(dos, ras, 0, 2, 2, 4);
		// Interlacing pass 6
		encodePass(dos, ras, 1, 0, 2, 2);
		// Interlacing pass 7
		encodePass(dos, ras, 0, 1, 1, 2);
	}
	else
	{
		encodePass(dos, ras, 0, 0, 1, 1);
	}

	dos.finish();
	ios.flush();
}
 
源代码18 项目: Bytecoder   文件: SimpleRenderedImage.java
/**
 * Copies an arbitrary rectangular region of the RenderedImage
 * into a caller-supplied WritableRaster.  The region to be
 * computed is determined by clipping the bounds of the supplied
 * WritableRaster against the bounds of the image.  The supplied
 * WritableRaster must have a SampleModel that is compatible with
 * that of the image.
 *
 * <p> If the raster argument is null, the entire image will
 * be copied into a newly-created WritableRaster with a SampleModel
 * that is compatible with that of the image.
 *
 * @param dest a WritableRaster to hold the returned portion of
 *        the image.
 * @return a reference to the supplied WritableRaster, or to a
 *         new WritableRaster if the supplied one was null.
 */
public WritableRaster copyData(WritableRaster dest) {
    // Get the image bounds.
    Rectangle imageBounds = getBounds();

    Rectangle bounds;
    if (dest == null) {
        // Create a WritableRaster for the entire image.
        bounds = imageBounds;
        Point p = new Point(minX, minY);
        SampleModel sm =
            sampleModel.createCompatibleSampleModel(width, height);
        dest = Raster.createWritableRaster(sm, p);
    } else {
        bounds = dest.getBounds();
    }

    // Determine tile limits for the intersection of the prescribed
    // bounds with the image bounds.
    Rectangle xsect = imageBounds.contains(bounds) ?
        bounds : bounds.intersection(imageBounds);
    int startX = XToTileX(xsect.x);
    int startY = YToTileY(xsect.y);
    int endX = XToTileX(xsect.x + xsect.width - 1);
    int endY = YToTileY(xsect.y + xsect.height - 1);

    // Loop over the tiles in the intersection.
    for (int j = startY; j <= endY; j++) {
        for (int i = startX; i <= endX; i++) {
            // Retrieve the tile.
            Raster tile = getTile(i, j);

            // Create a child of the tile for the intersection of
            // the tile bounds and the bounds of the requested area.
            Rectangle tileRect = tile.getBounds();
            Rectangle intersectRect =
                bounds.intersection(tile.getBounds());
            Raster liveRaster = tile.createChild(intersectRect.x,
                                                 intersectRect.y,
                                                 intersectRect.width,
                                                 intersectRect.height,
                                                 intersectRect.x,
                                                 intersectRect.y,
                                                 null);

            // Copy the data from the child.
            dest.setRect(liveRaster);
        }
    }

    return dest;
}
 
源代码19 项目: openjdk-jdk9   文件: SimpleRenderedImage.java
/**
 * Copies an arbitrary rectangular region of the RenderedImage
 * into a caller-supplied WritableRaster.  The region to be
 * computed is determined by clipping the bounds of the supplied
 * WritableRaster against the bounds of the image.  The supplied
 * WritableRaster must have a SampleModel that is compatible with
 * that of the image.
 *
 * <p> If the raster argument is null, the entire image will
 * be copied into a newly-created WritableRaster with a SampleModel
 * that is compatible with that of the image.
 *
 * @param dest a WritableRaster to hold the returned portion of
 *        the image.
 * @return a reference to the supplied WritableRaster, or to a
 *         new WritableRaster if the supplied one was null.
 */
public WritableRaster copyData(WritableRaster dest) {
    // Get the image bounds.
    Rectangle imageBounds = getBounds();

    Rectangle bounds;
    if (dest == null) {
        // Create a WritableRaster for the entire image.
        bounds = imageBounds;
        Point p = new Point(minX, minY);
        SampleModel sm =
            sampleModel.createCompatibleSampleModel(width, height);
        dest = Raster.createWritableRaster(sm, p);
    } else {
        bounds = dest.getBounds();
    }

    // Determine tile limits for the intersection of the prescribed
    // bounds with the image bounds.
    Rectangle xsect = imageBounds.contains(bounds) ?
        bounds : bounds.intersection(imageBounds);
    int startX = XToTileX(xsect.x);
    int startY = YToTileY(xsect.y);
    int endX = XToTileX(xsect.x + xsect.width - 1);
    int endY = YToTileY(xsect.y + xsect.height - 1);

    // Loop over the tiles in the intersection.
    for (int j = startY; j <= endY; j++) {
        for (int i = startX; i <= endX; i++) {
            // Retrieve the tile.
            Raster tile = getTile(i, j);

            // Create a child of the tile for the intersection of
            // the tile bounds and the bounds of the requested area.
            Rectangle tileRect = tile.getBounds();
            Rectangle intersectRect =
                bounds.intersection(tile.getBounds());
            Raster liveRaster = tile.createChild(intersectRect.x,
                                                 intersectRect.y,
                                                 intersectRect.width,
                                                 intersectRect.height,
                                                 intersectRect.x,
                                                 intersectRect.y,
                                                 null);

            // Copy the data from the child.
            dest.setRect(liveRaster);
        }
    }

    return dest;
}