好文档 - 专业文书写作范文服务资料分享网站

z i g z a g 压 缩 算 法( 2 0 2 0) 

天下 分享 时间: 加入收藏 我要投稿 点赞

output_ptr;}-* DCT for One block(8x8) *- static void DCT (INT16 * data) {? UINT16 i;? INT32 x0, x1, x2, x3, x4, x5, x6, x7, x8;? -*?All values are shifted left by 10?and rounded off to nearest integer *- ? static const UINT16 c1 = 1420;?-* cos PI-16 * root(2)? *-? static const UINT16 c2 = 1338;?-* cos PI-8 * root(2)? *-? static const UINT16 c3 = 1204;?-* cos 3PI-16 * root(2) *-? static const UINT16 c5 = 805;?-* cos 5PI-16 * root(2) *-? static const UINT16 c6 = 554;?-* cos 3PI-8 * root(2)? *-? static const UINT16 c7 = 283;?-* cos 7PI-16 * root(2) *-? static const UINT16 s1 = 3;? static const UINT16 s2 = 10;? static const UINT16 s3 = 13;? for (i = 8; i 0; i--) {? x8 = data[0] + data[7];? x0 = data[0] - data[7];? x7 = data[1] + data[6];? x1 = data[1] - data[6];? x6 = data[2] + data[5];? x2 = data[2] - data[5];? x5 = data[3] + data[4];? x3 = data[3] - data[4];? x4 = x8 + x5;? x8 -= x5;? x5 = x7 + x6;? x7 -= x6;? data[0] = (INT16) (x4 + x5);? data[4] = (INT16) (x4 - x5);? data[2] = (INT16) ((x8 * c2 + x7 * c6) s2);? data[6] = (INT16) ((x8 * c6 - x7 * c2) s2);? data[7] = (INT16) ((x0 * c7 - x1 * c5 + x2 * c3 - x3 * c1) s2);? data[5] = (INT16) ((x0 * c5 - x1 * c1 + x2 * c7 + x3 * c3) s2);? data[3] = (INT16) ((x0 * c3 - x1 * c7 - x2 * c1 - x3 * c5) s2);? data[1] = (INT16) ((x0 * c1 + x1 * c3 + x2 * c5 + x3 * c7) s2);? data += 8;? }? data -= 64;? for (i = 8; i 0; i--) {? x8 = data[0]

+ data[56];? x0 = data[0] - data[56];? x7 = data[8] + data[48];? x1 = data[8] - data[48];? x6 = data[16] + data[40];? x2 = data[16] - data[40];? x5 = data[24] + data[32];? x3 = data[24] - data[32];? x4 = x8 + x5;? x8 -= x5;? x5 = x7 + x6;? x7 -= x6;? data[0] = (INT16) ((x4 + x5) s1);? data[32] = (INT16) ((x4 - x5) s1);? data[16] = (INT16) ((x8 * c2 + x7 * c6) s3);? data[48] = (INT16) ((x8 * c6 - x7 * c2) s3);? data[56] = (INT16) ((x0 * c7 - x1 * c5 + x2 * c3 - x3 * c1) s3);? data[40] = (INT16) ((x0 * c5 - x1 * c1 + x2 * c7 + x3 * c3) s3);? data[24] = (INT16) ((x0 * c3 - x1 * c7 - x2 * c1 - x3 * c5) s3);? data[8] = (INT16) ((x0 * c1 + x1 * c3 + x2 * c5 + x3 * c7) s3);? data++;? }}-* multiply DCT Coefficients with Quantization table and store in ZigZag location *- void quantization (INT16 * const data, UINT16 * const quant_table_ptr) {? INT16 i;? INT32 value;? for (i = 63; i = 0; i--) {? value = data[i] * quant_table_ptr[i];? value = (value + 0x4000) 15;? Temp[zigzag_table[i]] = (INT16) value;? }}UINT8 * huffman (JPEG_ENCODER_STRUCTURE * jpeg_encoder_structure,UINT16 component, UINT8 * output_ptr) {? UINT16 i;? UINT16 * DcCodeTable, *DcSizeTable, *AcCodeTable, *AcSizeTable;? INT16 * Temp_Ptr, Coeff, LastDc;? UINT16 AbsCoeff, HuffCode, HuffSize, RunLength = 0, DataSize = 0, index;? INT16 bits_in_next_word;? UINT16 numbits;? UINT32

data;? Temp_Ptr = Temp;? Coeff = *Temp_Ptr++;? if (component == 1) {? DcCodeTable = luminance_dc_code_table;? DcSizeTable =

luminance_dc_size_table;?

AcCodeTable AcSizeTable LastDc

= = =

luminance_ac_code_table;? luminance_ac_size_table;?

jpeg_encoder_structure-ldc1;? jpeg_encoder_structure-ldc1 = Coeff;? } else {? DcCodeTable = chrominance_dc_code_table;? DcSizeTable = chrominance_dc_size_table;? AcCodeTable = chrominance_ac_code_table;?

AcSizeTable

=

chrominance_ac_size_table;? if (component == 2)?{? LastDc = jpeg_encoder_structure-ldc2;? jpeg_encoder_structure-ldc2 = Coeff;?} else?{? LastDc = jpeg_encoder_structure-ldc3;? jpeg_encoder_structure-ldc3 = Coeff;?}? }? Coeff -= LastDc;? AbsCoeff = (Coeff 0) ? -Coeff-- : Coeff;? while (AbsCoeff != 0) {? AbsCoeff = 1;? DataSize++;? }? HuffCode = DcCodeTable[DataSize];? HuffSize = DcSizeTable[DataSize];? Coeff = (1 DataSize) - 1;? data = (HuffCode DataSize) | Coeff;? numbits = HuffSize + DataSize;? --PUTBITS? { ? bits_in_next_word = (INT16) (bitindex + numbits - 32); ? if (bits_in_next_word 0) ? { ? lcode = (lcode numbits) | data; ? bitindex += numbits; ? } ? else ? { ? lcode = (lcode (32 - bitindex)) | (data bits_in_next_word); ? if ((*output_ptr++ =

(UINT8) (lcode 24)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 16)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 8)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) lcode) == 0xff) ? *output_ptr++ = 0; ? lcode = data; ? bitindex = bits_in_next_word; ? } ? } for (i = 63; i 0; i--) {? if ((Coeff = *Temp_Ptr++) != 0)?{? while (RunLength 15) {? RunLength -= 16;? data = AcCodeTable[161];? numbits = AcSizeTable[161];? --PUTBITS? { ? bits_in_next_word = (INT16) (bitindex + numbits - 32); ? if (bits_in_next_word 0) ? { ? lcode = (lcode numbits) | data; ? bitindex += numbits; ? } ? else ? { ? lcode = (lcode (32 - bitindex)) | (data bits_in_next_word); ? if ((*output_ptr++ = (UINT8) (lcode 24)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 16)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 8)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) lcode) == 0xff) ? *output_ptr++ = 0; ? lcode = data; ? bitindex = bits_in_next_word; ? } ? } }? AbsCoeff = (Coeff 0) ? -Coeff-- : Coeff;? if (AbsCoeff 8 == 0)? DataSize = bitsize[AbsCoeff]; else? DataSize = bitsize[AbsCoeff 8] + 8;? index = RunLength * 10 + DataSize;? HuffCode = AcCodeTable[index];? HuffSize = AcSizeTable[index];? Coeff = (1 DataSize) - 1;? data =

(HuffCode DataSize) | Coeff;? numbits = HuffSize + DataSize;? -- PUTBITS? { ? bits_in_next_word = (INT16) (bitindex + numbits - 32); ? if (bits_in_next_word 0) ? { ? lcode = (lcode numbits) | data; ? bitindex += numbits; ? } ? else ? { ? lcode = (lcode (32 - bitindex)) | (data bits_in_next_word); ? if ((*output_ptr++ = (UINT8) (lcode 24)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 16)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 8)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) lcode) == 0xff) ? *output_ptr++ = 0; ? lcode = data; ? bitindex = bits_in_next_word; ? } ? } RunLength = 0;?} else?RunLength++;? }? if (RunLength != 0) {? data = AcCodeTable[0];? numbits = AcSizeTable[0];? -- PUTBITS ? { ? bits_in_next_word = (INT16) (bitindex + numbits - 32); ? if (bits_in_next_word 0) ? { ? lcode = (lcode numbits) | data; ? bitindex += numbits; ? } ? else ? { ? lcode = (lcode (32 - bitindex)) | (data bits_in_next_word); ? if ((*output_ptr++ = (UINT8) (lcode 24)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 16)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) (lcode 8)) == 0xff) ? *output_ptr++ = 0; ? if ((*output_ptr++ = (UINT8) lcode) == 0xff) ? *output_ptr++ = 0; ? lcode = data; ? bitindex =

z i g z a g 压 缩 算 法( 2 0 2 0) 

output_ptr;}-*DCTforOneblock(8x8)*-staticvoidDCT(INT16*data){?UINT16i;?INT32x0,x1,x2,x3,x4,x5,x6,x7,x8;?-*?Allvaluesareshiftedleftby10?androundedofftonearestinte
推荐度:
点击下载文档文档为doc格式
4qrhw3xvcy0a6ri16ozy38gut0xt46013rd
领取福利

微信扫码领取福利

微信扫码分享