⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pngencoder.java

📁 遗传算法改进神经网络源程序 该小程序可以添加条形码功能到你的网页或者applet上,这个applet把大写字母和数字转换为标准的条形码。
💻 JAVA
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2007-11-23 16:17:29
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   PngEncoder.java

package com.bokai.barcodes;

import com.bokai.drawing.SimpleColor;
import java.awt.Color;
import java.awt.Image;
import java.awt.image.PixelGrabber;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.CRC32;
import java.util.zip.Deflater;

// Referenced classes of package com.bokai.barcodes:
//            ImageEncoder

public class PngEncoder
    implements ImageEncoder
{

    public PngEncoder()
    {
    }

    private byte byteFromInts(int ai[], int i, int j)
    {
        int k = 0;
        for(int l = 0; l < j; l++)
            k |= (ai[l + i] & 0xffffff) != 0 ? 1 << 7 - l : 0;

        return (byte)k;
    }

    public void encode(Image image, Color color, Color color1, boolean flag, OutputStream outputstream)
        throws Exception
    {
        int i = image.getWidth(null);
        int j = image.getHeight(null);
        PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, i, j, true);
        boolean flag1 = pixelgrabber.grabPixels();
        if(!flag1)
            throw new Exception("grabPixels failed");
        int ai[] = (int[])pixelgrabber.getPixels();
        int k = (i + 7) / 8;
        byte abyte0[] = new byte[k * j];
        int l = 0;
        int i1 = 0;
        for(int j1 = 0; j1 < j; j1++)
        {
            for(int k1 = 0; k1 < k; k1++)
            {
                int l1 = k1 * 8 + l;
                abyte0[k1 + i1] = byteFromInts(ai, l1, Math.min(8, i - k1 * 8));
            }

            i1 += k;
            l += i;
        }

        internalEncode(abyte0, i, j, new SimpleColor(color), new SimpleColor(color1), flag, outputstream);
    }

    public void encode(byte abyte0[], int i, int j, SimpleColor simplecolor, SimpleColor simplecolor1, boolean flag, OutputStream outputstream)
        throws Exception
    {
        internalEncode(abyte0, i, j, simplecolor, simplecolor1, flag, outputstream);
    }

    private void internalEncode(byte abyte0[], int i, int j, SimpleColor simplecolor, SimpleColor simplecolor1, boolean flag, OutputStream outputstream)
        throws Exception
    {
        int k = i;
        int l = j;
        int i1 = (k + 7) / 8;
        int j1 = 1 + i1;
        byte abyte1[] = new byte[j1 * l];
        int k1 = 0;
        int l1 = 0;
        for(int i2 = 0; i2 < l; i2++)
        {
            abyte1[l1++] = 0;
            System.arraycopy(abyte0, k1, abyte1, l1, i1);
            l1 += i1;
            k1 += i1;
        }

        writeSignature(outputstream);
        if((simplecolor.getRGB() & 0xffffff) == 0 && (simplecolor1.getRGB() & 0xffffff) == 0xffffff && !flag)
        {
            writeIHDR(outputstream, k, l, 1, 0, 0, 0, 0);
        } else
        {
            byte abyte2[] = new byte[6];
            byte byte0 = 6;
            abyte2[0] = (byte)simplecolor.getRed();
            abyte2[1] = (byte)simplecolor.getGreen();
            abyte2[2] = (byte)simplecolor.getBlue();
            abyte2[3] = (byte)simplecolor1.getRed();
            abyte2[4] = (byte)simplecolor1.getGreen();
            abyte2[5] = (byte)simplecolor1.getBlue();
            writeIHDR(outputstream, k, l, 1, 3, 0, 0, 0);
            writePLTE(outputstream, abyte2, byte0);
            if(flag)
            {
                byte abyte3[] = new byte[2];
                abyte3[0] = -1;
                abyte3[1] = 0;
                writetRNS(outputstream, abyte3, 2);
            }
        }
        writeIDAT(outputstream, abyte1, j1 * l);
        writeIEND(outputstream);
    }

    private void networkOrderInt32(int i, byte abyte0[], int j)
    {
        abyte0[j] = (byte)(i >> 24 & 0xff);
        abyte0[j + 1] = (byte)(i >> 16 & 0xff);
        abyte0[j + 2] = (byte)(i >> 8 & 0xff);
        abyte0[j + 3] = (byte)(i & 0xff);
    }

    public boolean use2ColorSource()
    {
        return true;
    }

    private void writeBytes(OutputStream outputstream, byte abyte0[], int i)
        throws IOException
    {
        outputstream.write(abyte0, 0, i);
    }

    private void writeChunk(OutputStream outputstream, byte abyte0[], byte abyte1[], int i)
        throws IOException
    {
        writeInt32(outputstream, i);
        writeBytes(outputstream, abyte0, 4);
        CRC32 crc32 = new CRC32();
        crc32.update(abyte0, 0, 4);
        if(i != 0)
        {
            writeBytes(outputstream, abyte1, i);
            crc32.update(abyte1, 0, i);
        }
        writeInt32(outputstream, (int)crc32.getValue());
    }

    private void writeIDAT(OutputStream outputstream, byte abyte0[], int i)
        throws IOException
    {
        int j = i + (i + 999) / 1000 + 12;
        byte abyte1[] = new byte[j];
        Deflater deflater = new Deflater();
        deflater.setInput(abyte0, 0, i);
        deflater.finish();
        j = deflater.deflate(abyte1, 0, j);
        writeChunk(outputstream, _pngIDAT, abyte1, j);
    }

    private void writeIEND(OutputStream outputstream)
        throws IOException
    {
        writeChunk(outputstream, _pngIEND, null, 0);
    }

    private void writeIHDR(OutputStream outputstream, int i, int j, int k, int l, int i1, int j1, 
            int k1)
        throws IOException
    {
        byte abyte0[] = new byte[13];
        networkOrderInt32(i, abyte0, 0);
        networkOrderInt32(j, abyte0, 4);
        abyte0[8] = (byte)k;
        abyte0[9] = (byte)l;
        abyte0[10] = (byte)i1;
        abyte0[11] = (byte)j1;
        abyte0[12] = (byte)k1;
        writeChunk(outputstream, _pngIHDR, abyte0, 13);
    }

    private void writeInt32(OutputStream outputstream, int i)
        throws IOException
    {
        byte abyte0[] = new byte[4];
        networkOrderInt32(i, abyte0, 0);
        outputstream.write(abyte0, 0, 4);
    }

    private void writePLTE(OutputStream outputstream, byte abyte0[], int i)
        throws IOException
    {
        writeChunk(outputstream, _pngPLTE, abyte0, i);
    }

    private void writeSignature(OutputStream outputstream)
        throws IOException
    {
        outputstream.write(_pngSign, 0, _pngSign.length);
    }

    private void writetRNS(OutputStream outputstream, byte abyte0[], int i)
        throws IOException
    {
        writeChunk(outputstream, _pngtRNS, abyte0, i);
    }

    public static final byte _pngSign[] = {
        -119, 80, 78, 71, 13, 10, 26, 10
    };
    public static final byte _pngIHDR[] = {
        73, 72, 68, 82
    };
    public static final byte _pngPLTE[] = {
        80, 76, 84, 69
    };
    public static final byte _pngtRNS[] = {
        116, 82, 78, 83
    };
    public static final byte _pngIDAT[] = {
        73, 68, 65, 84
    };
    public static final byte _pngIEND[] = {
        73, 69, 78, 68
    };
    public static final byte _pngbKGD[] = {
        98, 75, 71, 68
    };

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -