Mercurial > hg > digilib-old
annotate servlet/src/digilib/servlet/Scaler.java @ 177:830b0111a0c9
Servlet version 1.17b2
- new mapping file for "virtual directories"
- direct file URLs now work without extension (even with wrong ones)
author | robcast |
---|---|
date | Mon, 10 Nov 2003 21:06:02 +0100 |
parents | d40922628e4a |
children | afe7ff98bb71 |
rev | line source |
---|---|
1 | 1 /* Scaler -- Scaler servlet main class |
2 | |
3 Digital Image Library servlet components | |
4 | |
73 | 5 Copyright (C) 2001, 2002, 2003 Robert Casties (robcast@mail.berlios.de) |
1 | 6 |
7 This program is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Please read license.txt for the full details. A copy of the GPL | |
13 may be found at http://www.gnu.org/copyleft/lgpl.html | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
149 | 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1 | 18 |
19 */ | |
20 | |
21 package digilib.servlet; | |
22 | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
23 import java.awt.geom.AffineTransform; |
100 | 24 import java.awt.geom.NoninvertibleTransformException; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
25 import java.awt.geom.Rectangle2D; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
26 import java.io.File; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
27 import java.io.IOException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
28 import java.util.List; |
1 | 29 |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
30 import javax.servlet.ServletConfig; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
31 import javax.servlet.ServletContext; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
32 import javax.servlet.ServletException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
33 import javax.servlet.http.HttpServlet; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
34 import javax.servlet.http.HttpServletRequest; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
35 import javax.servlet.http.HttpServletResponse; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
36 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
37 import digilib.Utils; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
38 import digilib.auth.AuthOpException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
39 import digilib.auth.AuthOps; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
40 import digilib.image.DocuImage; |
122 | 41 import digilib.image.DocuInfo; |
149 | 42 import digilib.image.ImageLoaderImageInfoDocuInfo; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
43 import digilib.image.ImageOpException; |
149 | 44 import digilib.image.ImageSize; |
86 | 45 import digilib.io.DocuDirCache; |
161 | 46 import digilib.io.ImageFile; |
47 import digilib.io.ImageFileset; | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
48 import digilib.io.FileOpException; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
49 import digilib.io.FileOps; |
1 | 50 |
64
5ea1999befd4
New JAI ImageLoader plugin. Currently uses first beta version of the plugin.
robcast
parents:
62
diff
changeset
|
51 //import tilecachetool.*; |
1 | 52 |
73 | 53 /** |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
54 * @author casties */ |
1 | 55 //public class Scaler extends HttpServlet implements SingleThreadModel { |
56 public class Scaler extends HttpServlet { | |
57 | |
73 | 58 // digilib servlet version (for all components) |
177 | 59 public static final String dlVersion = "1.17b2"; |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
60 |
73 | 61 // Utils instance with debuglevel |
62 Utils util; | |
63 // FileOps instance | |
64 FileOps fileOp; | |
65 // AuthOps instance | |
66 AuthOps authOp; | |
67 // ServletOps instance | |
68 ServletOps servletOp; | |
86 | 69 // DocuDirCache instance |
70 DocuDirCache dirCache; | |
161 | 71 |
153 | 72 // deny image file |
73 File denyImgFile; | |
74 // error image file | |
75 File errorImgFile; | |
76 // subsampling before scaling | |
77 float minSubsample = 2f; | |
78 // send files as is? | |
79 boolean sendFileAllowed = true; | |
80 // default scaling quality | |
81 int defaultQuality = 1; | |
1 | 82 |
94 | 83 // DigilibConfiguration instance |
73 | 84 DigilibConfiguration dlConfig; |
1 | 85 |
73 | 86 // use authorization database |
87 boolean useAuthentication = true; | |
1 | 88 |
100 | 89 // EXPRIMENTAL |
90 // try to enlarge cropping area for "oblique" angles | |
91 boolean wholeRotArea = false; | |
92 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
93 /** |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
94 * Initialisation on first run. |
73 | 95 * |
96 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) | |
97 */ | |
98 public void init(ServletConfig config) throws ServletException { | |
99 super.init(config); | |
1 | 100 |
73 | 101 // Debuggin! |
102 //TCTool tctool = new TCTool(); | |
153 | 103 |
147 | 104 System.out.println( |
105 "***** Digital Image Library Servlet (version " | |
106 + dlVersion | |
107 + ") *****"); | |
1 | 108 |
73 | 109 // get our ServletContext |
110 ServletContext context = config.getServletContext(); | |
111 // see if there is a Configuration instance | |
112 dlConfig = | |
113 (DigilibConfiguration) context.getAttribute( | |
86 | 114 "digilib.servlet.configuration"); |
73 | 115 if (dlConfig == null) { |
116 // create new Configuration | |
117 try { | |
118 dlConfig = new DigilibConfiguration(config); | |
86 | 119 context.setAttribute("digilib.servlet.configuration", dlConfig); |
73 | 120 } catch (Exception e) { |
121 throw new ServletException(e); | |
122 } | |
123 } | |
124 // first we need an Utils | |
125 util = dlConfig.getUtil(); | |
126 // set our AuthOps | |
153 | 127 useAuthentication = dlConfig.getAsBoolean("use-authorization"); |
128 authOp = (AuthOps) dlConfig.getValue("servlet.auth.op"); | |
73 | 129 // FileOps instance |
130 fileOp = new FileOps(util); | |
131 // AuthOps instance | |
132 servletOp = new ServletOps(util); | |
86 | 133 // DocuDirCache instance |
153 | 134 dirCache = (DocuDirCache) dlConfig.getValue("servlet.dir.cache"); |
135 denyImgFile = new File(dlConfig.getAsString("denied-image")); | |
136 errorImgFile = new File(dlConfig.getAsString("error-image")); | |
137 sendFileAllowed = dlConfig.getAsBoolean("sendfile-allowed"); | |
138 minSubsample = dlConfig.getAsFloat("subsample-minimum"); | |
139 defaultQuality = dlConfig.getAsInt("default-quality"); | |
73 | 140 } |
1 | 141 |
73 | 142 /** Process the HTTP Get request*/ |
143 public void doGet(HttpServletRequest request, HttpServletResponse response) | |
144 throws ServletException, IOException { | |
145 util.dprintln(1, "The servlet has received a GET!"); | |
146 // create new request with defaults | |
147 DigilibRequest dlReq = new DigilibRequest(); | |
148 // set with request parameters | |
149 dlReq.setWithRequest(request); | |
150 // add DigilibRequest to ServletRequest | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
151 request.setAttribute("digilib.servlet.request", dlReq); |
73 | 152 // do the processing |
153 processRequest(request, response); | |
154 } | |
1 | 155 |
73 | 156 /**Process the HTTP Post request*/ |
157 public void doPost( | |
158 HttpServletRequest request, | |
159 HttpServletResponse response) | |
160 throws ServletException, IOException { | |
161 util.dprintln(1, "The servlet has received a POST!"); | |
162 // create new request with defaults | |
163 DigilibRequest dlReq = new DigilibRequest(); | |
164 // set with request parameters | |
165 dlReq.setWithRequest(request); | |
166 // add DigilibRequest to ServletRequest | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
167 request.setAttribute("digilib.servlet.request", dlReq); |
73 | 168 // do the processing |
169 processRequest(request, response); | |
170 } | |
171 | |
172 /** main request handler. */ | |
173 void processRequest( | |
174 HttpServletRequest request, | |
175 HttpServletResponse response) | |
176 throws ServletException, IOException { | |
1 | 177 |
73 | 178 // time for benchmarking |
179 long startTime = System.currentTimeMillis(); | |
180 // output mime/type | |
181 String mimeType = "image/png"; | |
1 | 182 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
183 /* parameters for a session */ |
1 | 184 |
73 | 185 // scale the image file to fit window size i.e. respect dw,dh |
186 boolean scaleToFit = true; | |
100 | 187 // scale the image by a fixed factor only |
188 boolean absoluteScale = false; | |
122 | 189 // only crop the image to fit |
190 boolean cropToFit = false; | |
149 | 191 // send the file as is |
192 boolean sendFile = false; | |
193 // use low resolution images only | |
194 boolean loresOnly = false; | |
195 // use hires images only | |
122 | 196 boolean hiresOnly = false; |
73 | 197 // interpolation to use for scaling |
153 | 198 int scaleQual = defaultQuality; |
73 | 199 // send html error message (or image file) |
200 boolean errorMsgHtml = false; | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
201 // mirror the image |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
202 boolean doMirror = false; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
203 // angle of mirror axis |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
204 double mirrorAngle = 0; |
130 | 205 // original (hires) image resolution |
206 double origResX = 0; | |
207 double origResY = 0; | |
1 | 208 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
209 /* request parameters */ |
73 | 210 |
211 DigilibRequest dlRequest = | |
212 (DigilibRequest) request.getAttribute("digilib.servlet.request"); | |
1 | 213 |
73 | 214 // destination image width |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
215 int paramDW = dlRequest.getAsInt("dw"); |
73 | 216 // destination image height |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
217 int paramDH = dlRequest.getAsInt("dh"); |
73 | 218 // relative area x_offset (0..1) |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
219 double paramWX = dlRequest.getAsFloat("wx"); |
73 | 220 // relative area y_offset |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
221 double paramWY = dlRequest.getAsFloat("wy"); |
73 | 222 // relative area width (0..1) |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
223 double paramWW = dlRequest.getAsFloat("ww"); |
73 | 224 // relative area height |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
225 double paramWH = dlRequest.getAsFloat("wh"); |
73 | 226 // scale factor (additional to dw/width, dh/height) |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
227 double paramWS = dlRequest.getAsFloat("ws"); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
228 // rotation angle |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
229 double paramROT = dlRequest.getAsFloat("rot"); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
230 // contrast enhancement |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
231 float paramCONT = dlRequest.getAsFloat("cont"); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
232 // brightness enhancement |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
233 float paramBRGT = dlRequest.getAsFloat("brgt"); |
86 | 234 // color modification |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
235 float[] paramRGBM = null; |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
236 Parameter p = dlRequest.get("rgbm"); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
237 if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
238 paramRGBM = p.parseAsFloatArray("/"); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
239 } |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
240 float[] paramRGBA = null; |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
241 p = dlRequest.get("rgba"); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
242 if (p.hasValue() && (!p.getAsString().equals("0/0/0"))) { |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
243 paramRGBA = p.parseAsFloatArray("/"); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
244 } |
130 | 245 // destination resolution (DPI) |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
246 float paramDDPIX = dlRequest.getAsFloat("ddpix"); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
247 float paramDDPIY = dlRequest.getAsFloat("ddpiy"); |
130 | 248 if ((paramDDPIX == 0) || (paramDDPIY == 0)) { |
249 // if X or Y resolution isn't set, use DDPI | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
250 paramDDPIX = dlRequest.getAsFloat("ddpi"); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
251 paramDDPIY = paramDDPIX; |
130 | 252 } |
1 | 253 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
254 /* |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
255 * operation mode: "fit": always fit to page, "clip": send original |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
256 * resolution cropped, "file": send whole file (if allowed) |
73 | 257 */ |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
258 if (dlRequest.hasOption("mo", "clip")) { |
73 | 259 scaleToFit = false; |
100 | 260 absoluteScale = false; |
73 | 261 cropToFit = true; |
149 | 262 sendFile = false; |
263 hiresOnly = true; | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
264 } else if (dlRequest.hasOption("mo", "fit")) { |
73 | 265 scaleToFit = true; |
100 | 266 absoluteScale = false; |
122 | 267 cropToFit = false; |
149 | 268 sendFile = false; |
269 hiresOnly = false; | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
270 } else if (dlRequest.hasOption("mo", "osize")) { |
100 | 271 scaleToFit = false; |
272 absoluteScale = true; | |
122 | 273 cropToFit = false; |
149 | 274 sendFile = false; |
122 | 275 hiresOnly = true; |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
276 } else if (dlRequest.hasOption("mo", "file")) { |
73 | 277 scaleToFit = false; |
100 | 278 absoluteScale = false; |
153 | 279 if (sendFileAllowed) { |
73 | 280 cropToFit = false; |
149 | 281 sendFile = true; |
73 | 282 } else { |
122 | 283 // crop to fit if send file not allowed |
73 | 284 cropToFit = true; |
149 | 285 sendFile = false; |
73 | 286 } |
122 | 287 hiresOnly = true; |
73 | 288 } |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
289 // operation mode: "lores": try to use scaled image, "hires": use |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
290 // unscaled image |
149 | 291 // "autores": try best fitting resolution |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
292 if (dlRequest.hasOption("mo", "lores")) { |
149 | 293 loresOnly = true; |
294 hiresOnly = false; | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
295 } else if (dlRequest.hasOption("mo", "hires")) { |
149 | 296 loresOnly = false; |
297 hiresOnly = true; | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
298 } else if (dlRequest.hasOption("mo", "autores")) { |
149 | 299 loresOnly = false; |
300 hiresOnly = false; | |
301 } | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
302 // operation mode: "errtxt": error message in html, "errimg": error |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
303 // image |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
304 if (dlRequest.hasOption("mo", "errtxt")) { |
73 | 305 errorMsgHtml = true; |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
306 } else if (dlRequest.hasOption("mo", "errimg")) { |
73 | 307 errorMsgHtml = false; |
308 } | |
309 // operation mode: "q0" - "q2": interpolation quality | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
310 if (dlRequest.hasOption("mo", "q0")) { |
73 | 311 scaleQual = 0; |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
312 } else if (dlRequest.hasOption("mo", "q1")) { |
73 | 313 scaleQual = 1; |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
314 } else if (dlRequest.hasOption("mo", "q2")) { |
73 | 315 scaleQual = 2; |
316 } | |
1 | 317 |
73 | 318 //"big" try for all file/image actions |
319 try { | |
320 | |
161 | 321 // ImageFileset of the image to load |
322 ImageFileset fileset = null; | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
323 |
122 | 324 // new DocuInfo instance |
149 | 325 DocuInfo docuInfo = new ImageLoaderImageInfoDocuInfo(); |
73 | 326 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
327 /* find the file to load/send */ |
1 | 328 |
73 | 329 // get PathInfo |
330 String loadPathName = dlRequest.getFilePath(); | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
331 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
332 /* check permissions */ |
73 | 333 if (useAuthentication) { |
334 // get a list of required roles (empty if no restrictions) | |
335 List rolesRequired = authOp.rolesForPath(loadPathName, request); | |
336 if (rolesRequired != null) { | |
337 util.dprintln(1, "Role required: " + rolesRequired); | |
338 util.dprintln(2, "User: " + request.getRemoteUser()); | |
339 // is the current request/user authorized? | |
340 if (!authOp.isRoleAuthorized(rolesRequired, request)) { | |
341 // send deny answer and abort | |
342 util.dprintln(1, "ERROR: access denied!"); | |
343 if (errorMsgHtml) { | |
344 ServletOps.htmlMessage( | |
345 "ERROR: Unauthorized access!", | |
346 response); | |
347 } else { | |
153 | 348 servletOp.sendFile(denyImgFile, response); |
73 | 349 } |
350 return; | |
351 } | |
352 } | |
353 } | |
1 | 354 |
122 | 355 // find the file(set) |
161 | 356 ImageFile fileToLoad; |
357 fileset = | |
358 (ImageFileset) dirCache.getFile( | |
359 loadPathName, | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
360 dlRequest.getAsInt("pn"), |
161 | 361 FileOps.CLASS_IMAGE); |
94 | 362 if (fileset == null) { |
363 throw new FileOpException( | |
364 "File " | |
365 + loadPathName | |
366 + "(" | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
367 + dlRequest.getAsInt("pn") |
94 | 368 + ") not found."); |
369 } | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
370 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
371 /* calculate expected source image size */ |
149 | 372 ImageSize expectedSourceSize = new ImageSize(); |
122 | 373 if (scaleToFit) { |
374 double scale = (1 / Math.min(paramWW, paramWH)) * paramWS; | |
149 | 375 expectedSourceSize.setSize( |
376 (int) (paramDW * scale), | |
377 (int) (paramDH * scale)); | |
122 | 378 } else { |
379 expectedSourceSize.setSize( | |
149 | 380 (int) (paramDW * paramWS), |
381 (int) (paramDH * paramWS)); | |
100 | 382 } |
383 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
384 /* select a resolution */ |
149 | 385 if (hiresOnly) { |
386 // get first element (= highest resolution) | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
387 fileToLoad = fileset.getBiggest(); |
149 | 388 } else if (loresOnly) { |
389 // enforced lores uses next smaller resolution | |
390 fileToLoad = | |
391 fileset.getNextSmaller(expectedSourceSize, docuInfo); | |
392 if (fileToLoad == null) { | |
393 // this is the smallest we have | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
394 fileToLoad = fileset.getSmallest(); |
149 | 395 } |
396 } else { | |
130 | 397 // autores: use next higher resolution |
122 | 398 fileToLoad = |
399 fileset.getNextBigger(expectedSourceSize, docuInfo); | |
400 if (fileToLoad == null) { | |
130 | 401 // this is the highest we have |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
402 fileToLoad = fileset.getBiggest(); |
122 | 403 } |
86 | 404 } |
405 util.dprintln(1, "Loading: " + fileToLoad.getFile()); | |
73 | 406 |
130 | 407 if (absoluteScale) { |
408 // get original resolution from metadata | |
409 fileset.checkMeta(); | |
410 origResX = fileset.getResX(); | |
411 origResY = fileset.getResY(); | |
139
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
412 if ((origResX == 0) || (origResY == 0)) { |
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
413 throw new ImageOpException("Missing image DPI information!"); |
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
414 } |
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
415 |
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
416 if ((paramDDPIX == 0) || (paramDDPIY == 0)) { |
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
417 throw new ImageOpException("Missing display DPI information!"); |
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
418 } |
130 | 419 } |
420 | |
86 | 421 // check the source image |
122 | 422 if (!fileToLoad.isChecked()) { |
149 | 423 docuInfo.checkFile(fileToLoad); |
122 | 424 } |
86 | 425 // get the source image type |
426 mimeType = fileToLoad.getMimetype(); | |
149 | 427 // get the source image size |
428 ImageSize imgSize = fileToLoad.getSize(); | |
429 | |
130 | 430 // decide if the image can be sent as is |
431 boolean mimetypeSendable = | |
122 | 432 mimeType.equals("image/jpeg") |
433 || mimeType.equals("image/png") | |
434 || mimeType.equals("image/gif"); | |
130 | 435 boolean imagoOptions = |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
436 dlRequest.hasOption("mo", "hmir") |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
437 || dlRequest.hasOption("mo", "vmir") |
130 | 438 || (paramROT != 0) |
439 || (paramRGBM != null) | |
440 || (paramRGBA != null) | |
441 || (paramCONT != 0) | |
442 || (paramBRGT != 0); | |
139
11cfe4c89fdc
Servlet version 1.11b1 with improved original-size.
robcast
parents:
130
diff
changeset
|
443 boolean imageSendable = mimetypeSendable && !imagoOptions; |
73 | 444 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
445 /* |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
446 * if not autoRes and image smaller than requested size then send |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
447 * as is. if autoRes and image has requested size then send as is. |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
448 * if not autoScale and not scaleToFit nor cropToFit then send as |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
449 * is (mo=file) |
73 | 450 */ |
149 | 451 if ((loresOnly |
122 | 452 && imageSendable |
149 | 453 && fileToLoad.getSize().isSmallerThan(expectedSourceSize)) |
153 | 454 || (!(loresOnly || hiresOnly) |
455 && fileToLoad.getSize().fitsIn(expectedSourceSize)) | |
149 | 456 || sendFile) { |
73 | 457 |
458 util.dprintln(1, "Sending File as is."); | |
1 | 459 |
86 | 460 servletOp.sendFile(fileToLoad.getFile(), response); |
1 | 461 |
73 | 462 util.dprintln( |
463 1, | |
464 "Done in " | |
465 + (System.currentTimeMillis() - startTime) | |
466 + "ms"); | |
467 return; | |
468 } | |
1 | 469 |
149 | 470 // new DocuImage instance |
471 DocuImage docuImage = dlConfig.getDocuImageInstance(); | |
472 if (docuImage == null) { | |
473 throw new ImageOpException("Unable to load DocuImage class!"); | |
474 } | |
475 | |
476 // set interpolation quality | |
477 docuImage.setQuality(scaleQual); | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
478 |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
479 // set missing dw or dh from aspect ratio |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
480 double imgAspect = fileToLoad.getAspect(); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
481 if (paramDW == 0) { |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
482 paramDW = (int) Math.round(paramDH * imgAspect); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
483 } else if (paramDH == 0) { |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
484 paramDH = (int) Math.round(paramDW / imgAspect); |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
485 } |
149 | 486 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
487 /* crop and scale the image */ |
1 | 488 |
149 | 489 util.dprintln( |
490 2, | |
491 "IMG: " + imgSize.getWidth() + "x" + imgSize.getHeight()); | |
73 | 492 util.dprintln( |
493 2, | |
494 "time " + (System.currentTimeMillis() - startTime) + "ms"); | |
1 | 495 |
73 | 496 // coordinates and scaling |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
497 double areaXoff; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
498 double areaYoff; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
499 double areaWidth; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
500 double areaHeight; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
501 double scaleX; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
502 double scaleY; |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
503 double scaleXY; |
1 | 504 |
100 | 505 // coordinates using Java2D |
506 // image size in pixels | |
507 Rectangle2D imgBounds = | |
149 | 508 new Rectangle2D.Double( |
509 0, | |
510 0, | |
511 imgSize.getWidth(), | |
512 imgSize.getHeight()); | |
100 | 513 // user window area in [0,1] coordinates |
514 Rectangle2D relUserArea = | |
515 new Rectangle2D.Double(paramWX, paramWY, paramWW, paramWH); | |
516 // transform from relative [0,1] to image coordinates. | |
517 AffineTransform imgTrafo = | |
149 | 518 AffineTransform.getScaleInstance( |
519 imgSize.getWidth(), | |
520 imgSize.getHeight()); | |
85 | 521 // transform user coordinate area to image coordinate area |
100 | 522 Rectangle2D userImgArea = |
523 imgTrafo.createTransformedShape(relUserArea).getBounds2D(); | |
524 | |
525 // calculate scaling factors based on inner user area | |
73 | 526 if (scaleToFit) { |
100 | 527 areaWidth = userImgArea.getWidth(); |
528 areaHeight = userImgArea.getHeight(); | |
73 | 529 scaleX = paramDW / areaWidth * paramWS; |
530 scaleY = paramDH / areaHeight * paramWS; | |
531 scaleXY = (scaleX > scaleY) ? scaleY : scaleX; | |
100 | 532 } else if (absoluteScale) { |
533 // absolute scale | |
130 | 534 scaleX = paramDDPIX / origResX; |
535 scaleY = paramDDPIY / origResY; | |
536 // currently only same scale :-( | |
537 scaleXY = scaleX; | |
538 areaWidth = paramDW / scaleXY * paramWS; | |
539 areaHeight = paramDH / scaleXY * paramWS; | |
100 | 540 // reset user area size |
541 userImgArea.setRect( | |
542 userImgArea.getX(), | |
543 userImgArea.getY(), | |
544 areaWidth, | |
545 areaHeight); | |
73 | 546 } else { |
547 // crop to fit | |
85 | 548 areaWidth = paramDW * paramWS; |
549 areaHeight = paramDH * paramWS; | |
100 | 550 // reset user area size |
551 userImgArea.setRect( | |
552 userImgArea.getX(), | |
553 userImgArea.getY(), | |
554 areaWidth, | |
555 areaHeight); | |
73 | 556 scaleX = 1f; |
557 scaleY = 1f; | |
558 scaleXY = 1f; | |
100 | 559 } |
85 | 560 |
100 | 561 // enlarge image area for rotations to cover additional pixels |
562 Rectangle2D outerUserImgArea = userImgArea; | |
563 Rectangle2D innerUserImgArea = userImgArea; | |
564 if (wholeRotArea) { | |
565 if (paramROT != 0) { | |
566 try { | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
567 // rotate user area coordinates around center of user |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
568 // area |
100 | 569 AffineTransform rotTrafo = |
570 AffineTransform.getRotateInstance( | |
571 Math.toRadians(paramROT), | |
572 userImgArea.getCenterX(), | |
573 userImgArea.getCenterY()); | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
574 // get bounds from rotated end position |
100 | 575 innerUserImgArea = |
576 rotTrafo | |
577 .createTransformedShape(userImgArea) | |
578 .getBounds2D(); | |
579 // get bounds from back-rotated bounds | |
580 outerUserImgArea = | |
581 rotTrafo | |
582 .createInverse() | |
583 .createTransformedShape(innerUserImgArea) | |
584 .getBounds2D(); | |
585 } catch (NoninvertibleTransformException e1) { | |
586 // this shouldn't happen anyway | |
587 e1.printStackTrace(); | |
588 } | |
589 } | |
73 | 590 } |
1 | 591 |
73 | 592 util.dprintln( |
593 1, | |
594 "Scale " | |
595 + scaleXY | |
596 + "(" | |
597 + scaleX | |
598 + "," | |
599 + scaleY | |
600 + ") on " | |
100 | 601 + outerUserImgArea); |
1 | 602 |
73 | 603 // clip area at the image border |
100 | 604 outerUserImgArea = outerUserImgArea.createIntersection(imgBounds); |
85 | 605 |
100 | 606 areaWidth = outerUserImgArea.getWidth(); |
607 areaHeight = outerUserImgArea.getHeight(); | |
608 areaXoff = outerUserImgArea.getX(); | |
609 areaYoff = outerUserImgArea.getY(); | |
1 | 610 |
73 | 611 util.dprintln( |
612 2, | |
85 | 613 "crop: " |
73 | 614 + areaXoff |
615 + "," | |
616 + areaYoff | |
617 + " " | |
618 + areaWidth | |
619 + "x" | |
620 + areaHeight); | |
1 | 621 |
73 | 622 // check image parameters sanity |
623 if ((areaWidth < 1) | |
624 || (areaHeight < 1) | |
625 || (scaleXY * areaWidth < 2) | |
626 || (scaleXY * areaHeight < 2)) { | |
627 util.dprintln(1, "ERROR: invalid scale parameter set!"); | |
628 throw new ImageOpException("Invalid scale parameter set!"); | |
629 } | |
1 | 630 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
631 /* crop and scale image */ |
85 | 632 |
633 // use subimage loading if possible | |
634 if (docuImage.isSubimageSupported()) { | |
635 System.out.println( | |
636 "Subimage: scale " + scaleXY + " = " + (1 / scaleXY)); | |
637 double subf = 1d; | |
638 double subsamp = 1d; | |
639 if (scaleXY < 1) { | |
640 subf = 1 / scaleXY; | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
641 // for higher quality reduce subsample factor by |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
642 // minSubsample |
140 | 643 if (scaleQual > 0) { |
161 | 644 subsamp = Math.max(Math.floor(subf / minSubsample), 1d); |
140 | 645 } else { |
646 subsamp = Math.floor(subf); | |
647 } | |
85 | 648 scaleXY = subsamp / subf; |
649 System.out.println( | |
650 "Using subsampling: " + subsamp + " rest " + scaleXY); | |
651 } | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
652 |
85 | 653 docuImage.loadSubimage( |
149 | 654 fileToLoad, |
100 | 655 outerUserImgArea.getBounds(), |
85 | 656 (int) subsamp); |
657 | |
658 System.out.println( | |
659 "SUBSAMP: " | |
660 + subsamp | |
661 + " -> " | |
662 + docuImage.getWidth() | |
663 + "x" | |
664 + docuImage.getHeight()); | |
665 | |
149 | 666 docuImage.scale(scaleXY, scaleXY); |
85 | 667 |
668 } else { | |
100 | 669 // else load and crop the whole file |
149 | 670 docuImage.loadImage(fileToLoad); |
85 | 671 docuImage.crop( |
672 (int) areaXoff, | |
673 (int) areaYoff, | |
674 (int) areaWidth, | |
675 (int) areaHeight); | |
676 | |
149 | 677 docuImage.scale(scaleXY, scaleXY); |
85 | 678 } |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
679 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
680 // mirror image |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
681 // operation mode: "hmir": mirror horizontally, "vmir": mirror |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
682 // vertically |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
683 if (dlRequest.hasOption("mo", "hmir")) { |
100 | 684 docuImage.mirror(0); |
685 } | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
686 if (dlRequest.hasOption("mo", "vmir")) { |
100 | 687 docuImage.mirror(90); |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
688 } |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
689 |
100 | 690 // rotate image |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
691 if (paramROT != 0d) { |
94 | 692 docuImage.rotate(paramROT); |
100 | 693 if (wholeRotArea) { |
694 // crop to the inner bounding box | |
695 double xcrop = | |
696 docuImage.getWidth() | |
697 - innerUserImgArea.getWidth() * scaleXY; | |
698 double ycrop = | |
699 docuImage.getHeight() | |
700 - innerUserImgArea.getHeight() * scaleXY; | |
701 if ((xcrop > 0) || (ycrop > 0)) { | |
702 // only crop smaller | |
703 xcrop = (xcrop > 0) ? xcrop : 0; | |
704 ycrop = (ycrop > 0) ? ycrop : 0; | |
705 // crop image | |
706 docuImage.crop( | |
707 (int) (xcrop / 2), | |
708 (int) (ycrop / 2), | |
709 (int) (docuImage.getWidth() - xcrop), | |
710 (int) (docuImage.getHeight() - ycrop)); | |
711 } | |
712 } | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
713 |
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
714 } |
1 | 715 |
86 | 716 // color modification |
717 if ((paramRGBM != null) || (paramRGBA != null)) { | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
718 // make shure we actually have two arrays |
86 | 719 if (paramRGBM == null) { |
720 paramRGBM = new float[3]; | |
721 } | |
722 if (paramRGBA == null) { | |
723 paramRGBA = new float[3]; | |
724 } | |
100 | 725 // calculate "contrast" values (c=2^x) |
86 | 726 float[] mult = new float[3]; |
727 for (int i = 0; i < 3; i++) { | |
94 | 728 mult[i] = (float) Math.pow(2, (double) paramRGBM[i]); |
86 | 729 } |
730 docuImage.enhanceRGB(mult, paramRGBA); | |
731 } | |
94 | 732 |
100 | 733 // contrast and brightness enhancement |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
734 if ((paramCONT != 0f) || (paramBRGT != 0f)) { |
100 | 735 double mult = Math.pow(2, paramCONT); |
736 docuImage.enhance((float) mult, (float) paramBRGT); | |
737 } | |
738 | |
73 | 739 util.dprintln( |
740 2, | |
741 "time " + (System.currentTimeMillis() - startTime) + "ms"); | |
742 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
743 /* write the resulting image */ |
1 | 744 |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
745 // setup output -- if source is JPG then dest will be JPG else it's |
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
746 // PNG |
100 | 747 if (mimeType.equals("image/jpeg") |
748 || mimeType.equals("image/jp2")) { | |
749 mimeType = "image/jpeg"; | |
750 } else { | |
73 | 751 mimeType = "image/png"; |
752 } | |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
753 response.setContentType(mimeType); |
1 | 754 |
73 | 755 // write the image |
79
63c8186455c1
Servlet version 1.6b. Further cleanup and new functionality:
robcast
parents:
73
diff
changeset
|
756 docuImage.writeImage(mimeType, response.getOutputStream()); |
1 | 757 |
73 | 758 util.dprintln( |
759 1, | |
760 "Done in " + (System.currentTimeMillis() - startTime) + "ms"); | |
761 | |
170
d40922628e4a
Servlet Version 1.16b2 with new DigilibParameter code.
robcast
parents:
161
diff
changeset
|
762 /* error handling */ |
1 | 763 |
73 | 764 } // end of "big" try |
156 | 765 catch (IOException e) { |
73 | 766 util.dprintln(1, "ERROR: File IO Error: " + e); |
767 try { | |
768 if (errorMsgHtml) { | |
769 ServletOps.htmlMessage( | |
770 "ERROR: File IO Error: " + e, | |
771 response); | |
772 } else { | |
153 | 773 servletOp.sendFile(errorImgFile, response); |
73 | 774 } |
775 } catch (FileOpException ex) { | |
776 } // so we don't get a loop | |
777 } catch (AuthOpException e) { | |
778 util.dprintln(1, "ERROR: Authorization error: " + e); | |
779 try { | |
780 if (errorMsgHtml) { | |
781 ServletOps.htmlMessage( | |
782 "ERROR: Authorization error: " + e, | |
783 response); | |
784 } else { | |
153 | 785 servletOp.sendFile(errorImgFile, response); |
73 | 786 } |
787 } catch (FileOpException ex) { | |
788 } // so we don't get a loop | |
789 } catch (ImageOpException e) { | |
790 util.dprintln(1, "ERROR: Image Error: " + e); | |
791 try { | |
792 if (errorMsgHtml) { | |
793 ServletOps.htmlMessage( | |
794 "ERROR: Image Operation Error: " + e, | |
795 response); | |
796 } else { | |
153 | 797 servletOp.sendFile(errorImgFile, response); |
73 | 798 } |
799 } catch (FileOpException ex) { | |
800 } // so we don't get a loop | |
801 } catch (RuntimeException e) { | |
802 // JAI likes to throw RuntimeExceptions ;-( | |
803 util.dprintln(1, "ERROR: Other Image Error: " + e); | |
804 try { | |
805 if (errorMsgHtml) { | |
806 ServletOps.htmlMessage( | |
807 "ERROR: Other Image Operation Error: " + e, | |
808 response); | |
809 } else { | |
153 | 810 servletOp.sendFile(errorImgFile, response); |
73 | 811 } |
812 } catch (FileOpException ex) { | |
813 } // so we don't get a loop | |
149 | 814 |
73 | 815 } |
816 } | |
1 | 817 |
73 | 818 } //Scaler class |