KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > renderable > RedRable


1 /*
2
3    Copyright 2001-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.ext.awt.image.renderable;
19
20 import java.awt.Rectangle JavaDoc;
21 import java.awt.RenderingHints JavaDoc;
22 import java.awt.Shape JavaDoc;
23 import java.awt.geom.AffineTransform JavaDoc;
24 import java.awt.geom.Rectangle2D JavaDoc;
25 import java.awt.image.RenderedImage JavaDoc;
26 import java.awt.image.renderable.RenderContext JavaDoc;
27
28 import org.apache.batik.ext.awt.image.rendered.AffineRed;
29 import org.apache.batik.ext.awt.image.rendered.CachableRed;
30 import org.apache.batik.ext.awt.image.rendered.TranslateRed;
31
32 /**
33  * RasterRable This is used to wrap a Rendered Image back into the
34  * RenderableImage world.
35  *
36  * @author <a HREF="mailto:Thomas.DeWeese@Kodak.com">Thomas DeWeese</a>
37  * @version $Id: RedRable.java,v 1.8 2005/03/27 08:58:33 cam Exp $
38  */

39 public class RedRable
40     extends AbstractRable {
41     CachableRed src;
42
43     public RedRable(CachableRed src) {
44         super((Filter)null);
45         this.src = src;
46     }
47
48     public CachableRed getSource() {
49         return src;
50     }
51
52     public Object JavaDoc getProperty(String JavaDoc name) {
53         return src.getProperty(name);
54     }
55
56     public String JavaDoc [] getPropertyNames() {
57         return src.getPropertyNames();
58     }
59
60     public Rectangle2D JavaDoc getBounds2D() {
61         return getSource().getBounds();
62     }
63
64     public RenderedImage JavaDoc createDefaultRendering() {
65         return getSource();
66     }
67
68
69     public RenderedImage JavaDoc createRendering(RenderContext JavaDoc rc) {
70         // System.out.println("RedRable Create Rendering: " + this);
71

72         // Just copy over the rendering hints.
73
RenderingHints JavaDoc rh = rc.getRenderingHints();
74         if (rh == null) rh = new RenderingHints JavaDoc(null);
75
76         Shape JavaDoc aoi = rc.getAreaOfInterest();
77         Rectangle JavaDoc aoiR;
78         if (aoi != null)
79             aoiR = aoi.getBounds();
80         else
81             aoiR = getBounds2D().getBounds();
82
83         // get the current affine transform
84
AffineTransform JavaDoc at = rc.getTransform();
85
86         // For high quality output we should really apply a Gaussian
87
// Blur when we are scaling the image down significantly this
88
// helps to prevent aliasing in the result image.
89
CachableRed cr = getSource();
90
91         if (aoiR.intersects(cr.getBounds()) == false)
92             return null;
93
94         if (at.isIdentity()) {
95             // System.out.println("Using as is");
96
return cr;
97         }
98
99         if ((at.getScaleX() == 1.0) && (at.getScaleY() == 1.0) &&
100             (at.getShearX() == 0.0) && (at.getShearY() == 0.0)) {
101             int xloc = (int)(cr.getMinX()+at.getTranslateX());
102             int yloc = (int)(cr.getMinY()+at.getTranslateY());
103             double dx = xloc - (cr.getMinX()+at.getTranslateX());
104             double dy = yloc - (cr.getMinY()+at.getTranslateY());
105             if (((dx > -0.0001) && (dx < 0.0001)) &&
106                 ((dy > -0.0001) && (dy < 0.0001))) {
107                 // System.out.println("Using TranslateRed");
108
return new TranslateRed(cr, xloc, yloc);
109             }
110         }
111
112         // System.out.println("Using Full affine: " + at);
113
return new AffineRed(cr, at, rh);
114     }
115 }
116
Popular Tags