KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > transcoder > image > AOITest


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.transcoder.image;
19
20 import java.awt.geom.Rectangle2D JavaDoc;
21
22 import java.util.Map JavaDoc;
23 import java.util.HashMap JavaDoc;
24
25 import org.apache.batik.transcoder.TranscoderInput;
26
27 /**
28  * Test the ImageTranscoder with the KEY_AOI transcoding hint.
29  *
30  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
31  * @version $Id: AOITest.java,v 1.5 2004/08/18 07:17:12 vhardy Exp $
32  */

33 public class AOITest extends AbstractImageTranscoderTest {
34
35     /** The URI of the input image. */
36     protected String JavaDoc inputURI;
37
38     /** The URI of the reference image. */
39     protected String JavaDoc refImageURI;
40
41     /** The area of interest. */
42     protected Rectangle2D JavaDoc aoi;
43
44     /** The width of the image. */
45     protected Float JavaDoc imgWidth;
46
47     /** The height of the image. */
48     protected Float JavaDoc imgHeight;
49
50     /**
51      * Constructs a new <tt>AOITest</tt>.
52      *
53      * @param inputURI the URI of the input image
54      * @param the URI of the reference image
55      * @param x the x coordinate of the area of interest
56      * @param y the y coordinate of the area of interest
57      * @param width the width of the area of interest
58      * @param height the height of the area of interest
59      */

60     public AOITest(String JavaDoc inputURI,
61            String JavaDoc refImageURI,
62            Float JavaDoc x,
63            Float JavaDoc y,
64            Float JavaDoc width,
65            Float JavaDoc height) {
66     this(inputURI,
67          refImageURI,
68          x,
69          y,
70          width,
71          height,
72          new Float JavaDoc(-1),
73          new Float JavaDoc(-1));
74     }
75
76     /**
77      * Constructs a new <tt>AOITest</tt>.
78      *
79      * @param inputURI the URI of the input image
80      * @param the URI of the reference image
81      * @param x the x coordinate of the area of interest
82      * @param y the y coordinate of the area of interest
83      * @param width the width of the area of interest
84      * @param height the height of the area of interest
85      * @param imgWidth the width of the image to generate
86      * @param imgHeight the height of the image to generate
87      */

88     public AOITest(String JavaDoc inputURI,
89            String JavaDoc refImageURI,
90            Float JavaDoc x,
91            Float JavaDoc y,
92            Float JavaDoc width,
93            Float JavaDoc height,
94            Float JavaDoc imgWidth,
95            Float JavaDoc imgHeight) {
96     this.inputURI = inputURI;
97     this.refImageURI = refImageURI;
98     this.aoi = new Rectangle2D.Float JavaDoc(x.floatValue(),
99                      y.floatValue(),
100                      width.floatValue(),
101                      height.floatValue());
102     this.imgWidth = imgWidth;
103     this.imgHeight = imgHeight;
104     }
105
106     /**
107      * Creates the <tt>TranscoderInput</tt>.
108      */

109     protected TranscoderInput createTranscoderInput() {
110     return new TranscoderInput(resolveURL(inputURI).toString());
111     }
112     
113     /**
114      * Creates a Map that contains additional transcoding hints.
115      */

116     protected Map JavaDoc createTranscodingHints() {
117     Map JavaDoc hints = new HashMap JavaDoc(11);
118     hints.put(ImageTranscoder.KEY_AOI, aoi);
119     if (imgWidth.floatValue() > 0) {
120         hints.put(ImageTranscoder.KEY_WIDTH, imgWidth);
121     }
122     if (imgHeight.floatValue() > 0) {
123         hints.put(ImageTranscoder.KEY_HEIGHT, imgHeight);
124     }
125     return hints;
126     }
127
128     /**
129      * Returns the reference image for this test.
130      */

131     protected byte [] getReferenceImageData() {
132     return createBufferedImageData(resolveURL(refImageURI));
133     }
134 }
135
Popular Tags