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);
}