comparison client/digitallibrary/modules/imago.js @ 131:7dc74e541d7c

unified scripts, nice xul sidebar, bugfixes
author luginbue
date Tue, 08 Jul 2003 03:00:57 +0200
parents 26e6b2715a15
children c70823f5af75
comparison
equal deleted inserted replaced
130:12b887d3a482 131:7dc74e541d7c
1 /* 1 /*
2
2 Copyright (C) 2003 WTWG, Uni Bern 3 Copyright (C) 2003 WTWG, Uni Bern
3 4
4 This program is free software; you can redistribute it and/or 5 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License 6 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2 7 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version. 8 of the License, or (at your option) any later version.
8 9
9 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 13 GNU General Public License for more details.
13 14
14 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17 18
18 Author: Christian Luginbuehl, 01.05.2003 , Version Alcatraz 0.3 19 Author: Christian Luginbuehl, 22.05.2003 , Version Alcatraz 0.4
20
19 */ 21 */
20 /**************************************************************************** 22
21 * - imago module for digilib * 23 /*************************************************************************
22 * * 24 * imago.js : digilib-module *
23 * adds brightness and color manipulation to digilib * 25 * *
24 * * 26 * desc: adds different image manipulation functions. *
25 * christian luginbuehl (luginbuehl@student.unibe.ch) * 27 * *
26 ****************************************************************************/ 28 *************************************************************************/
27
28 // overriding (some kind of inheriting) init in navigation_XX.js
29 function init_imago(pu, pn, ws, mo, mk, wx, wy, ww, wh, pt, brgt, cont, rot, rgba, rgbm) {
30
31 // debug window to check the parameters passed
32 //alert ("DEBUG message (parameters in init imago.js):\n\npu = " + pu + "\npn = " + pn + "\nws = " + ws + "\nmo = " + mo + "\nmk = " + mk + "\nwx = " + wx + "\nwy = " + wy + "\nww = " + ww + "\nwh = " + wh + "\npt = " + pt + "\nbrgt = " + brgt + "\ncont = " + cont + "\nrot = " + rot + "\nrgba = " + rgba + "\nrgbm = " + rgbm);
33
34 // calling original init
35 init_pagesTotal(pu, pn, ws, mo, mk, wx, wy, ww, wh, pt);
36
37 att.brgt = parseInt(brgt);
38 att.cont = parseFloat(cont);
39 att.rot = parseFloat(rot);
40 att.rgba = rgba;
41 att.rgbm = rgbm;
42
43 focus();
44 }
45
46
47 /**
48 * overriding 'loadPicture' in navigation
49 */
50 function loadPicture(detailGrade, keepArea) {
51
52 // the different detailGrades:
53 // 0 -> back, next, page
54 // 1 -> zoomout
55 // 2 -> zoomarea, zoompoint, moveto, scaledef
56
57 var newQuery = "fn=" + att.fn + "&pn=" + att.pn + "&ws=" + att.ws + "&mo=" + att.mo;
58
59 if (detailGrade == 0) {
60 att.mk = "0/0";
61 att.brgt = 0;
62 att.cont = 0;
63 }
64
65 if ((detailGrade == 1) || (detailGrade == 0 && !keepArea)) {
66 att.wx = 0;
67 att.wy = 0;
68 att.ww = 1;
69 att.wh = 1;
70 }
71
72 newQuery += "&mk=" + att.mk + "&wx=" + att.wx + "&wy=" + att.wy + "&ww=" + att.ww + "&wh=" + att.wh;
73
74 if (navigator.appName.toLowerCase() == "netscape") { // mozilla-browsers (netscape 4.xx, netscape 6.xx, etc.)
75 newQuery += "&dw=" + (innerWidth-30) + "&dh=" + (innerHeight-30);
76 } else { // ie, opera
77 newQuery += "&dw=" + (document.body.clientWidth-30) + "&dh=" + (document.body.clientHeight-30);
78 }
79
80 newQuery += "&pt=" + att.pt;
81
82 newQuery += "&brgt=" + att.brgt;
83 newQuery += "&cont=" + att.cont;
84 newQuery += "&rot=" + att.rot;
85 newQuery += "&rgba=" + att.rgba;
86 newQuery += "&rgbm=" + att.rgbm;
87
88 newQuery += "&lv=1";
89
90 // debug window - checking the parameters passed to the next image
91 //alert ("DEBUG MESSAGE (query-string in loadPicture):\n\n" + newQuery);
92 //alert(location.host + ":" + location.port + location.pathname);
93 location.href = location.protocol + "//" + location.host + location.pathname + "?" + newQuery;
94 }
95 29
96 30
97 /** 31 /**
98 * brightness (value of brightness between -255 - +255) 32 * brightness (value of brightness between -255 - +255)
99 */ 33 */
100 function brightness(value) { 34 function brightness(value) {
101 35
102 if ((value < -255) || (value > 255)) { 36 if ( (value >= -255) && (value <= 255) ) {
103
104 alert ("Illegal brightness value (-255 to +255)");
105 37
106 } else { 38 dlParams.brgt.value = value;
107 39 display(3);
108 att.brgt = value; 40
109 41 }
110 loadPicture(2); 42
111 } 43 }
112 44
113 }
114 45
115 /** 46 /**
116 * contrast (value of contrast - range?) 47 * contrast (value of contrast - range?)
117 */ 48 */
118 function contrast(value) { 49 function contrast(value) {
119 50
120 att.cont = parseFloat(value); 51 dlParams.cont.value = parseFloat(value);
121 52 display(3);
122 loadPicture(2); 53
123 54 }
124 } 55
125 56
126 /** 57 /**
127 * rotation (value from 0 to 360 degrees) 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 }
70
71 }
72
73
74 /**
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
128 */ 102 */
129 function rotation(value) { 103 function rotation(value) {
130 104
131 value = parseFloat(value) % 360; 105 value = parseFloat(value) % 360;
132 106
133 if (value < 0) { 107 if ( value < 0 ) {
134 value += 360; 108 value += 360;
135 } 109 }
136 110
137 att.rot = value; 111 dlParams.rot.value = value;
138 112 display(3);
139 loadPicture(2); 113
140 114 }
141 } 115
142 116
143 /** 117 /**
144 * rgb add (r/g/b, each value from -255 to +255) 118 * rgb add (r/g/b, each value from -255 to +255)
145 */ 119 */
146 function rgba(value) { 120 function rgba(value) {
147 121
148 values = value.split("/"); 122 values = value.split("/");
149 123
150 if (values.length != 3) { 124 if ( values.length != 3 ) {
151 alert ("Illegal parameter format (r/g/b)"); 125 alert ("Illegal parameter format (r/g/b)");
152 } else if ((values[0] < -255) || (values[0] > 255)) { 126 } else if ( (values[0] < -255) || (values[0] > 255) ) {
153 alert ("Illegal red additioner (-255 to 255)"); 127 alert ("Illegal red additioner (-255 to 255)");
154 } else if ((values[1] < -255) || (values[1] > 255)) { 128 } else if ( (values[1] < -255) || (values[1] > 255) ) {
155 alert ("Illegal green additioner (-255 to 255)"); 129 alert ("Illegal green additioner (-255 to 255)");
156 } else if ((values[2] < -255) || (values[2] > 255)) { 130 } else if ( (values[2] < -255) || (values[2] > 255) ) {
157 alert ("Illegal blue additioner (-255 to 255)"); 131 alert ("Illegal blue additioner (-255 to 255)");
158 } else { 132 } else {
159 133
160 att.rgba = value; 134 dlParams.rgba.value = value;
161 loadPicture(2); 135 display(3);
162 136
163 } 137 }
164 } 138 }
165 139
166 /** 140
167 * rgb multiply (r/g/b, each value from ??? ) 141 /**
142 * rgb mutiply (r/g/b, range?)
168 */ 143 */
169 function rgbm(value) { 144 function rgbm(value) {
170 145
171 values = value.split("/"); 146 values = value.split("/");
172 147
173 if (values.length != 3) { 148 if ( values.length != 3 ) {
174 alert ("Illegal parameter format (r/g/b)"); 149 alert ("Illegal parameter format (r/g/b)");
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");
175 } else { 156 } else {
176 157
177 att.rgbm = value; 158 dlParams.rgbm.value = value;
178 loadPicture(2); 159 display(3);
179 160
180 } 161 }
181 } 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);
185
186 }
187 }
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
219 dlParams.ddpix.value = dpi_h;
220 dlParams.ddpiy.value = dpi_v;
221
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
235 dlParams.ws.value = factor;
236
237 removeMoFlag('clip');
238 removeMoFlag('osize');
239
240 display(3);
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
251 if ( dlParams.mk.value != '' ) {
252
253 var mark = dlParams.mk.value.split(";");
254 var mark_count = mark.length;
255
256 // maximum of marks is 8
257 // we do not report this error because this is already done in function 'mark'
258 if ( mark_count > 8 ) mark_count = 8;
259
260 var picWidth = (document.all) ? parseInt(document.all.lay1.offsetWidth) : (typeof(document.getElementById) == "function") ? parseInt(document.pic.offsetWidth) : parseInt(document.lay1.clip.width);
261 var picHeight = (document.all) ? parseInt(document.all.lay1.offsetHeight) : (typeof(document.getElementById) == "function") ? parseInt(document.pic.offsetHeight) : parseInt(document.lay1.clip.height);
262
263 // catch the cases where the picture had not been loaded already and
264 // make a timeout so that the coordinates are calculated with the real dimensions
265 if ( (picWidth > 30) || (document.pic.complete) ) {
266
267 var xOffset = (document.all) ? parseInt(document.all.lay1.style.left) : (typeof(document.getElementById) == "function") ? parseInt(document.getElementById('lay1').style.left) : document.lay1.left;
268 var yOffset = (document.all) ? parseInt(document.all.lay1.style.top) : (typeof(document.getElementById) == "function") ? parseInt(document.getElementById('lay1').style.top) : document.lay1.top;
269
270 for (var i = 0; i < mark_count; i++) {
271 mark[i] = mark[i].split("/");
272
273 if ( (parseFloat(mark[i][0]) >= parseFloat(dlParams.wx.value)) &&
274 (parseFloat(mark[i][1]) >= parseFloat(dlParams.wy.value)) &&
275 (parseFloat(mark[i][0]) <= (parseFloat(dlParams.wx.value) + parseFloat(dlParams.ww.value))) &&
276 (parseFloat(mark[i][1]) <= (parseFloat(dlParams.wy.value) + parseFloat(dlParams.wh.value))) ) {
277
278 mark[i][0] = (mark[i][0] - dlParams.wx.value)/dlParams.ww.value;
279 mark[i][1] = (mark[i][1] - dlParams.wy.value)/dlParams.wh.value;
280
281 // mirror
282 if ( dlParams.mo.value.indexOf('hmir') > -1 ) {
283 mark[i][0] = 1 - mark[i][0];
284 }
285 if ( dlParams.mo.value.indexOf('vmir') > -1 ) {
286 mark[i][1] = 1 - mark[i][1];
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
302 mark[i][0] = parseInt(xOffset + picWidth * mark[i][0]);
303 mark[i][1] = parseInt(yOffset + picHeight * mark[i][1]);
304
305 if ( (document.all) || (typeof(document.getElementById) == "function") ) {
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 {
312 document.layers[i+1].moveTo(mark[i][0]-5, mark[i][1]-5);
313 document.layers[i+1].visibility = "show";
314 }
315 }
316 }
317
318 } else {
319 setTimeout("placeMarks()", 100);
320 }
321 }
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
441 }