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