Mercurial > hg > digilib-old
annotate servlet/src/digilib/io/ImageSet.java @ 576:dad720e9b12b stream
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
author | robcast |
---|---|
date | Wed, 22 Dec 2010 20:19:06 +0100 |
parents | 790cbfb58b52 |
children | bb8dfc05674f |
rev | line source |
---|---|
574 | 1 /* ImageSet -- digilib image file info class. |
176 | 2 * Digital Image Library servlet components |
3 * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) | |
4 * | |
5 * This program is free software; you can | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
6 * redistribute it and/or modify it under the terms of the GNU General Public |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
7 * License as published by the Free Software Foundation; either version 2 of |
176 | 8 * the License, or (at your option) any later version. |
9 * | |
10 * Please read license.txt for the full details. A copy of the GPL may be | |
11 * found at http://www.gnu.org/copyleft/lgpl.html | |
12 * | |
13 * You should have received a copy of the GNU General Public License along | |
14 * with this program; if not, write to the Free Software Foundation, Inc., | |
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
159 | 16 */ |
176 | 17 |
159 | 18 package digilib.io; |
19 | |
20 import java.io.IOException; | |
21 import java.util.ArrayList; | |
531 | 22 import java.util.List; |
159 | 23 import java.util.ListIterator; |
24 | |
25 import digilib.image.ImageSize; | |
563 | 26 import digilib.servlet.DigilibConfiguration; |
159 | 27 |
28 /** | |
29 * @author casties | |
30 */ | |
574 | 31 public class ImageSet { |
159 | 32 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
33 /** list of files (ImageFile) */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
34 protected List<ImageInput> list = null; |
233 | 35 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
36 /** aspect ratio (width/height) */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
37 protected float aspect = 0f; |
574 | 38 |
39 /** resolution of the biggest image (DPI) */ | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
40 protected float resX = 0f; |
233 | 41 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
42 /** resolution of the biggest image (DPI) */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
43 protected float resY = 0f; |
159 | 44 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
45 /** |
259 | 46 * Creator for empty fileset. |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
47 * |
159 | 48 * |
49 * @param initialCapacity | |
50 */ | |
574 | 51 public ImageSet() { |
52 list = new ArrayList<ImageInput>(); | |
159 | 53 } |
54 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
55 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
56 * The number of image files in this Fileset. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
57 * |
159 | 58 * |
59 * @return number of image files | |
60 */ | |
61 public int size() { | |
62 return (list != null) ? list.size() : 0; | |
63 } | |
64 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
65 /** |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
66 * Gets the default Input. |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
67 * |
159 | 68 */ |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
69 public ImageInput get() { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
70 return (list != null) ? list.get(0) : null; |
159 | 71 } |
72 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
73 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
74 * Get the ImageFile at the index. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
75 * |
159 | 76 * |
77 * @param index | |
78 * @return | |
79 */ | |
574 | 80 public ImageInput get(int index) { |
531 | 81 return list.get(index); |
159 | 82 } |
83 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
84 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
85 * Get the next smaller ImageFile than the given size. |
159 | 86 * |
233 | 87 * Returns the ImageFile from the set that has a width and height smaller or |
88 * equal the given size. Returns null if there isn't any smaller image. | |
159 | 89 * Needs DocuInfo instance to checkFile(). |
90 * | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
91 * |
159 | 92 * @param size |
93 * @param info | |
94 * @return | |
95 */ | |
574 | 96 public ImageInput getNextSmaller(ImageSize size) { |
97 for (ListIterator<ImageInput> i = getHiresIterator(); i.hasNext();) { | |
98 ImageInput f = i.next(); | |
159 | 99 try { |
100 if (!f.isChecked()) { | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
101 DigilibConfiguration.docuImageIdentify((ImageFile) f); // FIXME: cast to file? |
159 | 102 } |
103 if (f.getSize().isTotallySmallerThan(size)) { | |
104 return f; | |
105 } | |
106 } catch (IOException e) { | |
107 } | |
108 } | |
109 return null; | |
110 } | |
111 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
112 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
113 * Get the next bigger ImageFile than the given size. |
159 | 114 * |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
115 * Returns the ImageFile from the set that has a width or height bigger or |
233 | 116 * equal the given size. Returns null if there isn't any bigger image. Needs |
117 * DocuInfo instance to checkFile(). | |
159 | 118 * |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
119 * |
159 | 120 * @param size |
121 * @param info | |
122 * @return | |
123 */ | |
574 | 124 public ImageInput getNextBigger(ImageSize size) { |
125 for (ListIterator<ImageInput> i = getLoresIterator(); i.hasPrevious();) { | |
126 ImageInput f = i.previous(); | |
159 | 127 try { |
128 if (!f.isChecked()) { | |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
129 DigilibConfiguration.docuImageIdentify((ImageFile) f); // FIXME: cast to file? |
159 | 130 } |
131 if (f.getSize().isBiggerThan(size)) { | |
132 return f; | |
133 } | |
134 } catch (IOException e) { | |
135 } | |
136 } | |
137 return null; | |
138 } | |
139 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
140 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
141 * Returns the biggest ImageFile in the set. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
142 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
143 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
144 * @return |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
145 */ |
574 | 146 public ImageInput getBiggest() { |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
147 return this.get(0); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
148 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
149 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
150 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
151 * Returns the biggest ImageFile in the set. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
152 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
153 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
154 * @return |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
155 */ |
574 | 156 public ImageInput getSmallest() { |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
157 return this.get(this.size() - 1); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
158 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
159 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
160 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
161 * Get an Iterator for this Fileset starting at the highest resolution |
159 | 162 * images. |
163 * | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
164 * |
159 | 165 * @return |
166 */ | |
574 | 167 public ListIterator<ImageInput> getHiresIterator() { |
159 | 168 return list.listIterator(); |
169 } | |
170 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
171 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
172 * Get an Iterator for this Fileset starting at the lowest resolution |
159 | 173 * images. |
174 * | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
175 * The Iterator starts at the last element, so you have to use it backwards |
159 | 176 * with hasPrevious() and previous(). |
177 * | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
178 * |
159 | 179 * @return |
180 */ | |
574 | 181 public ListIterator<ImageInput> getLoresIterator() { |
159 | 182 return list.listIterator(list.size()); |
183 } | |
184 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
185 /** |
159 | 186 * @return |
187 */ | |
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
188 public float getResX() { |
159 | 189 return resX; |
190 } | |
191 | |
192 /** | |
193 * @return | |
194 */ | |
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
195 public float getResY() { |
159 | 196 return resY; |
197 } | |
198 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
199 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
200 * Sets the aspect ratio from an ImageSize. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
201 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
202 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
203 * @param f |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
204 */ |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
205 public void setAspect(ImageSize s) { |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
206 aspect = s.getAspect(); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
207 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
208 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
209 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
210 * Returns the aspect ratio. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
211 * |
233 | 212 * Aspect ratio is (width/height). So it's <1 for portrait and >1 for |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
213 * landscape. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
214 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
215 * |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
216 * @return |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
217 */ |
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
218 public float getAspect() { |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
219 return aspect; |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
220 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
221 |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
222 public void checkMeta() { |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
223 // TODO Auto-generated method stub |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
224 |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
225 } |
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
226 |
233 | 227 } |