Java Code Examples for java.awt.image.WritableRaster#getDataElements()
The following examples show how to use
java.awt.image.WritableRaster#getDataElements() .
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: GlyphPage.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Loads a single glyph to the backing texture, if it fits. * * @param glyph The glyph to be rendered * @param width The expected width of the glyph * @param height The expected height of the glyph * @throws SlickException if the glyph could not be rendered. */ private void renderGlyph(Glyph glyph, int width, int height) throws SlickException { // Draw the glyph to the scratch image using Java2D. scratchGraphics.setComposite(AlphaComposite.Clear); scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE); scratchGraphics.setComposite(AlphaComposite.SrcOver); scratchGraphics.setColor(java.awt.Color.white); for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) ((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph); glyph.setShape(null); // The shape will never be needed again. WritableRaster raster = scratchImage.getRaster(); int[] row = new int[width]; for (int y = 0; y < height; y++) { raster.getDataElements(0, y, width, 1, row); scratchIntBuffer.put(row); } GL.glTexSubImage2D(SGL.GL_TEXTURE_2D, 0, pageX, pageY, width, height, SGL.GL_BGRA, SGL.GL_UNSIGNED_BYTE, scratchByteBuffer); scratchIntBuffer.clear(); glyph.setImage(pageImage.getSubImage(pageX, pageY, width, height)); }
Example 2
Source File: IMGUtils.java From icafe with Eclipse Public License 1.0 | 6 votes |
public static void RGB2YCCK_Inverted(ICC_ColorSpace cmykColorSpace, int[] rgb, float[][] Y, float[][] Cb, float[][] Cr, float[][] K, int imageWidth, int imageHeight) { DataBuffer db = new DataBufferInt(rgb, rgb.length); WritableRaster raster = Raster.createPackedRaster(db, imageWidth, imageHeight, imageWidth, new int[] {0x00ff0000, 0x0000ff00, 0x000000ff}, null); ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorConvertOp cco = new ColorConvertOp(sRGB, cmykColorSpace, null); BufferedImage rgbImage = new BufferedImage(new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff), raster, false, null); BufferedImage cmykImage = cco.filter(rgbImage, null); WritableRaster cmykRaster = cmykImage.getRaster(); byte[] cmyk = (byte[])cmykRaster.getDataElements(0, 0, imageWidth, imageHeight, null); float c, m, y; for(int i = 0, index = 0; i < imageHeight; i++) { for(int j = 0; j < imageWidth; j++) { c = 255.0f - (cmyk[index++]&0xff); // Red m = 255.0f - (cmyk[index++]&0xff); // Green y = 255.0f - (cmyk[index++]&0xff); // Blue Y[i][j] = 128.0f - (c*0.299f + m*0.587f + y*0.114f); Cb[i][j] = 0.16874f*c + 0.33126f*m - 0.5f*y; Cr[i][j] = - 0.5f*c + 0.41869f*m + 0.08131f*y; K[i][j] = 128.0f - (cmyk[index++]&0xff); } } }
Example 3
Source File: BiImage.java From logbook-kai with MIT License | 6 votes |
/** * {@code image}で指定された画像と{@code color}で指定された色からBiImageを構築します * * @param image ソース画像 * @param color 黒色として認識する色 */ public BiImage(BufferedImage image, Color color) { this.color = color.getRGB() & 0xffffff; // truncate alpha this.width = image.getWidth(); this.height = image.getHeight(); this.wwl = ((this.width - 1) >> ADDRESS_BITS_PER_WORD) + 1; this.hwl = ((this.height - 1) >> ADDRESS_BITS_PER_WORD) + 1; WritableRaster raster; if (image.getType() == BufferedImage.TYPE_INT_RGB) { raster = image.getRaster(); } else { BufferedImage newimg = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = newimg.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); raster = newimg.getRaster(); } int[] data = (int[]) raster.getDataElements(0, 0, this.width, this.height, null); this.init(data, this.width, this.height, this.color); }
Example 4
Source File: PointFilter.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public BufferedImage filter( BufferedImage src, BufferedImage dst ) { int width = src.getWidth(); int height = src.getHeight(); int type = src.getType(); WritableRaster srcRaster = src.getRaster(); if ( dst == null ) dst = createCompatibleDestImage( src, null ); WritableRaster dstRaster = dst.getRaster(); setDimensions( width, height); int[] inPixels = new int[width]; for ( int y = 0; y < height; y++ ) { // We try to avoid calling getRGB on images as it causes them to become unmanaged, causing horrible performance problems. if ( type == BufferedImage.TYPE_INT_ARGB ) { srcRaster.getDataElements( 0, y, width, 1, inPixels ); for ( int x = 0; x < width; x++ ) inPixels[x] = filterRGB( x, y, inPixels[x] ); dstRaster.setDataElements( 0, y, width, 1, inPixels ); } else { src.getRGB( 0, y, width, 1, inPixels, 0, width ); for ( int x = 0; x < width; x++ ) inPixels[x] = filterRGB( x, y, inPixels[x] ); dst.setRGB( 0, y, width, 1, inPixels, 0, width ); } } return dst; }
Example 5
Source File: ImageProcessor.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
static private String hash (BufferedImage image) { try { MessageDigest digest = MessageDigest.getInstance("SHA1"); // Ensure image is the correct format. int width = image.getWidth(); int height = image.getHeight(); if (image.getType() != BufferedImage.TYPE_INT_ARGB) { BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); newImage.getGraphics().drawImage(image, 0, 0, null); image = newImage; } WritableRaster raster = image.getRaster(); int[] pixels = new int[width]; for (int y = 0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); for (int x = 0; x < width; x++) hash(digest, pixels[x]); } hash(digest, width); hash(digest, height); return new BigInteger(1, digest.digest()).toString(16); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException(ex); } }
Example 6
Source File: OffScreenImageSource.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void sendPixels() { ColorModel cm = image.getColorModel(); WritableRaster raster = image.getRaster(); int numDataElements = raster.getNumDataElements(); int dataType = raster.getDataBuffer().getDataType(); int[] scanline = new int[width*numDataElements]; boolean needToCvt = true; if (cm instanceof IndexColorModel) { byte[] pixels = new byte[width]; theConsumer.setColorModel(cm); if (raster instanceof ByteComponentRaster) { needToCvt = false; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (raster instanceof BytePackedRaster) { needToCvt = false; // Binary image. Need to unpack it for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); for (int x=0; x < width; x++) { pixels[x] = (byte) scanline[x]; } theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) { // Probably a short or int "GRAY" image needToCvt = false; for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } } } else if (cm instanceof DirectColorModel) { theConsumer.setColorModel(cm); needToCvt = false; switch (dataType) { case DataBuffer.TYPE_INT: for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_BYTE: byte[] bscanline = new byte[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, bscanline); for (int x=0; x < width; x++) { scanline[x] = bscanline[x]&0xff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_USHORT: short[] sscanline = new short[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, sscanline); for (int x=0; x < width; x++) { scanline[x] = sscanline[x]&0xffff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; default: needToCvt = true; } } if (needToCvt) { // REMIND: Need to add other types of CMs here ColorModel newcm = ColorModel.getRGBdefault(); theConsumer.setColorModel(newcm); for (int y=0; y < height; y++) { for (int x=0; x < width; x++) { scanline[x] = image.getRGB(x, y); } theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width); } } }
Example 7
Source File: TexturePaintContext.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
public void setRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.srcRas; WritableRaster outRas = this.outRas; int rgbs[] = filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.getDataElements(x, y, data); if (filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, y, data); rgbs[1] = colorModel.getRGB(data); data = srcRas.getDataElements(x, nexty, data); rgbs[2] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, nexty, data); rgbs[3] = colorModel.getRGB(data); int rgb = TexturePaintContext.blend(rgbs, xerr, yerr); data = colorModel.getDataElements(rgb, data); } outRas.setDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MAX_VALUE; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MAX_VALUE; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MAX_VALUE; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MAX_VALUE; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
Example 8
Source File: TexturePaintContext.java From Java8CN with Apache License 2.0 | 4 votes |
public void setRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.srcRas; WritableRaster outRas = this.outRas; int rgbs[] = filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.getDataElements(x, y, data); if (filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, y, data); rgbs[1] = colorModel.getRGB(data); data = srcRas.getDataElements(x, nexty, data); rgbs[2] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, nexty, data); rgbs[3] = colorModel.getRGB(data); int rgb = TexturePaintContext.blend(rgbs, xerr, yerr); data = colorModel.getDataElements(rgb, data); } outRas.setDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MAX_VALUE; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MAX_VALUE; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MAX_VALUE; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MAX_VALUE; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
Example 9
Source File: OffScreenImageSource.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
private void sendPixels() { ColorModel cm = image.getColorModel(); WritableRaster raster = image.getRaster(); int numDataElements = raster.getNumDataElements(); int dataType = raster.getDataBuffer().getDataType(); int[] scanline = new int[width*numDataElements]; boolean needToCvt = true; if (cm instanceof IndexColorModel) { byte[] pixels = new byte[width]; theConsumer.setColorModel(cm); if (raster instanceof ByteComponentRaster) { needToCvt = false; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (raster instanceof BytePackedRaster) { needToCvt = false; // Binary image. Need to unpack it for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); for (int x=0; x < width; x++) { pixels[x] = (byte) scanline[x]; } theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) { // Probably a short or int "GRAY" image needToCvt = false; for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } } } else if (cm instanceof DirectColorModel) { theConsumer.setColorModel(cm); needToCvt = false; switch (dataType) { case DataBuffer.TYPE_INT: for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_BYTE: byte[] bscanline = new byte[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, bscanline); for (int x=0; x < width; x++) { scanline[x] = bscanline[x]&0xff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_USHORT: short[] sscanline = new short[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, sscanline); for (int x=0; x < width; x++) { scanline[x] = sscanline[x]&0xffff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; default: needToCvt = true; } } if (needToCvt) { // REMIND: Need to add other types of CMs here ColorModel newcm = ColorModel.getRGBdefault(); theConsumer.setColorModel(newcm); for (int y=0; y < height; y++) { for (int x=0; x < width; x++) { scanline[x] = image.getRGB(x, y); } theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width); } } }
Example 10
Source File: OffScreenImageSource.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void sendPixels() { ColorModel cm = image.getColorModel(); WritableRaster raster = image.getRaster(); int numDataElements = raster.getNumDataElements(); int dataType = raster.getDataBuffer().getDataType(); int[] scanline = new int[width*numDataElements]; boolean needToCvt = true; if (cm instanceof IndexColorModel) { byte[] pixels = new byte[width]; theConsumer.setColorModel(cm); if (raster instanceof ByteComponentRaster) { needToCvt = false; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (raster instanceof BytePackedRaster) { needToCvt = false; // Binary image. Need to unpack it for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); for (int x=0; x < width; x++) { pixels[x] = (byte) scanline[x]; } theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) { // Probably a short or int "GRAY" image needToCvt = false; for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } } } else if (cm instanceof DirectColorModel) { theConsumer.setColorModel(cm); needToCvt = false; switch (dataType) { case DataBuffer.TYPE_INT: for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_BYTE: byte[] bscanline = new byte[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, bscanline); for (int x=0; x < width; x++) { scanline[x] = bscanline[x]&0xff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_USHORT: short[] sscanline = new short[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, sscanline); for (int x=0; x < width; x++) { scanline[x] = sscanline[x]&0xffff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; default: needToCvt = true; } } if (needToCvt) { // REMIND: Need to add other types of CMs here ColorModel newcm = ColorModel.getRGBdefault(); theConsumer.setColorModel(newcm); for (int y=0; y < height; y++) { for (int x=0; x < width; x++) { scanline[x] = image.getRGB(x, y); } theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width); } } }
Example 11
Source File: TexturePaintContext.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public void setRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.srcRas; WritableRaster outRas = this.outRas; int rgbs[] = filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.getDataElements(x, y, data); if (filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, y, data); rgbs[1] = colorModel.getRGB(data); data = srcRas.getDataElements(x, nexty, data); rgbs[2] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, nexty, data); rgbs[3] = colorModel.getRGB(data); int rgb = TexturePaintContext.blend(rgbs, xerr, yerr); data = colorModel.getDataElements(rgb, data); } outRas.setDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MAX_VALUE; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MAX_VALUE; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MAX_VALUE; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MAX_VALUE; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
Example 12
Source File: OffScreenImageSource.java From hottub with GNU General Public License v2.0 | 4 votes |
private void sendPixels() { ColorModel cm = image.getColorModel(); WritableRaster raster = image.getRaster(); int numDataElements = raster.getNumDataElements(); int dataType = raster.getDataBuffer().getDataType(); int[] scanline = new int[width*numDataElements]; boolean needToCvt = true; if (cm instanceof IndexColorModel) { byte[] pixels = new byte[width]; theConsumer.setColorModel(cm); if (raster instanceof ByteComponentRaster) { needToCvt = false; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (raster instanceof BytePackedRaster) { needToCvt = false; // Binary image. Need to unpack it for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); for (int x=0; x < width; x++) { pixels[x] = (byte) scanline[x]; } theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) { // Probably a short or int "GRAY" image needToCvt = false; for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } } } else if (cm instanceof DirectColorModel) { theConsumer.setColorModel(cm); needToCvt = false; switch (dataType) { case DataBuffer.TYPE_INT: for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_BYTE: byte[] bscanline = new byte[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, bscanline); for (int x=0; x < width; x++) { scanline[x] = bscanline[x]&0xff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_USHORT: short[] sscanline = new short[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, sscanline); for (int x=0; x < width; x++) { scanline[x] = sscanline[x]&0xffff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; default: needToCvt = true; } } if (needToCvt) { // REMIND: Need to add other types of CMs here ColorModel newcm = ColorModel.getRGBdefault(); theConsumer.setColorModel(newcm); for (int y=0; y < height; y++) { for (int x=0; x < width; x++) { scanline[x] = image.getRGB(x, y); } theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width); } } }
Example 13
Source File: OffScreenImageSource.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
private void sendPixels() { ColorModel cm = image.getColorModel(); WritableRaster raster = image.getRaster(); int numDataElements = raster.getNumDataElements(); int dataType = raster.getDataBuffer().getDataType(); int[] scanline = new int[width*numDataElements]; boolean needToCvt = true; if (cm instanceof IndexColorModel) { byte[] pixels = new byte[width]; theConsumer.setColorModel(cm); if (raster instanceof ByteComponentRaster) { needToCvt = false; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (raster instanceof BytePackedRaster) { needToCvt = false; // Binary image. Need to unpack it for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); for (int x=0; x < width; x++) { pixels[x] = (byte) scanline[x]; } theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) { // Probably a short or int "GRAY" image needToCvt = false; for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } } } else if (cm instanceof DirectColorModel) { theConsumer.setColorModel(cm); needToCvt = false; switch (dataType) { case DataBuffer.TYPE_INT: for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_BYTE: byte[] bscanline = new byte[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, bscanline); for (int x=0; x < width; x++) { scanline[x] = bscanline[x]&0xff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_USHORT: short[] sscanline = new short[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, sscanline); for (int x=0; x < width; x++) { scanline[x] = sscanline[x]&0xffff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; default: needToCvt = true; } } if (needToCvt) { // REMIND: Need to add other types of CMs here ColorModel newcm = ColorModel.getRGBdefault(); theConsumer.setColorModel(newcm); for (int y=0; y < height; y++) { for (int x=0; x < width; x++) { scanline[x] = image.getRGB(x, y); } theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width); } } }
Example 14
Source File: OffScreenImageSource.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private void sendPixels() { ColorModel cm = image.getColorModel(); WritableRaster raster = image.getRaster(); int numDataElements = raster.getNumDataElements(); int dataType = raster.getDataBuffer().getDataType(); int[] scanline = new int[width*numDataElements]; boolean needToCvt = true; if (cm instanceof IndexColorModel) { byte[] pixels = new byte[width]; theConsumer.setColorModel(cm); if (raster instanceof ByteComponentRaster) { needToCvt = false; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (raster instanceof BytePackedRaster) { needToCvt = false; // Binary image. Need to unpack it for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); for (int x=0; x < width; x++) { pixels[x] = (byte) scanline[x]; } theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) { // Probably a short or int "GRAY" image needToCvt = false; for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } } } else if (cm instanceof DirectColorModel) { theConsumer.setColorModel(cm); needToCvt = false; switch (dataType) { case DataBuffer.TYPE_INT: for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_BYTE: byte[] bscanline = new byte[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, bscanline); for (int x=0; x < width; x++) { scanline[x] = bscanline[x]&0xff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_USHORT: short[] sscanline = new short[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, sscanline); for (int x=0; x < width; x++) { scanline[x] = sscanline[x]&0xffff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; default: needToCvt = true; } } if (needToCvt) { // REMIND: Need to add other types of CMs here ColorModel newcm = ColorModel.getRGBdefault(); theConsumer.setColorModel(newcm); for (int y=0; y < height; y++) { for (int x=0; x < width; x++) { scanline[x] = image.getRGB(x, y); } theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width); } } }
Example 15
Source File: TexturePaintContext.java From jdk-1.7-annotated with Apache License 2.0 | 4 votes |
public void setRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.srcRas; WritableRaster outRas = this.outRas; int rgbs[] = filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.getDataElements(x, y, data); if (filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, y, data); rgbs[1] = colorModel.getRGB(data); data = srcRas.getDataElements(x, nexty, data); rgbs[2] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, nexty, data); rgbs[3] = colorModel.getRGB(data); int rgb = TexturePaintContext.blend(rgbs, xerr, yerr); data = colorModel.getDataElements(rgb, data); } outRas.setDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MAX_VALUE; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MAX_VALUE; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MAX_VALUE; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MAX_VALUE; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
Example 16
Source File: OffScreenImageSource.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void sendPixels() { ColorModel cm = image.getColorModel(); WritableRaster raster = image.getRaster(); int numDataElements = raster.getNumDataElements(); int dataType = raster.getDataBuffer().getDataType(); int[] scanline = new int[width*numDataElements]; boolean needToCvt = true; if (cm instanceof IndexColorModel) { byte[] pixels = new byte[width]; theConsumer.setColorModel(cm); if (raster instanceof ByteComponentRaster) { needToCvt = false; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, pixels); theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (raster instanceof BytePackedRaster) { needToCvt = false; // Binary image. Need to unpack it for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); for (int x=0; x < width; x++) { pixels[x] = (byte) scanline[x]; } theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width); } } else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) { // Probably a short or int "GRAY" image needToCvt = false; for (int y=0; y < height; y++) { raster.getPixels(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } } } else if (cm instanceof DirectColorModel) { theConsumer.setColorModel(cm); needToCvt = false; switch (dataType) { case DataBuffer.TYPE_INT: for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, scanline); theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_BYTE: byte[] bscanline = new byte[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, bscanline); for (int x=0; x < width; x++) { scanline[x] = bscanline[x]&0xff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; case DataBuffer.TYPE_USHORT: short[] sscanline = new short[width]; for (int y=0; y < height; y++) { raster.getDataElements(0, y, width, 1, sscanline); for (int x=0; x < width; x++) { scanline[x] = sscanline[x]&0xffff; } theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width); } break; default: needToCvt = true; } } if (needToCvt) { // REMIND: Need to add other types of CMs here ColorModel newcm = ColorModel.getRGBdefault(); theConsumer.setColorModel(newcm); for (int y=0; y < height; y++) { for (int x=0; x < width; x++) { scanline[x] = image.getRGB(x, y); } theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width); } } }
Example 17
Source File: TexturePaintContext.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void setRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.srcRas; WritableRaster outRas = this.outRas; int rgbs[] = filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.getDataElements(x, y, data); if (filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, y, data); rgbs[1] = colorModel.getRGB(data); data = srcRas.getDataElements(x, nexty, data); rgbs[2] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, nexty, data); rgbs[3] = colorModel.getRGB(data); int rgb = TexturePaintContext.blend(rgbs, xerr, yerr); data = colorModel.getDataElements(rgb, data); } outRas.setDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MAX_VALUE; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MAX_VALUE; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MAX_VALUE; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MAX_VALUE; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
Example 18
Source File: TexturePaintContext.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public void setRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.srcRas; WritableRaster outRas = this.outRas; int rgbs[] = filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.getDataElements(x, y, data); if (filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, y, data); rgbs[1] = colorModel.getRGB(data); data = srcRas.getDataElements(x, nexty, data); rgbs[2] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, nexty, data); rgbs[3] = colorModel.getRGB(data); int rgb = TexturePaintContext.blend(rgbs, xerr, yerr); data = colorModel.getDataElements(rgb, data); } outRas.setDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MAX_VALUE; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MAX_VALUE; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MAX_VALUE; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MAX_VALUE; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
Example 19
Source File: TexturePaintContext.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void setRaster(int x, int y, int xerr, int yerr, int w, int h, int bWidth, int bHeight, int colincx, int colincxerr, int colincy, int colincyerr, int rowincx, int rowincxerr, int rowincy, int rowincyerr) { Object data = null; int rowx = x; int rowy = y; int rowxerr = xerr; int rowyerr = yerr; WritableRaster srcRas = this.srcRas; WritableRaster outRas = this.outRas; int rgbs[] = filter ? new int[4] : null; for (int j = 0; j < h; j++) { x = rowx; y = rowy; xerr = rowxerr; yerr = rowyerr; for (int i = 0; i < w; i++) { data = srcRas.getDataElements(x, y, data); if (filter) { int nextx, nexty; if ((nextx = x + 1) >= bWidth) { nextx = 0; } if ((nexty = y + 1) >= bHeight) { nexty = 0; } rgbs[0] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, y, data); rgbs[1] = colorModel.getRGB(data); data = srcRas.getDataElements(x, nexty, data); rgbs[2] = colorModel.getRGB(data); data = srcRas.getDataElements(nextx, nexty, data); rgbs[3] = colorModel.getRGB(data); int rgb = TexturePaintContext.blend(rgbs, xerr, yerr); data = colorModel.getDataElements(rgb, data); } outRas.setDataElements(i, j, data); if ((xerr += colincxerr) < 0) { xerr &= Integer.MAX_VALUE; x++; } if ((x += colincx) >= bWidth) { x -= bWidth; } if ((yerr += colincyerr) < 0) { yerr &= Integer.MAX_VALUE; y++; } if ((y += colincy) >= bHeight) { y -= bHeight; } } if ((rowxerr += rowincxerr) < 0) { rowxerr &= Integer.MAX_VALUE; rowx++; } if ((rowx += rowincx) >= bWidth) { rowx -= bWidth; } if ((rowyerr += rowincyerr) < 0) { rowyerr &= Integer.MAX_VALUE; rowy++; } if ((rowy += rowincy) >= bHeight) { rowy -= bHeight; } } }
Example 20
Source File: CoverageDataPng.java From geopackage-java with MIT License | 3 votes |
/** * Get the pixel value as an "unsigned short" from the raster and the * coordinate * * @param raster * image raster * @param x * x coordinate * @param y * y coordinate * @return "unsigned short" pixel value */ public short getPixelValue(WritableRaster raster, int x, int y) { Object pixelData = raster.getDataElements(x, y, null); short sdata[] = (short[]) pixelData; if (sdata.length != 1) { throw new UnsupportedOperationException( "This method is not supported by this color model"); } short pixelValue = sdata[0]; return pixelValue; }