Java Code Examples for java.awt.image.WritableRaster#getNumDataElements()
The following examples show how to use
java.awt.image.WritableRaster#getNumDataElements() .
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: UnrestrictedSizeUploadServlet.java From easybuggy with Apache License 2.0 | 6 votes |
private boolean reverseColor(String fileName) throws IOException { boolean isConverted = false; try { BufferedImage image = ImageIO.read(new File(fileName)); WritableRaster raster = image.getRaster(); int[] pixelBuffer = new int[raster.getNumDataElements()]; for (int y = 0; y < raster.getHeight(); y++) { for (int x = 0; x < raster.getWidth(); x++) { raster.getPixel(x, y, pixelBuffer); pixelBuffer[0] = ~pixelBuffer[0]; pixelBuffer[1] = ~pixelBuffer[1]; pixelBuffer[2] = ~pixelBuffer[2]; raster.setPixel(x, y, pixelBuffer); } } // Output the image ImageIO.write(image, "png", new File(fileName)); isConverted = true; } catch (Exception e) { // Log and ignore the exception log.warn("Exception occurs: ", e); } return isConverted; }
Example 2
Source File: OffScreenImageSource.java From dragonwell8_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 3
Source File: OffScreenImageSource.java From TencentKona-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 4
Source File: OffScreenImageSource.java From jdk8u60 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 5
Source File: OffScreenImageSource.java From openjdk-jdk8u 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 6
Source File: OffScreenImageSource.java From openjdk-jdk8u-backup 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: OffScreenImageSource.java From Bytecoder with Apache License 2.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 8
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 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 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 11
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 12
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 13
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 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: 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); } } }