1 23 24 package org.infoglue.deliver.util.graphics; 25 26 import java.awt.Color ; 27 import java.awt.image.BufferedImage ; 28 import java.io.DataOutputStream ; 29 import java.util.Hashtable ; 30 import java.util.Iterator ; 31 import java.util.TreeSet ; 32 import java.util.Vector ; 33 34 public class GifEncoder 35 { 36 37 String b; 38 int g; 39 int a; 40 int h; 41 int f; 42 int c[]; 43 int i[]; 44 int e[]; 45 TreeSet d; 46 47 private void a(int ai[], int j, DataOutputStream dataoutputstream) throws Exception 48 { 49 try 50 { 51 boolean flag2 = false; 52 int l; 53 int j3 = (1 << (l = j + 1)) - 1; 54 int i2 = (1 << j) + 2; 55 byte abyte0[] = new byte[255]; 56 int ai1[] = new int[4096]; 57 int ai2[] = new int[4096]; 58 int ai3[] = new int[4096]; 59 int ai4[] = new int[i2]; 60 int k; 61 for(k = 0; k < i2; k++) 62 { 63 ai4[k] = 0xffffffff | k; 64 ai3[k] = -1; 65 } 66 67 for(; k < 4096; k++) 68 { 69 ai3[k] = -1; 70 } 71 72 System.arraycopy(ai3, 0, ai1, 0, 4096); 73 System.arraycopy(ai3, 0, ai2, 0, 4096); 74 System.arraycopy(ai4, 0, ai1, 0, i2); 75 int j1 = ai[0]; 76 k = 1; 77 boolean flag1 = false; 78 int j2 = 0; 79 int k2 = (1 << l) - 1; 80 boolean flag = true; 81 int i3 = 0; 82 int i1 = 0; 83 j2 |= 1 << j + i3; 84 for(i3 += l; i3 >= 8;) 85 { 86 try 87 { 88 abyte0[i1++] = (byte)j2; 89 } 90 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception) 91 { 92 dataoutputstream.writeByte(255); 93 dataoutputstream.write(abyte0); 94 abyte0[i1 = 0] = (byte)j2; 95 i1++; 96 } 97 i3 -= 8; 98 j2 >>= 8; 99 } 100 101 try 102 { 103 do 104 { 105 int k1; 106 int l1 = j1 << 16 | (k1 = ai[k++]); 107 int k3; 108 for(k3 = j1; ai1[k3] != l1 && ai2[k3] >= 0; k3 = ai2[k3]) { } 109 if(ai1[k3] != l1) 110 { 111 j2 |= j1 << i3; 112 for(i3 += l; i3 >= 8;) 113 { 114 try 115 { 116 abyte0[i1++] = (byte)j2; 117 } 118 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception1) 119 { 120 dataoutputstream.writeByte(255); 121 dataoutputstream.write(abyte0); 122 abyte0[i1 = 0] = (byte)j2; 123 i1++; 124 } 125 i3 -= 8; 126 j2 >>= 8; 127 } 128 129 if(i2 > j3) 130 { 131 l++; 132 j3 = (j3 << 1) + 1; 133 } 134 try 135 { 136 ai2[k3] = i2; 137 ai1[i2++] = j1 << 16 | k1; 138 j1 = k1; 139 } 140 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception2) 141 { 142 j1 = k1; 143 l--; 144 j2 |= 1 << j + i3; 145 for(i3 += l; i3 >= 8;) 146 { 147 try 148 { 149 abyte0[i1++] = (byte)j2; 150 } 151 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception5) 152 { 153 dataoutputstream.writeByte(255); 154 dataoutputstream.write(abyte0); 155 abyte0[i1 = 0] = (byte)j2; 156 i1++; 157 } 158 i3 -= 8; 159 j2 >>= 8; 160 } 161 162 j3 = (1 << (l = j + 1)) - 1; 163 i2 = (1 << j) + 2; 164 int l2 = (1 << l) - 1; 165 System.arraycopy(ai3, 0, ai1, 0, 4096); 166 System.arraycopy(ai3, 0, ai2, 0, 4096); 167 System.arraycopy(ai4, 0, ai1, 0, i2); 168 } 169 } 170 else 171 { 172 j1 = k3; 173 } 174 } 175 while(true); 176 } 177 catch(Exception exception) 178 { 179 j2 |= j1 << i3; 180 } 181 for(i3 += l; i3 >= 8;) 182 { 183 try 184 { 185 abyte0[i1++] = (byte)j2; 186 } 187 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception3) 188 { 189 dataoutputstream.writeByte(255); 190 dataoutputstream.write(abyte0); 191 abyte0[i1 = 0] = (byte)j2; 192 i1++; 193 } 194 i3 -= 8; 195 j2 >>= 8; 196 } 197 198 j2 |= (1 << j) + 1 << i3; 199 for(i3 += l; i3 > 0;) 200 { 201 try 202 { 203 abyte0[i1++] = (byte)j2; 204 } 205 catch(ArrayIndexOutOfBoundsException arrayindexoutofboundsexception4) 206 { 207 dataoutputstream.writeByte(255); 208 dataoutputstream.write(abyte0); 209 abyte0[i1 = 0] = (byte)j2; 210 i1++; 211 } 212 i3 -= 8; 213 j2 >>= 8; 214 } 215 216 dataoutputstream.writeByte(i1); 217 dataoutputstream.write(abyte0, 0, i1); 218 dataoutputstream.writeByte(0); 219 return; 220 } 221 catch(Exception e) { } 222 } 223 224 public void addTransparentColor(Color color) 225 { 226 try 227 { 228 if(f < 256) 229 { 230 c[f++] = color.getRGB(); 231 } 232 return; 233 } 234 catch(Exception e) { } 235 } 236 237 public void setTransparentColors(Vector vector) 238 { 239 try 240 { 241 Iterator iterator = vector.iterator(); 242 while(iterator.hasNext()) 243 { 244 Color color = (Color )iterator.next(); 245 addTransparentColor(color); 246 } 247 248 return; 249 } 250 catch(Exception e) { } 251 } 252 253 public void encode(BufferedImage bufferedimage, DataOutputStream dataoutputstream, Hashtable hashtable) throws Exception 254 { 255 try 256 { 257 a = bufferedimage.getWidth(); 258 g = bufferedimage.getHeight(); 259 e = bufferedimage.getRGB(0, 0, a, g, null, 0, a); 260 int i4 = 0; 261 b = hashtable.get("encoding").toString(); 262 if(b.equals("websafe")) 263 { 264 int ai[] = new int[256]; 265 i = new int[256]; 266 h = 8; 267 int k1 = 0; 268 int j; 269 int j1 = j = 0; 270 for(; j <= 255; j += 51) 271 { 272 for(int l = 0; l <= 255; l += 51) 273 { 274 for(int i1 = 0; i1 <= 255;) 275 { 276 i[j1] = (j << 16) + (l << 8) + i1; 277 ai[k1++] = j1; 278 i1 += 51; 279 j1++; 280 } 281 282 } 283 284 } 285 286 if(f > 0) 287 { 288 int j4 = c[0]; 289 int l1 = ((c[0] >> 16 & 0xff) + 25) / 51; 290 int k2 = ((c[0] >> 8 & 0xff) + 25) / 51; 291 int j3 = ((c[0] & 0xff) + 25) / 51; 292 i4 = l1 * 36 + k2 * 6 + j3; 293 for(j = 1; j < f; j++) 294 { 295 int i2 = ((c[j] >> 16 & 0xff) + 25) / 51; 296 int l2 = ((c[j] >> 8 & 0xff) + 25) / 51; 297 int k3 = ((c[j] & 0xff) + 25) / 51; 298 ai[i2 * 36 + l2 * 6 + k3] = i4; 299 } 300 301 } 302 j = 0; 303 try 304 { 305 do 306 { 307 int i5 = e[j]; 308 int j2 = ((i5 >> 16 & 0xff) + 25) / 51; 309 int i3 = ((i5 >> 8 & 0xff) + 25) / 51; 310 int l3 = ((i5 & 0xff) + 25) / 51; 311 e[j++] = ai[j2 * 36 + i3 * 6 + l3]; 312 } 313 while(true); 314 } 315 catch(Exception exception1) { } 316 } 317 368 dataoutputstream.write("GIF89a".getBytes()); 369 dataoutputstream.writeByte(a); 370 dataoutputstream.writeByte(a >> 8); 371 dataoutputstream.writeByte(g); 372 dataoutputstream.writeByte(g >> 8); 373 dataoutputstream.writeByte(0xf0 | h - 1); 374 dataoutputstream.writeByte(0); 375 dataoutputstream.writeByte(0); 376 int k = 0; 377 try 378 { 379 do 380 { 381 int l4 = i[k++]; 382 dataoutputstream.writeByte(l4 >> 16 & 0xff); 383 dataoutputstream.writeByte(l4 >> 8 & 0xff); 384 dataoutputstream.writeByte(l4 & 0xff); 385 } 386 while(true); 387 } 388 catch(Exception exception) { } 389 if(f > 0) 390 { 391 dataoutputstream.writeByte(33); 392 dataoutputstream.writeByte(249); 393 dataoutputstream.writeByte(4); 394 dataoutputstream.writeByte(1); 395 dataoutputstream.writeByte(0); 396 dataoutputstream.writeByte(0); 397 dataoutputstream.writeByte(i4); 398 dataoutputstream.writeByte(0); 399 } 400 dataoutputstream.writeByte(44); 401 dataoutputstream.writeByte(0); 402 dataoutputstream.writeByte(0); 403 dataoutputstream.writeByte(0); 404 dataoutputstream.writeByte(0); 405 dataoutputstream.writeByte(a); 406 dataoutputstream.writeByte(a >> 8); 407 dataoutputstream.writeByte(g); 408 dataoutputstream.writeByte(g >> 8); 409 dataoutputstream.writeByte(0); 410 dataoutputstream.writeByte(h); 411 a(e, h, dataoutputstream); 412 dataoutputstream.writeByte(59); 413 dataoutputstream.flush(); 414 return; 415 } 416 catch(Exception e) { } 417 } 418 419 public GifEncoder() 420 { 421 f = 0; 422 c = new int[256]; 423 } 424 } 425 | Popular Tags |