#if TRACE_QH
fprintf(p_table,\code, code_size);
fflush(p_table); #if TRACE_QH
fprintf(p_table,\ fflush(p_table);
输出DC图像并经过huffman统计其概率分布,输出某一个AC值图像并统计其概率分布。
-* tinyjpeg.h *- FILE *p_dc;--add by xhy FILE *p_ac;--add by xhy short int *dc_Buf;--add by xhy short int *ac_Buf;--add by xhy
void dc_ac_image_write(struct jdec_private *priv, unsigned int xstride, unsigned int ystride);--add by xhy
#define DC_YUV \#define AC_YUV \-* tinyjpeg.c *-
int tinyjpeg_decode(struct jdec_private *priv, int pixfmt) #if TRACE_QH dc_Buf
=
(short
int
*)malloc(sizeof(short
int)*priv-height*priv-width-ystride_by_mcu-xstride_by_mcu);
ac_Buf
=
(short
int
*)malloc(sizeof(short
int)*priv-height*priv-width-ystride_by_mcu-xstride_by_mcu);
-* Just the decode the image by macroblock (size is 8x8, 8x16, or 16x16) *-
for (y=0; y priv-height-ystride_by_mcu; y++) --trace(\
for (x=0; x priv-width; x+=xstride_by_mcu) decode_MCU(priv); #if TRACE_QH
dc_Buf[x-xstride_by_mcu + y*priv-width-xstride_by_mcu] = priv-component_infos[cY].DCT[0];
ac_Buf[x-xstride_by_mcu + y*priv-width-xstride_by_mcu] = priv-component_infos[cY].DCT[1];
convert_to_pixfmt(priv); #if TRACE_QH
dc_ac_image_write(priv, xstride_by_mcu, ystride_by_mcu); free(dc_Buf); free(ac_Buf);
void dc_ac_image_write(struct jdec_private *priv, unsigned int xstride, unsigned int ystride)
short int dc_max, dc_min, ac_max, ac_min;
unsigned char* dc_temp; unsigned char* ac_temp; dc_temp
=
(unsigned
char
*)malloc(priv-height*priv-width-ystride-xstride);
ac_temp
=
(unsigned
char
*)malloc(priv-height*priv-width-ystride-xstride);
dc_max = dc_Buf[0]; dc_min = dc_Buf[0]; ac_max = ac_Buf[0]; ac_min = ac_Buf[0];
for(i=0;ipriv-height*priv-width-ystride-xstride;i++) if(dc_Buf[i] dc_max) dc_max = dc_Buf[i]; if(dc_Buf[i] dc_min) dc_min = dc_Buf[i]; if(ac_Buf[i] ac_max) ac_max = ac_Buf[i]; if(ac_Buf[i] ac_min) ac_min = ac_Buf[i];
for(i=0;ipriv-height*priv-width-ystride-xstride;i++) dc_temp[i] =(unsigned char) 255 * (dc_Buf[i] - dc_min) - (dc_max - dc_min);
ac_temp[i] =(unsigned char) 255 * (ac_Buf[i] - ac_min) - (ac_max - ac_min);
fwrite(dc_temp, 1, priv-height*priv-width-ystride-xstride, p_dc);
fwrite(ac_temp, 1, priv-height*priv-width-ystride-xstride, p_ac);
free(dc_temp); free(ac_temp);
重建DC、AC系数后,其值不在0~255范围内,所以需要将它的值映射到0~255范围内,再作为亮度信息写入输出的YUV文件。
实验结果
实验所用测试图片
以txt文件输出所有的量化矩阵和所有的HUFFMAN码表 输出DC、AC图像并经过huffman编码统计其概率分布 图像类型 输出图像 概率分布图 DCT[0]-DC DCT[1]-AC
(3)无损模式:基于DPCM,保证解码后完全精确恢复到原图像采样值; [-8] = [10001000]原 = [1111 0111]反
Scanner scanner= new Scanner(System.in);
= (00000000_00000000_00000000_00000010)补
可以看出,对于低频部分采用细量化(较小的量化步长),对于高频采用了粗量化(较大的量化步长)
?-- image width?*output_ptr++ = (UINT8) (image_width
8);?*output_ptr++ = (UINT8) image_width;
(1)对每个单独的彩色图像分量,把整个分量图像分成若干个8×8的图像块,如图所示,并作为两维离散余弦变换DCT的输入。通过DCT变换,把能量集中在少数几个系数上。?
dct_amend = log(abs(dctfre) * 5 + 1); % 修正DCT系数以便频谱观察
JPEG采用的是YCrCb颜色空间,而BMP采用的是RGB颜色空间,要想对BMP图片进行压缩,首先需要进行颜色空间的转换。YCrCb颜色空间中,Y代表亮度,U代表饱和度,V代表色度。U,V也可以通称为色度。
43
printf(\
+
host_b[%d]
=
%d
+
%d
= %d\