欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOCX文档下载  

    将JPEG文件转换为BMP文件.docx

    • 资源ID:3448892       资源大小:41.44KB        全文页数:30页
    • 资源格式: DOCX        下载积分:6.99金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要6.99金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    将JPEG文件转换为BMP文件.docx

    将JPEG文件转换为BMP文件#include &ltstdio.h&gt#include &ltmalloc.h&gt#include &ltmath.h&gt#include &ltstdlib.h&gt#define PI 3.1415927 #define widthbytes(i) (i+31)/32*4) int sampleYH,sampleYV,sampleUH,sampleUV,sampleVH,sampleVV; int HYtoU,VYtoU,HYtoV,VYtoV,YinMCU,UinMCU,VinMCU; int compressnum=0,Qt364,*YQt,*UQt,*VQt,codepos416,codelen416; unsigned char compressindex3,YDCindex,YACindex,UVDCindex,UVACindex; unsigned char HufTabindex,And9=0,1,3,7,0xf,0x1f,0x3f,0x7f,0xff; unsigned int codevalue4256,hufmax416,hufmin416; int bitpos=0,curbyte=0,run=0,value=0,MCUbuffer10*64,blockbuffer64; int ycoef=0,ucoef=0,vcoef=0,intervalflag=0,interval=0,restart=0; long Y4*64,U4*64,V4*64,QtZMCUbuffer10*64; unsigned long imgwidth=0,imgheight=0,width=0,height=0,linebytes; int Z88=0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42, 3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53, 10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60, 21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63; struct unsigned char type2; long size; long reserved; long offset; head; struct long size; long width; long height; int plane; int bitcount; long compression; long imagesize; long xpels; long ypels; long colorused; long colorimportant; bmp; void error(char *s) printf("%sn",s); exit(1); void makebmpheader(FILE *fp) int i,j; unsigned long colorbits,imagebytes; colorbits=24; linebytes=widthbytes(colorbits*imgwidth); imagebytes=(unsigned long)imgheight*linebytes; head.type0='B'head.type1='M' head.size=imagebytes+0x36; head.reserved=0; head.offset=0x36; fwrite(&head,sizeof(head),1,fp); bmp.size=0x28; bmp.width=(long)imgwidth; bmp.height=(long)imgheight; bmp.plane=1L; bmp.bitcount=colorbits; pression=0; bmp.imagesize=imagebytes; bmp.xpels=0xece; bmp.ypels=0xec4; bmp.colorused=0; bmp.colorimportant=0; fwrite(&bmp,sizeof(bmp),1,fp); for(j=0;j&ltimgheight;j+) for(i=0;i&ltlinebytes;i+) fputc(0,fp); void initialize(FILE *fp) unsigned char *p,*q,hfindex,qtindex,number; int i,j,k,finish=0,huftab1,huftab2,huftabindex,count; unsigned int length,flag; fread(&flag,sizeof(unsigned int),1,fp); if(flag!=0xd8ff) error("Error Jpg File format!"); while(!finish) fread(&flag,sizeof(unsigned int),1,fp); fread(&length,sizeof(int),1,fp); length=(length&lt&lt8)|(length&gt&gt8)-2; switch(flag) case 0xe0ff: fseek(fp,length,1);break; case 0xdbff: p=malloc(length); fread(p,length,1,fp); qtindex=(*p)&0x0f; q=p+1; if(length+2&lt80) for(i=0;i&lt64;i+) Qtqtindexi=(int)*(q+); else for(i=0;i&lt64;i+) Qtqtindexi=(int)*(q+); qtindex=*(q+)&0x0f; for(i=0;i&lt64;i+) Qtqtindexi=(int)*(q+); free(p);break; case 0xc0ff: p=malloc(length); fread(p,length,1,fp); imgheight=(*(p+1)&lt&lt8)+(*(p+2); imgwidth=(*(p+3)&lt&lt8)+(*(p+4); compressnum=*(p+5); if(compressnum!=1)&&(compressnum!=3) error("Error Jpg File format!"); if(compressnum=3) compressindex0=*(p+6); sampleYH=(*(p+7)&gt&gt4; sampleYV=(*(p+7)&0x0f; YQt=(int *)Qt*(p+8); compressindex1=*(p+9); sampleUH=(*(p+10)&gt&gt4; sampleUV=(*(p+10)&0x0f; UQt=(int *)Qt*(p+11); compressindex2=*(p+12); sampleVH=(*(p+13)&gt&gt4; sampleVV=(*(p+13)&0x0f; VQt=(int *)Qt*(p+14); else compressindex0=*(p+6); sampleYH=(*(p+7)&gt&gt4; sampleYV=(*(p+7)&0x0f; YQt=(int *)Qt*(p+8); compressindex1=*(p+6); sampleUH=1; sampleUV=1; UQt=(int *)Qt*(p+8); compressindex2=*(p+6); sampleVH=1; sampleVV=1; VQt=(int *)Qt*(p+8); free(p);break; case 0xc4ff: p=malloc(length+1); fread(p,length,1,fp); plength=0xff; if(length+2&lt0xd0) huftab1=(int)(*p)&gt&gt4; huftab2=(int)(*p)&0x0f; huftabindex=huftab1*2+huftab2; q=p+1; for(i=0;i&lt16;i+) codelenhuftabindexi=(int)(*(q+); j=0; for(i=0;i&lt16;i+) if(codelenhuftabindexi!=0) k=0; while(k&ltcodelenhuftabindexi) codevaluehuftabindexk+j=(int)(*(q+); k+; j+=k; i=0; while(codelenhuftabindexi=0) i+; for(j=0;j&lti;j+) hufminhuftabindexj=0; hufmaxhuftabindexj=0; hufminhuftabindexi=0; hufmaxhuftabindexi=codelenhuftabindexi-1; for(j=i+1;j&lt16;j+) hufminhuftabindexj=(hufmaxhuftabindexj-1+1)&lt&lt1; hufmaxhuftabindexj=hufminhuftabindexj+codelenhuftabindexj-1; codeposhuftabindex0=0; for(j=1;j&lt16;j+) codeposhuftabindexj=codelenhuftabindexj-1+codeposhuftabindexj-1; else hfindex=*p; while(hfindex!=0xff) huftab1=(int)hfindex&gt&gt4; huftab2=(int)hfindex&0x0f; huftabindex=huftab1*2+huftab2; q=p+1; count=0; for(i=0;i&lt16;i+) codelenhuftabindexi=(int)(*(q+); count+=codelenhuftabindexi; count+=17; j=0; for(i=0;i&lt16;i+) if(codelenhuftabindexi!=0) k=0; while(k&ltcodelenhuftabindexi) codevaluehuftabindexk+j=(int)(*(q+); k+; j+=k; i=0; while(codelenhuftabindexi=0) i+; for(j=0;j&lti;j+) hufminhuftabindexj=0; hufmaxhuftabindexj=0; hufminhuftabindexi=0; hufmaxhuftabindexi=codelenhuftabindexi-1; for(j=i+1;j&lt16;j+) hufminhuftabindexj=(hufmaxhuftabindexj-1+1)&lt&lt1; hufmaxhuftabindexj=hufminhuftabindexj+codelenhuftabindexj-1; codeposhuftabindex0=0; for(j=1;j&lt16;j+) codeposhuftabindexj=codelenhuftabindexj-1+codeposhuftabindexj-1; p+=count; hfindex=*p; p-=length; free(p);break; case 0xddff: p=malloc(length); fread(p,length,1,fp); restart=(*p)&lt&lt8)|(*(p+1); free(p);break; case 0xdaff: p=malloc(length*sizeof(unsigned char); fread(p,length,1,fp); number=*p; if(number!=compressnum) error("Error Jpg File format!"); q=p+1; for(i=0;i&ltcompressnum;i+) if(*q=compressindex0) YDCindex=(*(q+1)&gt&gt4; YACindex=(*(q+1)&0x0f)+2; else UVDCindex=(*(q+1)&gt&gt4; UVACindex=(*(q+1)&0x0f)+2; q+=2; finish=1; free(p);break; case 0xd9ff: error("Error Jpg File format!");break; default: if(flag&0xf000)!=0xd000) fseek(fp,length,1); break; void savebmp(FILE *fp) int i,j; unsigned char r,g,b; long y,u,v,rr,gg,bb; for(i=0;i&ltsampleYV*8;i+) if(height+i)&ltimgheight) fseek(fp,(unsigned long)(imgheight-height-i-1)*linebytes+3*width+54,0); for(j=0;j&ltsampleYH*8;j+) if(width+j)&ltimgwidth) y=Yi*8*sampleYH+j; u=U(i/VYtoU)*8*sampleYH+j/HYtoU; v=V(i/VYtoV)*8*sampleYH+j/HYtoV; /*rr=y+(359*v)&gt&gt8;gg=y-(88*u-183*v)&gt&gt8);bb=(y&lt&lt8)+301*u)&gt&gt8; */rr=(long)(y+1.402*v);gg=(long)(y-0.34414*u-0.71414*v);bb=(long)(y+1.772*u);r=(unsigned char)rr; g=(unsigned char)gg; b=(unsigned char)bb; if(rr&0xffffff00) if (rr&gt255) r=255; else if (rr&lt0) r=0; if(gg&0xffffff00) if (gg&gt255) g=255; else if (gg&lt0) g=0; if(bb&0xffffff00) if (bb&gt255) b=255; else if (bb&lt0) b=0; fputc(b,fp);fputc(g,fp);fputc(r,fp); else break; else break; unsigned char readbyte(FILE *fp) unsigned char c; c=fgetc(fp); if(c=0xff) fgetc(fp); bitpos=8; curbyte=c; return c; int DecodeElement(FILE *fp) int codelength; long thiscode,tempcode; unsigned int temp,new; unsigned char hufbyte,runsize,tempsize,sign; unsigned char newbyte,lastbyte; if(bitpos&gt=1) bitpos-; thiscode=(unsigned char)curbyte&gt&gtbitpos; curbyte=curbyte&Andbitpos; else lastbyte=readbyte(fp); bitpos-; newbyte=curbyte&Andbitpos; thiscode=lastbyte&gt&gt7; curbyte=newbyte; codelength=1; while(thiscode&lthufminHufTabindexcodelength-1)| (codelenHufTabindexcodelength-1=0)| (thiscode&gthufmaxHufTabindexcodelength-1) if(bitpos&gt=1) bitpos-; tempcode=(unsigned char)curbyte&gt&gtbitpos; curbyte=curbyte&Andbitpos; else lastbyte=readbyte(fp); bitpos-; newbyte=curbyte&Andbitpos; tempcode=(unsigned char)lastbyte&gt&gt7; curbyte=newbyte; thiscode=(thiscode&lt&lt1)+tempcode; codelength+; if(codelength&gt16) error("Error Jpg File format!"); temp=thiscode-hufminHufTabindexcodelength-1+codeposHufTabindexcodelength-1; hufbyte=(unsigned char)codevalueHufTabindextemp; run=(int)(hufbyte&gt&gt4); runsize=hufbyte&0x0f; if(runsize=0) value=0; return 1; tempsize=runsize; if(bitpos&gt=runsize) bitpos-=runsize; new=(unsigned char)curbyte&gt&gtbitpos; curbyte=curbyte&Andbitpos; else new=curbyte; tempsize-=bitpos; while(tempsize&gt8) lastbyte=readbyte(fp); new=(new&lt&lt8)+(unsigned char)lastbyte; tempsize-=8; lastbyte=readbyte(fp); bitpos-=tempsize; new=(new&lt&lttempsize)+(lastbyte&gt&gtbitpos); curbyte=lastbyte&Andbitpos; sign=new&gt&gt(runsize-1); if(sign) value=new; else new=new0xffff; temp=0xffff&lt&ltrunsize; value=-(int)(newtemp); return 1; int HufBlock(FILE *fp,unsigned char dchufindex, unsigned char achufindex) int i,count=0; HufTabindex=dchufindex; if(DecodeElement(fp)!=1) return 0; blockbuffercount+=value; HufTabindex=achufindex; while (count&lt64) if(DecodeElement(fp)!=1) return 0; if(run=0)&&(value=0) for(i=count;i&lt64;i+) blockbufferi=0; count=64; else for(i=0;i&ltrun;i+) blockbuffercount+=0; blockbuffercount+=value; return 1; int DecodeMCUBlock(FILE *fp) int i,j,*pMCUBuffer; if(intervalflag) fseek(fp,2,1); ycoef=ucoef=vcoef=0; bitpos=0; curbyte=0; switch(compressnum) case 3: pMCUBuffer=MCUbuffer; for(i=0;i&ltsampleYH*sampleYV;i+) if(HufBlock(fp,YDCindex,YACindex)!=1) return 0; blockbuffer0=blockbuffer0+ycoef; ycoef=blockbuffer0; for(j=0;j&lt64;j+) *pMCUBuffer+=blockbufferj; for(i=0;i&ltsampleUH*sampleUV;i+) if(HufBlock(fp,UVDCindex,UVACindex)!=1) return 0; blockbuffer0=blockbuffer0+ucoef; ucoef=blockbuffer0; for(j=0;j&lt64;j+) *pMCUBuffer+=blockbufferj; for(i=0;i&ltsampleVH*sampleVV;i+) if(HufBlock(fp,UVDCindex,UVACindex)!=1) return 0; blockbuffer0=blockbuffer0+vcoef; vcoef=blockbuffer0; for(j=0;j&lt64;j+) *pMCUBuffer+=blockbufferj; break; case 1: pMCUBuffer=MCUbuffer; if(HufBlock(fp,YDCindex,YACindex)!=1) return 0; blockbuffer0=blockbuffer0+ycoef; ycoef=blockbuffer0; for(j=0;j&lt64;j+) *pMCUBuffer+=blockbufferj; for(i=0;i&lt128;i+) *pMCUBuffer+=0; break; default: error("Error Jpg File format"); return(1); void idct(long *p,int k) long x,x0,x1,x2,x3,x4,x5,x6,x7; x1=pk*4&lt&lt11;x2=pk*6;x3=pk*2;x4=pk*1; x5=pk*7;x6=pk*5;x7=pk*3;x0=(p0&lt&lt11)+1024; x=565*(x4+x5);x4=x+2276*x4;x5=x-3406*x5; x=2408*(x6+x7);x6=x-799*x6;x7=x-4017*x7; x=1108*(x3+x2);x2=x-3784*x2;x3=x+1568*x3; x=x6;x6=x5+x7;x5-=x7;x7=x0+x1;x0-=x1;x1=x+x4;x4-=x; x=x5;x5=x7-x3;x7+=x3;x3=x0+x2;x0-=x2; x2=(181*(x4+x)+128)&gt&gt8;x4=(181*(x4-x)+128)&gt&gt8; p0=(x7+x1)&gt&gt11;pk*1=(x3+x2)&gt&gt11; pk*2=(x0+x4)&gt&gt11;pk*3=(x5+x6)&gt&gt11; pk*4=(x5-x6)&gt&gt11;pk*5=(x0-x4)&gt&gt11; pk*6=(x3-x2)&gt&gt11;pk*7=(x7-x1)&gt&gt11; void IDCTint(long *metrix) int i; for(i=0;i&lt8;i+) idct(metrix+8*i,1); for(i=0;i&lt8;i+) idct(metrix+i,8); void IQtZBlock(int *s,long *d,int *pQt,int correct) int i,j,tag; long *pbuffer,buffer88; for(i=0;i&lt8;i+) for(j=0;j&lt8;j+) tag=Zij; bufferij=(long)stag*(long)pQttag; pbuffer=(long *)buffer; IDCTint(pbuffer); for(i=0;i&lt8;i+) for(j=0;j&lt8;j+) di*8+j=(bufferij&gt&gt3)+correct; void IQtZMCU(int xx,int yy,int offset,int *pQt,int correct) int i,j,*pMCUBuffer; long *pQtZMCUBuffer; pMCUBuffer=MCUbuffer+offset; pQtZMCUBuffer=QtZMCUbuffer+offset; for(i=0;i&ltyy;i+) for(j=0;j&ltxx;j+) IQtZBlock(pMCUBuffer+(i*xx+j)*64,pQtZMCUBuffer+(i*xx+j)*64,pQt,correct); void getYUV(int xx,int yy,long *buf,int offset) int i,j,k,n; long *pQtZMCU; pQtZMCU=QtZMCUbuffer+offset; for(i=0;i&ltyy;i+) for(j=0;j&ltxx;j+) for(k=0;k&lt8;k+) for(n=0;n&lt8;n+) buf(i*8+k)*sampleYH*8+j*8+n=*pQtZMCU+; void decode(FILE *fp1,FILE *fp2) int Yinbuf,Uinbuf,Vinbuf; YinMCU=sampleYH*sampleYV; UinMCU=sampleUH*sampleUV; VinMCU=sampleVH*sampleVV; HYtoU=sampleYH/sampleUH; VYtoU=sampleYV/sampleUV; HYtoV=sampleYH/sampleVH; VYtoV=sampleYV/sampleVV; Yinbuf=0;Uinbuf=YinMCU*64; Vinbuf=(YinMCU+UinMCU)*64; while(DecodeMCUBlock(fp1) interval+; if(restart)&&(interval%restart=0) intervalflag=1; else intervalflag=0; IQtZMCU(sampleYH,sampleYV,Yinbuf,YQt,128); IQtZMCU(sampleUH,sampleUV,Uinbuf,UQt,0); IQtZMCU(sampleVH,sampleVV,Vinbuf,VQt,0); getYUV(sampleYH,sampleYV,Y,Yinbuf); getYUV(sampleUH,sampleUV,U,Uinbuf); getYUV(sampleVH,sampleVV,V,Vinbuf); savebmp(fp2); width+=sampleYH*8; if(width&gt=imgwidth) width=0; height+=sampleYV*8; if(width=0)&&(h

    注意事项

    本文(将JPEG文件转换为BMP文件.docx)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开