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