KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2002 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  */
package org.apache.batik.transcoder.image;
18
19 import java.util.Map JavaDoc;
20 import java.util.HashMap JavaDoc;
21
22 import org.apache.batik.transcoder.TranscoderInput;
23
24 /**
25  * Test the ImageTranscoder with the KEY_MAX_WIDTH and/or the KEY_MAX_HEIGHT
26  * transcoding hint.
27  *
28  * @author <a HREF="mailto:ruini@iki.fi">Henri Ruini</a>
29  * @version $Id: MaxDimensionTest.java,v 1.3 2004/08/18 07:17:12 vhardy Exp $
30  */

31 public class MaxDimensionTest extends AbstractImageTranscoderTest {
32
33     //-- Variables -----------------------------------------------------------
34
/** The URI of the input image. */
35     protected String JavaDoc inputURI;
36     /** The URI of the reference image. */
37     protected String JavaDoc refImageURI;
38     /** The maximum width of the image. */
39     protected Float JavaDoc maxWidth = new Float JavaDoc(Float.NaN);
40     /** The maximum height of the image. */
41     protected Float JavaDoc maxHeight = new Float JavaDoc(Float.NaN);
42     /** The width of the image. */
43     protected Float JavaDoc width = new Float JavaDoc(Float.NaN);
44     /** The height of the image. */
45     protected Float JavaDoc height = new Float JavaDoc(Float.NaN);
46
47
48     //-- Constructors --------------------------------------------------------
49
/**
50      * Constructs a new <tt>MaxDimensionTest</tt>.
51      *
52      * @param inputURI URI of the input image.
53      * @param refImageURI URI of the reference image.
54      * @param maxWidth Maximum image width (KEY_MAX_WIDTH value).
55      * @param maxHeight Maximum image height (KEY_MAX_HEIGHT value).
56      */

57     public MaxDimensionTest(String JavaDoc inputURI, String JavaDoc refImageURI, Float JavaDoc maxWidth, Float JavaDoc maxHeight) {
58         this.inputURI = inputURI;
59         this.refImageURI = refImageURI;
60         this.maxWidth = maxWidth;
61         this.maxHeight = maxHeight;
62     }
63
64     /**
65      * Constructs a new <tt>MaxDimensionTest</tt>.
66      *
67      * @param inputURI URI of the input image.
68      * @param refImageURI URI of the reference image.
69      * @param maxWidth Maximum image width (KEY_MAX_WIDTH value).
70      * @param maxHeight Maximum image height (KEY_MAX_HEIGHT value).
71      * @param width Image width (KEY_WIDTH value).
72      * @param height Image height (KEY_HEIGH value).
73      */

74     public MaxDimensionTest(String JavaDoc inputURI, String JavaDoc refImageURI, Float JavaDoc maxWidth, Float JavaDoc maxHeight, Float JavaDoc width, Float JavaDoc height) {
75         this.inputURI = inputURI;
76         this.refImageURI = refImageURI;
77         this.maxWidth = maxWidth;
78         this.maxHeight = maxHeight;
79         this.width = width;
80         this.height = height;
81     }
82
83
84     //-- Methods -------------------------------------------------------------
85
/**
86      * Creates the <tt>TranscoderInput</tt>.
87      */

88     protected TranscoderInput createTranscoderInput() {
89         return new TranscoderInput(resolveURL(inputURI).toString());
90     }
91     
92     /**
93      * Creates a Map that contains additional transcoding hints.
94      *
95      * @return Transcoding hint values.
96      */

97     protected Map JavaDoc createTranscodingHints() {
98         Map JavaDoc hints = new HashMap JavaDoc(7);
99         if (!width.isNaN() && width.floatValue() > 0) {
100             hints.put(ImageTranscoder.KEY_WIDTH, width);
101         }
102         if (!height.isNaN() && height.floatValue() > 0) {
103             hints.put(ImageTranscoder.KEY_HEIGHT, height);
104         }
105         if (maxWidth.floatValue() > 0) {
106             hints.put(ImageTranscoder.KEY_MAX_WIDTH, maxWidth);
107         }
108         if (maxHeight.floatValue() > 0) {
109             hints.put(ImageTranscoder.KEY_MAX_HEIGHT, maxHeight);
110         }
111         return hints;
112     }
113
114     /**
115      * Returns the reference image for this test.
116      */

117     protected byte [] getReferenceImageData() {
118         return createBufferedImageData(resolveURL(refImageURI));
119     }
120 }
121
122
Popular Tags