?? imagetogif.java
字號:
/** * File and FTP Explorer * Copyright 2002 * BOESCH Vincent * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package javaexplorer.io.encoder;import java.awt.*;import java.awt.image.PixelGrabber;import java.io.*;import java.util.Vector;public class ImageToGif extends Canvas { //private final static int COLOR_MAX = 256; //private final static int TABLESIZE = 5003; private short[] Block; private short BlockPos; private short clearCode; private short[] code; private short[] codeCharacter; private DataOutputStream dataOut; private short endCode; private byte flagLSD; private short freeSlot; private Image image; private short imgHeight; private short imgWidth; private short lzwBits; private int lzwData; private boolean message; private OutputStream output; private int[] palArr; private int palSize; private short[] pixCol; private short[] prefix; private short sActCodeSize; private short sOriginalCodeSize; /** * Constructeur objet ImageToGif * *@param image1 Description * of the Parameter *@param outputstream Description * of the Parameter *@param flag Description * of the Parameter *@exception IOException Description * of the Exception */ public ImageToGif(Image image1, OutputStream outputstream, boolean flag) throws IOException { image = image1; output = outputstream; message = flag; startProc(); } /** */ public void CalcSpecialCodes() { clearCode = (short) (1 << sOriginalCodeSize); for (short word0 = 0; word0 < clearCode; word0++) { prefix[word0] = word0; codeCharacter[word0] = (byte) word0; } endCode = (short) (clearCode + 1); freeSlot = (short) (clearCode + 2); sActCodeSize = (short) (sOriginalCodeSize + 1); } /** */ public void ClearCompressionTable() { for (short word0 = 0; word0 < 5003; word0++) { code[word0] = -1; } } /** *@param word0 Description of the Parameter *@param word1 Description of the Parameter *@return Description of the Return * Value */ public short FindSlot(short word0, short word1) { short word2 = (short) ((word1 << 4) ^ word0); short word3 = (short) ((word2 != 0) ? (5003 - word2) : 1); do { do { if (code[word2] == -1) { return word2; } if ((prefix[word2] == word0) && (codeCharacter[word2] == word1)) { return word2; } word2 -= word3; } while (word2 >= 0); word2 += 5003; } while (true); } /** *@param word0 Description of the Parameter *@return Description of the Return * Value */ public char MSBtoLSB(short word0) { short word1 = (short) (word0 >> 8); short word2 = (short) ((word0 & 0xff) << 8); return (char) (word2 + word1); } /** *@return Description of the Return * Value */ public boolean calcGif() { try { return writeHeader() && writeLSD() && writeGlobalPalette() && writeImageDescriptor() && writeDataBlocks(); } catch (Exception ex) { return false; } } /** *@return Description of the Return * Value */ public boolean closeGif() { try { dataOut.writeByte(59); output.close(); return true; } catch (Exception ex) { return false; } } /** * Gets the imageInfo attribute of the * ImageToGif object * *@return The imageInfo value */ public boolean getImageInfo() { int i1 = 0; int j1 = 0; int k1 = 0; int[] ai1 = { 0xffffff, 0xffffff, 0xe0e0c0, 0xe0e0e0, 0xf0f0f0, 0xf8f8f8, 0xfcfcfc, 0xfefefe, 0xffffff, 0xffffff }; try { imgWidth = (short) image.getWidth(this); imgHeight = (short) image.getHeight(this); int l = imgWidth * imgHeight; int[] ai = new int[l]; PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, imgWidth, imgHeight, ai, 0, imgWidth); Vector vector = new Vector(256); Vector vector1 = new Vector(1); Integer[] ainteger = new Integer[0]; Integer[] ainteger1 = new Integer[1]; pixelgrabber.grabPixels(); vector1.addElement(new Integer(0)); while ((j1 <= 256) || (ai1[i1] == 0xffffff)) { ainteger = new Integer[vector.size()]; vector.copyInto(ainteger); k1 = j1; i1++; vector.removeAllElements(); vector.addElement(new Integer(ai[0] & ai1[i1])); vector.addElement(new Integer(0x1000000)); j1 = 2; palSize = 2; boolean flag1 = true; byte byte0 = 2; for (int l1 = 1; l1 < l; l1++) { int i = ai[l1] & ai1[i1]; int j = palSize - 1; int k = palSize; boolean flag; do { vector1.setElementAt(vector.elementAt(j), 0); vector1.copyInto(ainteger1); if (i == ainteger1[0].intValue()) { k = 0; flag = true; } else { k /= 2; if (i < ainteger1[0].intValue()) { j -= k; } else { j += k; } flag = false; } } while (k > 0); if (flag) { continue; } vector1.setElementAt(vector.elementAt(j), 0); vector1.copyInto(ainteger1); if (i < ainteger1[0].intValue()) { vector.insertElementAt(new Integer(ai[l1] & ai1[i1]), j); } else { vector.insertElementAt(new Integer(ai[l1] & ai1[i1]), j + 1); } if (j1++ > 256) { break; } vector.removeElement(vector.lastElement()); if (j1 > palSize) { for (int j2 = palSize; j2 < (2 * palSize); j2++) { vector.addElement(new Integer(0x1000000)); } palSize *= 2; } } if ((--j1 <= 256) && (ai1[i1] == 0xffffff)) { ainteger = new Integer[vector.size()]; vector.copyInto(ainteger); k1 = j1; break; } if (((j1 > 256) && (ai1[i1] != 0xffffff)) || ((i1 > 3) && (ai1[i1] == 0xffffff))) { break; } } i1--; palSize = k1; palArr = new int[palSize]; for (int i2 = 0; i2 < palSize; i2++) { palArr[i2] = ainteger[i2].intValue() | (((ai1[i1] ^ 0xffffff) >> 1) & (ai1[i1] ^ 0xffffff)); } pixCol = new short[l]; for (int k2 = 0; k2 < l; k2++) { for (short word0 = 0; word0 < palSize; word0++) { if ((ai[k2] & ai1[i1]) != (palArr[word0] & ai1[i1])) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -