public static void storeTiledTiff(RenderedImage image, String filePath) { final TIFFEncodeParam encodeParam = new TIFFEncodeParam(); encodeParam.setTileSize(image.getTileWidth(), image.getTileHeight()); encodeParam.setWriteTiled(true); encodeParam.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE); System.out.println("Storing tiled TIFF image to " + filePath + "..."); FileStoreDescriptor.create(image, filePath, "TIFF", encodeParam, false, null); }
public ImageHeader(RenderedImage image, String tileFormat) { this( new ImageLayout( image.getMinX(), image.getMinY(), image.getWidth(), image.getHeight(), image.getTileGridXOffset(), image.getTileGridYOffset(), image.getTileWidth(), image.getTileHeight(), image.getSampleModel(), image.getColorModel()), tileFormat); }
/** Set source */ private void setDefaults(RenderedImage imgsrc) { // override the params in the super class setSuperProperties(); tilingMode = MODE_EXPLICIT; if (imgsrc != null) { this.imgsrc = imgsrc; tileGridXOffset = imgsrc.getTileGridXOffset(); tileGridYOffset = imgsrc.getTileGridYOffset(); tileWidth = imgsrc.getTileWidth(); tileHeight = imgsrc.getTileHeight(); tilingSet = true; numTiles = imgsrc.getNumXTiles() * imgsrc.getNumYTiles(); numComponents = imgsrc.getSampleModel().getNumBands(); } setDefaults(); }
public static void dumpImageInfo(RenderedImage image) { final SampleModel sampleModel = image.getSampleModel(); final ColorModel colorModel = image.getColorModel(); System.out.println("image: " + image); System.out.println(" minX = " + image.getMinX()); System.out.println(" minY = " + image.getMinY()); System.out.println(" width = " + image.getWidth()); System.out.println(" height = " + image.getHeight()); System.out.println( " colorModel = " + (colorModel != null ? colorModel.getClass() : "null")); System.out.println( " colorSpace = " + (colorModel != null ? colorModel.getColorSpace() : "null")); System.out.println(" sampleModel = " + sampleModel.getClass()); System.out.println(" numBands = " + sampleModel.getNumBands()); System.out.println(" dataType = " + sampleModel.getDataType()); System.out.println(" transferType = " + sampleModel.getTransferType()); System.out.println(" tileGridXOffset = " + image.getTileGridXOffset()); System.out.println(" tileGridYOffset = " + image.getTileGridYOffset()); System.out.println(" minTileX = " + image.getMinTileX()); System.out.println(" minTileY = " + image.getMinTileY()); System.out.println(" tileWidth = " + image.getTileWidth()); System.out.println(" tileHeight = " + image.getTileHeight()); }
/** * Creates a new instance of <code>MlibWarpOpImage</code> in the rendered image mode. * * @param args The source images. * @param hints May contain rendering hints and destination image layout. */ public RenderedImage create(ParameterBlock args, RenderingHints hints) { /* Get ImageLayout and TileCache from RenderingHints. */ ImageLayout layout = RIFUtil.getImageLayoutHint(hints); RenderedImage source = args.getRenderedSource(0); if (!MediaLibAccessor.isMediaLibCompatible(args, layout) || !MediaLibAccessor.hasSameNumBands(args, layout) || // Medialib cannot deal with source image having tiles with any // dimension greater than or equal to 32768 source.getTileWidth() >= 32768 || source.getTileHeight() >= 32768) { return null; } /* Get BorderExtender from hints if any. */ BorderExtender extender = RIFUtil.getBorderExtenderHint(hints); Warp warp = (Warp) args.getObjectParameter(0); Interpolation interp = (Interpolation) args.getObjectParameter(1); double[] backgroundValues = (double[]) args.getObjectParameter(2); int filter = -1; if (interp instanceof InterpolationNearest) { filter = Constants.MLIB_NEAREST; } else if (interp instanceof InterpolationBilinear) { filter = Constants.MLIB_BILINEAR; } else if (interp instanceof InterpolationBicubic) { filter = Constants.MLIB_BICUBIC; } else if (interp instanceof InterpolationBicubic2) { filter = Constants.MLIB_BICUBIC2; } else if (interp instanceof InterpolationTable) {; // filter = Constants.MLIB_TABLE; not defined yet; } else { /* Other kinds of interpolation cannot be handled via mlib. */ return null; } if (warp instanceof WarpGrid) { if (interp instanceof InterpolationTable) { return new MlibWarpGridTableOpImage( source, extender, hints, layout, (WarpGrid) warp, interp, backgroundValues); } else { return new MlibWarpGridOpImage( source, extender, hints, layout, (WarpGrid) warp, interp, filter, backgroundValues); } } else if (warp instanceof WarpPolynomial) { if (interp instanceof InterpolationTable) { return new MlibWarpPolynomialTableOpImage( source, extender, hints, layout, (WarpPolynomial) warp, interp, backgroundValues); } else { return new MlibWarpPolynomialOpImage( source, extender, hints, layout, (WarpPolynomial) warp, interp, filter, backgroundValues); } } else { return null; } }
private void testType(RenderedImage src, boolean nodataUsed, boolean roiUsed) { // Optional No Data Range used Range noData; // Source image data type int dataType = src.getSampleModel().getDataType(); // If no Data are present, the No Data Range associated is used if (nodataUsed) { switch (dataType) { case DataBuffer.TYPE_BYTE: noData = noDataByte; break; case DataBuffer.TYPE_USHORT: noData = noDataUShort; break; case DataBuffer.TYPE_SHORT: noData = noDataShort; break; case DataBuffer.TYPE_INT: noData = noDataInt; break; case DataBuffer.TYPE_FLOAT: noData = noDataFloat; break; case DataBuffer.TYPE_DOUBLE: noData = noDataDouble; break; default: throw new IllegalArgumentException("Wrong data type"); } } else { noData = null; } ROI roi; if (roiUsed) { roi = roiObject; } else { roi = null; } // BandCombined result RenderedOp combined = BandCombineDescriptor.create(src, matrix, roi, noData, destinationNoData, null); int tileWidth = combined.getTileWidth(); int tileHeight = combined.getTileHeight(); int minTileX = combined.getMinTileX(); int minTileY = combined.getMinTileY(); int numXTiles = combined.getNumXTiles(); int numYTiles = combined.getNumYTiles(); int maxTileX = minTileX + numXTiles; int maxTileY = minTileY + numYTiles; // Ensure same size assertEquals(combined.getWidth(), src.getWidth()); assertEquals(combined.getHeight(), src.getHeight()); assertEquals(combined.getMinX(), src.getMinX()); assertEquals(combined.getMinY(), src.getMinY()); assertEquals(minTileX, src.getMinTileX()); assertEquals(minTileY, src.getMinTileY()); assertEquals(numXTiles, src.getNumXTiles()); assertEquals(numYTiles, src.getNumYTiles()); assertEquals(tileWidth, src.getTileWidth()); assertEquals(tileHeight, src.getTileHeight()); int srcBands = src.getSampleModel().getNumBands(); int dstBands = combined.getNumBands(); // Ensure a correct band size assertEquals(dstBands, matrix.length); // Check on all the pixels if they have been calculate correctly for (int tileX = minTileX; tileX < maxTileX; tileX++) { for (int tileY = minTileY; tileY < maxTileY; tileY++) { Raster tile = combined.getTile(tileX, tileY); Raster srcTile = src.getTile(tileX, tileY); int minX = tile.getMinX(); int minY = tile.getMinY(); int maxX = minX + tileWidth - 1; int maxY = minY + tileHeight - 1; for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { boolean isValidRoi = !roiUsed || (roiUsed && roiObject.contains(x, y)); if (isValidRoi) { for (int b = 0; b < dstBands; b++) { // Getting the result double result = tile.getSampleDouble(x, y, b); // Calculating the expected result from sources boolean valid = false; double calculated = 0; for (int i = 0; i < srcBands; i++) { double sample = srcTile.getSampleDouble(x, y, i); boolean isValidData = !nodataUsed || (nodataUsed && !noDataDouble.contains(sample)); valid |= isValidData; if (isValidData) { switch (dataType) { case DataBuffer.TYPE_BYTE: calculated += ((int) sample & 0xFF) * matrix[b][i]; break; case DataBuffer.TYPE_USHORT: calculated += ((int) sample & 0xFFFF) * matrix[b][i]; break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_INT: case DataBuffer.TYPE_FLOAT: case DataBuffer.TYPE_DOUBLE: calculated += sample * matrix[b][i]; break; default: break; } } } if (valid) { calculated += matrix[b][srcBands]; switch (dataType) { case DataBuffer.TYPE_BYTE: calculated = ImageUtil.clampRoundByte(calculated); result = ImageUtil.clampRoundByte(result); break; case DataBuffer.TYPE_USHORT: calculated = ImageUtil.clampRoundUShort(calculated); result = ImageUtil.clampRoundUShort(result); break; case DataBuffer.TYPE_SHORT: calculated = ImageUtil.clampRoundShort(calculated); result = ImageUtil.clampRoundShort(result); break; case DataBuffer.TYPE_INT: calculated = ImageUtil.clampRoundInt(calculated); result = ImageUtil.clampRoundInt(result); break; case DataBuffer.TYPE_FLOAT: calculated = (float) calculated; calculated = (float) result; break; case DataBuffer.TYPE_DOUBLE: break; default: break; } assertEquals(result, calculated, TOLERANCE); } else { assertEquals(result, destNoData, TOLERANCE); } } } else { for (int b = 0; b < dstBands; b++) { assertEquals(tile.getSampleDouble(x, y, b), destNoData, TOLERANCE); } } } } } } // Disposal of the output image combined.dispose(); }