| <test title="RescaleOp Testing"> |
| <description> |
| This test validates the convertion of Java 2D RescaleOp |
| into an SVG filter. |
| </description> |
| <description> |
| It uses a simple inverter lookup. |
| </description> |
| <javaCode> |
| <![CDATA[ |
| g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
| RenderingHints.VALUE_ANTIALIAS_ON); |
| |
| AffineTransform defaultTransform = g.getTransform(); |
| |
| // |
| // Load Image |
| // |
| Image image = Toolkit.getDefaultToolkit().createImage("/work/doc/svg/src/usecases/html/images/vangogh.jpg"); |
| MediaTracker tracker = new MediaTracker(new Button("")); |
| tracker.addImage(image, 0); |
| try{ |
| tracker.waitForAll(); |
| }catch(InterruptedException e){ |
| tracker.removeImage(image); |
| image = null; |
| }finally { |
| if(image != null) |
| tracker.removeImage(image); |
| if(tracker.isErrorAny()) |
| image = null; |
| if(image != null){ |
| if(image.getWidth(null)<0 || |
| image.getHeight(null)<0) |
| image = null; |
| } |
| } |
| |
| if(image == null){ |
| throw new Error("Could not load image"); |
| } |
| |
| BufferedImage bi = new BufferedImage(image.getWidth(null), |
| image.getHeight(null), BufferedImage.TYPE_INT_RGB); |
| Graphics2D ig = bi.createGraphics(); |
| ig.drawImage(image, 0, 0, null); |
| |
| RescaleOp brighten = new RescaleOp(1.5f, 0, null); |
| RescaleOp darken = new RescaleOp(.6f, 0, null); |
| |
| // Simply paint the image without and with rescale filters |
| g.setPaint(Color.black); |
| g.drawString("Brighter / Normal / Darker", 10, 20); |
| g.drawImage(bi, brighten, 10, 30); |
| g.drawImage(image, 10 + bi.getWidth() + 10, 30, null); |
| g.drawImage(bi, darken, 10 + 2*(bi.getWidth() + 10), 30); |
| |
| g.translate(0, bi.getHeight() + 30 + 20); |
| g.drawString("Rescale Red / Green / Blue", 10, 20); |
| RescaleOp redStress = new RescaleOp(new float[]{ 2f, 1f, 1f }, |
| new float[]{ 0, 0, 0 }, null); |
| RescaleOp greenStress = new RescaleOp(new float[]{ 1f, 2f, 1f }, |
| new float[]{ 0, 0, 0 }, null); |
| RescaleOp blueStress = new RescaleOp(new float[]{ 1f, 1f, 2f }, |
| new float[]{ 0, 0, 0 }, null); |
| |
| g.drawImage(bi, redStress, 10, 30); |
| g.drawImage(bi, greenStress, 10 + bi.getWidth() + 10, 30); |
| g.drawImage(bi, blueStress, 10 + 2*(bi.getWidth() + 10), 30); |
| |
| ]]> |
| </javaCode> |
| </test> |