JAL-1807 test
[jalviewjs.git] / bin / javajs / img / GifEncoder.js
1 Clazz.declarePackage ("javajs.img");
2 Clazz.load (["javajs.img.ImageEncoder", "javajs.util.Lst", "$.P3"], "javajs.img.GifEncoder", ["java.lang.Boolean", "java.util.Hashtable", "javajs.util.CU", "$.M3"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.params = null;
5 this.palette = null;
6 this.backgroundColor = 0;
7 this.interlaced = false;
8 this.addHeader = true;
9 this.addImage = true;
10 this.addTrailer = true;
11 this.isTransparent = false;
12 this.floydSteinberg = true;
13 this.capturing = false;
14 this.looping = false;
15 this.delayTime100ths = -1;
16 this.bitsPerPixel = 1;
17 this.byteCount = 0;
18 if (!Clazz.isClassDefined ("javajs.img.GifEncoder.ColorItem")) {
19 javajs.img.GifEncoder.$GifEncoder$ColorItem$ ();
20 }
21 if (!Clazz.isClassDefined ("javajs.img.GifEncoder.ColorCell")) {
22 javajs.img.GifEncoder.$GifEncoder$ColorCell$ ();
23 }
24 this.initCodeSize = 0;
25 this.curpt = 0;
26 this.nBits = 0;
27 this.maxbits = 12;
28 this.maxcode = 0;
29 this.maxmaxcode = 4096;
30 this.htab = null;
31 this.codetab = null;
32 this.hsize = 5003;
33 this.freeEnt = 0;
34 this.clearFlag = false;
35 this.clearCode = 0;
36 this.EOFCode = 0;
37 this.countDown = 0;
38 this.pass = 0;
39 this.curx = 0;
40 this.cury = 0;
41 this.curAccum = 0;
42 this.curBits = 0;
43 this.masks = null;
44 this.bufPt = 0;
45 this.buf = null;
46 Clazz.instantialize (this, arguments);
47 }, javajs.img, "GifEncoder", javajs.img.ImageEncoder);
48 Clazz.prepareFields (c$, function () {
49 this.htab =  Clazz.newIntArray (5003, 0);
50 this.codetab =  Clazz.newIntArray (5003, 0);
51 this.masks =  Clazz.newIntArray (-1, [0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF]);
52 this.buf =  Clazz.newByteArray (256, 0);
53 });
54 Clazz.overrideMethod (c$, "setParams", 
55 function (params) {
56 this.params = params;
57 var ic = params.get ("transparentColor");
58 if (ic == null) {
59 ic = params.get ("backgroundColor");
60 if (ic != null) this.backgroundColor = ic.intValue ();
61 } else {
62 this.backgroundColor = ic.intValue ();
63 this.isTransparent = true;
64 }this.interlaced = (Boolean.TRUE === params.get ("interlaced"));
65 if (params.containsKey ("captureRootExt") || !params.containsKey ("captureMode")) return;
66 this.interlaced = false;
67 this.capturing = true;
68 try {
69 this.byteCount = (params.get ("captureByteCount")).intValue ();
70 } catch (e) {
71 if (Clazz.exceptionOf (e, Exception)) {
72 } else {
73 throw e;
74 }
75 }
76 switch ("maec".indexOf ((params.get ("captureMode")).substring (0, 1))) {
77 case 0:
78 params.put ("captureMode", "add");
79 this.addImage = false;
80 this.addTrailer = false;
81 break;
82 case 1:
83 this.addHeader = false;
84 this.addTrailer = false;
85 var fps = Math.abs ((params.get ("captureFps")).intValue ());
86 this.delayTime100ths = (fps == 0 ? 0 : Clazz.doubleToInt (100 / fps));
87 this.looping = (Boolean.FALSE !== params.get ("captureLooping"));
88 break;
89 case 2:
90 this.addHeader = false;
91 this.addImage = false;
92 break;
93 case 3:
94 this.addHeader = false;
95 this.addImage = false;
96 this.out.cancel ();
97 break;
98 }
99 }, "java.util.Map");
100 Clazz.overrideMethod (c$, "generate", 
101 function () {
102 if (this.addHeader) this.writeHeader ();
103 this.addHeader = false;
104 if (this.addImage) {
105 this.createPalette ();
106 this.writeGraphicControlExtension ();
107 if (this.delayTime100ths >= 0 && this.looping) this.writeNetscapeLoopExtension ();
108 this.writeImage ();
109 }});
110 Clazz.overrideMethod (c$, "close", 
111 function () {
112 if (this.addTrailer) {
113 this.writeTrailer ();
114 } else {
115 this.doClose = false;
116 }if (this.capturing) this.params.put ("captureByteCount", Integer.$valueOf (this.byteCount));
117 });
118 Clazz.defineMethod (c$, "createPalette", 
119 ($fz = function () {
120 var tempColors =  new javajs.util.Lst ();
121 var ciHash =  new java.util.Hashtable ();
122 for (var i = 0, n = this.pixels.length; i < n; i++) {
123 var rgb = this.pixels[i];
124 var key = Integer.$valueOf (rgb);
125 var item = ciHash.get (key);
126 if (item == null) {
127 item = Clazz.innerTypeInstance (javajs.img.GifEncoder.ColorItem, this, null, rgb, rgb == this.backgroundColor);
128 ciHash.put (key, item);
129 tempColors.addLast (item);
130 }}
131 var nColors = tempColors.size ();
132 System.out.println ("GIF total image colors: " + nColors);
133 ciHash = null;
134 var cells = this.quantizeColors (tempColors);
135 nColors = cells.size ();
136 System.out.println ("GIF final color count: " + nColors);
137 var colorMap =  new java.util.Hashtable ();
138 this.bitsPerPixel = (nColors <= 2 ? 1 : nColors <= 4 ? 2 : nColors <= 16 ? 4 : 8);
139 this.palette =  new Array (1 << this.bitsPerPixel);
140 for (var i = 0; i < nColors; i++) {
141 var c = cells.get (i);
142 colorMap.put (Integer.$valueOf (javajs.util.CU.colorPtToFFRGB (this.palette[i] = c.setColor ())), c);
143 }
144 this.pixels = this.indexPixels (cells, colorMap);
145 }, $fz.isPrivate = true, $fz));
146 Clazz.defineMethod (c$, "quantizeColors", 
147 ($fz = function (tempColors) {
148 var n = tempColors.size ();
149 var cells =  new javajs.util.Lst ();
150 var cc = Clazz.innerTypeInstance (javajs.img.GifEncoder.ColorCell, this, null, 0);
151 cc.addLast (Clazz.innerTypeInstance (javajs.img.GifEncoder.ColorItem, this, null, this.backgroundColor, true));
152 cells.addLast (cc);
153 cc = Clazz.innerTypeInstance (javajs.img.GifEncoder.ColorCell, this, null, 1);
154 if (n > 256) cells.addLast (cc);
155 for (var i = 0; i < n; i++) {
156 var c = tempColors.get (i);
157 if (c.isBackground) continue;
158 cc.addLast (c);
159 if (n <= 256) {
160 cells.addLast (cc);
161 cc = Clazz.innerTypeInstance (javajs.img.GifEncoder.ColorCell, this, null, cells.size ());
162 }}
163 tempColors.clear ();
164 if (n > 256) while ((n = cells.size ()) < 256) {
165 var maxVol = 0;
166 var maxCell = null;
167 for (var i = n; --i >= 1; ) {
168 var c = cells.get (i);
169 var v = c.getVolume (false);
170 if (v > maxVol) {
171 maxVol = v;
172 maxCell = c;
173 }}
174 if (maxCell == null || !maxCell.splitCell (cells)) break;
175 }
176 return cells;
177 }, $fz.isPrivate = true, $fz), "javajs.util.Lst");
178 Clazz.defineMethod (c$, "indexPixels", 
179 ($fz = function (cells, colorMap) {
180 var w2 = this.width + 2;
181 var errors =  new Array (w2);
182 var newPixels =  Clazz.newIntArray (this.pixels.length, 0);
183 var err =  new javajs.util.P3 ();
184 var lab;
185 var rgb;
186 var nearestCell =  new java.util.Hashtable ();
187 for (var i = 0, p = 0; i < this.height; ++i) {
188 var notLastRow = (i != this.height - 1);
189 for (var j = 0; j < this.width; ++j, p++) {
190 if (this.pixels[p] == this.backgroundColor) {
191 continue;
192 }var pe = errors[p % w2];
193 if (pe == null || pe.x == 3.4028235E38) {
194 lab = null;
195 rgb = this.pixels[p];
196 } else {
197 lab = this.toLABnorm (this.pixels[p]);
198 err = pe;
199 err.x = this.clamp (err.x, -75, 75);
200 err.y = this.clamp (err.y, -75, 75);
201 err.z = this.clamp (err.z, -75, 75);
202 lab.add (err);
203 rgb = javajs.util.CU.colorPtToFFRGB (this.toRGB (lab));
204 }var key = Integer.$valueOf (rgb);
205 var cell = colorMap.get (key);
206 if (cell == null) {
207 lab = this.toLABnorm (rgb);
208 cell = nearestCell.get (key);
209 if (cell == null) {
210 var maxerr = 3.4028235E38;
211 for (var ib = cells.size (); --ib >= 1; ) {
212 var c = cells.get (ib);
213 err.sub2 (lab, c.center);
214 var d = err.lengthSquared ();
215 if (d < maxerr) {
216 maxerr = d;
217 cell = c;
218 }}
219 nearestCell.put (key, cell);
220 }if (this.floydSteinberg) {
221 err.sub2 (lab, cell.center);
222 var notLastCol = (j < this.width - 1);
223 if (notLastCol) this.addError (err, 7, errors, p + 1, w2);
224 if (notLastRow) {
225 if (j > 0) this.addError (err, 3, errors, p + this.width - 1, w2);
226 this.addError (err, 5, errors, p + this.width, w2);
227 if (notLastCol) this.addError (err, 1, errors, p + this.width + 1, w2);
228 }}err.x = 3.4028235E38;
229 }newPixels[p] = cell.index;
230 }
231 }
232 return newPixels;
233 }, $fz.isPrivate = true, $fz), "javajs.util.Lst,java.util.Map");
234 Clazz.defineMethod (c$, "addError", 
235 ($fz = function (err, f, errors, p, w2) {
236 if (this.pixels[p] == this.backgroundColor) return;
237 p %= w2;
238 var errp = errors[p];
239 if (errp == null) errp = errors[p] =  new javajs.util.P3 ();
240  else if (errp.x == 3.4028235E38) errp.set (0, 0, 0);
241 errp.scaleAdd2 (f / 16, err, errp);
242 }, $fz.isPrivate = true, $fz), "javajs.util.P3,~N,~A,~N,~N");
243 Clazz.defineMethod (c$, "toLABnorm", 
244 function (rgb) {
245 var lab = javajs.util.CU.colorPtFromInt (rgb, null);
246 this.rgbToXyz (lab, lab);
247 this.xyzToLab (lab, lab);
248 lab.y = (lab.y + 86.185) / (184.439) * 100;
249 lab.z = (lab.z + 107.863) / (202.345) * 100;
250 return lab;
251 }, "~N");
252 Clazz.defineMethod (c$, "toRGB", 
253 function (lab) {
254 var xyz = javajs.util.P3.newP (lab);
255 xyz.y = xyz.y / 100 * (184.439) - 86.185;
256 xyz.z = xyz.z / 100 * (202.345) - 107.863;
257 this.labToXyz (xyz, xyz);
258 return this.xyzToRgb (xyz, xyz);
259 }, "javajs.util.P3");
260 Clazz.defineMethod (c$, "rgbToXyz", 
261 function (rgb, xyz) {
262 if (xyz == null) xyz =  new javajs.util.P3 ();
263 xyz.x = this.sxyz (rgb.x);
264 xyz.y = this.sxyz (rgb.y);
265 xyz.z = this.sxyz (rgb.z);
266 javajs.img.GifEncoder.rgb2xyz.rotate (xyz);
267 return xyz;
268 }, "javajs.util.P3,javajs.util.P3");
269 Clazz.defineMethod (c$, "sxyz", 
270 ($fz = function (x) {
271 x /= 255;
272 return (x <= 0.04045 ? x / 12.92 : Math.pow (((x + 0.055) / 1.055), 2.4)) * 100;
273 }, $fz.isPrivate = true, $fz), "~N");
274 Clazz.defineMethod (c$, "xyzToRgb", 
275 function (xyz, rgb) {
276 if (rgb == null) rgb =  new javajs.util.P3 ();
277 rgb.setT (xyz);
278 rgb.scale (0.01);
279 javajs.img.GifEncoder.xyz2rgb.rotate (rgb);
280 rgb.x = this.clamp (this.srgb (rgb.x), 0, 255);
281 rgb.y = this.clamp (this.srgb (rgb.y), 0, 255);
282 rgb.z = this.clamp (this.srgb (rgb.z), 0, 255);
283 return rgb;
284 }, "javajs.util.P3,javajs.util.P3");
285 Clazz.defineMethod (c$, "srgb", 
286 ($fz = function (x) {
287 return (x > 0.0031308 ? (1.055 * Math.pow (x, 0.4166666666666667)) - 0.055 : x * 12.92) * 255;
288 }, $fz.isPrivate = true, $fz), "~N");
289 Clazz.defineMethod (c$, "xyzToLab", 
290 function (xyz, lab) {
291 if (lab == null) lab =  new javajs.util.P3 ();
292 var x = this.flab (xyz.x / 95.0429);
293 var y = this.flab (xyz.y / 100);
294 var z = this.flab (xyz.z / 108.89);
295 lab.x = (116 * y) - 16;
296 lab.y = 500 * (x - y);
297 lab.z = 200 * (y - z);
298 return lab;
299 }, "javajs.util.P3,javajs.util.P3");
300 Clazz.defineMethod (c$, "flab", 
301 ($fz = function (t) {
302 return (t > 8.85645168E-3 ? Math.pow (t, 0.333333333) : 7.78703704 * t + 0.137931034);
303 }, $fz.isPrivate = true, $fz), "~N");
304 Clazz.defineMethod (c$, "labToXyz", 
305 function (lab, xyz) {
306 if (xyz == null) xyz =  new javajs.util.P3 ();
307 xyz.setT (lab);
308 var y = (xyz.x + 16) / 116;
309 var x = xyz.y / 500 + y;
310 var z = y - xyz.z / 200;
311 xyz.x = this.fxyz (x) * 95.0429;
312 xyz.y = this.fxyz (y) * 100;
313 xyz.z = this.fxyz (z) * 108.89;
314 return xyz;
315 }, "javajs.util.P3,javajs.util.P3");
316 Clazz.defineMethod (c$, "fxyz", 
317 ($fz = function (t) {
318 return (t > 0.206896552 ? t * t * t : 0.128418549 * (t - 0.137931034));
319 }, $fz.isPrivate = true, $fz), "~N");
320 Clazz.defineMethod (c$, "clamp", 
321 ($fz = function (c, min, max) {
322 c = (c < min ? min : c > max ? max : c);
323 return (min == 0 ? Math.round (c) : c);
324 }, $fz.isPrivate = true, $fz), "~N,~N,~N");
325 Clazz.defineMethod (c$, "writeHeader", 
326 ($fz = function () {
327 this.putString ("GIF89a");
328 this.putWord (this.width);
329 this.putWord (this.height);
330 this.putByte (0);
331 this.putByte (0);
332 this.putByte (0);
333 }, $fz.isPrivate = true, $fz));
334 Clazz.defineMethod (c$, "writeGraphicControlExtension", 
335 ($fz = function () {
336 if (this.isTransparent || this.delayTime100ths >= 0) {
337 this.putByte (0x21);
338 this.putByte (0xf9);
339 this.putByte (4);
340 this.putByte ((this.isTransparent ? 9 : 0) | (this.delayTime100ths > 0 ? 2 : 0));
341 this.putWord (this.delayTime100ths > 0 ? this.delayTime100ths : 0);
342 this.putByte (0);
343 this.putByte (0);
344 }}, $fz.isPrivate = true, $fz));
345 Clazz.defineMethod (c$, "writeNetscapeLoopExtension", 
346 ($fz = function () {
347 this.putByte (0x21);
348 this.putByte (0xff);
349 this.putByte (0x0B);
350 this.putString ("NETSCAPE2.0");
351 this.putByte (3);
352 this.putByte (1);
353 this.putWord (0);
354 this.putByte (0);
355 }, $fz.isPrivate = true, $fz));
356 Clazz.defineMethod (c$, "writeImage", 
357 ($fz = function () {
358 this.putByte (0x2C);
359 this.putWord (0);
360 this.putWord (0);
361 this.putWord (this.width);
362 this.putWord (this.height);
363 var packedFields = 0x80 | (this.interlaced ? 0x40 : 0) | (this.bitsPerPixel - 1);
364 this.putByte (packedFields);
365 var colorMapSize = 1 << this.bitsPerPixel;
366 var p =  new javajs.util.P3 ();
367 for (var i = 0; i < colorMapSize; i++) {
368 if (this.palette[i] != null) p = this.palette[i];
369 this.putByte (Clazz.floatToInt (p.x));
370 this.putByte (Clazz.floatToInt (p.y));
371 this.putByte (Clazz.floatToInt (p.z));
372 }
373 this.putByte (this.initCodeSize = (this.bitsPerPixel <= 1 ? 2 : this.bitsPerPixel));
374 this.compress ();
375 this.putByte (0);
376 }, $fz.isPrivate = true, $fz));
377 Clazz.defineMethod (c$, "writeTrailer", 
378 ($fz = function () {
379 this.putByte (0x3B);
380 }, $fz.isPrivate = true, $fz));
381 Clazz.defineMethod (c$, "nextPixel", 
382 ($fz = function () {
383 if (this.countDown-- == 0) return -1;
384 var colorIndex = this.pixels[this.curpt];
385 ++this.curx;
386 if (this.curx == this.width) {
387 this.curx = 0;
388 if (this.interlaced) this.updateY (javajs.img.GifEncoder.INTERLACE_PARAMS[this.pass], javajs.img.GifEncoder.INTERLACE_PARAMS[this.pass + 4]);
389  else ++this.cury;
390 }this.curpt = this.cury * this.width + this.curx;
391 return colorIndex & 0xff;
392 }, $fz.isPrivate = true, $fz));
393 Clazz.defineMethod (c$, "updateY", 
394 ($fz = function (yNext, yNew) {
395 this.cury += yNext;
396 if (yNew >= 0 && this.cury >= this.height) {
397 this.cury = yNew;
398 ++this.pass;
399 }}, $fz.isPrivate = true, $fz), "~N,~N");
400 Clazz.defineMethod (c$, "putWord", 
401 ($fz = function (w) {
402 this.putByte (w);
403 this.putByte (w >> 8);
404 }, $fz.isPrivate = true, $fz), "~N");
405 c$.MAXCODE = Clazz.defineMethod (c$, "MAXCODE", 
406 ($fz = function (nBits) {
407 return (1 << nBits) - 1;
408 }, $fz.isPrivate = true, $fz), "~N");
409 Clazz.defineMethod (c$, "compress", 
410 ($fz = function () {
411 this.countDown = this.width * this.height;
412 this.pass = 0;
413 this.curx = 0;
414 this.cury = 0;
415 this.clearFlag = false;
416 this.nBits = this.initCodeSize + 1;
417 this.maxcode = javajs.img.GifEncoder.MAXCODE (this.nBits);
418 this.clearCode = 1 << this.initCodeSize;
419 this.EOFCode = this.clearCode + 1;
420 this.freeEnt = this.clearCode + 2;
421 this.bufPt = 0;
422 var ent = this.nextPixel ();
423 var hshift = 0;
424 var fcode;
425 for (fcode = this.hsize; fcode < 65536; fcode *= 2) ++hshift;
426
427 hshift = 8 - hshift;
428 var hsizeReg = this.hsize;
429 this.clearHash (hsizeReg);
430 this.output (this.clearCode);
431 var c;
432 outer_loop : while ((c = this.nextPixel ()) != -1) {
433 fcode = (c << this.maxbits) + ent;
434 var i = (c << hshift) ^ ent;
435 if (this.htab[i] == fcode) {
436 ent = this.codetab[i];
437 continue;
438 } else if (this.htab[i] >= 0) {
439 var disp = hsizeReg - i;
440 if (i == 0) disp = 1;
441 do {
442 if ((i -= disp) < 0) i += hsizeReg;
443 if (this.htab[i] == fcode) {
444 ent = this.codetab[i];
445 continue outer_loop;
446 }} while (this.htab[i] >= 0);
447 }this.output (ent);
448 ent = c;
449 if (this.freeEnt < this.maxmaxcode) {
450 this.codetab[i] = this.freeEnt++;
451 this.htab[i] = fcode;
452 } else {
453 this.clearBlock ();
454 }}
455 this.output (ent);
456 this.output (this.EOFCode);
457 }, $fz.isPrivate = true, $fz));
458 Clazz.defineMethod (c$, "output", 
459 ($fz = function (code) {
460 this.curAccum &= this.masks[this.curBits];
461 if (this.curBits > 0) this.curAccum |= (code << this.curBits);
462  else this.curAccum = code;
463 this.curBits += this.nBits;
464 while (this.curBits >= 8) {
465 this.byteOut ((this.curAccum & 0xff));
466 this.curAccum >>= 8;
467 this.curBits -= 8;
468 }
469 if (this.freeEnt > this.maxcode || this.clearFlag) {
470 if (this.clearFlag) {
471 this.maxcode = javajs.img.GifEncoder.MAXCODE (this.nBits = this.initCodeSize + 1);
472 this.clearFlag = false;
473 } else {
474 ++this.nBits;
475 if (this.nBits == this.maxbits) this.maxcode = this.maxmaxcode;
476  else this.maxcode = javajs.img.GifEncoder.MAXCODE (this.nBits);
477 }}if (code == this.EOFCode) {
478 while (this.curBits > 0) {
479 this.byteOut ((this.curAccum & 0xff));
480 this.curAccum >>= 8;
481 this.curBits -= 8;
482 }
483 this.flushBytes ();
484 }}, $fz.isPrivate = true, $fz), "~N");
485 Clazz.defineMethod (c$, "clearBlock", 
486 ($fz = function () {
487 this.clearHash (this.hsize);
488 this.freeEnt = this.clearCode + 2;
489 this.clearFlag = true;
490 this.output (this.clearCode);
491 }, $fz.isPrivate = true, $fz));
492 Clazz.defineMethod (c$, "clearHash", 
493 ($fz = function (hsize) {
494 for (var i = 0; i < hsize; ++i) this.htab[i] = -1;
495
496 }, $fz.isPrivate = true, $fz), "~N");
497 Clazz.defineMethod (c$, "byteOut", 
498 ($fz = function (c) {
499 this.buf[this.bufPt++] = c;
500 if (this.bufPt >= 254) this.flushBytes ();
501 }, $fz.isPrivate = true, $fz), "~N");
502 Clazz.defineMethod (c$, "flushBytes", 
503 function () {
504 if (this.bufPt > 0) {
505 this.putByte (this.bufPt);
506 this.out.write (this.buf, 0, this.bufPt);
507 this.byteCount += this.bufPt;
508 this.bufPt = 0;
509 }});
510 c$.$GifEncoder$ColorItem$ = function () {
511 Clazz.pu$h ();
512 c$ = Clazz.decorateAsClass (function () {
513 Clazz.prepareCallback (this, arguments);
514 this.isBackground = false;
515 Clazz.instantialize (this, arguments);
516 }, javajs.img.GifEncoder, "ColorItem", javajs.util.P3);
517 Clazz.makeConstructor (c$, 
518 function (a, b) {
519 Clazz.superConstructor (this, javajs.img.GifEncoder.ColorItem, []);
520 this.isBackground = b;
521 this.setT (this.b$["javajs.img.GifEncoder"].toLABnorm (a));
522 }, "~N,~B");
523 c$ = Clazz.p0p ();
524 };
525 c$.$GifEncoder$ColorCell$ = function () {
526 Clazz.pu$h ();
527 c$ = Clazz.decorateAsClass (function () {
528 Clazz.prepareCallback (this, arguments);
529 this.index = 0;
530 this.center = null;
531 this.volume = 0;
532 Clazz.instantialize (this, arguments);
533 }, javajs.img.GifEncoder, "ColorCell", javajs.util.Lst);
534 Clazz.makeConstructor (c$, 
535 function (a) {
536 Clazz.superConstructor (this, javajs.img.GifEncoder.ColorCell, []);
537 this.index = a;
538 }, "~N");
539 Clazz.defineMethod (c$, "getVolume", 
540 function (a) {
541 if (this.volume != 0) return this.volume;
542 if (this.size () < 2) return -1;
543 var b = -2147483647;
544 var c = 2147483647;
545 var d = -2147483647;
546 var e = 2147483647;
547 var f = -2147483647;
548 var g = 2147483647;
549 var h = this.size ();
550 for (var i = h; --i >= 0; ) {
551 var j = this.get (i);
552 if (j.x < c) c = j.x;
553 if (j.y < e) e = j.y;
554 if (j.z < g) g = j.z;
555 if (j.x > b) b = j.x;
556 if (j.y > d) d = j.y;
557 if (j.z > f) f = j.z;
558 }
559 var j = (b - c);
560 var k = (d - e);
561 var l = (f - g);
562 return this.volume = j * j + k * k + l * l;
563 }, "~B");
564 Clazz.defineMethod (c$, "setColor", 
565 function () {
566 var a = this.size ();
567 this.center =  new javajs.util.P3 ();
568 for (var b = a; --b >= 0; ) this.center.add (this.get (b));
569
570 this.center.scale (1 / a);
571 return this.b$["javajs.img.GifEncoder"].toRGB (this.center);
572 });
573 Clazz.defineMethod (c$, "splitCell", 
574 function (a) {
575 var b = this.size ();
576 if (b < 2) return false;
577 var c = a.size ();
578 var d = Clazz.innerTypeInstance (javajs.img.GifEncoder.ColorCell, this, null, c);
579 a.addLast (d);
580 var e =  Clazz.newFloatArray (3, 3, 0);
581 for (var f = 0; f < 3; f++) {
582 var g = 3.4028235E38;
583 var h = -3.4028235E38;
584 for (var i = b; --i >= 0; ) {
585 var j = this.get (i);
586 var k = (f == 0 ? j.x : f == 1 ? j.y : j.z);
587 if (g > k) g = k;
588 if (h < k) h = k;
589 }
590 e[0][f] = g;
591 e[1][f] = h;
592 e[2][f] = h - g;
593 }
594 var g = e[2];
595 var h = (g[0] >= g[1] ? (g[0] >= g[2] ? 0 : 2) : g[1] >= g[2] ? 1 : 2);
596 var i = e[0][h] + e[2][h] / 2;
597 this.volume = 0;
598 switch (h) {
599 case 0:
600 for (var j = b; --j >= 0; ) if (this.get (j).x >= i) d.addLast (this.remove (j));
601
602 break;
603 case 1:
604 for (var k = b; --k >= 0; ) if (this.get (k).y >= i) d.addLast (this.remove (k));
605
606 break;
607 case 2:
608 for (var l = this.size (); --l >= 0; ) if (this.get (l).z >= i) d.addLast (this.remove (l));
609
610 break;
611 }
612 return true;
613 }, "javajs.util.Lst");
614 c$ = Clazz.p0p ();
615 };
616 Clazz.defineStatics (c$,
617 "xyz2rgb", null,
618 "rgb2xyz", null);
619 {
620 javajs.img.GifEncoder.rgb2xyz = javajs.util.M3.newA9 ( Clazz.newFloatArray (-1, [0.4124, 0.3576, 0.1805, 0.2126, 0.7152, 0.0722, 0.0193, 0.1192, 0.9505]));
621 javajs.img.GifEncoder.xyz2rgb = javajs.util.M3.newA9 ( Clazz.newFloatArray (-1, [3.2406, -1.5372, -0.4986, -0.9689, 1.8758, 0.0415, 0.0557, -0.204, 1.0570]));
622 }Clazz.defineStatics (c$,
623 "EOF", -1,
624 "INTERLACE_PARAMS",  Clazz.newIntArray (-1, [8, 8, 4, 2, 4, 2, 1, 0]),
625 "BITS", 12,
626 "HSIZE", 5003);
627 });