Mercurial > hg > digilib-old
annotate servlet/src/digilib/image/ImageJobDescription.java @ 774:4568e539abd2 stream
merge from jquery branch
19754e80cc9fb019a073b61891415233b4ef591a
author | robcast |
---|---|
date | Fri, 11 Feb 2011 10:12:41 +0100 |
parents | 5d3f74f378dd 4b686a0d44f7 |
children | a23c4c15a6a8 |
rev | line source |
---|---|
557 | 1 package digilib.image; |
500 | 2 |
3 import java.awt.geom.AffineTransform; | |
4 import java.awt.geom.Rectangle2D; | |
5 import java.io.IOException; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import digilib.io.DocuDirCache; | |
541 | 10 import digilib.io.DocuDirectory; |
500 | 11 import digilib.io.FileOpException; |
12 import digilib.io.FileOps; | |
563 | 13 import digilib.io.FileOps.FileClass; |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
14 import digilib.io.ImageInput; |
574 | 15 import digilib.io.ImageSet; |
557 | 16 import digilib.servlet.DigilibConfiguration; |
596 | 17 import digilib.util.ImageSize; |
557 | 18 import digilib.util.OptionsSet; |
19 import digilib.util.Parameter; | |
20 import digilib.util.ParameterMap; | |
500 | 21 |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
22 /** |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
23 * A class for storing the set of parameters necessary for scaling images |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
24 * with an ImageWorker. |
500 | 25 * |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
26 * This contains the functionality formerly found in Scaler.processRequest(), |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
27 * only factorized. |
500 | 28 * |
547 | 29 * @author cmielack, casties |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
30 * |
500 | 31 */ |
32 | |
547 | 33 public class ImageJobDescription extends ParameterMap { |
500 | 34 |
35 DigilibConfiguration dlConfig = null; | |
36 protected static Logger logger = Logger.getLogger("digilib.servlet"); | |
37 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
38 ImageInput input = null; |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
39 ImageSet imageSet = null; |
541 | 40 DocuDirectory fileDir = null; |
41 String filePath = null; | |
500 | 42 ImageSize expectedSourceSize = null; |
43 Float scaleXY = null; | |
44 Rectangle2D userImgArea = null; | |
589 | 45 Rectangle2D outerUserImgArea = null; |
502 | 46 Boolean imageSendable = null; |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
47 String mimeType = null; |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
48 Integer paramDW = null; |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
49 Integer paramDH = null; |
547 | 50 |
51 /** create empty ImageJobDescription. | |
52 * @param dlcfg | |
53 */ | |
54 public ImageJobDescription(DigilibConfiguration dlcfg) { | |
500 | 55 super(30); |
547 | 56 dlConfig = dlcfg; |
552 | 57 } |
58 | |
59 | |
60 /** set up Parameters | |
557 | 61 * @see digilib.util.ParameterMap#initParams() |
552 | 62 */ |
63 @Override | |
64 protected void initParams() { | |
500 | 65 // url of the page/document (second part) |
66 newParameter("fn", "", null, 's'); | |
67 // page number | |
68 newParameter("pn", new Integer(1), null, 's'); | |
69 // width of client in pixels | |
70 newParameter("dw", new Integer(0), null, 's'); | |
71 // height of client in pixels | |
72 newParameter("dh", new Integer(0), null, 's'); | |
73 // left edge of image (float from 0 to 1) | |
74 newParameter("wx", new Float(0), null, 's'); | |
75 // top edge in image (float from 0 to 1) | |
76 newParameter("wy", new Float(0), null, 's'); | |
77 // width of image (float from 0 to 1) | |
78 newParameter("ww", new Float(1), null, 's'); | |
79 // height of image (float from 0 to 1) | |
80 newParameter("wh", new Float(1), null, 's'); | |
81 // scale factor | |
82 newParameter("ws", new Float(1), null, 's'); | |
83 // special options like 'fit' for gifs | |
547 | 84 newParameter("mo", this.options, null, 's'); |
500 | 85 // rotation angle (degree) |
86 newParameter("rot", new Float(0), null, 's'); | |
87 // contrast enhancement factor | |
88 newParameter("cont", new Float(0), null, 's'); | |
89 // brightness enhancement factor | |
90 newParameter("brgt", new Float(0), null, 's'); | |
91 // color multiplicative factors | |
92 newParameter("rgbm", "0/0/0", null, 's'); | |
93 // color additive factors | |
94 newParameter("rgba", "0/0/0", null, 's'); | |
95 // display dpi resolution (total) | |
96 newParameter("ddpi", new Float(0), null, 's'); | |
97 // display dpi X resolution | |
98 newParameter("ddpix", new Float(0), null, 's'); | |
99 // display dpi Y resolution | |
100 newParameter("ddpiy", new Float(0), null, 's'); | |
101 // scale factor for mo=ascale | |
102 newParameter("scale", new Float(1), null, 's'); | |
103 } | |
104 | |
503
fdb824bd57ab
first functional version of PDFCache after restructuring the code
cmielack
parents:
502
diff
changeset
|
105 |
552 | 106 /* (non-Javadoc) |
107 * @see digilib.servlet.ParameterMap#initOptions() | |
547 | 108 */ |
552 | 109 @Override |
110 protected void initOptions() { | |
565 | 111 String s = this.getAsString("mo"); |
112 options = new OptionsSet(s); | |
500 | 113 } |
552 | 114 |
115 | |
116 /** Creates new ImageJobDescription by merging Parameters from another ParameterMap. | |
117 * @param pm | |
118 * @param dlcfg | |
119 * @return | |
120 */ | |
557 | 121 public static ImageJobDescription getInstance(ParameterMap pm, DigilibConfiguration dlcfg) { |
552 | 122 ImageJobDescription newMap = new ImageJobDescription(dlcfg); |
123 // add all params to this map | |
557 | 124 newMap.params.putAll(pm.getParams()); |
552 | 125 newMap.initOptions(); |
126 return newMap; | |
127 } | |
128 | |
500 | 129 |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
130 /** Returns the mime-type (of the input). |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
131 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
132 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
133 */ |
547 | 134 public String getMimeType() throws IOException { |
135 if (mimeType == null) { | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
136 input = getInput(); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
137 mimeType = input.getMimetype(); |
502 | 138 } |
500 | 139 return mimeType; |
140 } | |
141 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
142 /** Returns the ImageInput to use. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
143 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
144 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
145 */ |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
146 public ImageInput getInput() throws IOException { |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
147 if(input == null){ |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
148 imageSet = getImageSet(); |
500 | 149 |
150 /* select a resolution */ | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
151 if (isHiresOnly()) { |
500 | 152 // get first element (= highest resolution) |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
153 input = imageSet.getBiggest(); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
154 } else if (isLoresOnly()) { |
500 | 155 // enforced lores uses next smaller resolution |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
156 input = imageSet.getNextSmaller(getExpectedSourceSize()); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
157 if (input == null) { |
500 | 158 // this is the smallest we have |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
159 input = imageSet.getSmallest(); |
500 | 160 } |
161 } else { | |
162 // autores: use next higher resolution | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
163 input = imageSet.getNextBigger(getExpectedSourceSize()); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
164 if (input == null) { |
500 | 165 // this is the highest we have |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
166 input = imageSet.getBiggest(); |
500 | 167 } |
168 } | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
169 logger.info("Planning to load: " + input); |
500 | 170 } |
171 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
172 return input; |
500 | 173 |
174 } | |
175 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
176 /** Returns the DocuDirectory for the input (file). |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
177 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
178 * @throws FileOpException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
179 */ |
557 | 180 public DocuDirectory getFileDirectory() throws FileOpException { |
555 | 181 if(fileDir == null){ |
500 | 182 DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); |
555 | 183 String fp = getFilePath(); |
184 fileDir = dirCache.getDirectory(fp); | |
541 | 185 if (fileDir == null) { |
186 throw new FileOpException("Directory " + getFilePath() + " not found."); | |
500 | 187 } |
188 } | |
541 | 189 return fileDir; |
500 | 190 } |
191 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
192 /** Returns the ImageSet to load. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
193 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
194 * @throws FileOpException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
195 */ |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
196 public ImageSet getImageSet() throws FileOpException { |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
197 if(imageSet==null){ |
541 | 198 DocuDirCache dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); |
199 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
200 imageSet = (ImageSet) dirCache.getFile(getFilePath(), getAsInt("pn"), FileClass.IMAGE); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
201 if (imageSet == null) { |
541 | 202 throw new FileOpException("File " + getFilePath() + "(" |
203 + getAsInt("pn") + ") not found."); | |
204 } | |
205 } | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
206 return imageSet; |
541 | 207 } |
208 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
209 /** Returns the file path name from the request. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
210 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
211 */ |
500 | 212 public String getFilePath() { |
541 | 213 if(filePath == null){ |
500 | 214 String s = this.getAsString("request.path"); |
215 s += this.getAsString("fn"); | |
541 | 216 filePath = FileOps.normalName(s); |
500 | 217 } |
541 | 218 return filePath; |
500 | 219 } |
220 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
221 public boolean isHiresOnly(){ |
547 | 222 return hasOption("clip") || hasOption("hires"); |
500 | 223 } |
224 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
225 public boolean isLoresOnly(){ |
547 | 226 return hasOption("lores"); |
500 | 227 } |
228 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
229 public boolean isScaleToFit() { |
547 | 230 return !(hasOption("clip") || hasOption("osize") || hasOption("ascale")); |
500 | 231 } |
232 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
233 public boolean isAbsoluteScale(){ |
547 | 234 return hasOption("osize") || hasOption("ascale"); |
500 | 235 } |
236 | |
237 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
238 /** Returns the minimum size the source image should have for scaling. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
239 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
240 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
241 */ |
547 | 242 public ImageSize getExpectedSourceSize() throws IOException { |
500 | 243 if (expectedSourceSize == null){ |
244 expectedSourceSize = new ImageSize(); | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
245 if (isScaleToFit()) { |
500 | 246 // scale to fit -- calculate minimum source size |
247 float scale = (1 / Math.min(getAsFloat("ww"), getAsFloat("wh"))) * getAsFloat("ws"); | |
547 | 248 expectedSourceSize.setSize((int) (getDw() * scale), |
249 (int) (getDh() * scale)); | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
250 } else if (isAbsoluteScale() && hasOption("ascale")) { |
500 | 251 // absolute scale -- apply scale to hires size |
547 | 252 expectedSourceSize = getHiresSize().getScaled(getAsFloat("scale")); |
500 | 253 } else { |
254 // clip to fit -- source = destination size | |
547 | 255 expectedSourceSize.setSize((int) (getDw() * getAsFloat("ws")), |
256 (int) (getDh() * getAsFloat("ws"))); | |
500 | 257 } |
258 } | |
259 return expectedSourceSize; | |
260 } | |
261 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
262 /** Returns the size of the highest resolution image. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
263 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
264 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
265 */ |
547 | 266 public ImageSize getHiresSize() throws IOException { |
500 | 267 logger.debug("get_hiresSize()"); |
268 | |
269 ImageSize hiresSize = null; | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
270 ImageSet fileset = getImageSet(); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
271 if (isAbsoluteScale()) { |
576
dad720e9b12b
try: DocuDirent as interface, ImageFile inherits from ImageInput and implements DocuDirent
robcast
parents:
574
diff
changeset
|
272 ImageInput hiresFile = fileset.getBiggest(); |
500 | 273 hiresSize = hiresFile.getSize(); |
274 } | |
275 return hiresSize; | |
276 } | |
277 | |
547 | 278 /** Returns image scaling factor. |
279 * Uses image size and user parameters. | |
280 * Modifies scaleXY, userImgArea. | |
281 * @return | |
282 * @throws IOException | |
283 * @throws ImageOpException | |
284 */ | |
285 public float getScaleXY() throws IOException, ImageOpException { | |
500 | 286 //logger.debug("get_scaleXY()"); |
287 if(scaleXY == null){ | |
288 // coordinates and scaling | |
289 float areaWidth; | |
290 float areaHeight; | |
547 | 291 float ws = getAsFloat("ws"); |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
292 ImageSize imgSize = getInput().getSize(); |
500 | 293 // user window area in [0,1] coordinates |
294 Rectangle2D relUserArea = new Rectangle2D.Float(getAsFloat("wx"), getAsFloat("wy"), | |
295 getAsFloat("ww"), getAsFloat("wh")); | |
296 // transform from relative [0,1] to image coordinates. | |
297 AffineTransform imgTrafo = AffineTransform.getScaleInstance(imgSize | |
298 .getWidth(), imgSize.getHeight()); | |
299 // transform user coordinate area to image coordinate area | |
547 | 300 userImgArea = imgTrafo.createTransformedShape( |
500 | 301 relUserArea).getBounds2D(); |
302 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
303 if (isScaleToFit()) { |
547 | 304 // calculate scaling factors based on inner user area |
500 | 305 areaWidth = (float) userImgArea.getWidth(); |
306 areaHeight = (float) userImgArea.getHeight(); | |
547 | 307 float scaleX = getDw() / areaWidth * ws; |
308 float scaleY = getDh() / areaHeight * ws; | |
500 | 309 scaleXY = (scaleX > scaleY) ? scaleY : scaleX; |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
310 } else if (isAbsoluteScale()) { |
547 | 311 // absolute scaling factor |
312 if (hasOption("osize")) { | |
313 // get original resolution from metadata | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
314 imageSet.checkMeta(); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
315 float origResX = imageSet.getResX(); |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
316 float origResY = imageSet.getResY(); |
547 | 317 if ((origResX == 0) || (origResY == 0)) { |
318 throw new ImageOpException("Missing image DPI information!"); | |
319 } | |
771 | 320 float ddpix = getAsFloat("ddpix"); |
321 float ddpiy = getAsFloat("ddpiy"); | |
322 if (ddpix == 0 || ddpiy == 0) { | |
323 float ddpi = getAsFloat("ddpi"); | |
324 if (ddpi == 0) { | |
325 throw new ImageOpException("Missing display DPI information!"); | |
326 } else { | |
327 ddpix = ddpi; | |
328 ddpiy = ddpi; | |
329 } | |
547 | 330 } |
331 // calculate absolute scale factor | |
771 | 332 float sx = ddpix / origResX; |
333 float sy = ddpiy / origResY; | |
547 | 334 // currently only same scale -- mean value |
335 scaleXY = (sx + sy) / 2f; | |
336 } else { | |
337 scaleXY = getAsFloat("scale"); | |
338 } | |
500 | 339 // we need to correct the factor if we use a pre-scaled image |
547 | 340 ImageSize hiresSize = getHiresSize(); |
500 | 341 if (imgSize.getWidth() != hiresSize.getWidth()) { |
342 scaleXY *= (float)hiresSize.getWidth() / (float)imgSize.getWidth(); | |
343 } | |
547 | 344 areaWidth = getDw() / scaleXY * ws; |
345 areaHeight = getDh() / scaleXY * ws; | |
500 | 346 // reset user area size |
347 userImgArea.setRect(userImgArea.getX(), userImgArea.getY(), | |
348 areaWidth, areaHeight); | |
349 } else { | |
547 | 350 // crop to fit -- don't scale |
351 areaWidth = getDw() * ws; | |
352 areaHeight = getDh() * ws; | |
500 | 353 // reset user area size |
354 userImgArea.setRect(userImgArea.getX(), userImgArea.getY(), | |
355 areaWidth, areaHeight); | |
356 scaleXY = 1f; | |
357 } | |
358 } | |
359 return (float) scaleXY; | |
360 } | |
361 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
362 /** Returns the width of the destination image. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
363 * Uses dh parameter and aspect ratio if dw parameter is empty. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
364 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
365 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
366 */ |
547 | 367 public int getDw() throws IOException { |
500 | 368 logger.debug("get_paramDW()"); |
547 | 369 if (paramDW == null) { |
500 | 370 |
547 | 371 paramDW = getAsInt("dw"); |
372 paramDH = getAsInt("dh"); | |
373 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
374 float imgAspect = getInput().getAspect(); |
500 | 375 if (paramDW == 0) { |
547 | 376 // calculate dw |
377 paramDW = Math.round(paramDH * imgAspect); | |
500 | 378 setValue("dw", paramDW); |
379 } else if (paramDH == 0) { | |
547 | 380 // calculate dh |
381 paramDH = Math.round(paramDW / imgAspect); | |
382 setValue("dh", paramDH); | |
500 | 383 } |
384 } | |
385 return paramDW; | |
386 } | |
387 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
388 /** Returns the height of the destination image. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
389 * Uses dw parameter and aspect ratio if dh parameter is empty. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
390 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
391 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
392 */ |
547 | 393 public int getDh() throws IOException { |
500 | 394 logger.debug("get_paramDH()"); |
547 | 395 if (paramDH == null) { |
396 | |
397 paramDW = getAsInt("dw"); | |
398 paramDH = getAsInt("dh"); | |
500 | 399 |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
400 float imgAspect = getInput().getAspect(); |
500 | 401 if (paramDW == 0) { |
547 | 402 // calculate dw |
403 paramDW = Math.round(paramDH * imgAspect); | |
404 setValue("dw", paramDW); | |
500 | 405 } else if (paramDH == 0) { |
547 | 406 // calculate dh |
407 paramDH = Math.round(paramDW / imgAspect); | |
408 setValue("dh", paramDH); | |
500 | 409 } |
410 } | |
411 return paramDH; | |
412 } | |
547 | 413 |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
414 /** Returns image quality as an integer. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
415 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
416 */ |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
417 public int getScaleQual(){ |
500 | 418 logger.debug("get_scaleQual()"); |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
419 int qual = dlConfig.getAsInt("default-quality"); |
547 | 420 if(hasOption("q0")) |
500 | 421 qual = 0; |
547 | 422 else if(hasOption("q1")) |
500 | 423 qual = 1; |
547 | 424 else if(hasOption("q2")) |
500 | 425 qual = 2; |
426 return qual; | |
427 } | |
428 | |
429 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
430 /** |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
431 * Returns the area of the source image that will be transformed into the |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
432 * destination image. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
433 * |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
434 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
435 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
436 * @throws ImageOpException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
437 */ |
547 | 438 public Rectangle2D getUserImgArea() throws IOException, ImageOpException{ |
439 if(userImgArea == null) { | |
440 // getScaleXY sets userImgArea | |
441 getScaleXY(); | |
500 | 442 } |
443 return userImgArea; | |
444 } | |
445 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
446 /** Returns the maximal area of the source image that will be used. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
447 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
448 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
449 * @throws ImageOpException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
450 */ |
547 | 451 public Rectangle2D getOuterUserImgArea() throws IOException, ImageOpException { |
500 | 452 if(outerUserImgArea == null){ |
547 | 453 outerUserImgArea = getUserImgArea(); |
500 | 454 |
455 // image size in pixels | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
456 ImageSize imgSize = getInput().getSize(); |
547 | 457 Rectangle2D imgBounds = new Rectangle2D.Float(0, 0, imgSize.getWidth(), |
458 imgSize.getHeight()); | |
500 | 459 |
460 // clip area at the image border | |
461 outerUserImgArea = outerUserImgArea.createIntersection(imgBounds); | |
462 | |
463 // check image parameters sanity | |
547 | 464 scaleXY = getScaleXY(); |
500 | 465 logger.debug("outerUserImgArea.getWidth()=" + outerUserImgArea.getWidth()); |
547 | 466 logger.debug("get_scaleXY() * outerUserImgArea.getWidth() = " + (scaleXY * outerUserImgArea.getWidth())); |
500 | 467 |
468 if ((outerUserImgArea.getWidth() < 1) | |
469 || (outerUserImgArea.getHeight() < 1) | |
547 | 470 || (scaleXY * outerUserImgArea.getWidth() < 2) |
471 || (scaleXY * outerUserImgArea.getHeight() < 2)) { | |
500 | 472 logger.error("ERROR: invalid scale parameter set!"); |
473 throw new ImageOpException("Invalid scale parameter set!"); | |
474 } | |
475 } | |
476 return outerUserImgArea; | |
477 } | |
478 | |
479 | |
547 | 480 public float[] getRGBM(){ |
502 | 481 float[] paramRGBM = null;//{0f,0f,0f}; |
547 | 482 Parameter p = params.get("rgbm"); |
500 | 483 if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { |
484 return p.parseAsFloatArray("/"); | |
485 } | |
486 return paramRGBM; | |
487 } | |
488 | |
547 | 489 public float[] getRGBA(){ |
502 | 490 float[] paramRGBA = null;//{0f,0f,0f}; |
547 | 491 Parameter p = params.get("rgba"); |
500 | 492 if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { |
493 paramRGBA = p.parseAsFloatArray("/"); | |
494 } | |
495 return paramRGBA; | |
496 } | |
497 | |
547 | 498 /** Has send-as-file been requested? |
499 * @return | |
500 */ | |
501 public boolean getSendAsFile(){ | |
502 return hasOption("file") | |
503 || hasOption("rawfile"); | |
500 | 504 } |
502 | 505 |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
506 /** |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
507 * Returns if the image can be sent without processing. Takes image type and |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
508 * additional image operations into account. Does not check requested size |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
509 * transformation. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
510 * |
547 | 511 * @return |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
512 * @throws IOException |
547 | 513 */ |
514 public boolean isImageSendable() throws IOException { | |
515 // cached result? | |
516 if (imageSendable == null) { | |
517 String mimeType = getMimeType(); | |
502 | 518 imageSendable = ( (mimeType.equals("image/jpeg") |
519 || mimeType.equals("image/png") | |
520 || mimeType.equals("image/gif") ) | |
521 && | |
547 | 522 !(hasOption("hmir") |
523 || hasOption("vmir") | |
524 || (getAsFloat("rot") != 0.0) | |
525 || (getRGBM() != null) | |
526 || (getRGBA() != null) | |
527 || (getAsFloat("cont") != 0.0) | |
528 || (getAsFloat("brgt") != 0.0))); | |
502 | 529 } |
530 | |
531 return imageSendable; | |
532 } | |
533 | |
534 | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
535 /** |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
536 * Returns if any transformation of the source image (image manipulation or |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
537 * format conversion) is required. |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
538 * |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
539 * @return |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
540 * @throws IOException |
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
541 */ |
547 | 542 public boolean isTransformRequired() throws IOException { |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
543 ImageSize is = getInput().getSize(); |
547 | 544 ImageSize ess = getExpectedSourceSize(); |
545 // nt = no transform required | |
546 boolean nt = isImageSendable() && ( | |
547 // lores: send if smaller | |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
548 (isLoresOnly() && is.isSmallerThan(ess)) |
547 | 549 // else send if it fits |
593
7768ea8f59cf
more work on stream input -- cleaning up references to files
robcast
parents:
589
diff
changeset
|
550 || (!(isLoresOnly() || isHiresOnly()) && is.fitsIn(ess))); |
547 | 551 return ! nt; |
502 | 552 } |
500 | 553 } |