/******************************************************************************* * * @inheritDoc * ******************************************************************************/ protected PlanarImage execute (final ChangeFormatOp operation, final EditableImage image, PlanarImage planarImage) { logger.info("execute(" + operation + ", " + image + ", " + planarImage); final ParameterBlock pb = new ParameterBlock(); pb.addSource(planarImage); pb.add(operation.getType().value()); RenderingHints hints = null; final EditableImage.DataType dataType = operation.getType(); if (dataType == EditableImage.DataType.SHORT) { final ImageLayout imageLayout = new ImageLayout(); imageLayout.setColorModel(planarImage.getColorModel()); hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout); logger.info(">>>> using hints: " + hints); } planarImage = JAI.create("format", pb, hints); JAIUtils.logImage(logger, ">>>> ChangeFormatJAIOp returning", planarImage); return planarImage; } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull @Override public EditableImage.DataType getDataType() { return EditableImage.DataType.valueOf(getBufferedImage().getRaster().getDataBuffer().getDataType()); }
/*********************************************************************** * * **********************************************************************/ public static DataType valueOf (final int value) { for (final EditableImage.DataType dataType : DataType.values()) { if (dataType.value() == value) { return dataType; } } return EditableImage.DataType.UNDEFINED; } }
/******************************************************************************* * * Returns an estimate of the memory allocated by this image. The default * implementation returns the number of pixels multiplied by the number of bands * multiplied the size in bytes of each pixel. Can be overridden for more * accurate implementations. * * @return the memory allocated for this image * ******************************************************************************/ public long getMemorySize() { final EditableImage.DataType dataType = getDataType(); return (dataType == null) ? 0 : ((long)dataType.getSize() * getWidth() * getHeight() * getBandCount()) / 8; }
/******************************************************************************* * * @inheritDoc * ******************************************************************************/ public EditableImage.DataType getDataType() { return (getPlanarImage() == null) ? null : EditableImage.DataType.valueOf(getPlanarImage().getSampleModel().getDataType()); }
/******************************************************************************************************************* * * Returns the number of sample bits for each band this EditableImage is * composed of. * * @return the number of bits * ******************************************************************************************************************/ public final int getBitsPerBand() { return getDataType().getSize(); }