小弟我在将JPG转换成BMP过程中,有一个函数不懂,哪位能给指教一下
我在将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;
short SampRate_Y_H,SampRate_Y_V;
short SampRate_U_H,SampRate_U_V;
short SampRate_V_H,SampRate_V_V;
short H_YtoU,V_YtoU,H_YtoV,V_YtoV;
short Y_in_MCU,U_in_MCU,V_in_MCU;
unsigned char *lpJpegBuf;
unsigned char *lp;
short qt_table[3][64];
short comp_num;
BYTE comp_index[3];
BYTE YDcIndex,YAcIndex,UVDcIndex,UVAcIndex;
BYTE HufTabIndex;
short *YQtTable,*UQtTable,*VQtTable;
BYTE And[9]={0,1,3,7,0xf,0x1f,0x3f,0x7f,0xff};
short code_pos_table[4][16],code_len_table[4][16];
unsigned short code_value_table[4][256];
unsigned short huf_max_value[4][16],huf_min_value[4][16];
short BitPos,CurByte;
short rrun,vvalue;
short MCUBuffer[10*64];
int QtZzMCUBuffer[10*64];
short BlockBuffer[64];
short ycoef,ucoef,vcoef;
BOOL IntervalFlag;
short interval=0;
int Y[4*64],U[4*64],V[4*64];
DWORD sizei,sizej;
short restart;
static long iclip[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文件。
#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;
short SampRate_Y_H,SampRate_Y_V;
short SampRate_U_H,SampRate_U_V;
short SampRate_V_H,SampRate_V_V;
short H_YtoU,V_YtoU,H_YtoV,V_YtoV;
short Y_in_MCU,U_in_MCU,V_in_MCU;
unsigned char *lpJpegBuf;
unsigned char *lp;
short qt_table[3][64];
short comp_num;
BYTE comp_index[3];
BYTE YDcIndex,YAcIndex,UVDcIndex,UVAcIndex;
BYTE HufTabIndex;
short *YQtTable,*UQtTable,*VQtTable;
BYTE And[9]={0,1,3,7,0xf,0x1f,0x3f,0x7f,0xff};
short code_pos_table[4][16],code_len_table[4][16];
unsigned short code_value_table[4][256];
unsigned short huf_max_value[4][16],huf_min_value[4][16];
short BitPos,CurByte;
short rrun,vvalue;
short MCUBuffer[10*64];
int QtZzMCUBuffer[10*64];
short BlockBuffer[64];
short ycoef,ucoef,vcoef;
BOOL IntervalFlag;
short interval=0;
int Y[4*64],U[4*64],V[4*64];
DWORD sizei,sizej;
short restart;
static long iclip[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文件。