Java Code Examples for java.awt.image.RenderedImage#getData()
The following examples show how to use
java.awt.image.RenderedImage#getData() .
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: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Creates a compatible {@link WritableRaster} from a {@link RenderedImage}. * * @param renderedImage the image to convert. * @param nullBorders a flag that indicates if the borders should be set to null. * @return the converted writable raster. */ public static WritableRaster renderedImage2WritableRaster( RenderedImage renderedImage, boolean nullBorders ) { int width = renderedImage.getWidth(); int height = renderedImage.getHeight(); Raster data = renderedImage.getData(); WritableRaster writableRaster = data.createCompatibleWritableRaster(); writableRaster.setDataElements(0, 0, data); if (nullBorders) { for( int c = 0; c < width; c++ ) { writableRaster.setSample(c, 0, 0, doubleNovalue); writableRaster.setSample(c, height - 1, 0, doubleNovalue); } for( int r = 0; r < height; r++ ) { writableRaster.setSample(0, r, 0, doubleNovalue); writableRaster.setSample(width - 1, r, 0, doubleNovalue); } } return writableRaster; }
Example 2
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public static WritableRaster renderedImage2DoubleWritableRaster( RenderedImage renderedImage, boolean nullBorders ) { int width = renderedImage.getWidth(); int height = renderedImage.getHeight(); Raster data = renderedImage.getData(); WritableRaster writableRaster = createWritableRaster(width, height, Double.class, null, null); writableRaster.setRect(data); if (nullBorders) { for( int c = 0; c < width; c++ ) { writableRaster.setSample(c, 0, 0, doubleNovalue); writableRaster.setSample(c, height - 1, 0, doubleNovalue); } for( int r = 0; r < height; r++ ) { writableRaster.setSample(0, r, 0, doubleNovalue); writableRaster.setSample(width - 1, r, 0, doubleNovalue); } } return writableRaster; }
Example 3
Source File: CoverageUtilities.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public static WritableRaster renderedImage2ShortWritableRaster( RenderedImage renderedImage, boolean nullBorders ) { int width = renderedImage.getWidth(); int height = renderedImage.getHeight(); Raster data = renderedImage.getData(); WritableRaster writableRaster = createWritableRaster(width, height, Short.class, null, null); writableRaster.setRect(data); if (nullBorders) { for( int c = 0; c < width; c++ ) { writableRaster.setSample(c, 0, 0, shortNovalue); writableRaster.setSample(c, height - 1, 0, shortNovalue); } for( int r = 0; r < height; r++ ) { writableRaster.setSample(0, r, 0, shortNovalue); writableRaster.setSample(width - 1, r, 0, shortNovalue); } } return writableRaster; }
Example 4
Source File: CsvExporter.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
static double getValue(RasterDataNode raster, int pixelX, int pixelY, int currentLevel) { final RenderedImage image = raster.getGeophysicalImage().getImage(currentLevel); final Rectangle pixelRect = new Rectangle(pixelX, pixelY, 1, 1); final Raster data = image.getData(pixelRect); final MultiLevelImage validMaskImage = raster.getValidMaskImage(); Raster validMaskData = null; if (validMaskImage != null) { final RenderedImage validMask = validMaskImage.getImage(currentLevel); validMaskData = validMask.getData(pixelRect); } final double value; if (validMaskData == null || validMaskData.getSample(pixelX, pixelY, 0) > 0) { value = data.getSampleDouble(pixelX, pixelY, 0); } else { value = Double.NaN; } return value; }
Example 5
Source File: GIFImageWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void writeRows(RenderedImage image, LZWCompressor compressor, int sx, int sdx, int sy, int sdy, int sw, int dy, int ddy, int dw, int dh, int numRowsWritten, int progressReportRowPeriod) throws IOException { if (DEBUG) System.out.println("Writing unoptimized"); int[] sbuf = new int[sw]; byte[] dbuf = new byte[dw]; Raster raster = image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ? image.getTile(0, 0) : image.getData(); for (int y = dy; y < dh; y += ddy) { if (numRowsWritten % progressReportRowPeriod == 0) { if (abortRequested()) { processWriteAborted(); return; } processImageProgress((numRowsWritten*100.0F)/dh); } raster.getSamples(sx, sy, sw, 1, 0, sbuf); for (int i = 0, j = 0; i < dw; i++, j += sdx) { dbuf[i] = (byte)sbuf[j]; } compressor.compress(dbuf, 0, dw); numRowsWritten++; sy += sdy; } }
Example 6
Source File: PaletteBuilder.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected PaletteBuilder(RenderedImage src, int size) { this.src = src; this.srcColorModel = src.getColorModel(); this.srcRaster = src.getData(); this.transparency = srcColorModel.getTransparency(); this.requiredSize = size; }
Example 7
Source File: GIFImageWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void writeRows(RenderedImage image, LZWCompressor compressor, int sx, int sdx, int sy, int sdy, int sw, int dy, int ddy, int dw, int dh, int numRowsWritten, int progressReportRowPeriod) throws IOException { if (DEBUG) System.out.println("Writing unoptimized"); int[] sbuf = new int[sw]; byte[] dbuf = new byte[dw]; Raster raster = image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ? image.getTile(0, 0) : image.getData(); for (int y = dy; y < dh; y += ddy) { if (numRowsWritten % progressReportRowPeriod == 0) { processImageProgress((numRowsWritten*100.0F)/dh); if (abortRequested()) { processWriteAborted(); return; } } raster.getSamples(sx, sy, sw, 1, 0, sbuf); for (int i = 0, j = 0; i < dw; i++, j += sdx) { dbuf[i] = (byte)sbuf[j]; } compressor.compress(dbuf, 0, dw); numRowsWritten++; sy += sdy; } }
Example 8
Source File: PaletteBuilder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
protected PaletteBuilder(RenderedImage src, int size) { this.src = src; this.srcColorModel = src.getColorModel(); this.srcRaster = src.getData(); this.transparency = srcColorModel.getTransparency(); this.requiredSize = size; }
Example 9
Source File: GIFImageWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void writeRows(RenderedImage image, LZWCompressor compressor, int sx, int sdx, int sy, int sdy, int sw, int dy, int ddy, int dw, int dh, int numRowsWritten, int progressReportRowPeriod) throws IOException { if (DEBUG) System.out.println("Writing unoptimized"); int[] sbuf = new int[sw]; byte[] dbuf = new byte[dw]; Raster raster = image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ? image.getTile(0, 0) : image.getData(); for (int y = dy; y < dh; y += ddy) { if (numRowsWritten % progressReportRowPeriod == 0) { if (abortRequested()) { processWriteAborted(); return; } processImageProgress((numRowsWritten*100.0F)/dh); } raster.getSamples(sx, sy, sw, 1, 0, sbuf); for (int i = 0, j = 0; i < dw; i++, j += sdx) { dbuf[i] = (byte)sbuf[j]; } compressor.compress(dbuf, 0, dw); numRowsWritten++; sy += sdy; } }
Example 10
Source File: GIFImageWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void writeRows(RenderedImage image, LZWCompressor compressor, int sx, int sdx, int sy, int sdy, int sw, int dy, int ddy, int dw, int dh, int numRowsWritten, int progressReportRowPeriod) throws IOException { if (DEBUG) System.out.println("Writing unoptimized"); int[] sbuf = new int[sw]; byte[] dbuf = new byte[dw]; Raster raster = image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ? image.getTile(0, 0) : image.getData(); for (int y = dy; y < dh; y += ddy) { if (numRowsWritten % progressReportRowPeriod == 0) { if (abortRequested()) { processWriteAborted(); return; } processImageProgress((numRowsWritten*100.0F)/dh); } raster.getSamples(sx, sy, sw, 1, 0, sbuf); for (int i = 0, j = 0; i < dw; i++, j += sdx) { dbuf[i] = (byte)sbuf[j]; } compressor.compress(dbuf, 0, dw); numRowsWritten++; sy += sdy; } }
Example 11
Source File: GIFImageWriter.java From hottub with GNU General Public License v2.0 | 5 votes |
private void writeRows(RenderedImage image, LZWCompressor compressor, int sx, int sdx, int sy, int sdy, int sw, int dy, int ddy, int dw, int dh, int numRowsWritten, int progressReportRowPeriod) throws IOException { if (DEBUG) System.out.println("Writing unoptimized"); int[] sbuf = new int[sw]; byte[] dbuf = new byte[dw]; Raster raster = image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ? image.getTile(0, 0) : image.getData(); for (int y = dy; y < dh; y += ddy) { if (numRowsWritten % progressReportRowPeriod == 0) { if (abortRequested()) { processWriteAborted(); return; } processImageProgress((numRowsWritten*100.0F)/dh); } raster.getSamples(sx, sy, sw, 1, 0, sbuf); for (int i = 0, j = 0; i < dw; i++, j += sdx) { dbuf[i] = (byte)sbuf[j]; } compressor.compress(dbuf, 0, dw); numRowsWritten++; sy += sdy; } }
Example 12
Source File: GIFImageWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void writeRows(RenderedImage image, LZWCompressor compressor, int sx, int sdx, int sy, int sdy, int sw, int dy, int ddy, int dw, int dh, int numRowsWritten, int progressReportRowPeriod) throws IOException { if (DEBUG) System.out.println("Writing unoptimized"); int[] sbuf = new int[sw]; byte[] dbuf = new byte[dw]; Raster raster = image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ? image.getTile(0, 0) : image.getData(); for (int y = dy; y < dh; y += ddy) { if (numRowsWritten % progressReportRowPeriod == 0) { if (abortRequested()) { processWriteAborted(); return; } processImageProgress((numRowsWritten*100.0F)/dh); } raster.getSamples(sx, sy, sw, 1, 0, sbuf); for (int i = 0, j = 0; i < dw; i++, j += sdx) { dbuf[i] = (byte)sbuf[j]; } compressor.compress(dbuf, 0, dw); numRowsWritten++; sy += sdy; } }
Example 13
Source File: PaletteBuilder.java From hottub with GNU General Public License v2.0 | 5 votes |
protected PaletteBuilder(RenderedImage src, int size) { this.src = src; this.srcColorModel = src.getColorModel(); this.srcRaster = src.getData(); this.transparency = srcColorModel.getTransparency(); this.requiredSize = size; }
Example 14
Source File: PaletteBuilder.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected PaletteBuilder(RenderedImage src, int size) { this.src = src; this.srcColorModel = src.getColorModel(); this.srcRaster = src.getData(); this.transparency = srcColorModel.getTransparency(); this.requiredSize = size; }
Example 15
Source File: GIFImageWriter.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void writeRows(RenderedImage image, LZWCompressor compressor, int sx, int sdx, int sy, int sdy, int sw, int dy, int ddy, int dw, int dh, int numRowsWritten, int progressReportRowPeriod) throws IOException { if (DEBUG) System.out.println("Writing unoptimized"); int[] sbuf = new int[sw]; byte[] dbuf = new byte[dw]; Raster raster = image.getNumXTiles() == 1 && image.getNumYTiles() == 1 ? image.getTile(0, 0) : image.getData(); for (int y = dy; y < dh; y += ddy) { if (numRowsWritten % progressReportRowPeriod == 0) { if (abortRequested()) { processWriteAborted(); return; } processImageProgress((numRowsWritten*100.0F)/dh); } raster.getSamples(sx, sy, sw, 1, 0, sbuf); for (int i = 0, j = 0; i < dw; i++, j += sdx) { dbuf[i] = (byte)sbuf[j]; } compressor.compress(dbuf, 0, dw); numRowsWritten++; sy += sdy; } }
Example 16
Source File: PaletteBuilder.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected PaletteBuilder(RenderedImage src, int size) { this.src = src; this.srcColorModel = src.getColorModel(); this.srcRaster = src.getData(); this.transparency = srcColorModel.getTransparency(); this.requiredSize = size; }
Example 17
Source File: PaletteBuilder.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
protected PaletteBuilder(RenderedImage src, int size) { this.src = src; this.srcColorModel = src.getColorModel(); this.srcRaster = src.getData(); this.transparency = srcColorModel.getTransparency(); this.requiredSize = size; }
Example 18
Source File: GridCoverageUtil.java From elasticgeo with GNU General Public License v3.0 | 5 votes |
public static GridCoverage2D scale(GridCoverage2D coverage, float width, float height) { final RenderedImage renderedImage = coverage.getRenderedImage(); final Raster renderedGrid = renderedImage.getData(); float yScale = width/renderedGrid.getWidth(); float xScale = height/renderedGrid.getHeight(); final Operations ops = new Operations(null); return (GridCoverage2D) ops.scale(coverage, xScale, yScale, 0, 0); }
Example 19
Source File: PaletteBuilder.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
protected PaletteBuilder(RenderedImage src, int size) { this.src = src; this.srcColorModel = src.getColorModel(); this.srcRaster = src.getData(); this.transparency = srcColorModel.getTransparency(); this.requiredSize = size; }
Example 20
Source File: S3HistogramEqualizerRIF.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
/** * Compute the output equalized image. In contrary to the QL generation the * stretching can only performed on full dataset. So no operator can be * provided to manage this operation by tile... * * @param paramBlock contains the RGB source image to produce the quicklook. * @param hints Optionally contains destination image layout. * @return the equalized image. * @throws IllegalArgumentException if source does not contains 3 bands. */ @SuppressWarnings ("unchecked") public RenderedImage create(ParameterBlock paramBlock, RenderingHints hints) { // One source supported RenderedImage image = (RenderedImage)paramBlock.getSource(0); int num_bands=image.getSampleModel().getNumBands(); Raster raster_data = image.getData(); if (num_bands != 3) // Support only RGB bands :-( { throw new IllegalArgumentException ( "S3 Equalization only support 3-banded RGB input image."); } int width = image.getWidth(); int height = image.getHeight(); List<int[]> histLUT; try { String equalizationFile = image instanceof QuicklookOlciOpImage ? "olci-equalization.dat" : null; // could be loaded statically or inside constructor ObjectInputStream objectinputstream = new ObjectInputStream( getClass().getClassLoader().getResourceAsStream(equalizationFile)); histLUT = (ArrayList<int[]>) objectinputstream.readObject(); } catch (Exception e) { LOGGER.warn("Unable to load LUT for equalization. " + "Using a dynamic LUT " + e.getMessage()); histLUT = histogramEqualizationLUT(raster_data); } BufferedImage histogramEQ = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); int red; int green; int blue; int new_pixel; for(int j=0; j<height; j++) { for(int i=0; i<width; i++) { // Get pixels by R, G, B red = getRed(raster_data, i, j); green = getGreen(raster_data, i, j); blue = getBlue(raster_data, i, j); // Set new pixel values using the histogram lookup table if(red == 0 && green == 0 && blue == 0) continue; red = histLUT.get(0)[red]; green = histLUT.get(1)[green]; blue = histLUT.get(2)[blue]; // Return back to original format new_pixel = new Color( red*255/Common.colorRange, green*255/Common.colorRange, blue*255/Common.colorRange).getRGB(); // Write pixels into image histogramEQ.setRGB(i, j, new_pixel); } } return histogramEQ; }