jpg转bmp c语言 linux,怎么用C语言将jpg格式的图片转换成bmp格式的图片

C/C++ code#include

#include

#include

#include

#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,Qt[3][64],*YQt,*UQt,*VQt,codepos[4][16],codelen[4][16];

unsigned char compressindex[3],YDCindex,YACindex,UVDCindex,UVACindex;

unsigned char HufTabindex,And[9]={0,1,3,7,0xf,0x1f,0x3f,0x7f,0xff};

unsigned int codevalue[4][256],hufmax[4][16],hufmin[4][16];

int bitpos=0,curbyte=0,run=0,value=0,MCUbuffer[10*64],blockbuffer[64];

int ycoef=0,ucoef=0,vcoef=0,intervalflag=0,interval=0,restart=0;

long Y[4*64],U[4*64],V[4*64],QtZMCUbuffer[10*64];

unsigned long imgwidth=0,imgheight=0,width=0,height=0,linebytes;

int Z[8][8]={{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 type[2];

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("%s\n",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.type[0]='B';head.type[1]='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;

bmp.compression=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

for(i=0;i

fputc(0,fp);

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值