final ImageWorker imageWorker = new ImageWorker(mosaic); hints = prepareHints(hints); imageWorker.setRenderingHints(hints); if (!imageWorker.isColorSpaceGRAYScale()) { if (!imageWorker.isColorSpaceRGB()) { imageWorker.forceColorSpaceRGB(); if (imageWorker.getRenderedImage().getColorModel().hasAlpha()) { .getRenderedImage(); imageWorker.retainBands(mosaic.getColorModel().getNumColorComponents()); imageWorker.addBand(maskedAlpha, false, true, null); } else { new ImageLayout( mosaic.getMinX(), mosaic.getMinY(), mosaic.getWidth(), final SampleModel sampleModel = mosaic.getSampleModel(); layout.setTileHeight(sampleModel.getWidth()) .setTileWidth(sampleModel.getHeight()); hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
final RenderingHints hints = getRenderingHints(); final ImageLayout layout = getImageLayout(hints); if (layout.isValid(ImageLayout.COLOR_MODEL_MASK)) { return hints; final ColorModel oldCm = image.getColorModel(); if (oldCm != null) { final ColorModel newCm = new ComponentColorModel( oldCm.getColorSpace(), oldCm.hasAlpha(), // If true, supports transparency. oldCm.isAlphaPremultiplied(), // If true, alpha is premultiplied. oldCm.getTransparency(), // What alpha values can be represented. layout.setColorModel(newCm); layout.setSampleModel( newCm.createCompatibleSampleModel(image.getWidth(), image.getHeight())); } else { final int numBands = image.getSampleModel().getNumBands(); final ColorModel newCm = new ComponentColorModel( layout.setColorModel(newCm); layout.setSampleModel( newCm.createCompatibleSampleModel(image.getWidth(), image.getHeight())); hints.put(JAI.KEY_IMAGE_LAYOUT, layout); return hints;
ImageLayout result = layout; if (result == null) { result = new ImageLayout(); int minXL = result.getMinX(source); int minYL = result.getMinY(source); int maxXL = result.getWidth(source) + minXL; int maxYL = result.getHeight(source) + minYL; for (int i = 0; i < n; i++) { source = sources.get(i); final int minX = source.getMinX(); final int minY = source.getMinY(); final int maxX = source.getWidth() + minX; if (mask != 0) { if (layout == result) { result = (ImageLayout) layout.clone(); if ((mask & 1) != 0) result.setMinX(minXL = minX); if ((mask & 2) != 0) result.setMinY(minYL = minY); if ((mask & 4) != 0) result.setWidth((maxXL = maxX) - minXL); if ((mask & 8) != 0) result.setHeight((maxYL = maxY) - minYL); if (result.isValid(ImageLayout.TILE_WIDTH_MASK)) { final int oldSize = result.getTileWidth(source); final int newSize = toTileSize(result.getWidth(source), oldSize); if (oldSize != newSize) { result.setTileWidth(newSize);
private void addAlphaColorModelHint(Hints localHints, int currentBandCount) { ImageLayout layout = new ImageLayout(); ColorModel alphaModel = getColorModelWithAlpha(currentBandCount); layout.setColorModel(alphaModel); localHints.put(JAI.KEY_IMAGE_LAYOUT, layout); }
try { layout = delegate.getImageLayout(referenceName); SampleModel originalSampleModel = layout.getSampleModel(null); SampleModel sampleModel = RasterFactory.createBandedSampleModel( originalSampleModel.getDataType(), originalSampleModel.getWidth(), originalSampleModel.getHeight(), coverageView.getCoverageBands().size()); this.imageLayout = new ImageLayout2( layout.getMinX(null), layout.getMinY(null), originalSampleModel.getWidth(), originalSampleModel.getHeight()); imageLayout.setSampleModel(sampleModel); imageLayout.setColorModel(colorModel); } catch (IOException e) { throw new RuntimeException(e);
+ format.getName()); ColorModel cm = imageLayout.getColorModel(null); if (cm == null) { throw new Exception( + format.getName()); SampleModel sm = imageLayout.getSampleModel(null); if (cm == null) { throw new Exception( + format.getName()); final int numBands = sm.getNumBands(); sampleDimensions = new GridSampleDimension[numBands];
ColorModel colorModel = image.getColorModel(); index.getPixelSize(), index.getMapSize(), reds, greens, blues, alphas); LookupTable table = buildOpacityLookupTable(0, 1, -1, image.getSampleModel().getDataType()); ImageLayout layout = new ImageLayout(image); layout.setColorModel(newColorModel); RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); expanded = new ImageWorker(image).forceComponentColorModel().getRenderedImage(); } else { expanded = image; if (!expanded.getColorModel().hasAlpha()) { new ImageLayout( image.getMinX(), image.getMinY(), (float) image.getHeight(), new Byte[] {Byte.valueOf(alpha)}, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); final int bands = expanded.getSampleModel().getNumBands(); int alphaBand = bands - 1;
Object property = src.getProperty("ROI"); if (property == null || property.equals(java.awt.Image.UndefinedProperty) srcBounds = new Rectangle( src.getMinX() + interp.getLeftPadding(), src.getMinY() + interp.getTopPadding(), src.getWidth() - interp.getWidth() + 1, src.getHeight() - interp.getHeight() + 1); Hints localHints = new Hints(op.getRenderingHints()); localHints.remove(JAI.KEY_IMAGE_LAYOUT); ImageLayout il = new ImageLayout(); Rectangle dstBounds = op.getBounds(); il.setMinX(dstBounds.x); il.setMinY(dstBounds.y); il.setWidth(dstBounds.width); il.setHeight(dstBounds.height); il.setTileWidth(op.getTileWidth()); il.setTileWidth(op.getTileHeight()); localHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il));
RenderingHints hints = ImageUtilities.getRenderingHints(image); if (hints == null) { hints = new RenderingHints(null); if (commonHints != null) { hints.add(commonHints); hints.putAll(commonHints); if (Boolean.FALSE.equals(hints.get(TILING_ALLOWED))) { final ImageLayout layout = getImageLayout(hints); if (commonHints == null || layout != commonHints.get(JAI.KEY_IMAGE_LAYOUT)) { layout.setTileWidth(image.getWidth()); layout.setTileHeight(image.getHeight()); layout.setTileGridXOffset(image.getMinX()); layout.setTileGridYOffset(image.getMinY()); hints.put(JAI.KEY_IMAGE_LAYOUT, layout);
if (raster.getColorModel() instanceof IndexColorModel && expandToRGB) { raster = new ImageWorker(raster).forceComponentColorModel().getRenderedImage(); raster = new ImageWorker(raster).retainBands(bands).getRenderedImage(); ColorModel colorModel = raster.getColorModel(); if (colorModel == null) { ImageLayout layout = (ImageLayout) hints.get(JAI.KEY_IMAGE_LAYOUT); if (layout == null) { layout = new ImageLayout(); ImageIOUtilities.createColorModel(raster.getSampleModel()); if (newColorModel != null) { layout.setColorModel(newColorModel); raster = new ImageWorker(raster) .setRenderingHints(hints) .format(raster.getSampleModel().getDataType()) .getRenderedImage(); final ImageLayout layout = new ImageLayout(); layout.setTileHeight(tileDimensions.width).setTileWidth(tileDimensions.height); localHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); } else { if (hints != null && hints.containsKey(JAI.KEY_IMAGE_LAYOUT)) { localHints.add( new RenderingHints( JAI.KEY_IMAGE_LAYOUT, ((ImageLayout) layout).clone()));
final ColorModel cm = image.getColorModel(); if (cm instanceof ComponentColorModel) { Color bgColor = getBackgroundColor(); if (bgColor == null) { bgColor = Color.BLACK; final RenderingHints hints = getRenderingHints(); final ImageLayout layout; final Object candidate = hints.get(JAI.KEY_IMAGE_LAYOUT); if (candidate instanceof ImageLayout) { layout = (ImageLayout) candidate; } else { layout = new ImageLayout(image); hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); bits, alpha, cm.isAlphaPremultiplied(), alpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE, datatype); final SampleModel destinationSampleModel = destinationColorModel.createCompatibleSampleModel( image.getWidth(), image.getHeight()); layout.setColorModel(destinationColorModel); layout.setSampleModel(destinationSampleModel);
? parameters.hints : ImageUtilities.getRenderingHints(sourceImage); if (targetHints == null) targetHints = new RenderingHints(null); if (parameters.hints != null) targetHints.add(parameters.hints); ImageLayout layout = (ImageLayout) targetHints.get(JAI.KEY_IMAGE_LAYOUT); if (layout != null) { layout = (ImageLayout) layout.clone(); } else { layout = new ImageLayout(sourceImage); layout.unsetTileLayout(); if ((layout.getValidMask() & (ImageLayout.TILE_WIDTH_MASK | ImageLayout.TILE_HEIGHT_MASK | ImageLayout.TILE_GRID_Y_OFFSET_MASK)) == 0) { layout.setTileGridXOffset(layout.getMinX(sourceImage)); layout.setTileGridYOffset(layout.getMinY(sourceImage)); final int width = layout.getWidth(sourceImage); final int height = layout.getHeight(sourceImage); if (layout.getTileWidth(sourceImage) > width) layout.setTileWidth(width); if (layout.getTileHeight(sourceImage) > height) layout.setTileHeight(height); sourceImage.getColorModel() instanceof IndexColorModel; layout.unsetValid(ImageLayout.COLOR_MODEL_MASK); layout.unsetValid(ImageLayout.SAMPLE_MODEL_MASK);
if (type != null && type.equalsIgnoreCase("HISTOGRAM")) { worker = new ImageWorker(sourceImage) .setROI(roi) .setNoData(nodata) .setRenderingHints(hints) .forceComponentColorModel() final ImageLayout imageLayout = new ImageLayout(); imageLayout.setColorModel(IHS.getColorModel()); imageLayout.setSampleModel(IHS.getSampleModel()); final RenderingHints rendHints = new RenderingHints(Collections.EMPTY_MAP); rendHints.add(hints); rendHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout)); Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); final ImageLayout imageLayout = new ImageLayout(); imageLayout.setColorModel(cm); imageLayout.setSampleModel( cm.createCompatibleSampleModel( intensityWorker.getRenderedImage().getWidth(), intensityWorker.getRenderedImage().getHeight())); final RenderedImage finalImage = intensityWorker.getRenderedImage(); final int numActualBands = finalImage.getSampleModel().getNumBands(); final GridCoverageFactory factory = getCoverageFactory(); final HashMap<Object, Object> props = new HashMap<Object, Object>();
int[] bands = baseReadParameters.getBands(); if (bands != null && cm != null && bands.length != cm.getNumComponents()) { final int nBands = bands.length; ColorSpace cs = null; new ComponentColorModel( cs, cm.hasAlpha(), cm.isAlphaPremultiplied(), sm = cm.createCompatibleSampleModel(sm.getWidth(), sm.getHeight()); .setTileGridYOffset(0) .setTileWidth((int) tileSize.getWidth()) .setTileHeight((int) tileSize.getHeight()); final RenderingHints renderingHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, il); .format(il.getSampleModel(null).getDataType()) il.setWidth(rasterBounds.width).setHeight(rasterBounds.height); if (rasterBounds.x != 0 || rasterBounds.y != 0) { il.setMinX(rasterBounds.x).setMinY(rasterBounds.y); hasAlpha = finalImage.getColorModel().hasAlpha(); if (!hasAlpha) { hasAlpha = finalImage.getColorModel().hasAlpha();
/** * Sets up the image layout information for this Operation. The minX, minY, width, and height are calculated based on the source's dimension and * padding values. Any of these values specified in the layout parameter is ignored. All other variables are taken from the layout parameter or * inherited from the source. */ private static ImageLayout layoutHelper(ImageLayout layout, RenderedImage source, int leftPad, int rightPad, int topPad, int bottomPad) { ImageLayout il = layout == null ? new ImageLayout() : (ImageLayout) layout.clone(); // Set the image bounds according to the padding. il.setMinX(source.getMinX() - leftPad); il.setMinY(source.getMinY() - topPad); il.setWidth(source.getWidth() + leftPad + rightPad); il.setHeight(source.getHeight() + topPad + bottomPad); // Set tile grid offset to minimize the probability that a // tile's bounds does not intersect the source image bounds. if (!il.isValid(ImageLayout.TILE_GRID_X_OFFSET_MASK)) { il.setTileGridXOffset(il.getMinX(null)); } if (!il.isValid(ImageLayout.TILE_GRID_Y_OFFSET_MASK)) { il.setTileGridYOffset(il.getMinY(null)); } // Force inheritance of source image SampleModel and ColorModel. il.setSampleModel(source.getSampleModel()); il.setColorModel(source.getColorModel()); return il; }
/** * Shave off the alpha band, JPEG cannot write it out * * @param ri * @return */ @Override public RenderedImage preprocess(RenderedImage ri) { if (ri.getColorModel().hasAlpha()) { final int numBands = ri.getSampleModel().getNumBands(); // handle both gray-alpha and RGBA (same code as in GeoTools ImageWorker) final int[] bands = new int[numBands - 1]; for (int i = 0; i < bands.length; i++) { bands[i] = i; } // ParameterBlock creation ParameterBlock pb = new ParameterBlock(); pb.setSource(ri, 0); pb.set(bands, 0); final RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, new ImageLayout(ri)); ri = JAI.create("BandSelect", pb, hints); } return ri; } };
assert image.getColorModel() instanceof IndexColorModel; IndexColorModel cm = (IndexColorModel) image.getColorModel(); final int numComponents = cm.getNumComponents(); int transparency = cm.getTransparency(); final ImageLayout layout = new ImageLayout(image); layout.setColorModel(cm); final RenderingHints hints = getRenderingHints(); hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); hints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.FALSE)); pb.set(image.getSampleModel().getDataType(), 0); setNoData(RangeFactory.convert(nodata, image.getSampleModel().getDataType())); invalidateStatistics(); return this;
final Hints hints = getHints(); final List<GridCoverage2D> sourceGridCoverages = new ArrayList<GridCoverage2D>(); ImageWorker w = new ImageWorker(); do { currentSourceCoverage .getRenderedImage() .getSampleModel() .getDataType()); layout = new ImageLayout(); layout.setColorModel(cm); } else if (!gg.equals(gridGeometry)) throw new IllegalArgumentException( w.setImage(op); w.setROI(CoverageUtilities.getROIProperty(currentSourceCoverage)); NoDataContainer container = CoverageUtilities.getNoDataProperty(currentSourceCoverage); if (layout != null) hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); if (hasAlpha && !op.getColorModel().hasAlpha()) { w.addBand(alpha, false, true, null); intermediateOps.add(op);
/** * This takes an image with an indexed color model that uses less than 256 colors and has a 8bit * sample model, and transforms it to one that has the optimal sample model (for example, 1bit * if the palette only has 2 colors) * * @param source */ private static RenderedImage optimizeSampleModel(RenderedImage source) { int w = source.getWidth(); int h = source.getHeight(); ImageLayout layout = new ImageLayout(); layout.setColorModel(source.getColorModel()); layout.setSampleModel(source.getColorModel().createCompatibleSampleModel(w, h)); // if I don't force tiling off with this setting an exception is thrown // when writing the image out... layout.setTileWidth(w); layout.setTileHeight(h); RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); LookupTable table = LookupTableFactory.create(IDENTITY_TABLE); // TODO SIMONE why not format? ImageWorker worker = new ImageWorker(source); worker.setRenderingHints(hints); worker.lookup(table); return worker.getRenderedImage(); }
private ImageLayout getImageLayout(RenderedImage image, RenderingHints hints) { ImageLayout layout = (ImageLayout) hints.get(JAI.KEY_IMAGE_LAYOUT); if (layout == null) layout = new ImageLayout(image); layout.setColorModel(this.paletteBuilder.getIndexColorModel()); layout.setSampleModel( paletteBuilder .getIndexColorModel() .createCompatibleSampleModel(image.getWidth(), image.getHeight())); return layout; }