类java.awt.image.SampleModel源码实例Demo

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

源代码1 项目: openjdk-8   文件: ImageUtil.java
public static int getElementSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof MultiPixelPackedSampleModel) {
        MultiPixelPackedSampleModel mppsm =
            (MultiPixelPackedSampleModel)sm;
        return mppsm.getSampleSize(0) * mppsm.getNumBands();
    } else if (sm instanceof ComponentSampleModel) {
        return sm.getNumBands() * elementSize;
    } else if (sm instanceof SinglePixelPackedSampleModel) {
        return elementSize;
    }

    return elementSize * sm.getNumBands();

}
 
源代码2 项目: openjdk-jdk9   文件: ImageUtil.java
public static long getBandSize(SampleModel sm) {
    int elementSize = DataBuffer.getDataTypeSize(sm.getDataType());

    if (sm instanceof ComponentSampleModel) {
        ComponentSampleModel csm = (ComponentSampleModel)sm;
        int pixelStride = csm.getPixelStride();
        int scanlineStride = csm.getScanlineStride();
        long size = Math.min(pixelStride, scanlineStride);

        if (pixelStride > 0)
            size += pixelStride * (sm.getWidth() - 1);
        if (scanlineStride > 0)
            size += scanlineStride * (sm.getHeight() - 1);
        return size * ((elementSize + 7) / 8);
    } else
        return getTileSize(sm);
}
 
源代码3 项目: openjdk-8   文件: BMPImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
源代码4 项目: JDKSourceCode1.8   文件: JPEGImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    SampleModel sampleModel = type.getSampleModel();

    // Find the maximum bit depth across all channels
    int[] sampleSize = sampleModel.getSampleSize();
    int bitDepth = sampleSize[0];
    for (int i = 1; i < sampleSize.length; i++) {
        if (sampleSize[i] > bitDepth) {
            bitDepth = sampleSize[i];
        }
    }

    // 4450894: Ensure bitDepth is between 1 and 8
    if (bitDepth < 1 || bitDepth > 8) {
        return false;
    }

    return true;
}
 
源代码5 项目: openjdk-jdk9   文件: BMPImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    int dataType= type.getSampleModel().getDataType();
    if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_INT)
        return false;

    SampleModel sm = type.getSampleModel();
    int numBands = sm.getNumBands();
    if (!(numBands == 1 || numBands == 3))
        return false;

    if (numBands == 1 && dataType != DataBuffer.TYPE_BYTE)
        return false;

    if (dataType > DataBuffer.TYPE_BYTE &&
          !(sm instanceof SinglePixelPackedSampleModel))
        return false;

    return true;
}
 
源代码6 项目: dragonwell8_jdk   文件: ICMColorDataTest.java
private static void makeImage() {
    int scanLineBytes = WIDTH / PIXELS_IN_BYTE;
    if ((WIDTH & (PIXELS_IN_BYTE - 1)) != 0) {
        // Make sure all the pixels in a scan line fit
        scanLineBytes += 1;
    }

    byte[]     bits    = new byte[scanLineBytes * HEIGHT];
    DataBuffer dataBuf = new DataBufferByte(bits, bits.length, 0);
    SampleModel sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                              WIDTH, HEIGHT, BITS_PER_PIXEL);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuf, null);
    IndexColorModel indexModel = new IndexColorModel(2, 2, RED, GREEN, BLUE);
    BufferedImage bufImage = new BufferedImage(indexModel, raster,
                                               indexModel.isAlphaPremultiplied(), null);

    Graphics g = bufImage.getGraphics();
    g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
    g.dispose();
}
 
源代码7 项目: dragonwell8_jdk   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: GIFImageWriterSpi.java
public boolean canEncodeImage(ImageTypeSpecifier type) {
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }

    SampleModel sm = type.getSampleModel();
    ColorModel cm = type.getColorModel();

    boolean canEncode = sm.getNumBands() == 1 &&
        sm.getSampleSize(0) <= 8 &&
        sm.getWidth() <= 65535 &&
        sm.getHeight() <= 65535 &&
        (cm == null || cm.getComponentSize()[0] <= 8);

    if (canEncode) {
        return true;
    } else {
        return PaletteBuilder.canCreatePalette(type);
    }
}
 
源代码9 项目: openjdk-jdk9   文件: ByteBandedRaster.java
/**
 *  Constructs a ByteBanded Raster with the given sampleModel
 *  and DataBuffer. The Raster's upper left corner is origin and
 *  it is the same size as the SampleModel.  The DataBuffer is not
 *  initialized and must be a DataBufferShort compatible with SampleModel.
 *  SampleModel must be of type BandedSampleModel.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param dataBuffer      The DataBufferByte that contains the image data.
 *  @param origin          The Point that specifies the origin.
 */
public ByteBandedRaster(SampleModel sampleModel,
                        DataBufferByte dataBuffer,
                        Point origin)
{
    this(sampleModel, dataBuffer,
         new Rectangle(origin.x , origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin, null);
}
 
源代码10 项目: openjdk-jdk8u   文件: SunWritableRaster.java
public SunWritableRaster(SampleModel sampleModel,
                         DataBuffer dataBuffer,
                         Rectangle aRegion,
                         Point sampleModelTranslate,
                         WritableRaster parent)
{
    super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent);
    theTrackable = stealTrackable(dataBuffer);
}
 
源代码11 项目: openjdk-jdk9   文件: 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));
}
 
源代码12 项目: TencentKona-8   文件: 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);
}
 
源代码13 项目: openjdk-8   文件: GIFImageWriter.java
private boolean needToCreateIndex(RenderedImage image) {

        SampleModel sampleModel = image.getSampleModel();
        ColorModel colorModel = image.getColorModel();

        return sampleModel.getNumBands() != 1 ||
            sampleModel.getSampleSize()[0] > 8 ||
            colorModel.getComponentSize()[0] > 8;
    }
 
源代码14 项目: hottub   文件: 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));

}
 
源代码15 项目: libreveris   文件: Picture.java
/**
 * Check if the image format (and especially its color model) is
 * properly handled by Audiveris.
 *
 * @throws ImageFormatException is the format is not supported
 */
private void checkImageFormat ()
        throws ImageFormatException
{
    ColorModel colorModel = image.getColorModel();
    int pixelSize = colorModel.getPixelSize();
    boolean hasAlpha = colorModel.hasAlpha();
    logger.debug("{}", colorModel);

    if (pixelSize == 1) {
        ///image = binaryToGray(image); // Only if rotation is needed!
        implicitForeground = 0;
    }

    // Check nb of bands
    SampleModel sampleModel = image.getSampleModel();
    int numBands = sampleModel.getNumBands();
    logger.debug("numBands={}", numBands);

    if (numBands == 1) {
        // Pixel gray value. Nothing to do
    } else if ((numBands == 2) && hasAlpha) {
        // Pixel + alpha
        // Discard alpha (TODO: check if premultiplied!!!)
        image = JAI.create("bandselect", image, new int[]{});
    } else if ((numBands == 3) && !hasAlpha) {
        // RGB
        image = RGBToGray(image);
    } else if ((numBands == 4) && hasAlpha) {
        // RGB + alpha
        image = RGBAToGray(image);
    } else {
        throw new ImageFormatException(
                "Unsupported sample model numBands=" + numBands);
    }
}
 
源代码16 项目: jdk8u60   文件: 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);
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: ImageFactory.java
public static void fillDCM(DataBuffer data, SampleModel sm, int csType,
                           int c1Bits, int c2Bits, int c3Bits)
{
    int [] pixel;
    pixel = new int[4];
    for (int i = 0; i < WIDTH; i++) {
        for (int j = 0; j < HEIGHT; j++) {
            pixel[0] = i >> (8 - c1Bits);
            pixel[1] = j >> (8 - c2Bits);
            pixel[2] = ((i + j)>>1) >> (8 - c3Bits);
            pixel[3] = 0xFF;
            sm.setPixel(i, j, pixel, data);
        }
    }
}
 
源代码18 项目: openjdk-jdk9   文件: 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));
}
 
源代码19 项目: jdk8u60   文件: 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);
}
 
源代码20 项目: dragonwell8_jdk   文件: ByteComponentRaster.java
/**
 * Constructs a ByteComponentRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same size as the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferByte compatible with SampleModel.
 * SampleModel must be of type SinglePixelPackedSampleModel
 * or ComponentSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public ByteComponentRaster(SampleModel sampleModel,
                              DataBuffer dataBuffer,
                              Point origin) {
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
源代码21 项目: jdk8u-jdk   文件: 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);
}
 
源代码22 项目: visualvm   文件: ImageBuilder.java
@Override
public SampleModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int width = fa.getInt(instance, "width");          // NOI18N
    int height = fa.getInt(instance, "height");  // NOI18N
    int dataType = fa.getInt(instance, "dataType");   // NOI18N
    int scanlineStride = fa.getInt(instance, "scanlineStride");  // NOI18N
    int[] bitMasks = fa.getIntArray(instance, "bitMasks", false);  // NOI18N
    return new SinglePixelPackedSampleModel(dataType, width, height, scanlineStride, bitMasks);
}
 
源代码23 项目: openjdk-8-source   文件: BytePackedRaster.java
/**
 * Constructs a BytePackedRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same size as the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferByte compatible with SampleModel.
 * SampleModel must be of type MultiPixelPackedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public BytePackedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Point origin) {
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
源代码24 项目: Bytecoder   文件: 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,
                                   (DataBufferUShort) dataBuffer,
                                   new Rectangle(x0, y0, width, height),
                                   new Point(sampleModelTranslateX+deltaX,
                                             sampleModelTranslateY+deltaY),
                                   this);
}
 
源代码25 项目: jdk8u_jdk   文件: BytePackedRaster.java
/**
 * Constructs a BytePackedRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same size as the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferByte compatible with SampleModel.
 * SampleModel must be of type MultiPixelPackedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public BytePackedRaster(SampleModel sampleModel,
                        DataBuffer dataBuffer,
                        Point origin) {
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
源代码26 项目: TencentKona-8   文件: 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();
}
 
源代码27 项目: scifio   文件: UnsignedIntColorModel.java
@Override
public WritableRaster createCompatibleWritableRaster(final int w,
	final int h)
{
	final int[] bandOffsets = new int[nChannels];
	for (int i = 0; i < nChannels; i++)
		bandOffsets[i] = i;

	final SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_INT, w, h,
		nChannels, w * nChannels, bandOffsets);
	final DataBuffer db = new DataBufferInt(w * h, nChannels);
	return Raster.createWritableRaster(m, db, null);
}
 
源代码28 项目: jdk8u-jdk   文件: ByteBandedRaster.java
/**
 *  Constructs a ByteBandedRaster with the given sampleModel. The
 *  Raster's upper left corner is origin and it is the same
 *  size as the SampleModel.  A dataBuffer large
 *  enough to describe the Raster is automatically created. SampleModel
 *  must be of type BandedSampleModel.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param origin          The Point that specifies the origin.
 */
public ByteBandedRaster(SampleModel sampleModel,
                           Point origin) {
    this(sampleModel,
         sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
源代码29 项目: openjdk-jdk9   文件: ShortComponentRaster.java
/**
 *  Constructs a ShortComponentRaster with the given SampleModel.
 *  The Raster's upper left corner is origin and it is the same
 *  size as the SampleModel.  A DataBuffer large enough to describe the
 *  Raster is automatically created.  SampleModel must be of type
 *  ComponentSampleModel or SinglePixelPackedSampleModel.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param origin          The Point that specified the origin.
 */
public ShortComponentRaster(SampleModel sampleModel, Point origin) {
    this(sampleModel,
         (DataBufferUShort) sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
源代码30 项目: jdk8u60   文件: 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);
}
 
 类所在包
 同包方法