java.awt.image.Raster Java Examples
The following examples show how to use
java.awt.image.Raster.
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: SignedColorModel.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public WritableRaster createCompatibleWritableRaster(final int w, final int h) { if (pixelBits == 16) { final int[] bandOffsets = new int[nChannels]; for (int i = 0; i < nChannels; i++) bandOffsets[i] = i; final SampleModel m = new ComponentSampleModel(DataBuffer.TYPE_SHORT, w, h, nChannels, w * nChannels, bandOffsets); final DataBuffer db = new DataBufferShort(w * h, nChannels); return Raster.createWritableRaster(m, db, null); } return helper.createCompatibleWritableRaster(w, h); }
Example #2
Source File: ShortInterleavedRaster.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Stores the Raster data at the specified location. * @param dstX The absolute X coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param dstY The absolute Y coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. */ private void setDataElements(int dstX, int dstY, int width, int height, Raster inRaster) { // Assume bounds checking has been performed previously if (width <= 0 || height <= 0) { return; } // Write inRaster (minX, minY) to (dstX, dstY) int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); Object tdata = null; // REMIND: Do something faster! // if (inRaster instanceof ShortInterleavedRaster) { // } for (int startY=0; startY < height; startY++) { // Grab one scanline at a time tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, width, 1, tdata); setDataElements(dstX, dstY + startY, width, 1, tdata); } }
Example #3
Source File: ColorPaintContext.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public synchronized Raster getRaster(int x, int y, int w, int h) { WritableRaster t = savedTile; if (t == null || w > t.getWidth() || h > t.getHeight()) { t = getColorModel().createCompatibleWritableRaster(w, h); IntegerComponentRaster icr = (IntegerComponentRaster) t; Arrays.fill(icr.getDataStorage(), color); // Note - markDirty is probably unnecessary since icr is brand new icr.markDirty(); if (w <= 64 && h <= 64) { savedTile = t; } } return t; }
Example #4
Source File: Calibration.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
public double getSlope(BufferedImage bi1, BufferedImage bi2, int u, int v, int s, int n) throws IOException { Raster r1 = bi1.getRaster().createTranslatedChild(0,0); Raster r2 = bi2.getRaster().createTranslatedChild(0,0); if (r1.getNumBands()>1) throw new IllegalArgumentException("only 1-banded rasters allowed here"); if (r2.getNumBands()>1) throw new IllegalArgumentException("only 1-banded rasters allowed here"); SimpleRegression reg = new SimpleRegression(true); int minX = u<0?u*-1:0; int minY = v<0?v*-1:0; int maxX = u>0?bi1.getWidth()-u: bi1.getWidth(); int maxY = v>0?bi1.getHeight()-v: bi1.getHeight(); for (int x=minX; x<maxX; x++) { for (int y=minY; y<maxY; y++) { double d1 = r1.getSampleDouble(x+u,y+v,0); if (d1> intensityThreshold) { double d2 = r2.getSampleDouble(x, y, 0); reg.addData(d2, d1); } } } double slope = reg.getSlope(); double intercept = reg.getIntercept(); logger.info("i,j: "+s+","+n+": "+ "slope: "+slope+" ; intercept: "+intercept); return slope; }
Example #5
Source File: ShortComponentRaster.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Stores the Raster data at the specified location. * @param dstX The absolute X coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param dstY The absolute Y coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. */ private void setDataElements(int dstX, int dstY, int width, int height, Raster inRaster) { // Assume bounds checking has been performed previously if (width <= 0 || height <= 0) { return; } // Write inRaster (minX, minY) to (dstX, dstY) int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); Object tdata = null; // // REMIND: Do something faster! // if (inRaster instanceof ShortComponentRaster) { // } for (int startY=0; startY < height; startY++) { // Grab one scanline at a time tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, width, 1, tdata); setDataElements(dstX, dstY + startY, width, 1, tdata); } }
Example #6
Source File: ShortBandedRaster.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Stores the Raster data at the specified location. * @param dstX The absolute X coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param dstY The absolute Y coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. */ private void setDataElements(int dstX, int dstY, int width, int height, Raster inRaster) { // Assume bounds checking has been performed previously if (width <= 0 || height <= 0) { return; } // Write inRaster (minX, minY) to (dstX, dstY) int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); Object tdata = null; // // REMIND: Do something faster! // if (inRaster instanceof ShortBandedRaster) { // } for (int startY=0; startY < height; startY++) { // Grab one scanline at a time tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, width, 1, tdata); setDataElements(dstX, dstY + startY, width, 1, tdata); } }
Example #7
Source File: AWTImageUtils.java From dawnsci with Eclipse Public License 1.0 | 6 votes |
/** * Get datasets from an image * @param image * @param keepBitWidth if true, then use signed primitives of same bit width for possibly unsigned data * @return array of datasets */ static public Dataset[] makeDatasets(final BufferedImage image, boolean keepBitWidth) { // make raster from buffered image final Raster ras = image.getData(); final SampleModel sm = ras.getSampleModel(); int[] dtype = getDTypeFromImage(sm, keepBitWidth); final int bands = ras.getNumBands(); Dataset[] data = new Dataset[bands]; createDatasets(ras, data, dtype[0]); if (dtype[1] == 1) { for (int i = 0; i < bands; i++) { tagIntForShortDataset(data[i]); } } return data; }
Example #8
Source File: IntegerRaster.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Constructs IntegerRaster with the given size. * @param _nrow the number of rows * @param _ncol the number of columns */ public IntegerRaster(int _nrow, int _ncol) { nrow = _nrow; ncol = _ncol; dimension = new Dimension(ncol, nrow); int size = nrow*ncol; ComponentColorModel ccm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8, 8, 8}, false, // hasAlpha false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); BandedSampleModel csm = new BandedSampleModel(DataBuffer.TYPE_BYTE, ncol, nrow, ncol, new int[] {0, 1, 2}, new int[] {0, 0, 0}); rgbData = new byte[3][size]; DataBuffer databuffer = new DataBufferByte(rgbData, size); WritableRaster raster = Raster.createWritableRaster(csm, databuffer, new Point(0, 0)); image = new BufferedImage(ccm, raster, false, null); // col in x direction, row in y direction xmin = 0; xmax = ncol; ymin = nrow; ymax = 0; // zero is on top }
Example #9
Source File: ShortInterleavedRaster.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Stores the Raster data at the specified location. * @param dstX The absolute X coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param dstY The absolute Y coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. */ private void setDataElements(int dstX, int dstY, int width, int height, Raster inRaster) { // Assume bounds checking has been performed previously if (width <= 0 || height <= 0) { return; } // Write inRaster (minX, minY) to (dstX, dstY) int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); Object tdata = null; // REMIND: Do something faster! // if (inRaster instanceof ShortInterleavedRaster) { // } for (int startY=0; startY < height; startY++) { // Grab one scanline at a time tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, width, 1, tdata); setDataElements(dstX, dstY + startY, width, 1, tdata); } }
Example #10
Source File: ShortBandedRaster.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Stores the Raster data at the specified location. * @param dstX The absolute X coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param dstY The absolute Y coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. */ private void setDataElements(int dstX, int dstY, int width, int height, Raster inRaster) { // Assume bounds checking has been performed previously if (width <= 0 || height <= 0) { return; } // Write inRaster (minX, minY) to (dstX, dstY) int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); Object tdata = null; // // REMIND: Do something faster! // if (inRaster instanceof ShortBandedRaster) { // } for (int startY=0; startY < height; startY++) { // Grab one scanline at a time tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, width, 1, tdata); setDataElements(dstX, dstY + startY, width, 1, tdata); } }
Example #11
Source File: RasterOpNullDestinationRasterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) { byte[][] data = new byte[1][10]; ByteLookupTable lut = new ByteLookupTable(0, data); RasterOp op = new LookupOp(lut, null); int[] bandOffsets = {0}; Point location = new Point(0, 0); DataBuffer db = new DataBufferByte(10 * 10); SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 10, 10, 1, 10, bandOffsets); Raster src = Raster.createRaster(sm, db, location); op.filter(src, null); // this used to result in NullPointerException }
Example #12
Source File: EffectUtils.java From Java8CN with Apache License 2.0 | 6 votes |
/** * <p>Returns an array of pixels, stored as integers, from a <code>BufferedImage</code>. The pixels are grabbed from * a rectangular area defined by a location and two dimensions. Calling this method on an image of type different * from <code>BufferedImage.TYPE_INT_ARGB</code> and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the * image.</p> * * @param img the source image * @param x the x location at which to start grabbing pixels * @param y the y location at which to start grabbing pixels * @param w the width of the rectangle of pixels to grab * @param h the height of the rectangle of pixels to grab * @param pixels a pre-allocated array of pixels of size w*h; can be null * @return <code>pixels</code> if non-null, a new array of integers otherwise * @throws IllegalArgumentException is <code>pixels</code> is non-null and of length < w*h */ static byte[] getPixels(BufferedImage img, int x, int y, int w, int h, byte[] pixels) { if (w == 0 || h == 0) { return new byte[0]; } if (pixels == null) { pixels = new byte[w * h]; } else if (pixels.length < w * h) { throw new IllegalArgumentException("pixels array must have a length >= w*h"); } int imageType = img.getType(); if (imageType == BufferedImage.TYPE_BYTE_GRAY) { Raster raster = img.getRaster(); return (byte[]) raster.getDataElements(x, y, w, h, pixels); } else { throw new IllegalArgumentException("Only type BYTE_GRAY is supported"); } }
Example #13
Source File: ImageTests.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void runTest(Object ctx, int numReps) { ImageOpTests.Context ictx = (ImageOpTests.Context)ctx; RasterOp op = ictx.rasterOp; Raster src = ictx.rasSrc; WritableRaster dst = ictx.rasDst; if (ictx.touchSrc) { Graphics gSrc = ictx.bufSrc.getGraphics(); do { gSrc.fillRect(0, 0, 1, 1); op.filter(src, dst); } while (--numReps > 0); } else { do { op.filter(src, dst); } while (--numReps > 0); } }
Example #14
Source File: TexturePaintContext.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
synchronized static WritableRaster makeByteRaster(Raster srcRas, int w, int h) { if (byteRasRef != null) { WritableRaster wr = (WritableRaster) byteRasRef.get(); if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) { byteRasRef = null; return wr; } } // If we are going to cache this Raster, make it non-tiny if (w <= 32 && h <= 32) { w = h = 32; } return srcRas.createCompatibleWritableRaster(w, h); }
Example #15
Source File: ShortBandedRaster.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Stores the Raster data at the specified location. * @param dstX The absolute X coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param dstY The absolute Y coordinate of the destination pixel * that will receive a copy of the upper-left pixel of the * inRaster * @param width The number of pixels to store horizontally * @param height The number of pixels to store vertically * @param inRaster Raster of data to place at x,y location. */ private void setDataElements(int dstX, int dstY, int width, int height, Raster inRaster) { // Assume bounds checking has been performed previously if (width <= 0 || height <= 0) { return; } // Write inRaster (minX, minY) to (dstX, dstY) int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); Object tdata = null; // // REMIND: Do something faster! // if (inRaster instanceof ShortBandedRaster) { // } for (int startY=0; startY < height; startY++) { // Grab one scanline at a time tdata = inRaster.getDataElements(srcOffX, srcOffY+startY, width, 1, tdata); setDataElements(dstX, dstY + startY, width, 1, tdata); } }
Example #16
Source File: BytePackedRaster.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Stores the Raster data at the specified location. * An ArrayIndexOutOfBounds exception will be thrown at runtime * if the pixel coordinates are out of bounds. * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param inRaster Raster of data to place at x,y location. */ public void setDataElements(int x, int y, Raster inRaster) { // Check if we can use fast code if (!(inRaster instanceof BytePackedRaster) || ((BytePackedRaster)inRaster).pixelBitStride != pixelBitStride) { super.setDataElements(x, y, inRaster); return; } int srcOffX = inRaster.getMinX(); int srcOffY = inRaster.getMinY(); int dstOffX = srcOffX + x; int dstOffY = srcOffY + y; int width = inRaster.getWidth(); int height = inRaster.getHeight(); if ((dstOffX < this.minX) || (dstOffY < this.minY) || (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } setDataElements(dstOffX, dstOffY, srcOffX, srcOffY, width, height, (BytePackedRaster)inRaster); }
Example #17
Source File: MapRenderer.java From dsworkbench with Apache License 2.0 | 6 votes |
@Override public Raster getRaster(int x, int y, int w, int h) { WritableRaster raster = getColorModel().createCompatibleWritableRaster(w, h); int[] data = new int[w * h * 4]; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { double distance = mPoint.distance(x + i, y + j); double radius = mRadius.distance(0, 0); double ratio = distance / radius; if (ratio > 1.0) { ratio = 1.0; } int base = (j * w + i) * 4; data[base] = (int) (color1.getRed() + ratio * (color2.getRed() - color1.getRed())); data[base + 1] = (int) (color1.getGreen() + ratio * (color2.getGreen() - color1.getGreen())); data[base + 2] = (int) (color1.getBlue() + ratio * (color2.getBlue() - color1.getBlue())); data[base + 3] = (int) (color1.getAlpha() + ratio * (color2.getAlpha() - color1.getAlpha())); } } raster.setPixels(0, 0, w, h, data); return raster; }
Example #18
Source File: KMLRenderer.java From beast-mcmc with GNU Lesser General Public License v2.1 | 6 votes |
public BufferedImage render(int width, int height) { image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); render(image); Raster raster = image.getData(); lattice = new int[width][height]; int[] pixel = new int[4]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { raster.getPixel(i, j, pixel); if (colorDistanceSquared(pixel, shapeColor) < colorDistanceSquared(pixel, background)) { lattice[i][j] = 1; } else { lattice[i][j] = 0; } } } return image; }
Example #19
Source File: MultipleGradientPaintContext.java From jdk-1.7-annotated with Apache License 2.0 | 6 votes |
/** * Took this cacheRaster code from GradientPaint. It appears to recycle * rasters for use by any other instance, as long as they are sufficiently * large. */ private static synchronized void putCachedRaster(ColorModel cm, Raster ras) { if (cached != null) { Raster cras = (Raster) cached.get(); if (cras != null) { int cw = cras.getWidth(); int ch = cras.getHeight(); int iw = ras.getWidth(); int ih = ras.getHeight(); if (cw >= iw && ch >= ih) { return; } if (cw * ch >= iw * ih) { return; } } } cachedModel = cm; cached = new WeakReference<Raster>(ras); }
Example #20
Source File: TexturePaintContext.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
synchronized static WritableRaster makeByteRaster(Raster srcRas, int w, int h) { if (byteRasRef != null) { WritableRaster wr = (WritableRaster) byteRasRef.get(); if (wr != null && wr.getWidth() >= w && wr.getHeight() >= h) { byteRasRef = null; return wr; } } // If we are going to cache this Raster, make it non-tiny if (w <= 32 && h <= 32) { w = h = 32; } return srcRas.createCompatibleWritableRaster(w, h); }
Example #21
Source File: ColCvtAlpha.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { BufferedImage src = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB); // Set src pixel values Color pelColor = new Color(100, 100, 100, 128); for (int i = 0; i < 10; i++) { src.setRGB(0, i, pelColor.getRGB()); } ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8,8}, true, src.getColorModel().isAlphaPremultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); SampleModel sm = new PixelInterleavedSampleModel (DataBuffer.TYPE_BYTE, 100, 100, 2, 200, new int [] { 0, 1 }); WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0)); BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); dst = dst.getSubimage(0, 0, 1, 10); ColorConvertOp op = new ColorConvertOp(null); op.filter(src, dst); for (int i = 0; i < 10; i++) { if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) { throw new RuntimeException( "Incorrect destination alpha value."); } } }
Example #22
Source File: PixelTests.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void runTest(Object context, int numReps) { Raster ras = ((Context) context).ras; Object elemdata = ((Context) context).elemdata; do { ras.getDataElements(numReps&7, 0, elemdata); } while (--numReps > 0); }
Example #23
Source File: MultipleGradientPaintContext.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public final Raster getRaster(int x, int y, int w, int h) { // If working raster is big enough, reuse it. Otherwise, // build a large enough new one. Raster raster = saved; if (raster == null || raster.getWidth() < w || raster.getHeight() < h) { raster = getCachedRaster(model, w, h); saved = raster; } // Access raster internal int array. Because we use a DirectColorModel, // we know the DataBuffer is of type DataBufferInt and the SampleModel // is SinglePixelPackedSampleModel. // Adjust for initial offset in DataBuffer and also for the scanline // stride. // These calls make the DataBuffer non-acceleratable, but the // Raster is never Stable long enough to accelerate anyway... DataBufferInt rasterDB = (DataBufferInt)raster.getDataBuffer(); int[] pixels = rasterDB.getData(0); int off = rasterDB.getOffset(); int scanlineStride = ((SinglePixelPackedSampleModel) raster.getSampleModel()).getScanlineStride(); int adjust = scanlineStride - w; fillRaster(pixels, off, adjust, x, y, w, h); // delegate to subclass return raster; }
Example #24
Source File: TexturePaintContext.java From Bytecoder with Apache License 2.0 | 5 votes |
static synchronized void dropRaster(ColorModel cm, Raster outRas) { if (outRas == null) { return; } if (xrgbmodel == cm) { xrgbRasRef = new WeakReference<>(outRas); } else if (argbmodel == cm) { argbRasRef = new WeakReference<>(outRas); } }
Example #25
Source File: ShortInterleavedRaster.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Stores the Raster data at the specified location. * An ArrayIndexOutOfBounds exception will be thrown at runtime * if the pixel coordinates are out of bounds. * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param inRaster Raster of data to place at x,y location. */ public void setDataElements(int x, int y, Raster inRaster) { int dstOffX = x + inRaster.getMinX(); int dstOffY = y + inRaster.getMinY(); int width = inRaster.getWidth(); int height = inRaster.getHeight(); if ((dstOffX < this.minX) || (dstOffY < this.minY) || (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } setDataElements(dstOffX, dstOffY, width, height, inRaster); }
Example #26
Source File: ImageRepresentation.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public BufferedImage getOpaqueRGBImage() { if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) { int w = bimage.getWidth(); int h = bimage.getHeight(); int size = w * h; // Note that we steal the data array here, but only for reading... DataBufferInt db = (DataBufferInt)biRaster.getDataBuffer(); int[] pixels = SunWritableRaster.stealData(db, 0); for (int i = 0; i < size; i++) { if ((pixels[i] >>> 24) != 0xff) { return bimage; } } ColorModel opModel = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff); int bandmasks[] = {0x00ff0000, 0x0000ff00, 0x000000ff}; WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w, bandmasks, null); try { BufferedImage opImage = createImage(opModel, opRaster, false, null); return opImage; } catch (Exception e) { return bimage; } } return bimage; }
Example #27
Source File: ByteInterleavedRaster.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void setRect(int dx, int dy, Raster srcRaster) { if (!(srcRaster instanceof ByteInterleavedRaster)) { super.setRect(dx, dy, srcRaster); return; } int width = srcRaster.getWidth(); int height = srcRaster.getHeight(); int srcOffX = srcRaster.getMinX(); int srcOffY = srcRaster.getMinY(); int dstOffX = dx+srcOffX; int dstOffY = dy+srcOffY; // Clip to this raster if (dstOffX < this.minX) { int skipX = minX - dstOffX; width -= skipX; srcOffX += skipX; dstOffX = this.minX; } if (dstOffY < this.minY) { int skipY = this.minY - dstOffY; height -= skipY; srcOffY += skipY; dstOffY = this.minY; } if (dstOffX+width > this.maxX) { width = this.maxX - dstOffX; } if (dstOffY+height > this.maxY) { height = this.maxY - dstOffY; } setDataElements(dstOffX, dstOffY, srcOffX, srcOffY, width, height, srcRaster); }
Example #28
Source File: BMPCompressionTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private boolean compare(final BufferedImage in, final BufferedImage out) { final int width = in.getWidth(); int height = in.getHeight(); if (out.getWidth() != width || out.getHeight() != height) { throw new RuntimeException("Dimensions changed!"); } Raster oldras = in.getRaster(); ColorModel oldcm = in.getColorModel(); Raster newras = out.getRaster(); ColorModel newcm = out.getColorModel(); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { Object oldpixel = oldras.getDataElements(i, j, null); int oldrgb = oldcm.getRGB(oldpixel); int oldalpha = oldcm.getAlpha(oldpixel); Object newpixel = newras.getDataElements(i, j, null); int newrgb = newcm.getRGB(newpixel); int newalpha = newcm.getAlpha(newpixel); if (newrgb != oldrgb || newalpha != oldalpha) { // showDiff(in, out); throw new RuntimeException("Pixels differ at " + i + ", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb)); } } } return true; }
Example #29
Source File: BMPSubsamplingTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) { ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w*3, 3, bOffs, null); return new BufferedImage(colorModel, raster, false, null); }
Example #30
Source File: ColCvtAlpha.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { BufferedImage src = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB); // Set src pixel values Color pelColor = new Color(100, 100, 100, 128); for (int i = 0; i < 10; i++) { src.setRGB(0, i, pelColor.getRGB()); } ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8,8}, true, src.getColorModel().isAlphaPremultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); SampleModel sm = new PixelInterleavedSampleModel (DataBuffer.TYPE_BYTE, 100, 100, 2, 200, new int [] { 0, 1 }); WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0)); BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); dst = dst.getSubimage(0, 0, 1, 10); ColorConvertOp op = new ColorConvertOp(null); op.filter(src, dst); for (int i = 0; i < 10; i++) { if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) { throw new RuntimeException( "Incorrect destination alpha value."); } } }