这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 通讯及无线技术 » jpeg压缩时用到的8*8的fdct代码

共6条 1/1 1 跳转至

jpeg压缩时用到的8*8的fdct代码

菜鸟
2002-09-30 05:12:43     打赏
下面是离散余弦变换代码,是jpeg压缩时用到的8*8的fdct代码,是从一个网站上找到的,可是我看不懂:(书上的余弦变换都是用cos表示出来的,而且是二维的,这里却用行列各一次余弦变换,哪位数字信号处理高手给分析一下吧,谢谢! void fdct_and_quantization(SBYTE *data,SWORD *outdata) { float tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; float tmp10, tmp11, tmp12, tmp13; float z1, z2, z3, z4, z5, z11, z13; float *dataptr; float datafloat[64]; float temp; SBYTE ctr; BYTE i; for (i=0;i<64;i++) datafloat[i]=data[i]; /* Pass 1: process rows. */ dataptr=datafloat; for (ctr = 7; ctr >= 0; ctr--) { tmp0 = dataptr[0] + dataptr[7]; tmp7 = dataptr[0] - dataptr[7]; tmp1 = dataptr[1] + dataptr[6]; tmp6 = dataptr[1] - dataptr[6]; tmp2 = dataptr[2] + dataptr[5]; tmp5 = dataptr[2] - dataptr[5]; tmp3 = dataptr[3] + dataptr[4]; tmp4 = dataptr[3] - dataptr[4]; /* Even part */ tmp10 = tmp0 + tmp3; /* phase 2 */ tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; dataptr[0] = tmp10 + tmp11; /* phase 3 */ dataptr[4] = tmp10 - tmp11; z1 = (tmp12 + tmp13) * ((float) 0.707106781); /* c4 */ dataptr[2] = tmp13 + z1; /* phase 5 */ dataptr[6] = tmp13 - z1; /* Odd part */ tmp10 = tmp4 + tmp5; /* phase 2 */ tmp11 = tmp5 + tmp6; tmp12 = tmp6 + tmp7; /* The rotator is modified from fig 4-8 to avoid extra negations. */ z5 = (tmp10 - tmp12) * ((float) 0.382683433); /* c6 */ z2 = ((float) 0.541196100) * tmp10 + z5; /* c2-c6 */ z4 = ((float) 1.306562965) * tmp12 + z5; /* c2+c6 */ z3 = tmp11 * ((float) 0.707106781); /* c4 */ z11 = tmp7 + z3; /* phase 5 */ z13 = tmp7 - z3; dataptr[5] = z13 + z2; /* phase 6 */ dataptr[3] = z13 - z2; dataptr[1] = z11 + z4; dataptr[7] = z11 - z4; dataptr += 8; /* advance pointer to next row */ } /* Pass 2: process columns. */ dataptr = datafloat; for (ctr = 7; ctr >= 0; ctr--) { tmp0 = dataptr[0] + dataptr[56]; tmp7 = dataptr[0] - dataptr[56]; tmp1 = dataptr[8] + dataptr[48]; tmp6 = dataptr[8] - dataptr[48]; tmp2 = dataptr[16] + dataptr[40]; tmp5 = dataptr[16] - dataptr[40]; tmp3 = dataptr[24] + dataptr[32]; tmp4 = dataptr[24] - dataptr[32]; /* Even part */ tmp10 = tmp0 + tmp3; /* phase 2 */ tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; dataptr[0] = tmp10 + tmp11; /* phase 3 */ dataptr[32] = tmp10 - tmp11; z1 = (tmp12 + tmp13) * ((float) 0.707106781); /* c4 */ dataptr[16] = tmp13 + z1; /* phase 5 */ dataptr[48] = tmp13 - z1; /* Odd part */ tmp10 = tmp4 + tmp5; /* phase 2 */ tmp11 = tmp5 + tmp6; tmp12 = tmp6 + tmp7; /* The rotator is modified from fig 4-8 to avoid extra negations. */ z5 = (tmp10 - tmp12) * ((float) 0.382683433); /* c6 */ z2 = ((float) 0.541196100) * tmp10 + z5; /* c2-c6 */ z4 = ((float) 1.306562965) * tmp12 + z5; /* c2+c6 */ z3 = tmp11 * ((float) 0.707106781); /* c4 */ z11 = tmp7 + z3; /* phase 5 */ z13 = tmp7 - z3; dataptr[40] = z13 + z2; /* phase 6 */ dataptr[24] = z13 - z2; dataptr[8] = z11 + z4; dataptr[56] = z11 - z4; dataptr++; /* advance pointer to next column */ } for (i = 0; i < 64; i++) { outdata[i] = (SWORD) datafloat[i]; } }



关键词: 缩时     用到     代码     float     tmp10     tmp1    

菜鸟
2002-09-30 17:03:00     打赏
2楼
急急急急急急!!!!!

菜鸟
2002-09-30 22:13:00     打赏
3楼
是不是这个问题太简单了,不值得回答:(? 还是这个问题太难了,没人懂哦,嘿嘿?

菜鸟
2002-09-30 22:59:00     打赏
4楼
结果我推出来了,不过和他的有点不一样,我推出的结果是一次8×8fdct变换要20×8=160次乘法,而这个例子里,一次8×8的fdct变换只要5×8=40次,不知其中奥妙在哪儿?

菜鸟
2002-10-09 01:36:00     打赏
5楼
我的分析文档马上就要出来了,到时候我和大家共享一下吧!这文档可花了我好几天时间才搞定的噢!大部分都是公式的推导和变换,挺烦的!

菜鸟
2002-10-09 03:55:00     打赏
6楼
错误再所难免,请高手指点![upload=zip]uploadImages/200210819553495116.zip[/upload]

共6条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]