Mercurial > hg > digilib-old
annotate servlet/src/digilib/io/ImageFileset.java @ 357:e03b4d7a7b46
better version of SVG Raster servlet
| author | robcast |
|---|---|
| date | Tue, 06 Dec 2005 14:36:31 +0100 |
| parents | 7958035abec1 |
| children | ee2b943420f5 |
| rev | line source |
|---|---|
| 176 | 1 /* ImageFileset -- digilib image file info class. |
| 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.File; | |
| 21 import java.io.IOException; | |
| 22 import java.util.ArrayList; | |
| 259 | 23 import java.util.Arrays; |
| 159 | 24 import java.util.Iterator; |
| 25 import java.util.ListIterator; | |
| 259 | 26 import java.util.Map; |
| 159 | 27 |
| 284 | 28 import org.apache.log4j.Logger; |
| 29 | |
| 30 import digilib.image.ImageOps; | |
| 159 | 31 import digilib.image.ImageSize; |
| 32 | |
| 33 /** | |
| 34 * @author casties | |
| 35 */ | |
| 36 public class ImageFileset extends DocuDirent { | |
| 37 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
38 /** this is an image file */ |
| 159 | 39 protected static int fileClass = FileOps.CLASS_IMAGE; |
| 284 | 40 |
| 41 /** logger for this class */ | |
| 42 private static Logger logger = Logger.getLogger(ImageFileset.class); | |
| 159 | 43 |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
44 /** list of files (ImageFile) */ |
| 159 | 45 private ArrayList list = null; |
| 233 | 46 |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
47 /** aspect ratio (width/height) */ |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
48 private float aspect = 0; |
| 233 | 49 |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
50 /** resolution of the biggest image (DPI) */ |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
51 private float resX = 0; |
| 233 | 52 |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
53 /** resolution of the biggest image (DPI) */ |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
54 private float resY = 0; |
| 159 | 55 |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
56 /** |
| 259 | 57 * Creator for empty fileset. |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
58 * |
| 159 | 59 * |
| 60 * @param initialCapacity | |
| 61 */ | |
| 259 | 62 public ImageFileset() { |
| 63 list = new ArrayList(); | |
| 159 | 64 } |
| 65 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
66 /** |
| 259 | 67 * Constructor with a file and hints. |
| 159 | 68 * |
| 259 | 69 * The hints are expected to contain 'basedirs' and 'scaledfilext' keys. |
| 233 | 70 * |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
71 * @param file |
| 259 | 72 * @param hints |
| 159 | 73 */ |
| 259 | 74 public ImageFileset(File file, Map hints) { |
| 75 Directory[] dirs = (Directory[]) hints.get(FileOps.HINT_BASEDIRS); | |
| 159 | 76 int nb = dirs.length; |
| 77 list = new ArrayList(nb); | |
| 78 parent = dirs[0]; | |
| 284 | 79 fill(dirs, file, hints); |
| 159 | 80 } |
| 284 | 81 |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
82 /** |
| 176 | 83 * Adds an ImageFile to this Fileset. |
| 159 | 84 * |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
85 * The files should be added in the order of higher to lower resolutions. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
86 * The first file is considered the hires "original". |
| 159 | 87 * |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
88 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
89 * @param f |
| 233 | 90 * file to add |
| 159 | 91 * @return true (always) |
| 92 */ | |
| 93 public boolean add(ImageFile f) { | |
| 94 f.setParent(this); | |
| 95 return list.add(f); | |
| 96 } | |
| 97 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
98 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
99 * The number of image files in this Fileset. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
100 * |
| 159 | 101 * |
| 102 * @return number of image files | |
| 103 */ | |
| 104 public int size() { | |
| 105 return (list != null) ? list.size() : 0; | |
| 106 } | |
| 107 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
108 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
109 * Gets the default File. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
110 * |
| 159 | 111 */ |
| 112 public File getFile() { | |
| 113 return (list != null) ? ((ImageFile) list.get(0)).getFile() : null; | |
| 114 } | |
| 115 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
116 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
117 * Get the ImageFile at the index. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
118 * |
| 159 | 119 * |
| 120 * @param index | |
| 121 * @return | |
| 122 */ | |
| 123 public ImageFile get(int index) { | |
| 124 return (ImageFile) list.get(index); | |
| 125 } | |
| 126 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
127 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
128 * Get the next smaller ImageFile than the given size. |
| 159 | 129 * |
| 233 | 130 * Returns the ImageFile from the set that has a width and height smaller or |
| 131 * equal the given size. Returns null if there isn't any smaller image. | |
| 159 | 132 * Needs DocuInfo instance to checkFile(). |
| 133 * | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
134 * |
| 159 | 135 * @param size |
| 136 * @param info | |
| 137 * @return | |
| 138 */ | |
| 284 | 139 public ImageFile getNextSmaller(ImageSize size) { |
| 159 | 140 for (Iterator i = getHiresIterator(); i.hasNext();) { |
| 141 ImageFile f = (ImageFile) i.next(); | |
| 142 try { | |
| 143 if (!f.isChecked()) { | |
| 284 | 144 ImageOps.checkFile(f); |
| 159 | 145 } |
| 146 if (f.getSize().isTotallySmallerThan(size)) { | |
| 147 return f; | |
| 148 } | |
| 149 } catch (IOException e) { | |
| 150 } | |
| 151 } | |
| 152 return null; | |
| 153 } | |
| 154 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
155 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
156 * Get the next bigger ImageFile than the given size. |
| 159 | 157 * |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
158 * Returns the ImageFile from the set that has a width or height bigger or |
| 233 | 159 * equal the given size. Returns null if there isn't any bigger image. Needs |
| 160 * DocuInfo instance to checkFile(). | |
| 159 | 161 * |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
162 * |
| 159 | 163 * @param size |
| 164 * @param info | |
| 165 * @return | |
| 166 */ | |
| 284 | 167 public ImageFile getNextBigger(ImageSize size) { |
| 159 | 168 for (ListIterator i = getLoresIterator(); i.hasPrevious();) { |
| 169 ImageFile f = (ImageFile) i.previous(); | |
| 170 try { | |
| 171 if (!f.isChecked()) { | |
| 284 | 172 ImageOps.checkFile(f); |
| 159 | 173 } |
| 174 if (f.getSize().isBiggerThan(size)) { | |
| 175 return f; | |
| 176 } | |
| 177 } catch (IOException e) { | |
| 178 } | |
| 179 } | |
| 180 return null; | |
| 181 } | |
| 182 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
183 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
184 * Returns the biggest ImageFile in the set. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
185 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
186 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
187 * @return |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
188 */ |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
189 public ImageFile getBiggest() { |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
190 return this.get(0); |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
191 } |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
192 |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
193 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
194 * Returns the biggest ImageFile in the set. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
195 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
196 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
197 * @return |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
198 */ |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
199 public ImageFile getSmallest() { |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
200 return this.get(this.size() - 1); |
|
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 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
204 * Get an Iterator for this Fileset starting at the highest resolution |
| 159 | 205 * images. |
| 206 * | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
207 * |
| 159 | 208 * @return |
| 209 */ | |
| 210 public ListIterator getHiresIterator() { | |
| 211 return list.listIterator(); | |
| 212 } | |
| 213 | |
|
170
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 * Get an Iterator for this Fileset starting at the lowest resolution |
| 159 | 216 * images. |
| 217 * | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
218 * The Iterator starts at the last element, so you have to use it backwards |
| 159 | 219 * with hasPrevious() and previous(). |
| 220 * | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
221 * |
| 159 | 222 * @return |
| 223 */ | |
| 224 public ListIterator getLoresIterator() { | |
| 225 return list.listIterator(list.size()); | |
| 226 } | |
| 227 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
228 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
229 * Fill the ImageFileset with files from different base directories. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
230 * |
| 159 | 231 * |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
232 * @param dirs |
| 233 | 233 * list of base directories |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
234 * @param fl |
| 233 | 235 * file (from first base dir) |
| 259 | 236 * @param hints |
| 284 | 237 * |
| 159 | 238 */ |
| 259 | 239 void fill(Directory[] dirs, File fl, Map hints) { |
| 240 String scalext = (String) hints.get(FileOps.HINT_FILEEXT); | |
| 159 | 241 int nb = dirs.length; |
| 242 String fn = fl.getName(); | |
| 259 | 243 String baseFn = FileOps.basename(fn); |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
244 // add the first ImageFile to the ImageFileset |
| 159 | 245 add(new ImageFile(fn, this, parent)); |
| 246 // iterate the remaining base directories | |
| 284 | 247 for (int dirIdx = 1; dirIdx < nb; dirIdx++) { |
| 248 if (dirs[dirIdx] == null) { | |
| 159 | 249 continue; |
| 250 } | |
| 284 | 251 // read the directory |
| 252 if (dirs[dirIdx].getFilenames() == null) { | |
| 253 dirs[dirIdx].readDir(); | |
| 259 | 254 } |
| 284 | 255 String[] dirFiles = dirs[dirIdx].getFilenames(); |
| 256 // try the same filename as the original | |
| 257 int fileIdx = Arrays.binarySearch(dirFiles, fn); | |
| 258 if (fileIdx < 0) { | |
| 259 // try closest matches without extension | |
| 260 fileIdx = -fileIdx - 1; | |
| 261 // try idx | |
| 262 if ((fileIdx < dirFiles.length) | |
| 263 && (FileOps.basename(dirFiles[fileIdx]).equals(baseFn))) { | |
| 264 // idx ok | |
| 265 } else if ((fileIdx > 0) | |
| 266 && (FileOps.basename(dirFiles[fileIdx - 1]) | |
| 267 .equals(baseFn))) { | |
| 268 // idx-1 ok | |
| 269 fileIdx = fileIdx - 1; | |
| 270 } else if ((fileIdx+1 < dirFiles.length) | |
| 271 && (FileOps.basename(dirFiles[fileIdx + 1]) | |
| 272 .equals(baseFn))) { | |
| 273 // idx+1 ok | |
| 274 fileIdx = fileIdx + 1; | |
| 275 } else { | |
| 276 // basename doesn't match | |
| 277 continue; | |
| 259 | 278 } |
| 159 | 279 } |
| 284 | 280 if (FileOps.classForFilename(dirFiles[fileIdx]) == FileOps.CLASS_IMAGE) { |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
281 /* logger.debug("adding file " + dirFiles[fileIdx] |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
282 + " to Fileset " + this.getName()); */ |
| 284 | 283 add(new ImageFile(dirFiles[fileIdx], this, dirs[dirIdx])); |
| 259 | 284 } |
| 159 | 285 } |
| 286 } | |
| 287 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
288 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
289 * Checks metadata and sets resolution in resX and resY. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
290 * |
| 159 | 291 */ |
| 292 public void checkMeta() { | |
| 293 if (metaChecked) { | |
| 294 return; | |
| 295 } | |
| 296 if (fileMeta == null) { | |
| 297 // try to read metadata file | |
| 298 readMeta(); | |
| 299 if (fileMeta == null) { | |
| 300 // try directory metadata | |
| 233 | 301 ((DocuDirectory) parent).checkMeta(); |
| 159 | 302 if (((DocuDirectory) parent).getDirMeta() != null) { |
| 303 fileMeta = ((DocuDirectory) parent).getDirMeta(); | |
| 304 } else { | |
| 233 | 305 // try parent directory metadata |
| 306 DocuDirectory gp = (DocuDirectory) parent.getParent(); | |
| 307 if (gp != null) { | |
| 308 gp.checkMeta(); | |
| 309 if (gp.getDirMeta() != null) { | |
| 310 fileMeta = gp.getDirMeta(); | |
| 311 } | |
| 312 } | |
| 159 | 313 } |
| 314 } | |
| 315 } | |
| 354 | 316 if (fileMeta == null) { |
| 317 // no metadata available | |
| 318 metaChecked = true; | |
| 319 return; | |
| 320 } | |
| 159 | 321 metaChecked = true; |
| 322 String s; | |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
323 float dpi = 0; |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
324 float dpix = 0; |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
325 float dpiy = 0; |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
326 float sizex = 0; |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
327 float sizey = 0; |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
328 float pixx = 0; |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
329 float pixy = 0; |
| 159 | 330 // DPI is valid for X and Y |
| 331 if (fileMeta.containsKey("original-dpi")) { | |
| 332 try { | |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
333 dpi = Float.parseFloat((String) fileMeta.get("original-dpi")); |
| 159 | 334 } catch (NumberFormatException e) { |
| 335 } | |
| 336 if (dpi != 0) { | |
| 337 resX = dpi; | |
| 338 resY = dpi; | |
| 339 return; | |
| 340 } | |
| 341 } | |
| 342 // DPI-X and DPI-Y | |
| 343 if (fileMeta.containsKey("original-dpi-x") | |
| 233 | 344 && fileMeta.containsKey("original-dpi-y")) { |
| 159 | 345 try { |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
346 dpix = Float.parseFloat((String) fileMeta |
| 233 | 347 .get("original-dpi-x")); |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
348 dpiy = Float.parseFloat((String) fileMeta |
| 233 | 349 .get("original-dpi-y")); |
| 159 | 350 } catch (NumberFormatException e) { |
| 351 } | |
| 352 if ((dpix != 0) && (dpiy != 0)) { | |
| 353 resX = dpix; | |
| 354 resY = dpiy; | |
| 355 return; | |
| 356 } | |
| 357 } | |
| 358 // SIZE-X and SIZE-Y and PIXEL-X and PIXEL-Y | |
| 359 if (fileMeta.containsKey("original-size-x") | |
| 233 | 360 && fileMeta.containsKey("original-size-y") |
| 361 && fileMeta.containsKey("original-pixel-x") | |
| 362 && fileMeta.containsKey("original-pixel-y")) { | |
| 159 | 363 try { |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
364 sizex = Float.parseFloat((String) fileMeta |
| 233 | 365 .get("original-size-x")); |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
366 sizey = Float.parseFloat((String) fileMeta |
| 233 | 367 .get("original-size-y")); |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
368 pixx = Float.parseFloat((String) fileMeta |
| 233 | 369 .get("original-pixel-x")); |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
370 pixy = Float.parseFloat((String) fileMeta |
| 233 | 371 .get("original-pixel-y")); |
| 159 | 372 } catch (NumberFormatException e) { |
| 373 } | |
| 374 if ((sizex != 0) && (sizey != 0) && (pixx != 0) && (pixy != 0)) { | |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
375 resX = pixx / (sizex * 100 / 2.54f); |
|
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
376 resY = pixy / (sizey * 100 / 2.54f); |
| 159 | 377 return; |
| 378 } | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 /** | |
| 383 * @return | |
| 384 */ | |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
385 public float getResX() { |
| 159 | 386 return resX; |
| 387 } | |
| 388 | |
| 389 /** | |
| 390 * @return | |
| 391 */ | |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
392 public float getResY() { |
| 159 | 393 return resY; |
| 394 } | |
| 395 | |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
396 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
397 * Sets the aspect ratio from an ImageSize. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
398 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
399 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
400 * @param f |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
401 */ |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
402 public void setAspect(ImageSize s) { |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
403 aspect = s.getAspect(); |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
404 } |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
405 |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
406 /** |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
407 * Returns the aspect ratio. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
408 * |
| 233 | 409 * 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
|
410 * landscape. |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
411 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
412 * |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
413 * @return |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
414 */ |
|
295
90bab835fc25
Servlet version 1.5.0b -- the beginning of the next generation :-)
robcast
parents:
284
diff
changeset
|
415 public float getAspect() { |
|
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
416 return aspect; |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
417 } |
|
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
159
diff
changeset
|
418 |
| 233 | 419 } |
