📄 zc030x_jpeg.c
字号:
if ((outarray[ctr][0])<0) outarray[ctr][0] = 0; if ((outarray[ctr][0])>255) outarray[ctr][0] = 255; outarray[ctr][7] = ((tmp0 - tmp7) >> 5)+128; if ((outarray[ctr][7])<0) outarray[ctr][7] = 0; if ((outarray[ctr][7])>255) outarray[ctr][7] = 255; outarray[ctr][1] = ((tmp1 + tmp6) >> 5)+128; if ((outarray[ctr][1])<0) outarray[ctr][1] = 0; if ((outarray[ctr][1])>255) outarray[ctr][1] = 255; outarray[ctr][6] = ((tmp1 - tmp6) >> 5)+128; if ((outarray[ctr][6])<0) outarray[ctr][6] = 0; if ((outarray[ctr][6])>255) outarray[ctr][6] = 255; outarray[ctr][2] = ((tmp2 + tmp5) >> 5)+128; if ((outarray[ctr][2])<0) outarray[ctr][2] = 0; if ((outarray[ctr][2])>255) outarray[ctr][2] = 255; outarray[ctr][5] = ((tmp2 - tmp5) >> 5)+128; if ((outarray[ctr][5])<0) outarray[ctr][5] = 0; if ((outarray[ctr][5])>255) outarray[ctr][5] = 255; outarray[ctr][4] = ((tmp3 + tmp4) >> 5)+128; if ((outarray[ctr][4])<0) outarray[ctr][4] = 0; if ((outarray[ctr][4])>255) outarray[ctr][4] = 255; outarray[ctr][3] = ((tmp3 - tmp4) >> 5)+128; if ((outarray[ctr][3])<0) outarray[ctr][3] = 0; if ((outarray[ctr][3])>255) outarray[ctr][3] = 255; } }/* Get a block to decode */int JPGGetBlock (s16 vector[8][8], u16 HuffDCNum, u16 HuffACNum, u16 QuantNum, s16 *dcCoef, u8 * jpgdata){ s16 array2[8][8]; s32 d; u16 XPos; u16 YPos; // u32 Sum; u16 bits; u16 zeros; s32 bitVal; u16 ACCount; u16 x; u16 y; // u16 v; u16 u; // s32 temp; s16 temp0; // u16 Add1 = 0; u16 ZigIndex; EOI = 0; for (x=0; x<8; x++) for (y=0; y<8; y++) array2[x][y] = 0; if (HuffDCNum) temp0 = JPGDecode(HuffmanDC1, jpgdata); // Get the DC coefficient else temp0 = JPGDecode(HuffmanDC0, jpgdata); // Get the DC coefficient // Error with the previous decoding if (EOI) { PDEBUG(3,"Error with the previous decoding"); return -1; } // if (EOI) d = 0; *dcCoef = *dcCoef + JPGReceiveBits(temp0, jpgdata); array2[0][0] = *dcCoef; //* Quant[QuantNum][0][0]; XPos = 0; YPos = 0; ZigIndex = 1; ACCount = 1; do { if (HuffACNum) d = JPGDecode(HuffmanAC1, jpgdata); else d = JPGDecode(HuffmanAC0, jpgdata); if (EOI) { PDEBUG(3,"Error with the previous decoding"); return -1; } zeros = d >> 4; bits = d & 15; bitVal = JPGReceiveBits(bits, jpgdata); if (bits) { ZigIndex += zeros; ACCount += zeros; if (ACCount >= 64) break; XPos = JPGZig1[ZigIndex]; YPos = JPGZig2[ZigIndex]; ZigIndex++; //Read(XPos, YPos); array2[XPos][YPos] = bitVal; // * Quant[QuantNum][XPos][YPos]; ACCount++; } else { if (zeros != 15) break; ZigIndex += 15; ACCount += 16; } } while (ACCount < 64);// if (HuffDCNum == Image.HuffDCTableY) Add1 = 128; jpeg_idct_ifast (array2, vector, QuantNum); return 0;}/* Get the huffman tables */u16 JPGGetHuffTables (u8 * jpgdata){ u16 HuffAmount[17]; //1-16 u32 l0; u16 c0; u16 temp0; s16 temp1; u16 total; u16 i; u16 t0; s32 CurNum; u16 CurIndex; u16 j; l0 = JPGGetWord(jpgdata); c0 = 2; do { temp0 = JPGGetByte(jpgdata); c0++; // Get the huffman table type (t0 == 0 => DC, AC else) t0 = (temp0 & 16) >> 4; // Now save the luminance or chrominance information (temp0 == 0 => Y, CbCr else) temp0 &= 15; switch (t0) { case 0: // DC Table total = 0; // Read the number of codes for (i=0; i<16; i++) { temp1 = JPGGetByte(jpgdata); c0++; total += temp1; HuffAmount[i+1] = temp1; } // Read all codes, for each length for (i=0; i<total; i++) { if (temp0) HuffmanDC1[i].Code = JPGGetByte(jpgdata); else HuffmanDC0[i].Code = JPGGetByte(jpgdata); c0++; } // Now create the table correctly CurNum = 0; CurIndex = -1; for (i=1; i<16+1; i++) { for (j=1; j<HuffAmount[i]+1; j++) { CurIndex++; if (temp0) { HuffmanDC1[CurIndex].Index = CurNum; HuffmanDC1[CurIndex].Length = i; } else { HuffmanDC0[CurIndex].Index = CurNum; HuffmanDC0[CurIndex].Length = i; } CurNum++; } CurNum *= 2; } DCTables++; break; case 1: total = 0; for (i=1; i<16+1; i++) { temp1 = JPGGetByte(jpgdata); c0++; total += temp1; HuffAmount[i] = temp1; } for (i=0; i<total; i++) { if (temp0) HuffmanAC1[i].Code = JPGGetByte(jpgdata); else HuffmanAC0[i].Code = JPGGetByte(jpgdata); c0++; } CurNum = 0; CurIndex = -1; for (i=1; i<16+1; i++) { for (j=1; j<HuffAmount[i]+1; j++) { CurIndex++; if (temp0) { HuffmanAC1[CurIndex].Index = CurNum; HuffmanAC1[CurIndex].Length = i; } else { HuffmanAC0[CurIndex].Index = CurNum; HuffmanAC0[CurIndex].Length = i; } CurNum++; } CurNum *= 2; } ACTables++; break; } } while (c0 < l0);return(1);}/* Get Image attributes */u16 JPGGetImageAttr (u8 * jpgdata){ /* Temporary variables */ u32 temp4; u16 temp0; u16 temp1; u16 i; u16 id; /* Segment length */ temp4 = JPGGetWord(jpgdata); /* Data precision (should be 8 bits) */ temp0 = JPGGetByte(jpgdata); if (temp0 != 8) return(0); /* Image height */ Image.Rows = JPGGetWord(jpgdata); /* Image width */ Image.Cols = JPGGetWord(jpgdata); /* Component number */ temp0 = JPGGetByte(jpgdata); for (i=1; i<temp0+1; i++) { /* Get the index of the tables */ id = JPGGetByte(jpgdata); switch (id) { case 1: temp1 = JPGGetByte(jpgdata); Image.SamplesY = (temp1 & 15) * (temp1 >> 4); Image.QuantTableY = JPGGetByte(jpgdata); break; case 2: case 3: temp1 = JPGGetByte(jpgdata); Image.SamplesCbCr = (temp1 & 15) * (temp1 >> 4); Image.QuantTableCbCr = JPGGetByte(jpgdata); break; } } /* Return */ PDEBUG(3,"%x Image size (%dx%d = %d:%d)", findex, Image.Rows, Image.Cols, Image.SamplesCbCr, Image.QuantTableCbCr); return(1);}/* Get the quantized tables */u8 JPGGetQuantTables(u8 * jpgdata){ u32 l0 = JPGGetWord(jpgdata); u16 c0 = 2; u16 temp0; u16 xp; u16 yp; u16 i; u16 ZigIndex; do { temp0 = JPGGetByte(jpgdata); c0++; if (temp0 & 0xf0) return(0); //we don't support 16-bit tables temp0 &= 15; ZigIndex = 0; xp = 0; yp = 0; for (i=0; i<64; i++) { xp = JPGZig1[ZigIndex]; yp = JPGZig2[ZigIndex]; ZigIndex++; /* For AA&N IDCT method, multipliers are equal to quantization * coefficients scaled by scalefactor[row]*scalefactor[col], where * scalefactor[0] = 1 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 */ QuantTable[temp0][xp][yp] = (JPGGetByte(jpgdata) * aanscales[(xp<<3) + yp]) >> 12; c0++; } QTables++; } while (c0 < l0); return(1);}/* Get the Start of Scan marker */u16 JPGGetSOS (u8 * jpgdata){ u32 temp4; u16 temp0; u16 temp1; u16 temp2; u16 i; temp4 = JPGGetWord(jpgdata); temp0 = JPGGetByte(jpgdata); if ((temp0 != 1) && (temp0 != 3)) return(0); Image.NumComp = temp0; PDEBUG(3,"Number of components : %d", Image.NumComp); for (i=1; i<temp0+1; i++) { temp1 = JPGGetByte(jpgdata); PDEBUG(3,"Identifiant : %d", temp1); switch (temp1) { case 1: temp2 = JPGGetByte(jpgdata); PDEBUG(3,"IndexY : %d", temp2); Image.HuffACTableY = temp2 & 15; Image.HuffDCTableY = temp2 >> 4; break; case 2: temp2 = JPGGetByte(jpgdata); PDEBUG(3,"IndexCb : %d", temp2); Image.HuffACTableCbCr = temp2 & 15; Image.HuffDCTableCbCr = temp2 >> 4; break; case 3: temp2 = JPGGetByte(jpgdata); PDEBUG(3,"IndexCr : %d", temp2); Image.HuffACTableCbCr = temp2 & 15; Image.HuffDCTableCbCr = temp2 >> 4; break; default: return(0); } } findex += 3; return(1);}/* Decode a picture */u32 gfxJpegRGB32 (u8 bGrey, u16 wWidth, u16 wHeight, u8 *vram, u8 * jpgdata, int format){ u8 exit = 1;// u16 u,v;// s16 x; s16 y;// float t; u16 Restart = 0; u16 XPos; u16 YPos; s16 dcY; s16 dcCb; s16 dcCr; u16 xindex; u16 yindex; u16 mcu; s16 YVector1[8][8]; // 4 vectors for Y attribute s16 YVector2[8][8]; // (not all may be needed) s16 CbVector[8][8]; // 1 vector for Cb attribute s16 CrVector[8][8]; // 1 vector for Cr attribute s16 height;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -