annotate servlet/src/digilib/io/ImageFileset.java @ 339:6d2032b6121d gen2_1

new directory and cache work
author robcast
date Wed, 17 Nov 2004 18:17:34 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
1 /* ImageFileset -- digilib image file info class.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
2 * Digital Image Library servlet components
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
3 * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de)
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
4 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
5 * This program is free software; you can
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
6 * redistribute it and/or modify it under the terms of the GNU General Public
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
7 * License as published by the Free Software Foundation; either version 2 of
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
8 * the License, or (at your option) any later version.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
9 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
10 * Please read license.txt for the full details. A copy of the GPL may be
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
11 * found at http://www.gnu.org/copyleft/lgpl.html
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
12 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
13 * You should have received a copy of the GNU General Public License along
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
14 * with this program; if not, write to the Free Software Foundation, Inc.,
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
16 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
17
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
18 package digilib.io;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
19
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
20 import java.io.File;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
21 import java.io.IOException;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
22 import java.util.ArrayList;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
23 import java.util.Iterator;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
24 import java.util.List;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
25 import java.util.ListIterator;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
26 import java.util.Map;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
27
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
28 import digilib.image.ImageOps;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
29 import digilib.image.ImageSize;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
30
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
31 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
32 * @author casties
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
33 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
34 public class ImageFileset extends DigiDirent {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
35
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
36 /** this is an image file */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
37 protected static int FILE_CLASS = FileOps.CLASS_IMAGE;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
38
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
39 /** list of files (ImageFile) */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
40 private List files;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
41
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
42 /** resolution of the biggest image (DPI) */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
43 private float resX = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
44
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
45 /** resolution of the biggest image (DPI) */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
46 private float resY = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
47
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
48 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
49 * Constructor with a file and hints.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
50 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
51 * The hints are expected to contain 'basedirs' and 'scaledfilext' keys.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
52 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
53 * @param file
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
54 * @param hints
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
55 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
56 public ImageFileset(File file, DigiDirectory parent, Map hints) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
57 super(file.getName(), parent);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
58 files = new ArrayList(FileOps.getBaseDirs().length);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
59 fill(file, hints);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
60 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
61
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
62 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
63 * Gets the default File.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
64 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
65 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
66 public ImageFile getFile() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
67 return (files != null) ? (ImageFile) files.get(0) : null;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
68 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
69
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
70 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
71 * Get the ImageFile at the index.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
72 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
73 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
74 * @param index
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
75 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
76 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
77 public ImageFile get(int index) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
78 return (files != null) ? (ImageFile) files.get(index) : null;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
79 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
80
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
81 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
82 * Get the next smaller ImageFile than the given size.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
83 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
84 * Returns the ImageFile from the set that has a width and height smaller or
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
85 * equal the given size. Returns null if there isn't any smaller image.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
86 * Needs DocuInfo instance to checkFile().
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
87 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
88 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
89 * @param size
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
90 * @param info
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
91 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
92 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
93 public ImageFile getNextSmaller(ImageSize size) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
94 for (Iterator i = getHiresIterator(); i.hasNext();) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
95 ImageFile f = (ImageFile) i.next();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
96 try {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
97 ImageOps.checkFile(f);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
98 if (f.getSize().isTotallySmallerThan(size)) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
99 return f;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
100 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
101 } catch (IOException e) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
102 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
103 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
104 return null;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
105 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
106
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
107 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
108 * Get the next bigger ImageFile than the given size.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
109 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
110 * Returns the ImageFile from the set that has a width or height bigger or
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
111 * equal the given size. Returns null if there isn't any bigger image. Needs
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
112 * DocuInfo instance to checkFile().
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
113 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
114 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
115 * @param size
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
116 * @param info
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
117 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
118 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
119 public ImageFile getNextBigger(ImageSize size) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
120 for (ListIterator i = getLoresIterator(); i.hasPrevious();) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
121 ImageFile f = (ImageFile) i.previous();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
122 try {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
123 ImageOps.checkFile(f);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
124 if (f.getSize().isBiggerThan(size)) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
125 return f;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
126 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
127 } catch (IOException e) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
128 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
129 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
130 return null;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
131 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
132
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
133 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
134 * Returns the biggest ImageFile in the set.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
135 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
136 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
137 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
138 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
139 public ImageFile getBiggest() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
140 return (ImageFile) files.get(0);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
141 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
142
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
143 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
144 * Returns the biggest ImageFile in the set.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
145 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
146 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
147 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
148 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
149 public ImageFile getSmallest() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
150 return (ImageFile) files.get(files.size() - 1);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
151 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
152
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
153 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
154 * Get an Iterator for this Fileset starting at the highest resolution
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
155 * images.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
156 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
157 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
158 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
159 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
160 public ListIterator getHiresIterator() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
161 return files.listIterator();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
162 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
163
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
164 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
165 * Get an Iterator for this Fileset starting at the lowest resolution
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
166 * images.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
167 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
168 * The Iterator starts at the last element, so you have to use it backwards
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
169 * with hasPrevious() and previous().
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
170 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
171 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
172 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
173 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
174 public ListIterator getLoresIterator() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
175 return files.listIterator(files.size());
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
176 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
177
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
178 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
179 * Fill the ImageFileset with files from different base directories.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
180 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
181 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
182 * @param dirs
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
183 * list of base directories
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
184 * @param imf
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
185 * file (from first base dir)
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
186 * @param hints
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
187 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
188 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
189 void fill(File imf, Map hints) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
190 File[][] scaledirs = (File[][]) hints.get(FileOps.HINT_BASEDIRS);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
191 File[] bd = FileOps.getBaseDirs();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
192 int nb = bd.length;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
193 if (scaledirs == null) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
194 // read all scaled directories
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
195 scaledirs = new File[nb][];
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
196 for (int i = 1; i < nb; i++) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
197 // check basedir + digilib path
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
198 File d = FileOps.getRealFile(bd[i], parent.getDLPath());
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
199 scaledirs[i] = d.listFiles();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
200 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
201 hints.put(FileOps.HINT_BASEDIRS, scaledirs);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
202 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
203 // add the first ImageFile to the ImageFileset
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
204 files.add(new ImageFile(imf));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
205 // iterate the remaining base directories
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
206 for (int dirIdx = 1; dirIdx < nb; dirIdx++) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
207 if (scaledirs[dirIdx] == null) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
208 continue;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
209 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
210 // find the file in the directory
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
211 File fn = FileOps.findFile(imf, scaledirs[dirIdx]);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
212 if (fn == null) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
213 continue;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
214 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
215 if (FileOps.classForFile(fn) == FileOps.CLASS_IMAGE) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
216 // add to the fileset
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
217 files.add(new ImageFile(fn));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
218 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
219 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
220 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
221
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
222 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
223 * Reads metadata and sets resolution in resX and resY.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
224 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
225 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
226 public void readMeta() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
227 if (isMetaRead) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
228 return;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
229 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
230 // read the metadata file
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
231 super.readMeta();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
232 if (meta == null) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
233 // try directory metadata
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
234 meta = parent.getMeta();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
235 if (meta == null) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
236 // no metadata available
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
237 isMetaRead = true;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
238 return;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
239 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
240 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
241 isMetaRead = true;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
242 String s;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
243 float dpi = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
244 float dpix = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
245 float dpiy = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
246 float sizex = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
247 float sizey = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
248 float pixx = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
249 float pixy = 0;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
250 // DPI is valid for X and Y
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
251 if (meta.containsKey("original-dpi")) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
252 try {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
253 dpi = Float.parseFloat((String) meta.get("original-dpi"));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
254 } catch (NumberFormatException e) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
255 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
256 if (dpi != 0) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
257 resX = dpi;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
258 resY = dpi;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
259 return;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
260 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
261 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
262 // DPI-X and DPI-Y
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
263 if (meta.containsKey("original-dpi-x")
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
264 && meta.containsKey("original-dpi-y")) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
265 try {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
266 dpix = Float.parseFloat((String) meta.get("original-dpi-x"));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
267 dpiy = Float.parseFloat((String) meta.get("original-dpi-y"));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
268 } catch (NumberFormatException e) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
269 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
270 if ((dpix != 0) && (dpiy != 0)) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
271 resX = dpix;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
272 resY = dpiy;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
273 return;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
274 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
275 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
276 // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
277 if (meta.containsKey("original-size-x")
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
278 && meta.containsKey("original-size-y")
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
279 && meta.containsKey("original-pixel-x")
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
280 && meta.containsKey("original-pixel-y")) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
281 try {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
282 sizex = Float.parseFloat((String) meta.get("original-size-x"));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
283 sizey = Float.parseFloat((String) meta.get("original-size-y"));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
284 pixx = Float.parseFloat((String) meta.get("original-pixel-x"));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
285 pixy = Float.parseFloat((String) meta.get("original-pixel-y"));
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
286 } catch (NumberFormatException e) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
287 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
288 if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
289 resX = pixx / (sizex * 100 / 2.54f);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
290 resY = pixy / (sizey * 100 / 2.54f);
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
291 return;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
292 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
293 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
294 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
295
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
296 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
297 * Returns the aspect ratio of the images.
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
298 *
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
299 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
300 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
301 public float getAspect() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
302 for (Iterator i = files.iterator(); i.hasNext();) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
303 ImageFile f = (ImageFile) i.next();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
304 ImageSize s = f.getSize();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
305 if (s != null) {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
306 return s.getAspect();
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
307 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
308 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
309 return 0f;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
310 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
311
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
312 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
313 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
314 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
315 public float getResX() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
316 return resX;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
317 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
318
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
319 /**
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
320 * @return
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
321 */
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
322 public float getResY() {
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
323 return resY;
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
324 }
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
325
6d2032b6121d new directory and cache work
robcast
parents:
diff changeset
326 }