use of java.awt.image.SampleModel in project Lucee by lucee.
the class Image method jpgImage.
private static BufferedImage jpgImage(BufferedImage src) {
int w = src.getWidth();
int h = src.getHeight();
SampleModel srcSM = src.getSampleModel();
WritableRaster srcWR = src.getRaster();
java.awt.image.DataBuffer srcDB = srcWR.getDataBuffer();
ColorModel rgb = new DirectColorModel(32, 0xff0000, 65280, 255);
int[] bitMasks = new int[] { 0xff0000, 65280, 255 };
SampleModel csm = new SinglePixelPackedSampleModel(3, w, h, bitMasks);
int[] data = new int[w * h];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int[] pix = null;
int[] sample = srcSM.getPixel(j, i, pix, srcDB);
if (sample[3] == 0 && sample[2] == 0 && sample[1] == 0 && sample[0] == 0)
data[i * w + j] = 0xffffff;
else
data[i * w + j] = sample[0] << 16 | sample[1] << 8 | sample[2];
}
}
java.awt.image.DataBuffer db = new DataBufferInt(data, w * h * 3);
WritableRaster wr = Raster.createWritableRaster(csm, db, new Point(0, 0));
return new BufferedImage(rgb, wr, false, null);
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class ByteBandedRaster method createWritableChild.
/**
* 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);
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class ShortBandedRaster method createWritableChild.
/**
* 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);
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class IntegerInterleavedRaster method createWritableChild.
/**
* 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);
}
use of java.awt.image.SampleModel in project jdk8u_jdk by JetBrains.
the class IntegerComponentRaster method createWritableChild.
/**
* 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);
}
Aggregations