Mercurial > hg > digilib-old
comparison common/src/main/java/digilib/util/ImageSize.java @ 903:7779b37d1d05
refactored into maven modules per servlet type.
can build servlet-api 2.3 and 3.0 via profile now!
author | robcast |
---|---|
date | Tue, 26 Apr 2011 20:24:31 +0200 |
parents | servlet/src/main/java/digilib/util/ImageSize.java@ba1eb2d821a2 |
children |
comparison
equal
deleted
inserted
replaced
902:89ba3ffcf552 | 903:7779b37d1d05 |
---|---|
1 /* | |
2 * ImageSize.java -- digilib image size class. | |
3 * Digital Image Library servlet components | |
4 * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) | |
5 * This program is free software; you can redistribute it and/or modify it under the | |
6 * terms of the GNU General Public License as published by the Free Software | |
7 * Foundation; either version 2 of the License, or (at your option) any later | |
8 * version. Please read license.txt for the full details. A copy of the GPL may | |
9 * be found at http://www.gnu.org/copyleft/lgpl.html You should have received a | |
10 * copy of the GNU General Public License along with this program; if not, | |
11 * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
12 * Boston, MA 02111-1307 USA Created on 26.08.2003 | |
13 */ | |
14 | |
15 package digilib.util; | |
16 | |
17 /** Class for image size (width, height). | |
18 * | |
19 * A width or height of 0 is treated as a 'wildcard' that matches any size. | |
20 * | |
21 * @author casties | |
22 * | |
23 */ | |
24 public class ImageSize { | |
25 public int width; | |
26 public int height; | |
27 | |
28 public ImageSize() { | |
29 super(); | |
30 } | |
31 | |
32 public ImageSize(int width, int height) { | |
33 this.width = width; | |
34 this.height = height; | |
35 } | |
36 | |
37 public ImageSize(ImageSize i) { | |
38 this.width = i.width; | |
39 this.height = i.height; | |
40 } | |
41 | |
42 public void setSize(int width, int height) { | |
43 this.width = width; | |
44 this.height = height; | |
45 } | |
46 | |
47 /** | |
48 * Returns if the size of this image is smaller in every dimension than the | |
49 * other image. | |
50 * | |
51 * | |
52 * | |
53 * @param is | |
54 * @return | |
55 */ | |
56 public boolean isTotallySmallerThan(ImageSize is) { | |
57 if ((this.width == 0)||(is.width == 0)) { | |
58 // width wildcard | |
59 return (this.height <= is.height); | |
60 } | |
61 if ((this.height == 0)||(is.height == 0)) { | |
62 // height wildcard | |
63 return (this.width <= is.width); | |
64 } | |
65 return ((this.width <= is.width)&&(this.height <= is.height)); | |
66 } | |
67 | |
68 /** | |
69 * Returns if the size of this image is smaller in at least one dimension | |
70 * than the other image. | |
71 * | |
72 * @param is | |
73 * @return | |
74 */ | |
75 public boolean isSmallerThan(ImageSize is) { | |
76 if ((this.width == 0)||(is.width == 0)) { | |
77 // width wildcard | |
78 return (this.height <= is.height); | |
79 } | |
80 if ((this.height == 0)||(is.height == 0)) { | |
81 // height wildcard | |
82 return (this.width <= is.width); | |
83 } | |
84 return ((this.width <= is.width) || (this.height <= is.height)); | |
85 } | |
86 | |
87 /** | |
88 * Returns if the size of this image is bigger in every dimension than the | |
89 * other image. | |
90 * | |
91 * | |
92 * | |
93 * @param is | |
94 * @return | |
95 */ | |
96 public boolean isTotallyBiggerThan(ImageSize is) { | |
97 if ((this.width == 0)||(is.width == 0)) { | |
98 // width wildcard | |
99 return (this.height >= is.height); | |
100 } | |
101 if ((this.height == 0)||(is.height == 0)) { | |
102 // height wildcard | |
103 return (this.width >= is.width); | |
104 } | |
105 return ((this.width >= is.width) && (this.height >= is.height)); | |
106 } | |
107 | |
108 /** | |
109 * Returns if the size of this image is bigger in at least one dimension | |
110 * than the other image. | |
111 * | |
112 * | |
113 * | |
114 * @param is | |
115 * @return | |
116 */ | |
117 public boolean isBiggerThan(ImageSize is) { | |
118 if ((this.width == 0)||(is.width == 0)) { | |
119 // width wildcard | |
120 return (this.height >= is.height); | |
121 } | |
122 if ((this.height == 0)||(is.height == 0)) { | |
123 // height wildcard | |
124 return (this.width >= is.width); | |
125 } | |
126 return ((this.width >= is.width) || (this.height >= is.height)); | |
127 } | |
128 | |
129 /** | |
130 * Returns if this image has the same size or height as the other image. | |
131 * | |
132 * | |
133 * | |
134 * @param is | |
135 * @return | |
136 */ | |
137 public boolean fitsIn(ImageSize is) { | |
138 if ((this.width == 0)||(is.width == 0)) { | |
139 // width wildcard | |
140 return (this.height == is.height); | |
141 } | |
142 if ((this.height == 0)||(is.height == 0)) { | |
143 // height wildcard | |
144 return (this.width == is.width); | |
145 } | |
146 return ( | |
147 (this.width == is.width) | |
148 && (this.height <= is.height) | |
149 || (this.width <= is.width) | |
150 && (this.height == is.height)); | |
151 } | |
152 | |
153 /** | |
154 * Returns if the size of this image is the same as the other image. | |
155 * | |
156 * | |
157 * | |
158 * @param is | |
159 * @return | |
160 */ | |
161 public boolean equals(ImageSize is) { | |
162 if ((this.width == 0)||(is.width == 0)) { | |
163 // width wildcard | |
164 return (this.height == is.height); | |
165 } | |
166 if ((this.height == 0)||(is.height == 0)) { | |
167 // height wildcard | |
168 return (this.width == is.width); | |
169 } | |
170 return ((this.width == is.width) && (this.height == is.height)); | |
171 } | |
172 | |
173 /** | |
174 * @return | |
175 */ | |
176 public int getHeight() { | |
177 return height; | |
178 } | |
179 | |
180 /** | |
181 * @param height | |
182 */ | |
183 public void setHeight(int height) { | |
184 this.height = height; | |
185 } | |
186 | |
187 /** | |
188 * @return | |
189 */ | |
190 public int getWidth() { | |
191 return width; | |
192 } | |
193 | |
194 /** | |
195 * @param width | |
196 */ | |
197 public void setWidth(int width) { | |
198 this.width = width; | |
199 } | |
200 | |
201 /** | |
202 * Returns the aspect ratio. | |
203 * | |
204 * Aspect ratio is (width/height). So it's <1 for portrait and >1 for | |
205 * landscape. | |
206 * | |
207 * @return | |
208 */ | |
209 public float getAspect() { | |
210 return (height > 0) ? ((float) width / (float) height) : 0; | |
211 } | |
212 | |
213 /** | |
214 * Returns a scaled copy of this image size. | |
215 * | |
216 * @param scale | |
217 * @return | |
218 */ | |
219 public ImageSize getScaled(float scale) { | |
220 return new ImageSize((int) (width * scale), (int) (height * scale)); | |
221 } | |
222 | |
223 /* (non-Javadoc) | |
224 * @see java.lang.Object#toString() | |
225 */ | |
226 public String toString() { | |
227 String s = "[" + width + "x" + height + "]"; | |
228 return s; | |
229 } | |
230 } |