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

📄 file_jpegstream_to_image.java

📁 基于J2ME的JPEG decode和encode
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    tab[tCount] = (short) (V[i][j] | ((i + 1) << 8));                    tCount++;                }            }        }        for (int i = 1; tCount < 256; i++, tCount++) {            tab[tCount] = (short) (i | MASK);        }        int curTable = 1;        tCount = 0;        for (int i = 8; i < 16; i++) {              for (int j = 0; j < L[i]; j++) {                for (int n = 0; n < (temp >> (i - 7)); n++) {                    tab[curTable * 256 + tCount] = (short) (V[i][j] | ((i + 1) << 8));                    tCount++;                }                if (tCount >= 256) {                    if (tCount > 256) {                        return;                    }                    tCount = 0;                    curTable++;                }            }        }    }    static int code = 0,  input,  mask = 0xFFFF;    static int MASK = (short) 0x8000;    private int countHuffman(short table[], int temp[], int index[], byte[] in){        try {            if (index[0] < 8) {                temp[0] <<= 8;                readStep(in);                temp[0] |= input;            } else {                index[0] -= 8;            }            code = table[temp[0] >> index[0]] & 0x0000ffff;            if ((code & MASK) != 0) {                if (markNumI != 0) {                    markNumI = 0;                    return 0xFF00 | markNum;                }                temp[0] &= (mask >> (16 - index[0]));                temp[0] <<= 8;                readStep(in);                if (index[0] < markNumI) {                    markNumI = 0;                    return 0xFF00 | markNum;                }                temp[0] |= input;                code = table[(code & 0xFF) * 256 + (temp[0] >> index[0])] & 0x0000ffff;                index[0] += 8;            }            index[0] += 8 - (code >> 8);            if (index[0] < 0) {                return 0;            }                        temp[0] &= (mask >> (16 - index[0]));        } catch (Exception e) {//            System.out.println("countHuffman: "+e.toString());        }        return code & 0xFF;    }    void readQualityTable(byte[] in){        int len;        int Pq[] = new int[4];        int Tq[] = new int[4];                int i, count = 0, temp, t;        len = get2Byte(in);        count += 2;        while (count < len) {            temp = getByte(in);            count++;            t = temp & 0x0F;            if (t > 3) {                return;            }            Pq[t] = temp >> 4;            if (Pq[t] == 0) {                Pq[t] = 8;            } else if (Pq[t] == 1) {                Pq[t] = 16;            } else {                return;            }            Tq[t] = 1;            if (Pq[t] == 8) {                for (i = 0; i < 64; i++) {                    Qtable[t][i] = getByte(in);                    count++;                }                countQuality(Qtable[t]);            } else {                for (i = 0; i < 64; i++) {                    Qtable[t][i] = get2Byte(in);                    count += 2;                }                countQuality(Qtable[t]);            }        }    }        void countQuality(int qt[]) {        int i;        for (i = 0; i < 8; i++) {            qt[JPEG_table[0 * 8 + i]] *= 90;            qt[JPEG_table[1 * 8 + i]] *= 126;            qt[JPEG_table[2 * 8 + i]] *= 118;            qt[JPEG_table[3 * 8 + i]] *= 106;            qt[JPEG_table[4 * 8 + i]] *= 90;            qt[JPEG_table[5 * 8 + i]] *= 71;            qt[JPEG_table[6 * 8 + i]] *= 49;            qt[JPEG_table[7 * 8 + i]] *= 25;        }        for (i = 0; i < 8; i++) {            qt[JPEG_table[0 + 8 * i]] *= 90;            qt[JPEG_table[1 + 8 * i]] *= 126;            qt[JPEG_table[2 + 8 * i]] *= 118;            qt[JPEG_table[3 + 8 * i]] *= 106;            qt[JPEG_table[4 + 8 * i]] *= 90;            qt[JPEG_table[5 + 8 * i]] *= 71;            qt[JPEG_table[6 + 8 * i]] *= 49;            qt[JPEG_table[7 + 8 * i]] *= 25;        }        for (i = 0; i < 64; i++) {            qt[i] >>= 6;        }    }        int result, one = 1, n_one = -1;    private int getBit(byte[] in, int n, int temp[], int index[]) {        if(n == 0)return 0;        result = 0;        input = 0;        index[0] -= n;        while(index[0] < 0){            temp[0] <<= 8;            readStep(in);            if (markNumI != 0) {                markNumI = 0;                return (0xFF00 | markNum) << 8;            }            temp[0] |= input;            index[0] += 8;                    }        result = temp[0] >> index[0];        temp[0] &= (mask >> (16 - index[0]));        if (result < (one << (n - 1))) {            result += (n_one << n) + 1;        }        return result;    }    void readStep(byte[] in) {        input = getByte(in);        if (input == 0xFF) {            markNum = getByte(in);            if (markNum != 0) {                markNumI = 9;            }        }    }    int tempB, tempG, tempR;    private short getRGB(int Y, int u, int v) {        Y += 128;        if (Y < 0) {            Y = 0;        }        tempR = (Y * 100 + 114 * v) / 100;        if (tempR < 0) {            tempR = 0;        } else if (tempR > 255) {            tempR = 255;        }        tempG = (Y * 100 - (39 * u + 58 * v)) / 100;        if (tempG < 0) {            tempG = 0;        } else if (tempG > 255) {            tempG = 255;        }        tempB = (Y * 100 + (203 * u)) / 100;        if (tempB < 0) {            tempB = 0;        } else if (tempB > 255) {            tempB = 255;        }        return (short) ((tempR * 31 / 255) << 11 | (tempG * 63 / 255) << 5 | (tempB * 31 / 255));    }    private int getRGB_int(int Y, int u, int v) {        if (Y < 0) {            Y = 0;        }        tempR = (Y * 100 + 114 * v) / 100;        if (tempR < 0) {            tempR = 0;        } else if (tempR > 255) {            tempR = 255;        }        tempG = (Y * 100 - (39 * u + 58 * v)) / 100;        if (tempG < 0) {            tempG = 0;        } else if (tempG > 255) {            tempG = 255;        }        tempB = (Y * 100 + (203 * u)) / 100;        if (tempB < 0) {            tempB = 0;        } else if (tempB > 255) {            tempB = 255;        }        return 0xff000000 | ((tempR << 16) + (tempG << 8) + tempB);    }    int tx, ty;    int k = 0;    short tc = 0;    int a,b,i,j;    private void outputPixel() {        if(MIDlet_Template.vbia != null){            MIDlet_Template.vbia.chunkI += Comp[1].samplingV*Comp[1].smaplingH;            MIDlet_Template.vbia.process = 20 + (MIDlet_Template.vbia.chunkI)*50/MIDlet_Template.vbia.chunkNum;        }        k = 0;        for (i = 0; i < Comp[1].samplingV; i++) {            for (j = 0; j < Comp[1].smaplingH; j++) {                ty = i * 32;                tx = temp = j * 4;                for (int l = 0; l < 64; l++) {                    if (x < oriW && y < oriH) {                        if (par.needZoom) {                            if (par.tabX[x] != null && par.tabY[y] != null) {                                tc = getRGB(chunkData[0][k][l], chunkData[1][0][ty + tx], chunkData[2][0][ty + tx]);                                                                for(a=0;a<par.tabX[x].length;a++){                                    for(b=0;b<par.tabY[y].length;b++){                                        MIDlet_Template.srcZoomBuf[par.tabX[x][a] + par.tabY[y][b] * par.desW] = tc;                                    }                                }                            }                        }                    }                    x++;                    if ((x % Comp[1].smaplingH) == 0) {                        tx++;                    }                    if ((x % 8) == 0) {                        y++;                        x -= 8;                        tx = temp;                        if ((y % Comp[1].samplingV) == 0) {                            ty += 8;                        }                    }                }                k++;                x += 8;                y -= 8;            }            x -= Comp[1].smaplingH * 8;            y += 8;        }        x += Comp[1].smaplingH * 8;        y -= Comp[1].samplingV * 8;        if (x >= oriW) {            y += Comp[1].samplingV * 8;            x = 0;        }    }    int Y_D[] = new int[64];    int U_D[] = new int[64];    int V_D[] = new int[64];    int Init_DCTable[] = {        0, 5, 40, 16, 45, 2, 7, 42,        21, 56, 8, 61, 18, 47, 1, 4,        41, 23, 58, 13, 32, 24, 37, 10,        63, 17, 44, 3, 6, 43, 20, 57,        15, 34, 29, 48, 53, 26, 39, 9,        60, 19, 46, 22, 59, 12, 33, 31,        50, 55, 25, 36, 11, 62, 14, 35,        28, 49, 52, 27, 38, 30, 51, 54    };    int value;    int Cs;    private int getDUArray(byte[] in, int PrevDC[],            int temp[], int index[]){        try {            for (Cs = 0; Cs < scanNum; Cs++) {                for (int i = 0; i < blockNum[Cs]; i++) {                    for (int k = 0; k < DCTable.length; k++) {                        DCTable[k] = 0;                    }                    value = countHuffman(dcT[Cs], temp, index, in);                    if (value >= 0xFF00) {                        return value;                    }                    int tt = getBit(in, value, temp, index);                    PrevDC[Cs] = DCTable[0] = PrevDC[Cs] + tt;                    DCTable[0] *= quTab[Cs][0];                    for (int j = 1; j < 64; j++) {                        value = countHuffman(acT[Cs], temp, index, in);                        if (value >= 0xFF00) {                            return value;                        }                        j += (value >> 4);                        if ((value & 0x0F) == 0) {                            if ((value >> 4) == 0) {                                break;                            }                        } else {                            tt = getBit(in, value & 0x0F, temp, index);                            DCTable[Init_DCTable[j]] = tt * quTab[Cs][j];                        }                    }                    getDU(chunkData[Cs][i]);                }            }        } catch (Exception e) {

⌨️ 快捷键说明

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