Mercurial > hg > digilib-old
annotate client/digitallibrary/modules/imago.js @ 346:5275a132dbd1
Servlet version 1.5.7b
- new max-waiting-threads parameter and handling
- DocumentBean also gets real image sizes (for dlInfo-xml et al.)
author | robcast |
---|---|
date | Fri, 22 Apr 2005 19:16:41 +0200 |
parents | 69b616b50431 |
children |
rev | line source |
---|---|
106 | 1 /* |
135 | 2 |
106 | 3 Copyright (C) 2003 WTWG, Uni Bern |
4 | |
5 This program is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU General Public License | |
7 as published by the Free Software Foundation; either version 2 | |
8 of the License, or (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
135 | 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
106 | 13 GNU General Public License for more details. |
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 | |
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
18 | |
135 | 19 Author: Christian Luginbuehl, 22.05.2003 , Version Alcatraz 0.4 |
106 | 20 |
135 | 21 */ |
106 | 22 |
135 | 23 /************************************************************************* |
24 * imago.js : digilib-module * | |
25 * * | |
26 * desc: adds different image manipulation functions. * | |
27 * * | |
28 *************************************************************************/ | |
106 | 29 |
30 | |
31 /** | |
32 * brightness (value of brightness between -255 - +255) | |
33 */ | |
34 function brightness(value) { | |
35 | |
135 | 36 if ( (value >= -255) && (value <= 255) ) { |
106 | 37 |
135 | 38 dlParams.brgt.value = value; |
39 display(3); | |
106 | 40 |
41 } | |
42 | |
43 } | |
44 | |
135 | 45 |
106 | 46 /** |
47 * contrast (value of contrast - range?) | |
48 */ | |
49 function contrast(value) { | |
50 | |
135 | 51 dlParams.cont.value = parseFloat(value); |
52 display(3); | |
53 | |
54 } | |
55 | |
106 | 56 |
135 | 57 /** |
58 * brightness/contrast in one call | |
59 */ | |
60 function brightnessContrast(brightness, contrast) { | |
61 | |
62 dlParams.cont.value = parseFloat(contrast); | |
63 | |
64 if ( (brightness >= -255) && (brightness <= 255) ) { | |
65 | |
66 dlParams.brgt.value = parseFloat(brightness); | |
67 display(3); | |
68 | |
69 } | |
106 | 70 |
71 } | |
72 | |
135 | 73 |
106 | 74 /** |
135 | 75 * mirror (horizontal or vertical) |
76 */ | |
77 function mirror(direction) { | |
78 | |
79 if ( direction == 'v' ) { | |
80 if ( dlParams.mo.value.indexOf('vmir') > -1 ) { | |
81 removeMoFlag('vmir'); | |
82 } else { | |
83 addMoFlag('vmir'); | |
84 } | |
85 } | |
86 | |
87 if ( direction == 'h' ) { | |
88 if ( dlParams.mo.value.indexOf('hmir') > -1 ) { | |
89 removeMoFlag('hmir'); | |
90 } else { | |
91 addMoFlag('hmir'); | |
92 } | |
93 } | |
94 | |
95 display(3); | |
96 | |
97 } | |
98 | |
99 | |
100 /** | |
101 * rotation | |
106 | 102 */ |
103 function rotation(value) { | |
104 | |
105 value = parseFloat(value) % 360; | |
106 | |
135 | 107 if ( value < 0 ) { |
106 | 108 value += 360; |
109 } | |
110 | |
135 | 111 dlParams.rot.value = value; |
112 display(3); | |
106 | 113 |
114 } | |
115 | |
135 | 116 |
106 | 117 /** |
118 * rgb add (r/g/b, each value from -255 to +255) | |
119 */ | |
120 function rgba(value) { | |
121 | |
122 values = value.split("/"); | |
123 | |
135 | 124 if ( values.length != 3 ) { |
106 | 125 alert ("Illegal parameter format (r/g/b)"); |
135 | 126 } else if ( (values[0] < -255) || (values[0] > 255) ) { |
106 | 127 alert ("Illegal red additioner (-255 to 255)"); |
135 | 128 } else if ( (values[1] < -255) || (values[1] > 255) ) { |
106 | 129 alert ("Illegal green additioner (-255 to 255)"); |
135 | 130 } else if ( (values[2] < -255) || (values[2] > 255) ) { |
106 | 131 alert ("Illegal blue additioner (-255 to 255)"); |
132 } else { | |
133 | |
135 | 134 dlParams.rgba.value = value; |
135 display(3); | |
106 | 136 |
137 } | |
138 } | |
139 | |
135 | 140 |
106 | 141 /** |
135 | 142 * rgb mutiply (r/g/b, range?) |
106 | 143 */ |
144 function rgbm(value) { | |
145 | |
146 values = value.split("/"); | |
147 | |
135 | 148 if ( values.length != 3 ) { |
106 | 149 alert ("Illegal parameter format (r/g/b)"); |
135 | 150 } else if ( !isFinite(values[0]) ) { |
151 alert ("Illegal red exponent"); | |
152 } else if ( !isFinite(values[1]) ) { | |
153 alert ("Illegal green exponent"); | |
154 } else if ( !isFinite(values[2]) ) { | |
155 alert ("Illegal blue exponent"); | |
106 | 156 } else { |
157 | |
135 | 158 dlParams.rgbm.value = value; |
159 display(3); | |
160 | |
161 } | |
162 } | |
163 | |
164 | |
165 /** | |
166 * rgba/rgbm in one call | |
167 */ | |
168 function colors(rgba, rgbm) { | |
169 | |
170 add = rgba.split("/"); | |
171 mult = rgba.split("/"); | |
172 | |
173 if ( (add.length) == 3 && (mult.length == 3) && | |
174 (add[0] >= -255) && (add[0] <= 255) && | |
175 (add[1] >= -255) && (add[1] <= 255) && | |
176 (add[2] >= -255) && (add[2] <= 255) && | |
177 (isFinite(mult[0])) && | |
178 (isFinite(mult[1])) && | |
179 (isFinite(mult[2])) ) { | |
180 | |
181 dlParams.rgba.value = rgba; | |
182 dlParams.rgbm.value = rgbm; | |
183 | |
184 display(3); | |
106 | 185 |
186 } | |
187 } | |
135 | 188 |
189 | |
190 /** | |
191 * pixel by pixel view of images | |
192 */ | |
193 function pixelByPixel() { | |
194 | |
195 removeMoFlag('osize'); | |
196 | |
197 addMoFlag('clip'); | |
198 | |
199 // change scale to 1 | |
200 dlParams.ws.value = 1.0; | |
201 | |
202 display(3); | |
203 | |
204 } | |
205 | |
206 | |
207 /** | |
208 * original size view of images | |
209 */ | |
210 function originalSize(dpi_v, dpi_h) { | |
211 | |
212 removeMoFlag('clip'); | |
213 | |
214 addMoFlag('osize'); | |
215 | |
216 // change scale to 1 | |
217 dlParams.ws.value = 1.0; | |
218 | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
219 dlParams.ddpix.value = cropFloat(dpi_h); |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
220 dlParams.ddpiy.value = cropFloat(dpi_v); |
232 | 221 |
135 | 222 display(3); |
223 | |
224 } | |
225 | |
226 | |
227 /** | |
228 * scale (overriding old one) | |
229 * as pixel by pixel is some kind of scale, it does turn scale factor to 1 | |
230 * if chosen. also if a scale factor is chosen, | |
231 * then pixel by pixel is turned off. | |
232 */ | |
233 function scale(factor) { | |
234 | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
235 dlParams.ws.value = factor; |
135 | 236 |
237 removeMoFlag('clip'); | |
238 removeMoFlag('osize'); | |
239 | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
240 display(3); |
135 | 241 |
242 } | |
243 | |
244 | |
245 /** | |
246 * placeMarks (overriding old one) | |
247 * take care of rotation and mirroring when placing marks | |
248 */ | |
249 function placeMarks() { | |
250 | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
251 if ( dlParams.mk.value != '' ) { |
135 | 252 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
253 var mark = dlParams.mk.value.split(";"); |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
254 var mark_count = mark.length; |
135 | 255 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
256 // maximum of marks is 8 |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
257 // we do not report this error because this is already done in function 'mark' |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
258 if ( mark_count > 8 ) mark_count = 8; |
135 | 259 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
260 var picWidth = (document.all) ? parseInt(document.all.lay1.offsetWidth) : (typeof(document.getElementById) == "function") ? parseInt(document.pic.offsetWidth) : parseInt(document.lay1.clip.width); |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
261 var picHeight = (document.all) ? parseInt(document.all.lay1.offsetHeight) : (typeof(document.getElementById) == "function") ? parseInt(document.pic.offsetHeight) : parseInt(document.lay1.clip.height); |
135 | 262 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
263 // catch the cases where the picture had not been loaded already and |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
264 // make a timeout so that the coordinates are calculated with the real dimensions |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
265 if ( (picWidth > 30) || (document.pic.complete) ) { |
135 | 266 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
267 var xOffset = (document.all) ? parseInt(document.all.lay1.style.left) : (typeof(document.getElementById) == "function") ? parseInt(document.getElementById('lay1').style.left) : document.lay1.left; |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
268 var yOffset = (document.all) ? parseInt(document.all.lay1.style.top) : (typeof(document.getElementById) == "function") ? parseInt(document.getElementById('lay1').style.top) : document.lay1.top; |
135 | 269 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
270 for (var i = 0; i < mark_count; i++) { |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
271 mark[i] = mark[i].split("/"); |
135 | 272 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
273 if ( (parseFloat(mark[i][0]) >= parseFloat(dlParams.wx.value)) && |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
274 (parseFloat(mark[i][1]) >= parseFloat(dlParams.wy.value)) && |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
275 (parseFloat(mark[i][0]) <= (parseFloat(dlParams.wx.value) + parseFloat(dlParams.ww.value))) && |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
276 (parseFloat(mark[i][1]) <= (parseFloat(dlParams.wy.value) + parseFloat(dlParams.wh.value))) ) { |
135 | 277 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
278 mark[i][0] = (mark[i][0] - dlParams.wx.value)/dlParams.ww.value; |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
279 mark[i][1] = (mark[i][1] - dlParams.wy.value)/dlParams.wh.value; |
135 | 280 |
281 // mirror | |
282 if ( dlParams.mo.value.indexOf('hmir') > -1 ) { | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
283 mark[i][0] = 1 - mark[i][0]; |
135 | 284 } |
285 if ( dlParams.mo.value.indexOf('vmir') > -1 ) { | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
286 mark[i][1] = 1 - mark[i][1]; |
135 | 287 } |
288 | |
289 // just the beginning - not working currently | |
290 var ang_rad = dlParams.rot.value*2*3.1415926/360; | |
291 | |
292 var ws = Math.sin(ang_rad)/(Math.cos(ang_rad)*dlParams.ww.value/dlParams.wh.value+Math.sin(ang_rad)) * picWidth; | |
293 var wc = (Math.cos(ang_rad)*dlParams.ww.value/dlParams.wh.value)/(Math.cos(ang_rad)*dlParams.ww.value/dlParams.wh.value+Math.sin(ang_rad)) * picWidth; | |
294 | |
295 var hs = (Math.sin(ang_rad)*dlParams.ww.value/dlParams.wh.value)/(Math.sin(ang_rad)*dlParams.ww.value/dlParams.wh.value+Math.cos(ang_rad)) * picHeight; | |
296 var hc = Math.cos(ang_rad)/(Math.sin(ang_rad)*dlParams.ww.value/dlParams.wh.value+Math.cos(ang_rad)) * picHeight; | |
297 | |
298 var origPicWidth = Math.sqrt(Math.pow(wc, 2) + Math.pow(hs, 2)); | |
299 var origPicHeight = Math.sqrt(Math.pow(ws, 2) + Math.pow(hc, 2)); | |
300 // end of the beginning ;-) | |
301 | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
302 mark[i][0] = parseInt(xOffset + picWidth * mark[i][0]); |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
303 mark[i][1] = parseInt(yOffset + picHeight * mark[i][1]); |
135 | 304 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
305 if ( (document.all) || (typeof(document.getElementById) == "function") ) { |
135 | 306 // suboptimal to place -5 pixels and not half size of mark-image |
307 // should be changed in the future | |
308 document.getElementById("dot" + i).style.left = mark[i][0]-5; | |
309 document.getElementById("dot" + i).style.top = mark[i][1]-5; | |
310 document.getElementById("dot" + i).style.visibility = "visible"; | |
311 } else { | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
312 document.layers[i+1].moveTo(mark[i][0]-5, mark[i][1]-5); |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
313 document.layers[i+1].visibility = "show"; |
135 | 314 } |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
315 } |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
316 } |
135 | 317 |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
318 } else { |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
319 setTimeout("placeMarks()", 100); |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
320 } |
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
321 } |
135 | 322 } |
323 | |
324 | |
325 /**** | |
326 * helper functions | |
327 ****/ | |
328 | |
329 /** | |
330 * Point (overriding old one) | |
331 * constructor holding different values of a point | |
332 * depending also on mirror or rotation | |
333 */ | |
334 function Point(evt) { | |
335 | |
336 if ( document.all ) { | |
337 | |
338 this.pageX = parseInt(document.body.scrollLeft+event.clientX); | |
339 this.pageY = parseInt(document.body.scrollLeft+event.clientY); | |
340 | |
341 this.x = this.pageX-parseInt(document.all.lay1.style.left); | |
342 this.y = this.pageY-parseInt(document.all.lay1.style.top); | |
343 | |
344 // mirror | |
345 if ( dlParams.mo.value.indexOf('hmir') > -1 ) { | |
346 this.relX = cropFloat(parseFloat(parseFloat(dlParams.wx.value)+parseFloat(dlParams.ww.value))-(dlParams.ww.value*this.x/document.all.lay1.offsetWidth)); | |
347 } else { | |
348 this.relX = cropFloat(parseFloat(dlParams.wx.value)+(dlParams.ww.value*this.x/document.all.lay1.offsetWidth)); | |
349 } | |
350 if ( dlParams.mo.value.indexOf('vmir') > -1 ) { | |
351 this.relY = cropFloat(parseFloat(parseFloat(dlParams.wy.value)+parseFloat(dlParams.wh.value))-(dlParams.wh.value*this.y/document.all.lay1.offsetHeight)); | |
352 } else { | |
353 this.relY = cropFloat(parseFloat(dlParams.wy.value)+(dlParams.wh.value*this.y/document.all.lay1.offsetHeight)); | |
354 } | |
355 | |
356 } else { | |
357 | |
358 this.pageX = parseInt(evt.pageX); | |
359 this.pageY = parseInt(evt.pageY); | |
360 | |
361 if ( typeof(document.getElementById) == "function" ) { | |
362 | |
363 this.x = this.pageX-parseInt(document.getElementById("lay1").style.left); | |
364 this.y = this.pageY-parseInt(document.getElementById("lay1").style.top); | |
365 | |
366 // mirror | |
367 if ( dlParams.mo.value.indexOf('hmir') > -1 ) { | |
368 this.relX = cropFloat(parseFloat(parseFloat(dlParams.wx.value)+parseFloat(dlParams.ww.value))-(dlParams.ww.value*this.x/document.pic.offsetWidth)); | |
369 } else { | |
370 this.relX = cropFloat(parseFloat(dlParams.wx.value)+(dlParams.ww.value*this.x/document.pic.offsetWidth)); | |
371 } | |
372 if ( dlParams.mo.value.indexOf('vmir') > -1 ) { | |
373 this.relY = cropFloat(parseFloat(parseFloat(dlParams.wy.value)+parseFloat(dlParams.wh.value))-(dlParams.wh.value*this.y/document.pic.offsetHeight)); | |
374 } else { | |
375 this.relY = cropFloat(parseFloat(dlParams.wy.value)+(dlParams.wh.value*this.y/document.pic.offsetHeight)); | |
376 } | |
377 | |
378 } else { | |
379 | |
380 this.x = this.pageX-document.lay1.left; | |
381 this.y = this.pageY-document.lay1.top; | |
382 | |
383 // mirror | |
384 if ( dlParams.mo.value.indexOf('hmir') > -1 ) { | |
385 this.relX = cropFloat(parseFloat(parseFloat(dlParams.wx.value)+parseFloat(dlParams.ww.value))-(dlParams.ww.value*this.x/document.lay1.clip.width)); | |
386 } else { | |
387 this.relX = cropFloat(parseFloat(dlParams.wx.value)+(dlParams.ww.value*this.x/document.lay1.clip.width)); | |
388 } | |
389 if ( dlParams.mo.value.indexOf('vmir') > -1 ) { | |
390 this.relY = cropFloat(parseFloat(parseFloat(dlParams.wy.value)+parseFloat(dlParams.wh.value))-(dlParams.wh.value*this.y/document.lay1.clip.height)); | |
391 } else { | |
392 this.relY = cropFloat(parseFloat(dlParams.wy.value)+(dlParams.wh.value*this.y/document.lay1.clip.height)); | |
393 } | |
394 | |
395 } | |
396 | |
397 } | |
398 | |
399 return this; | |
400 | |
401 } | |
402 | |
403 | |
404 /** | |
405 * removeMoFlag from mo parameter | |
406 */ | |
407 function removeMoFlag(name) { | |
408 | |
409 if ( dlParams.mo.value != '' ) { | |
410 | |
411 var idx_comma_after = dlParams.mo.value.indexOf(name + ','); | |
412 var idx_comma_before = dlParams.mo.value.indexOf(',' + name); | |
413 var idx_nocomma = dlParams.mo.value.indexOf(name); | |
414 | |
415 if ( idx_comma_after > -1 ) { | |
416 dlParams.mo.value = dlParams.mo.value.slice(0, idx_comma_after) + dlParams.mo.value.slice(idx_comma_after+name.length+1); | |
417 }else if ( idx_comma_before > -1 ) { | |
418 dlParams.mo.value = dlParams.mo.value.slice(0, idx_comma_before) + dlParams.mo.value.slice(idx_comma_before+name.length+1); | |
419 } else if ( idx_nocomma > -1 ) { | |
420 dlParams.mo.value = dlParams.mo.value.slice(0, idx_nocomma) + dlParams.mo.value.slice(idx_nocomma+name.length); | |
421 } | |
422 } | |
423 | |
424 } | |
425 | |
426 | |
427 /** | |
428 * addMoFlag from mo parameter | |
429 */ | |
430 function addMoFlag(name) { | |
431 | |
432 if ( dlParams.mo.value.indexOf(name) == -1 ) { | |
433 | |
434 if ( dlParams.mo.value.length > 0 ) { | |
435 dlParams.mo.value += ',' + name; | |
436 } else { | |
437 dlParams.mo.value = name; | |
438 } | |
439 } | |
440 | |
228
fddb9a2577fc
new versions on modules and contexto tool to show text
luginbue
parents:
135
diff
changeset
|
441 } |