ImageVerifierCode 换一换
格式:DOCX , 页数:34 ,大小:23.82KB ,
资源ID:11389089      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11389089.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(BMP图片转JPEG图片C程序源代码.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

BMP图片转JPEG图片C程序源代码.docx

1、BMP图片转JPEG图片C程序源代码/ A BMP truecolor to JPEG encoder/ Copyright 1999 Cristian Cuturicu#include #include #include #include jtypes.h#include jglobals.h#include jtables.hvoid write_APP0info()/Nothing to overwrite for APP0info writeword(APP0info.marker); writeword(APP0info.length); writebyte(J); writebyt

2、e(F); writebyte(I); writebyte(F); writebyte(0); writebyte(APP0info.versionhi); writebyte(APP0info.versionlo); writebyte(APP0info.xyunits); writeword(APP0info.xdensity); writeword(APP0info.ydensity); writebyte(APP0info.thumbnwidth); writebyte(APP0info.thumbnheight);void write_SOF0info()/ We should ov

3、erwrite width and height writeword(SOF0info.marker); writeword(SOF0info.length); writebyte(SOF0info.precision); writeword(SOF0info.height); writeword(SOF0info.width); writebyte(SOF0info.nrofcomponents); writebyte(SOF0info.IdY); writebyte(SOF0info.HVY); writebyte(SOF0info.QTY); writebyte(SOF0info.IdC

4、b); writebyte(SOF0info.HVCb); writebyte(SOF0info.QTCb); writebyte(SOF0info.IdCr); writebyte(SOF0info.HVCr); writebyte(SOF0info.QTCr);void write_DQTinfo() BYTE i; writeword(DQTinfo.marker); writeword(DQTinfo.length); writebyte(DQTinfo.QTYinfo); for (i=0; i64; i+) writebyte(DQTinfo.Ytablei); writebyte

5、(DQTinfo.QTCbinfo); for (i=0; i64; i+) writebyte(DQTinfo.Cbtablei);void set_quant_table(BYTE *basic_table, BYTE scale_factor, BYTE *newtable)/ Set quantization table and zigzag reorder it BYTE i; long temp; for (i=0; i64; i+) temp = (long) basic_tablei * scale_factor + 50L) / 100L; / limit the value

6、s to the valid range if (temp 255L) temp = 255L; newtablezigzagi = (BYTE) temp; void set_DQTinfo() BYTE scalefactor = 50;/ scalefactor controls the visual quality of the image / the smaller is the better image well get, and the smaller / compression well achieve DQTinfo.marker = 0xFFDB; DQTinfo.leng

7、th = 132; DQTinfo.QTYinfo = 0; DQTinfo.QTCbinfo = 1; set_quant_table(std_luminance_qt, scalefactor, DQTinfo.Ytable); set_quant_table(std_chrominance_qt, scalefactor, DQTinfo.Cbtable);void write_DHTinfo() BYTE i; writeword(DHTinfo.marker); writeword(DHTinfo.length); writebyte(DHTinfo.HTYDCinfo); for

8、(i=0; i16; i+) writebyte(DHTinfo.YDC_nrcodesi); for (i=0; i12; i+) writebyte(DHTinfo.YDC_valuesi); writebyte(DHTinfo.HTYACinfo); for (i=0; i16; i+) writebyte(DHTinfo.YAC_nrcodesi); for (i=0; i162; i+) writebyte(DHTinfo.YAC_valuesi); writebyte(DHTinfo.HTCbDCinfo); for (i=0; i16; i+) writebyte(DHTinfo

9、.CbDC_nrcodesi); for (i=0; i12; i+) writebyte(DHTinfo.CbDC_valuesi); writebyte(DHTinfo.HTCbACinfo); for (i=0; i16; i+) writebyte(DHTinfo.CbAC_nrcodesi); for (i=0; i162; i+) writebyte(DHTinfo.CbAC_valuesi);void set_DHTinfo() BYTE i; / fill the DHTinfo structure get the values from the standard Huffma

10、n tables DHTinfo.marker = 0xFFC4; DHTinfo.length = 0x01A2; DHTinfo.HTYDCinfo = 0; for (i=0; i16; i+) DHTinfo.YDC_nrcodesi = std_dc_luminance_nrcodesi+1; for (i=0; i12; i+) DHTinfo.YDC_valuesi = std_dc_luminance_valuesi; DHTinfo.HTYACinfo = 0x10; for (i=0; i16; i+) DHTinfo.YAC_nrcodesi = std_ac_lumin

11、ance_nrcodesi+1; for (i=0; i162; i+) DHTinfo.YAC_valuesi = std_ac_luminance_valuesi; DHTinfo.HTCbDCinfo = 1; for (i=0; i16; i+) DHTinfo.CbDC_nrcodesi = std_dc_chrominance_nrcodesi+1; for (i=0; i12; i+) DHTinfo.CbDC_valuesi = std_dc_chrominance_valuesi; DHTinfo.HTCbACinfo = 0x11; for (i=0; i16; i+) D

12、HTinfo.CbAC_nrcodesi = std_ac_chrominance_nrcodesi+1; for (i=0; i162; i+) DHTinfo.CbAC_valuesi = std_ac_chrominance_valuesi;void write_SOSinfo()/Nothing to overwrite for SOSinfo writeword(SOSinfo.marker); writeword(SOSinfo.length); writebyte(SOSinfo.nrofcomponents); writebyte(SOSinfo.IdY); writebyte

13、(SOSinfo.HTY); writebyte(SOSinfo.IdCb); writebyte(SOSinfo.HTCb); writebyte(SOSinfo.IdCr); writebyte(SOSinfo.HTCr); writebyte(SOSinfo.Ss); writebyte(SOSinfo.Se); writebyte(SOSinfo.Bf);void write_comment(BYTE *comment) WORD i, length; writeword(0xFFFE); / The COM marker length = strlen(const char *)co

14、mment); writeword(length + 2); for (i=0; ilength; i+) writebyte(commenti);void writebits(bitstring bs)/ A portable version; it should be done in assembler WORD value; SBYTE posval;/ bit position in the bitstring we read, should be =0 value = bs.value; posval = bs.length - 1; while (posval = 0) if (v

15、alue & maskposval) bytenew |= maskbytepos; posval-; bytepos-; if (bytepos 0) / write it if (bytenew = 0xFF) / special case writebyte(0xFF); writebyte(0); else writebyte(bytenew); / reinit bytepos = 7; bytenew = 0; void compute_Huffman_table(BYTE *nrcodes, BYTE *std_table, bitstring *HT) BYTE k,j; BY

16、TE pos_in_table; WORD codevalue; codevalue = 0; pos_in_table = 0; for (k=1; k=16; k+) for (j=1; j=nrcodesk; j+) HTstd_tablepos_in_table.value = codevalue; HTstd_tablepos_in_table.length = k; pos_in_table+; codevalue+; codevalue = 1; void init_Huffman_tables() / Compute the Huffman tables used for en

17、coding compute_Huffman_table(std_dc_luminance_nrcodes, std_dc_luminance_values, YDC_HT); compute_Huffman_table(std_ac_luminance_nrcodes, std_ac_luminance_values, YAC_HT); compute_Huffman_table(std_dc_chrominance_nrcodes, std_dc_chrominance_values, CbDC_HT); compute_Huffman_table(std_ac_chrominance_n

18、rcodes, std_ac_chrominance_values, CbAC_HT);void exitmessage(char *error_message) printf(%sn,error_message); exit(EXIT_FAILURE);void set_numbers_category_and_bitcode() SDWORD nr; SDWORD nrlower, nrupper; BYTE cat; category_alloc = (BYTE *)malloc(65535*sizeof(BYTE); if (category_alloc = NULL) exitmes

19、sage(Not enough memory.); /allow negative subscripts category = category_alloc + 32767; bitcode_alloc=(bitstring *)malloc(65535*sizeof(bitstring); if (bitcode_alloc=NULL) exitmessage(Not enough memory.); bitcode = bitcode_alloc + 32767; nrlower = 1; nrupper = 2; for (cat=1; cat=15; cat+) /Positive n

20、umbers for (nr=nrlower; nrnrupper; nr+) categorynr = cat; bitcodenr.length = cat; bitcodenr.value = (WORD)nr; /Negative numbers for (nr=-(nrupper-1); nr=-nrlower; nr+) categorynr = cat; bitcodenr.length = cat; bitcodenr.value = (WORD)(nrupper-1+nr); nrlower = 1; nrupper = 1; void precalculate_YCbCr_

21、tables() WORD R,G,B; for (R=0; R256; R+) YRtabR = (SDWORD)(65536*0.299+0.5)*R; CbRtabR = (SDWORD)(65536*-0.16874+0.5)*R; CrRtabR = (SDWORD)(32768)*R; for (G=0; G256; G+) YGtabG = (SDWORD)(65536*0.587+0.5)*G; CbGtabG = (SDWORD)(65536*-0.33126+0.5)*G; CrGtabG = (SDWORD)(65536*-0.41869+0.5)*G; for (B=0

22、; B256; B+) YBtabB = (SDWORD)(65536*0.114+0.5)*B; CbBtabB = (SDWORD)(32768)*B; CrBtabB = (SDWORD)(65536*-0.08131+0.5)*B; / Using a bit modified form of the FDCT routine from IJGs C source:/ Forward DCT routine idea taken from Independent JPEG Groups C source for/ JPEG encoders/decoders/* For float A

23、A&N IDCT method, divisors are equal to quantization coefficients scaled by scalefactorrow*scalefactorcol, where scalefactor0 = 1 scalefactork = cos(k*PI/16) * sqrt(2) for k=1.7 We apply a further scale factor of 8. Whats actually stored is 1/divisor so that the inner loop can use a multiplication ra

24、ther than a division. */void prepare_quant_tables() double aanscalefactor8 = 1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 0.785694958, 0.541196100, 0.275899379; BYTE row, col; BYTE i = 0; for (row = 0; row 8; row+) for (col = 0; col 8; col+) fdtbl_Yi = (float) (1.0 / (double) DQTinfo.Ytablezigza

25、gi * aanscalefactorrow * aanscalefactorcol * 8.0); fdtbl_Cbi = (float) (1.0 / (double) DQTinfo.Cbtablezigzagi * aanscalefactorrow * aanscalefactorcol * 8.0); i+; void fdct_and_quantization(SBYTE *data, float *fdtbl, SWORD *outdata) float tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; float tmp10, t

26、mp11, tmp12, tmp13; float z1, z2, z3, z4, z5, z11, z13; float *dataptr; float datafloat64; float temp; SBYTE ctr; BYTE i; for (i=0; i= 0; ctr-) tmp0 = dataptr0 + dataptr7; tmp7 = dataptr0 - dataptr7; tmp1 = dataptr1 + dataptr6; tmp6 = dataptr1 - dataptr6; tmp2 = dataptr2 + dataptr5; tmp5 = dataptr2

27、- dataptr5; tmp3 = dataptr3 + dataptr4; tmp4 = dataptr3 - dataptr4; /* Even part */ tmp10 = tmp0 + tmp3; /* phase 2 */ tmp13 = tmp0 - tmp3; tmp11 = tmp1 + tmp2; tmp12 = tmp1 - tmp2; dataptr0 = tmp10 + tmp11; /* phase 3 */ dataptr4 = tmp10 - tmp11; z1 = (tmp12 + tmp13) * (float) 0.707106781); /* c4 *

28、/ dataptr2 = tmp13 + z1; /* phase 5 */ dataptr6 = 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 =

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1