java.awt.image.DataBufferUShort Java Examples

The following examples show how to use java.awt.image.DataBufferUShort. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectUtils.java    From WorldPainter with GNU General Public License v3.0 6 votes vote down vote up
public static DataBuffer clone(DataBuffer dataBuffer) {
    if (dataBuffer instanceof DataBufferByte) {
        return clone((DataBufferByte) dataBuffer);
    } else if (dataBuffer instanceof DataBufferDouble) {
        return clone((DataBufferDouble) dataBuffer);
    } else if (dataBuffer instanceof DataBufferFloat) {
        return clone((DataBufferFloat) dataBuffer);
    } else if (dataBuffer instanceof DataBufferInt) {
        return clone((DataBufferInt) dataBuffer);
    } else if (dataBuffer instanceof DataBufferShort) {
        return clone((DataBufferShort) dataBuffer);
    } else if (dataBuffer instanceof DataBufferUShort) {
        return clone((DataBufferUShort) dataBuffer);
    } else {
        throw new UnsupportedOperationException("Don't know how to clone " + dataBuffer.getClass().getName());
    }
}
 
Example #2
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Extracts pixel data as arrays of unsigned shorts, one per channel. */
public static short[][] getShorts(final WritableRaster r, final int x,
	final int y, final int w, final int h)
{
	if (canUseBankDataDirectly(r, DataBuffer.TYPE_USHORT,
		DataBufferUShort.class) && x == 0 && y == 0 && w == r.getWidth() && h == r
			.getHeight())
	{
		return ((DataBufferUShort) r.getDataBuffer()).getBankData();
	}
	final int c = r.getNumBands();
	final short[][] samples = new short[c][w * h];
	final int[] buf = new int[w * h];
	for (int i = 0; i < c; i++) {
		r.getSamples(x, y, w, h, i, buf);
		for (int j = 0; j < buf.length; j++)
			samples[i][j] = (short) buf[j];
	}
	return samples;
}
 
Example #3
Source File: GraphicsUtils.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
public static Object getData(final DataBuffer db) {
	if (db instanceof DataBufferByte) {
		return ((DataBufferByte) db).getData();
	} else if (db instanceof DataBufferUShort) {
		return ((DataBufferUShort) db).getData();
	} else if (db instanceof DataBufferShort) {
		return ((DataBufferShort) db).getData();
	} else if (db instanceof DataBufferInt) {
		return ((DataBufferInt) db).getData();
	} else if (db instanceof DataBufferFloat) {
		return ((DataBufferFloat) db).getData();
	} else if (db instanceof DataBufferDouble) {
		return ((DataBufferDouble) db).getData();
	} else {
		throw new RuntimeException("Not found DataBuffer class !");
	}
}
 
Example #4
Source File: ShortComponentRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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);
}
 
Example #5
Source File: ShortBandedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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,
                                 (DataBufferUShort) dataBuffer,
                                 new Rectangle(x0, y0, width, height),
                                 new Point(sampleModelTranslateX+deltaX,
                                           sampleModelTranslateY+deltaY),
                                 this);

}
 
Example #6
Source File: ShortBandedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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,
                         DataBufferUShort dataBuffer,
                         Rectangle aRegion,
                         Point origin,
                         ShortBandedRaster parent)
{
    super(sampleModel, dataBuffer, aRegion, origin, parent);
    this.maxX = minX + width;
    this.maxY = minY + height;

    if (sampleModel instanceof BandedSampleModel) {
        BandedSampleModel bsm = (BandedSampleModel)sampleModel;
        this.scanlineStride = bsm.getScanlineStride();
        int bankIndices[] = bsm.getBankIndices();
        int bandOffsets[] = bsm.getBandOffsets();
        int dOffsets[] = dataBuffer.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(dataBuffer, bankIndices[i]);
           dataOffsets[i] = dOffsets[bankIndices[i]] +
               xOffset + yOffset*scanlineStride + bandOffsets[i];
        }
    } else {
        throw new RasterFormatException("ShortBandedRasters must have "+
            "BandedSampleModels");
    }
    verify();
}
 
Example #7
Source File: ShortBandedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster 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 specified the origin.
 */
public ShortBandedRaster(SampleModel sampleModel, Point origin) {
    this(sampleModel,
         (DataBufferUShort) sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
Example #8
Source File: ShortInterleavedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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,
                                   (DataBufferUShort) dataBuffer,
                                   new Rectangle(x0, y0, width, height),
                                   new Point(sampleModelTranslateX+deltaX,
                                             sampleModelTranslateY+deltaY),
                                   this);
}
 
Example #9
Source File: ShortInterleavedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortInterleavedRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same sizes the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferUShort compatible with SampleModel.
 * SampleModel must be of type PixelInterleavedSampleModel or
 * SinglePixelPackedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public ShortInterleavedRaster(SampleModel sampleModel,
                              DataBufferUShort dataBuffer,
                              Point origin)
{
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
Example #10
Source File: ShortInterleavedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Constructs a ShortInterleavedRaster 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
 *  PixelInterleavedSampleModel or SinglePixelPackedSampleModel.
 *  @param sampleModel     The SampleModel that specifies the layout.
 *  @param origin          The Point that specified the origin.
 */
public ShortInterleavedRaster(SampleModel sampleModel, Point origin) {
    this(sampleModel,
         (DataBufferUShort) sampleModel.createDataBuffer(),
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
Example #11
Source File: ShortComponentRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #12
Source File: ShortComponentRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortComponentRaster with the given SampleModel
 * and DataBuffer.  The Raster's upper left corner is origin and
 * it is the same sizes the SampleModel.  The DataBuffer is not
 * initialized and must be a DataBufferUShort compatible with SampleModel.
 * SampleModel must be of type ComponentSampleModel or
 * SinglePixelPackedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public ShortComponentRaster(SampleModel sampleModel,
                            DataBufferUShort dataBuffer,
                            Point origin)
{
    this(sampleModel,
         dataBuffer,
         new Rectangle(origin.x,
                       origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin,
         null);
}
 
Example #13
Source File: ShortBandedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #14
Source File: ShortBandedRaster.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * 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,
                                 (DataBufferUShort) dataBuffer,
                                 new Rectangle(x0, y0, width, height),
                                 new Point(sampleModelTranslateX+deltaX,
                                           sampleModelTranslateY+deltaY),
                                 this);

}
 
Example #15
Source File: ShortComponentRaster.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 *  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);
}
 
Example #16
Source File: ImageBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public DataBuffer convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int size = fa.getInt(instance, "size");                        // NOI18N
    int[] offsets = fa.getIntArray(instance, "offsets", false);      // NOI18N
    short[][] bankdata = fa.getShortArray2(instance, "bankdata", false); // NOI18N
    return new DataBufferUShort(bankdata, size, offsets);
}
 
Example #17
Source File: ShortBandedRaster.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #18
Source File: TestChildRasterOp.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testShortRaster() {
    WritableRaster srcRaster, dstRaster;

    short[] pixels =
        { 11, 12, 13, 14,
          21, 22, 23, 24,
          31, 32, 33, 34,
          41, 42, 43, 44 };

    DataBuffer db = new DataBufferUShort(pixels, pixels.length);
    srcRaster =
        Raster.createInterleavedRaster(db, 4, 4, 4, 1, offsets, null);
    srcRaster = srcRaster.createWritableChild(1, 1, 3, 3, 0, 0, null);
    dstRaster = rop.filter(srcRaster, null);
}
 
Example #19
Source File: ShortBandedRaster.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a ShortBandedRaster 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 DataBufferUShort compatible with SampleModel.
 * SampleModel must be of type BandedSampleModel.
 * @param sampleModel     The SampleModel that specifies the layout.
 * @param dataBuffer      The DataBufferUShort that contains the image data.
 * @param origin          The Point that specifies the origin.
 */
public ShortBandedRaster(SampleModel sampleModel,
                         DataBufferUShort dataBuffer,
                         Point origin)
{
    this(sampleModel, dataBuffer,
         new Rectangle(origin.x, origin.y,
                       sampleModel.getWidth(),
                       sampleModel.getHeight()),
         origin, null);
}
 
Example #20
Source File: ShortBandedRaster.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #21
Source File: ShortBandedRaster.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #22
Source File: ImageBuilder.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DataBuffer convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
    int size = fa.getInt(instance, "size");                        // NOI18N
    int[] offsets = fa.getIntArray(instance, "offsets", false);      // NOI18N
    short[][] bankdata = fa.getShortArray2(instance, "bankdata", false); // NOI18N
    return new DataBufferUShort(bankdata, size, offsets);
}
 
Example #23
Source File: ShortBandedRaster.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #24
Source File: ShortBandedRaster.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #25
Source File: ShortBandedRaster.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #26
Source File: ShortBandedRaster.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #27
Source File: MenuMisc.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
public static void WritePNGfile(String imagename, short[] linear, int width, int height) {
    BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_555_RGB);
    DataBufferUShort sh = (DataBufferUShort) buf.getRaster().getDataBuffer();
    short[] shd = sh.getData();
    System.arraycopy(linear, 0, shd, 0, Math.min(linear.length, shd.length));
    try {
        ImageIO.write(buf, "PNG", new File(imagename));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #28
Source File: SoftwareGraphicsSystem.java    From mochadoom with GNU General Public License v3.0 5 votes vote down vote up
public DataBuffer newBuffer(DoomScreen screen) {
    final V buffer = screens.get(screen);
    if (buffer.getClass() == int[].class) {
        return new DataBufferInt((int[]) buffer, ((int[]) buffer).length);
    } else if (buffer.getClass() == short[].class) {
        return new DataBufferUShort((short[]) buffer, ((short[]) buffer).length);
    } else if (buffer.getClass() == byte[].class) {
        return new DataBufferByte((byte[]) buffer, ((byte[]) buffer).length);
    }
    
    throw new UnsupportedOperationException(String.format("SoftwareVideoRenderer does not support %s buffers", buffer.getClass()));
}
 
Example #29
Source File: AWTLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Object extractImageData(BufferedImage img){
    DataBuffer buf = img.getRaster().getDataBuffer();
    switch (buf.getDataType()){
        case DataBuffer.TYPE_BYTE:
            DataBufferByte byteBuf = (DataBufferByte) buf;
            return byteBuf.getData();
        case DataBuffer.TYPE_USHORT:
            DataBufferUShort shortBuf = (DataBufferUShort) buf;
            return shortBuf.getData();
    }
    return null;
}
 
Example #30
Source File: GrayscalePlot.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the data storage to the given value.
 *
 * @param _griddata new data storage
 */
public void setGridData(GridData _griddata) {
  griddata = _griddata;
  if(griddata==null) {
    return;
  }
  int nx = griddata.getNx();
  int ny = griddata.getNy();
  int size = nx*ny;
  Grid newgrid = new Grid(nx, ny, xmin, xmax, ymin, ymax);
  if(grid!=null) {
    newgrid.setColor(grid.getColor());
    newgrid.setVisible(grid.isVisible());
  } else {
    newgrid.setColor(Color.pink);
  }
  grid = newgrid;
  ComponentColorModel ccm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {16}, false, // hasAlpha
    false, // alspha premultiplied
      Transparency.OPAQUE, DataBuffer.TYPE_USHORT);
  ComponentSampleModel csm = new ComponentSampleModel(DataBuffer.TYPE_USHORT, nx, ny, 1, nx, new int[] {0});
  bwData = new short[size];
  DataBuffer databuffer = new DataBufferUShort(bwData, size);
  WritableRaster raster = Raster.createWritableRaster(csm, databuffer, new Point(0, 0));
  image = new BufferedImage(ccm, raster, true, null);
  xmin = griddata.getLeft();
  xmax = griddata.getRight();
  ymin = griddata.getBottom();
  ymax = griddata.getTop();
}