我在将JPG转换成BMP过程中,有一个函数不懂,哪位能给指教一下?
#include "bmp.h"
#include "jpeg.h"
#include "memory.h"
#include "math.h"
#include "stdio.h"
#define WIDTHBYTES(i) ((i+31)/32*4)
#define PI 3.1415926535
#define FUNC_OK 0
#define FUNC_MEMORY_ERROR 1
#define FUNC_FILE_ERROR 2
#define FUNC_FORMAT_ERROR 3
BOOL LoadJpegFile(char *BmpFileName);
void showerror(int funcret);
int InitTag();
void InitTable();
int Decode();
int DecodeMCUBlock();
int HufBlock(unsigned char dchufindex,unsigned char achufindex);
int DecodeElement();
void IQtIZzMCUComponent(short flag);
void IQtIZzBlock(short *s ,int * d,short flag);
void GetYUV(short flag);
void StoreBuffer();
BYTE ReadByte();
void Initialize_Fast_IDCT();
void Fast_IDCT(int * block);
void idctrow(int * blk);
void idctcol(int * blk);
BITMAPFILEHEADER bf;
BITMAPINFOHEADER bi;
HBITMAP hBitmap=NULL;
HGLOBAL hImgData=NULL;
DWORD NumColors;
DWORD LineBytes;
DWORD ImgWidth=0 , ImgHeight=0;
unsigned int PcxBytesPerLine;
LPSTR lpPtr;
shortSampRate_Y_H,SampRate_Y_V;
shortSampRate_U_H,SampRate_U_V;
shortSampRate_V_H,SampRate_V_V;
shortH_YtoU,V_YtoU,H_YtoV,V_YtoV;
shortY_in_MCU,U_in_MCU,V_in_MCU;
unsigned char *lpJpegBuf;
unsigned char *lp;
shortqt_table[3][64];
shortcomp_num;
BYTEcomp_index[3];
BYTE YDcIndex,YAcIndex,UVDcIndex,UVAcIndex;
BYTEHufTabIndex;
short *YQtTable,*UQtTable,*VQtTable;
BYTEAnd[9]={0,1,3,7,0xf,0x1f,0x3f,0x7f,0xff};
short code_pos_table[4][16],code_len_table[4][16];
unsigned shortcode_value_table[4][256];
unsigned shorthuf_max_value[4][16],huf_min_value[4][16];
shortBitPos,CurByte;
shortrrun,vvalue;
shortMCUBuffer[10*64];
intQtZzMCUBuffer[10*64];
shortBlockBuffer[64];
shortycoef,ucoef,vcoef;
BOOLIntervalFlag;
shortinterval=0;
intY[4*64],U[4*64],V[4*64];
DWORD sizei,sizej;
short restart;
static longiclip[1024];
static long*iclp;
char s[80];
int LoadJpegFile (char *JpegFileName)
{
HFILE hfjpg;
DWORD ImgSize;
DWORD BufSize,JpegBufSize;
HFILE hfbmp;
HGLOBAL hJpegBuf;
int funcret,i;
LPBITMAPINFOHEADER lpImgData;
if((hfjpg=_lopen(JpegFileName,OF_READ))==HFILE_ERROR)
{
showerror(FUNC_FILE_ERROR);
return 0;
}
JpegBufSize=_llseek(hfjpg,0L,SEEK_END);
_llseek(hfjpg,0L,SEEK_SET);
if((hJpegBuf=GlobalAlloc(GHND,JpegBufSize))==NULL)
{
_lclose(hfjpg);
showerror(FUNC_MEMORY_ERROR);
return 0;
}
lpJpegBuf=(unsigned char *)GlobalLock(hJpegBuf);
_hread(hfjpg,(unsigned char *)lpJpegBuf,JpegBufSize);
_lclose(hfjpg);
[解决办法]
其实主要功能都写在LoadJpegFile里面了。将Jpeg格式的文件数据读取出来,然后根据BMP文件的格式填充BMP文件。