/******************************************************************************************************************* * * Creates a resized image. - FIXME should be removed * @deprecated * ******************************************************************************************************************/ public final EditableImage createResizedImage (final int width, final int height, final Quality quality) { double hScale = (double)width / (double)getWidth(); double vScale = (double)height / (double)getHeight(); ScaleOp scaleOp = new ScaleOp(hScale, vScale, quality); execute(scaleOp); return this; }
@Override public void render (final EditableImage image) { image.execute2(new DrawOp(new DrawOp.Executor() { @Override public void draw (final Graphics2D g, final EditableImage image) { attributes.drawRectangle(g, image); } })); }
/*************************************************************************************************************** * * **************************************************************************************************************/ @Nonnull private static EditableImage create (final @Nonnull BufferedImage image) { return new EditableImage(Lookup.getDefault().lookup(ImplementationFactoryJ2D.class).createImageModel(image)); }
/******************************************************************************************************************* * * Returns the number of sample bits for each pixel this EditableImage is * composed of. * * @return the number of bits * ******************************************************************************************************************/ public final int getBitsPerPixel() { return getBandCount() * getBitsPerBand(); }
/******************************************************************************* * * Executes an operation adding the elapsed time to the statistics. * * @param image the image to process * @param operation the operation to execute * @param operationName the name used for the statistics * @return the result * *******************************************************************************/ protected EditableImage execute2 (EditableImage image, Operation operation, String operationName) { final EditableImage result = image.execute2(operation); result.setNickName(operationName); registerTime(operationName, result); return result; }
double maxSize = scale * Math.max(image.getWidth(), image.getHeight()); boolean needScaling = true; int rotationDeltaX = 0; scaledImage = optimizedImage.execute2(new ScaleOp(scale, getScaleQuality())); final int prevWidth = scaledImage.getWidth(); final int prevHeight = scaledImage.getHeight(); scaledImage.execute(new RotateOp(angle, getRotateQuality())); rotationDeltaX = (prevWidth - scaledImage.getWidth()) / 2; rotationDeltaY = (prevHeight - scaledImage.getHeight()) / 2; shownImageWidth = scaledImage.getWidth(); shownImageHeight = scaledImage.getHeight(); needScaling = false; shownImageWidth = (int)Math.round(scale * optimizedImage.getWidth()); shownImageHeight = (int)Math.round(scale * optimizedImage.getHeight()); : new PaintOp(g2, shownImageX, shownImageY, previewSettings, null); imageToDraw.execute(paintOp);
/******************************************************************************* * * Computes a new origin so that the given image point is shown at the given * relative coordinates. * * @param imagePoint the coordinates of the image pixel * @param componentPoint the relative coordinates where to show imagePoint * @return the new origin * ******************************************************************************/ protected Point computeOrigin (final Point imagePoint, final Point componentPoint, final double scale) { if (image == null) { return null; } int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); if ((imageWidth == 0) || (imageHeight == 0)) // can happen if metadata is not loaded yet { return null; } return new Point((int)Math.round(imagePoint.x - (componentPoint.x / scale)), (int)Math.round(imagePoint.y - (componentPoint.y / scale))); }
@Test public void test1() throws IOException { Lookup.getDefault().lookup(ImplementationFactoryJ2D.class).registerImplementation(ChangeBufferTypeOp.class, ChangeBufferTypeJ2DOp.class); EditableImage image = EditableImage.create(new ReadOp(file_timezones32_png)); AssertJUnit.assertEquals(4, image.getBandCount()); image.execute(new ScaleOp(0.5, Quality.BEST)); AssertJUnit.assertEquals(4, image.getBandCount()); image.execute(new ChangeBufferTypeOp(BufferedImage.TYPE_3BYTE_BGR)); AssertJUnit.assertEquals(3, image.getBandCount()); File file = new File(tmp + "/result.jpg"); image.execute(new WriteOp("JPEG", file)); assertChecksum("ec0149544e522dbbb441b4f83a358425", file); } }
/******************************************************************************* * * Executes an operation adding the elapsed time to the statistics. * * @param image the image to process * @param operation the operation to execute * @param operationName the name used for the statistics * @return the operation (as a convenience in case it carries * results) * *******************************************************************************/ protected <T extends Operation> T execute (EditableImage image, T operation, String operationName) { image.execute(operation); image.setNickName(operationName); registerTime(operationName, image); return operation; }
/******************************************************************************************************************* * * Creates a new EditableImage as specified by the parameter * * @param createOp the way the image should be created * @return the image * ******************************************************************************************************************/ @Nonnull public static EditableImage create (final @Nonnull AbstractCreateOp createOp) { final EditableImage editableImage = new EditableImage(null); final Object image = editableImage.internalExecute(createOp); final ImageModel imageModel = Lookup.getDefault().lookup(ImplementationFactoryRegistry.class).createImageModel(image); editableImage.imageModelHolder = ImageModelHolder.wrap(imageModel); return editableImage; }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Override public Object clone() { return cloneImage(); }
/******************************************************************************* * * * ******************************************************************************/ private Point computeCenterPoint() { return new Point(-(int)Math.round(((getAvailableWidth() / scale) - image.getWidth()) / 2), -(int)Math.round(((getAvailableHeight() / scale) - image.getHeight()) / 2)); }
/******************************************************************************************************************* * * Executes an operation. The original image is untouched as the results are * placed in a brand new instance of EditableImage. * * @param operation the operation to perform * @return the result * ******************************************************************************************************************/ @Nonnull public final EditableImage execute2 (final @Nonnull Operation operation) { try { long time = System.currentTimeMillis(); Object image = internalExecute(operation); Class modelClass = imageModelHolder.get().getClass(); Constructor constructor = modelClass.getConstructor(Object.class); ImageModel newModel = (ImageModel)constructor.newInstance(image); EditableImage result = new EditableImage(newModel); result.attributeMapByName = new HashMap<String, Object>(attributeMapByName); result.latestOperationTime = System.currentTimeMillis() - time; return result; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public int print (final Graphics graphics, final PageFormat pageFormat, final int pageIndex) throws PrinterException { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } Graphics2D g2d = (Graphics2D)graphics; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); final double xScale = pageFormat.getImageableWidth() / image.getWidth(); final double yScale = pageFormat.getImageableHeight() / image.getHeight(); final double aspectScale = Math.min(xScale, yScale); final int width = (int)Math.round(image.getWidth() * aspectScale); final int height = (int)Math.round(image.getHeight() * aspectScale); image.execute(new PaintOp(g2d, 0, 0, width, height, null, null)); return Printable.PAGE_EXISTS; } };
@Override public void render (final EditableImage image) { image.execute2(new DrawOp(new DrawOp.Executor() { @Override public void draw (final Graphics2D g, final EditableImage image) { attributes.drawString(g, image, text); } })); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull public static EditableImage createImage (final @Nonnull BufferedImage bufferedImage) // FIXME: try to remove this { return new EditableImage(new ImageModelJ2D(bufferedImage)); }
/******************************************************************************* * * Flush all image caches. * ******************************************************************************/ public void flushAllCaches() { logger.info("flushAllCaches()"); logger.info(">>>> all caches will be recomputed from: " + image); flushScaledImageCache(); if (image != null) { optimizedImage = optimizedImageEnabled ? image.execute2(new OptimizeOp()) : image; } else { optimizedImage = null; } }
public static EditableImage createImage (RenderedImage renderedImage) { return new EditableImage(new ImageModelJAI(renderedImage)); }