Java 类java.awt.image.RasterFormatException 实例源码

项目:bitbox    文件:PainterLogic.java   
@Override
public SortedMap<Integer, String> parseString(String fieldString) {
    CharStream is = CharStreams.fromString(fieldString);
    DrawGrammarLexer lex = new DrawGrammarLexer(is);
    CommonTokenStream tokens = new CommonTokenStream(lex);
    DrawGrammarParser parser = new DrawGrammarParser(tokens);
    palette = Palette.makeDefaultPalette("DarkSpectrum");
    final SortedMap<Integer, String> resultMap;
    try {
        resultMap = parser.root().map;
    } catch (RecognitionException | NullPointerException | StringIndexOutOfBoundsException | RasterFormatException re) {
        //Something wrong with the parsing do not update.
        return null;
    }
    return resultMap;
}
项目:litiengine    文件:Spritesheet.java   
public BufferedImage getSprite(final int index) {
  final String imageCacheKey = MessageFormat.format("{0}_{1}", this.hashCode, index);
  if (ImageCache.SPRITES.containsKey(imageCacheKey)) {
    return ImageCache.SPRITES.get(imageCacheKey);
  }

  if (this.getImage() == null) {
    log.warning("no image defined for sprite '" + this.getName() + "'");
    return null;
  }

  final Point position = this.getLocation(index);
  try {
    final BufferedImage smallImage = this.getImage().getSubimage(position.x, position.y, this.spriteWidth, this.spriteHeight);
    ImageCache.SPRITES.put(imageCacheKey, smallImage);
    return smallImage;
  } catch (final RasterFormatException rfe) {
    log.warning("could not read sprite of size [" + this.spriteWidth + "x" + this.spriteHeight + " at position [" + position.x + "," + position.y + "] from sprite'" + this.getName() + "'");
    return null;
  }
}
项目:javify    文件:CairoSurface.java   
public WritableRaster createWritableChild(int parentX, int parentY,
                                          int w, int h, int childMinX,
                                          int childMinY, int[] bandList)
{
  if (parentX < minX || parentX + w > minX + width
      || parentY < minY || parentY + h > minY + height)
    throw new RasterFormatException("Child raster extends beyond parent");

  SampleModel sm = (bandList == null) ?
    sampleModel :
    sampleModel.createSubsetSampleModel(bandList);

  return new CairoSurface(sm, this,
                          new Rectangle(childMinX, childMinY, w, h),
                          new Point(sampleModelTranslateX + childMinX - parentX,
                                    sampleModelTranslateY + childMinY - parentY));
}
项目:jvm-stm    文件:CairoSurface.java   
public WritableRaster createWritableChild(int parentX, int parentY,
                                          int w, int h, int childMinX,
                                          int childMinY, int[] bandList)
{
  if (parentX < minX || parentX + w > minX + width
      || parentY < minY || parentY + h > minY + height)
    throw new RasterFormatException("Child raster extends beyond parent");

  SampleModel sm = (bandList == null) ?
    sampleModel :
    sampleModel.createSubsetSampleModel(bandList);

  return new CairoSurface(sm, this,
                          new Rectangle(childMinX, childMinY, w, h),
                          new Point(sampleModelTranslateX + childMinX - parentX,
                                    sampleModelTranslateY + childMinY - parentY));
}
项目:jdk7-jdk    文件:ByteComponentRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    // Make sure data for Raster is in a legal range
    for (int i=0; i < dataOffsets.length; i++) {
        if (dataOffsets[i] < 0) {
            throw new RasterFormatException("Data offsets for band "+i+
                                            "("+dataOffsets[i]+
                                            ") must be >= 0");
        }
    }

    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize+" )");
    }
}
项目:jdk7-jdk    文件:BytePackedRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.
 * If strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    // Make sure data for Raster is in a legal range
    if (dataBitOffset < 0) {
        throw new RasterFormatException("Data offsets must be >= 0");
    }

    int lastbit = (dataBitOffset
                   + (height-1) * scanlineStride * 8
                   + (width-1) * pixelBitStride
                   + pixelBitStride - 1);
    if (lastbit / 8 >= data.length) {
        throw new RasterFormatException("raster dimensions overflow " +
                                        "array bounds");
    }
    if (strictCheck) {
        if (height > 1) {
            lastbit = width * pixelBitStride - 1;
            if (lastbit / 8 >= scanlineStride) {
                throw new RasterFormatException("data for adjacent" +
                                                " scanlines overlaps");
            }
        }
    }
}
项目:jdk7-jdk    文件:ByteInterleavedRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize+" )");
    }
}
项目:jdk7-jdk    文件:ShortInterleavedRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize+" )");
    }
}
项目:jdk7-jdk    文件:IntegerComponentRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    if (dataOffsets[0] < 0) {
        throw new RasterFormatException("Data offset ("+dataOffsets[0]+
                                        ") must be >= 0");
    }

    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize
                                      +" but is "+data.length+" )");
    }
}
项目:openjdk-source-code-learn    文件:ShortComponentRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    // Make sure data for Raster is in a legal range
    for (int i=0; i < dataOffsets.length; i++) {
        if (dataOffsets[i] < 0) {
            throw new RasterFormatException("Data offsets for band "+i+
                                            "("+dataOffsets[i]+
                                            ") must be >= 0");
        }
    }

    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize+" )");
    }
}
项目:openjdk-source-code-learn    文件:BytePackedRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.
 * If strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    // Make sure data for Raster is in a legal range
    if (dataBitOffset < 0) {
        throw new RasterFormatException("Data offsets must be >= 0");
    }

    int lastbit = (dataBitOffset
                   + (height-1) * scanlineStride * 8
                   + (width-1) * pixelBitStride
                   + pixelBitStride - 1);
    if (lastbit / 8 >= data.length) {
        throw new RasterFormatException("raster dimensions overflow " +
                                        "array bounds");
    }
    if (strictCheck) {
        if (height > 1) {
            lastbit = width * pixelBitStride - 1;
            if (lastbit / 8 >= scanlineStride) {
                throw new RasterFormatException("data for adjacent" +
                                                " scanlines overlaps");
            }
        }
    }
}
项目:openjdk-source-code-learn    文件:ByteInterleavedRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize+" )");
    }
}
项目:openjdk-source-code-learn    文件:ShortInterleavedRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize+" )");
    }
}
项目:openjdk-source-code-learn    文件:IntegerComponentRaster.java   
/**
 * Verify that the layout parameters are consistent with
 * the data.  If strictCheck
 * is false, this method will check for ArrayIndexOutOfBounds conditions.  If
 * strictCheck is true, this method will check for additional error
 * conditions such as line wraparound (width of a line greater than
 * the scanline stride).
 * @return   String   Error string, if the layout is incompatible with
 *                    the data.  Otherwise returns null.
 */
private void verify (boolean strictCheck) {
    if (dataOffsets[0] < 0) {
        throw new RasterFormatException("Data offset ("+dataOffsets[0]+
                                        ") must be >= 0");
    }

    int maxSize = 0;
    int size;

    for (int i=0; i < numDataElements; i++) {
        size = (height-1)*scanlineStride + (width-1)*pixelStride +
            dataOffsets[i];
        if (size > maxSize) {
            maxSize = size;
        }
    }
    if (data.length < maxSize) {
        throw new RasterFormatException("Data array too small (should be "+
                                      maxSize
                                      +" but is "+data.length+" )");
    }
}
项目:JamVM-PH    文件:CairoSurface.java   
public WritableRaster createWritableChild(int parentX, int parentY,
                                          int w, int h, int childMinX,
                                          int childMinY, int[] bandList)
{
  if (parentX < minX || parentX + w > minX + width
      || parentY < minY || parentY + h > minY + height)
    throw new RasterFormatException("Child raster extends beyond parent");

  SampleModel sm = (bandList == null) ?
    sampleModel :
    sampleModel.createSubsetSampleModel(bandList);

  return new CairoSurface(sm, this,
                          new Rectangle(childMinX, childMinY, w, h),
                          new Point(sampleModelTranslateX + childMinX - parentX,
                                    sampleModelTranslateY + childMinY - parentY));
}
项目:SikuliX2    文件:Capture.java   
private BufferedImage cropSelection() {
  int w = rectSelection.width, h = rectSelection.height;
  if (w <= 0 || h <= 0) {
    return null;
  }
  int x = rectSelection.x;
  int y = rectSelection.y;
  if (!isLocalScreen && scr_img_scale != 1) {
    x = (int) (x / scr_img_scale);
    y = (int) (y / scr_img_scale);
    w = (int) (w / scr_img_scale);
    h = (int) (h / scr_img_scale);

  }
  BufferedImage crop = new BufferedImage(w, h, scr_img_type);
  Graphics2D crop_g2d = crop.createGraphics();
  try {
    crop_g2d.drawImage(scr_img_original.get().getSubimage(x, y, w, h), null, 0, 0);
  } catch (RasterFormatException e) {
    log.error("cropSelection: RasterFormatException", e.getMessage());
  }
  crop_g2d.dispose();
  return crop;
}
项目:OpenJSharp    文件:ByteComponentRaster.java   
/**
 * Creates a Writable subRaster given a region of the Raster. The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this Raster to the upper-left corner
 * of the subRaster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subRaster will reference the same
 * DataBuffer as the parent Raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent Raster.
 */
public WritableRaster createWritableChild(int x, int y,
                                          int width, int height,
                                          int x0, int y0,
                                          int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside the raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside the raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ByteComponentRaster(sm,
                                   dataBuffer,
                                   new Rectangle(x0, y0, width, height),
                                   new Point(sampleModelTranslateX+deltaX,
                                             sampleModelTranslateY+deltaY),
                                   this);
}
项目:OpenJSharp    文件:ByteComponentRaster.java   
/**
 * Creates a Raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);

    return new ByteComponentRaster(sm , new Point(0,0));

}
项目:OpenJSharp    文件:ByteBandedRaster.java   
/**
 *  Constructs a ByteBandedRaster with the given sampleModel,
 *  DataBuffer, and parent. DataBuffer must be a DataBufferShort and
 *  SampleModel must be of type BandedSampleModel.
 *  When translated into the base Raster's
 *  coordinate system, aRegion must be contained by the base Raster.
 *  Origin is the coordinate in the new Raster's coordinate system of
 *  the origin of the base Raster.  (The base Raster is the Raster's
 *  ancestor which has no parent.)
 *
 *  Note that this constructor should generally be called by other
 *  constructors or create methods, it should not be used directly.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferShort that contains the image data.
 *  @param aRegion         The Rectangle that specifies the image area.
 *  @param origin          The Point that specifies the origin.
 *  @param parent          The parent (if any) of this raster.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Rectangle aRegion,
                        Point origin,
                        ByteBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (!(dataBuffer instanceof DataBufferByte)) {
       throw new RasterFormatException("ByteBandedRaster must have" +
            "byte DataBuffers");
    }
    DataBufferByte dbb = (DataBufferByte)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbb.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new byte[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbb, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ByteBandedRasters must have"+
            "BandedSampleModels");
    }
    verify();
}
项目:OpenJSharp    文件:ByteBandedRaster.java   
/**
 * Creates a Writable subraster given a region of the raster.  The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this raster to the upper-left corner
 * of the subraster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subraster will reference the same
 * DataBuffers as the parent raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width of the subraster.
 * @param height          Height of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent raster.
 */
public WritableRaster createWritableChild (int x, int y,
                                           int width, int height,
                                           int x0, int y0,
                                           int bandList[]) {

    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x+width < x) || (x+width > this.width + this.minX)) {
        throw new RasterFormatException("(x + width) is outside raster") ;
    }
    if ((y+height < y) || (y+height > this.height + this.minY)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ByteBandedRaster(sm,
                                dataBuffer,
                                new Rectangle(x0,y0,width,height),
                                new Point(sampleModelTranslateX+deltaX,
                                          sampleModelTranslateY+deltaY),
                                this);
}
项目:OpenJSharp    文件:ByteBandedRaster.java   
/**
 * Creates a Raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);

    return new ByteBandedRaster(sm, new Point(0,0));
}
项目:OpenJSharp    文件:ShortComponentRaster.java   
/**
 * Creates a Writable subRaster given a region of the Raster. The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this Raster to the upper-left corner
 * of the subRaster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subRaster will reference the same
 * DataBuffers as the parent Raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent Raster.
 */
public WritableRaster createWritableChild(int x, int y,
                                          int width, int height,
                                          int x0, int y0,
                                          int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside the raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside the raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ShortComponentRaster(sm,
                                   dataBuffer,
                                   new Rectangle(x0, y0, width, height),
                                   new Point(sampleModelTranslateX+deltaX,
                                             sampleModelTranslateY+deltaY),
                                   this);
}
项目:OpenJSharp    文件:ShortComponentRaster.java   
/**
 * Creates a Raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);

    return new ShortComponentRaster(sm, new Point(0, 0));
}
项目:OpenJSharp    文件:BytePackedRaster.java   
/**
 * Creates a Writable subRaster given a region of the Raster. The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this Raster to the upper-left corner
 * of the subRaster.  The bandList is ignored.
 * A translation to the subRaster may also be specified.
 * Note that the subRaster will reference the same
 * DataBuffer as the parent Raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent Raster.
 */
public WritableRaster createWritableChild(int x, int y,
                                          int width, int height,
                                          int x0, int y0,
                                          int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside the raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside the raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }

    SampleModel sm;

    if (bandList != null) {
        sm = sampleModel.createSubsetSampleModel(bandList);
    }
    else {
        sm = sampleModel;
    }

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new BytePackedRaster(sm,
                                dataBuffer,
                                new Rectangle(x0, y0, width, height),
                                new Point(sampleModelTranslateX+deltaX,
                                          sampleModelTranslateY+deltaY),
                                this);
}
项目:OpenJSharp    文件:BytePackedRaster.java   
/**
 * Creates a raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);

    return new BytePackedRaster(sm, new Point(0,0));
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerInterleavedRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerInterleavedRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Creates a subraster given a region of the raster.  The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this raster to the upper-left corner
 * of the subraster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subraster will reference the same
 * DataBuffer as the parent raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent raster.
 */
public WritableRaster createWritableChild (int x, int y,
                                           int width, int height,
                                           int x0, int y0,
                                           int bandList[]) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new IntegerInterleavedRaster(sm,
                                      dataBuffer,
                                      new Rectangle(x0,y0,width,height),
                                      new Point(sampleModelTranslateX+deltaX,
                                                sampleModelTranslateY+deltaY),
                                      this);
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Creates a raster with the same band layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);

    return new IntegerInterleavedRaster(sm, new Point(0,0));
}
项目:OpenJSharp    文件:ByteInterleavedRaster.java   
/**
 * Creates a Writable subRaster given a region of the Raster. The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this Raster to the upper-left corner
 * of the subRaster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subRaster will reference the same
 * DataBuffer as the parent Raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent Raster.
 */
public WritableRaster createWritableChild(int x, int y,
                                          int width, int height,
                                          int x0, int y0,
                                          int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside the raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside the raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ByteInterleavedRaster(sm,
                                   dataBuffer,
                                   new Rectangle(x0, y0, width, height),
                                   new Point(sampleModelTranslateX+deltaX,
                                             sampleModelTranslateY+deltaY),
                                   this);
}
项目:OpenJSharp    文件:ByteInterleavedRaster.java   
/**
 * Creates a Raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);

    return new ByteInterleavedRaster(sm, new Point(0,0));

}
项目:OpenJSharp    文件:ShortInterleavedRaster.java   
/**
 * Creates a Writable subRaster given a region of the Raster. The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this Raster to the upper-left corner
 * of the subRaster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subRaster will reference the same
 * DataBuffers as the parent Raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent Raster.
 */
public WritableRaster createWritableChild(int x, int y,
                                          int width, int height,
                                          int x0, int y0,
                                          int[] bandList) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside the raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside the raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ShortInterleavedRaster(sm,
                                   dataBuffer,
                                   new Rectangle(x0, y0, width, height),
                                   new Point(sampleModelTranslateX+deltaX,
                                             sampleModelTranslateY+deltaY),
                                   this);
}
项目:OpenJSharp    文件:ShortInterleavedRaster.java   
/**
 * Creates a Raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);

    return new ShortInterleavedRaster(sm, new Point(0, 0));
}
项目:OpenJSharp    文件:ShortBandedRaster.java   
/**
 * Constructs a ShortBandedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferUShort and
 * SampleModel must be of type BandedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coordinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public ShortBandedRaster(SampleModel sampleModel,
                            DataBuffer dataBuffer,
                            Rectangle aRegion,
                            Point origin,
                            ShortBandedRaster parent) {

    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferUShort)) {
       throw new RasterFormatException("ShortBandedRaster must have " +
            "ushort DataBuffers");
    }
    DataBufferUShort dbus = (DataBufferUShort)dataBuffer;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dbus.getOffsets();
        dataOffsets = new int[bankIndices.length];
        data = new short[bankIndices.length][];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        for (int i = 0; i < bankIndices.length; i++) {
           data[i] = stealData(dbus, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
项目:OpenJSharp    文件:ShortBandedRaster.java   
/**
 * Creates a Writable subRaster given a region of the Raster.  The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this Raster to the upper-left corner
 * of the subRaster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subRaster will reference the same
 * DataBuffers as the parent Raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent Raster.
 */
public WritableRaster createWritableChild(int x, int y,
                                          int width, int height,
                                          int x0, int y0,
                                          int bandList[]) {

    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside of Raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside of Raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new ShortBandedRaster(sm,
                                 dataBuffer,
                                 new Rectangle(x0, y0, width, height),
                                 new Point(sampleModelTranslateX+deltaX,
                                           sampleModelTranslateY+deltaY),
                                 this);

}
项目:OpenJSharp    文件:ShortBandedRaster.java   
/**
 * Creates a Raster with the same layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                        ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);

    return new ShortBandedRaster(sm, new Point(0,0));
}
项目:OpenJSharp    文件:IntegerComponentRaster.java   
/**
 * Creates a subraster given a region of the raster.  The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this raster to the upper-left corner
 * of the subraster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subraster will reference the same
 * DataBuffer as the parent raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent raster.
 */
public WritableRaster createWritableChild (int x, int y,
                                           int width, int height,
                                           int x0, int y0,
                                           int bandList[]) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new IntegerComponentRaster(sm,
                                      dataBuffer,
                                      new Rectangle(x0,y0,width,height),
                                      new Point(sampleModelTranslateX+deltaX,
                                                sampleModelTranslateY+deltaY),
                                      this);
}
项目:OpenJSharp    文件:IntegerComponentRaster.java   
/**
 * Creates a raster with the same band layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);

    return new IntegerComponentRaster(sm, new Point(0,0));
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Constructs a IntegerInterleavedRaster with the given SampleModel,
 * DataBuffer, and parent.  DataBuffer must be a DataBufferInt and
 * SampleModel must be of type SinglePixelPackedSampleModel.
 * When translated into the base Raster's
 * coordinate system, aRegion must be contained by the base Raster.
 * Origin is the coodinate in the new Raster's coordinate system of
 * the origin of the base Raster.  (The base Raster is the Raster's
 * ancestor which has no parent.)
 *
 * Note that this constructor should generally be called by other
 * constructors or create methods, it should not be used directly.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferInt that contains the image data.
 * @param aRegion         The Rectangle that specifies the image area.
 * @param origin          The Point that specifies the origin.
 * @param parent          The parent (if any) of this raster.
 */
public IntegerInterleavedRaster(SampleModel sampleModel,
                                 DataBuffer dataBuffer,
                                 Rectangle aRegion,
                                 Point origin,
                                 IntegerInterleavedRaster parent){
    super(sampleModel,dataBuffer,aRegion,origin,parent);
    this.maxX = minX + width;
    this.maxY = minY + height;
    if (!(dataBuffer instanceof DataBufferInt)) {
       throw new RasterFormatException("IntegerInterleavedRasters must have" +
            "integer DataBuffers");
    }
    DataBufferInt dbi = (DataBufferInt)dataBuffer;
    this.data = stealData(dbi, 0);

    if (sampleModel instanceof SinglePixelPackedSampleModel) {
        SinglePixelPackedSampleModel sppsm =
                (SinglePixelPackedSampleModel)sampleModel;
        this.scanlineStride = sppsm.getScanlineStride();
        this.pixelStride    = 1;
        this.dataOffsets = new int[1];
        this.dataOffsets[0] = dbi.getOffset();
        this.bandOffset = this.dataOffsets[0];
        int xOffset = aRegion.x - origin.x;
        int yOffset = aRegion.y - origin.y;
        dataOffsets[0] += xOffset+yOffset*scanlineStride;
        this.numDataElems = sppsm.getNumDataElements();
    } else {
        throw new RasterFormatException("IntegerInterleavedRasters must have"+
                                        " SinglePixelPackedSampleModel");
    }
    verify();
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Creates a subraster given a region of the raster.  The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this raster to the upper-left corner
 * of the subraster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subraster will reference the same
 * DataBuffer as the parent raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent raster.
 */
public WritableRaster createWritableChild (int x, int y,
                                           int width, int height,
                                           int x0, int y0,
                                           int bandList[]) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new IntegerInterleavedRaster(sm,
                                      dataBuffer,
                                      new Rectangle(x0,y0,width,height),
                                      new Point(sampleModelTranslateX+deltaX,
                                                sampleModelTranslateY+deltaY),
                                      this);
}
项目:OpenJSharp    文件:IntegerInterleavedRaster.java   
/**
 * Creates a raster with the same band layout but using a different
 * width and height, and with new zeroed data arrays.
 */
public WritableRaster createCompatibleWritableRaster(int w, int h) {
    if (w <= 0 || h <=0) {
        throw new RasterFormatException("negative "+
                                      ((w <= 0) ? "width" : "height"));
    }

    SampleModel sm = sampleModel.createCompatibleSampleModel(w,h);

    return new IntegerInterleavedRaster(sm, new Point(0,0));
}