⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpeg.h

📁 JPEG解压软件,包含PC端的测试程序,程序结构比较清晰
💻 H
字号:

#ifndef _JPEG_EXP_H
#define _JPEG_EXP_H

#include "AMStream.h"
/*
* The return information for function JPG_Decompress and JPG_GetInfo.
*/

#define ERROR_FREE					0
#define NO_ENOUGH_MEMORY			-1
#define IMAGE_BUFFER_TOO_SMALL		-2
#define READ_IMAGE_ERROR			-3
#define UNKNOW_THIS_FORMAT_ERROR	-4
#define DECODE_JPEG_HUFFMAN_ERROR	-5
#define INPUT_IMAGE_SIZE_ERROR		-6


/*
* To JPEG library, we maybe will provide different version with different functions to appication.
* By this way, we can reduce the code size and remove the unuseful code from appication. At current stage,
* we define the following four versions:
*/
#define JPG_VERSION_RB //only read features, basic version, not support EXIF, JPEG2000 and so on
#define JPG_VERSION_RE //only read features, extend version,support EXIF, JPEG2000 and so on
#define JPG_VERSION_RWB //support read/write features, basic version, not support EXIF, JPEG2000 and so on
#define JPG_VERSION_RWE //support read/write features, extend version,support EXIF, JPEG2000 and so on

/*
 *In this library, a callback function is used for feedback the image data when decompress( read image file ) 
 *The following is a sample code of this callback function.
	
struct MyCallbackParam { 
	HANDLE hDib ; 
	MByte * pDib ; 
}

MBool JPEG_Decompress_CallBack ( LPJPG_CALLBACK_PARAM pCallBackParam) 
{
	// check the input parameter
	if( NULL==pCallBackParam ) 
		return FALSE ; 
	 
	struct MyCallbackParam *  pParam = (struct MyCallbackParam *)pCallBackParam->lUserParam ; 

	if( pCallBackParam->lStatus&JPG_CALLBACK_INIT)
	{
		//allocate the Dib memory and initialize it. 

		pParam->hDib = NewDib( pCallBackParam->lOutWidth , pCallBackParam->lOutHeight ) ; 
		if(NULL==pParam->hDib )
			return FALSE ; 
		pParam->pDib = ::GlobalLock( pParam->hDib) ; 
		if(NULL==pParam->pDib )
			return FALSE ; 
	}

	if( pCallBackParam->lStatus&JPG_CALLBACK_RETURNIMGDATA) 
	{ 
		//do display

		//re-modify the point of buffer 
		next call need the buffer size is: pCallBackParam->nextLineCount * pCallBackParam->lLineBytes ;
	}

	if( pCallBackParam->lStatus&JPG_CALLBACK_END )
	{
		//unlock the buffer 
		if( pParam->pDib ) 
			::GlobalUnlock(  pParam->hDib ) ; 
	}

	if( IsAbort( ) ) 
		return FALSE ; 

	return TRUE ; 
}

void main( ) 
{
	struct MyCallbackParam cbp ; 
	memset ( &cbp, 0 , sizeof(  struct MyCallbackParam ) ) ; 
	JPG_Decompress( 
		"c:\\", "test.jpeg", 0, 0, 
		JPEG_Decompress_CallBack,FALSE, 
		&cbp ) ;
	if( cbp.hDib) 
		::GlobalFree(cbp.hDib) ; 
}
 
*/

#define JPG_CALLBACK_INIT			0x00000001  
#define JPG_CALLBACK_RETURNIMGDATA	0x00000002
#define JPG_CALLBACK_END            0x00000004

#define RELEASE_VERSION

#ifdef __cplusplus
extern "C" {
#endif


// for test
#ifndef RELEASE_VERSION

extern int CT_List[16]; 

#endif

// The struct of decompress call back function 
// 
typedef struct _tagJPG_CALLBACK_PROC_PARAM {
	MLong lStatus ;  // from decompress to call back function.
					 // specifies the current status of decompress callback function, 
					 // this parameter can be a combination of the following value,
					 //  JPG_CALLBACK_INIT
					 //  JPG_CALLBACK_RETURNIMGDATA
					 //  JPG_CALLBACK_END
	
	MByte *pBuffer ; // from call back function to decompress.
	                 // the buffer of decompress image data, 
					 // NOTES: It is the caller's responsibility to allocate and free this buffer 
					 // in the callback function. The caller should specified the buffer to this parameter

	MLong nextBufferSize ;// from call back function to decompress, can be changed in JPG_CALLBACK_INIT and JPG_CALLBACK_RETURNIMGDATA,
	                      //recoder the buffer size for next step decode. 
						  // from decompress to call back function , must be used in JPG_CALLBACK_INIT, 
						  //recoder the min buffer size for decode. 

	MLong lLineBytes ;  // from decompress to call back function, only set befor JPG_CALLBACK_INIT, don't change in other status.
	                    //the bytes of one scan line
						// only available when JPG_CALLBACK_INIT and JPG_CALLBACK_RETURNIMGDATA has been setted to lStatus

	MLong lStartLine ;  // from decompress to call back function, changed in JPG_CALLBACK_INIT and JPG_CALLBACK_RETURNIMGDATA
	                    //the start scan line of returned image block 
						// only available when JPG_CALLBACK_RETURNIMGDATA has been setted to lStatus

	MLong lLineCount ;  // from decompress to call back function, changed in JPG_CALLBACK_INIT and JPG_CALLBACK_RETURNIMGDATA
	                    //the number of scan line in the decompress image data buffer. 
						// only available when JPG_CALLBACK_RETURNIMGDATA has been setted to lStatus

	MLong lOutWidth ;   // from decompress to call back function, only set befor JPG_CALLBACK_INIT, don't change in other status.
	                    // the actual width of decompress image after resample 
						// only available when JPG_CALLBACK_INIT and JPG_CALLBACK_RETURNIMGDATA has been setted to lStatus

	MLong lOutHeight ;  // from decompress to call back function,, only set befor JPG_CALLBACK_INIT, don't change in other status.
	                    // the actual height of decompress image after resample 
						// only available when JPG_CALLBACK_INIT and JPG_CALLBACK_RETURNIMGDATA has been setted to lStatus

	MLong colorBits ;   // from decompress to call back function,, only set befor JPG_CALLBACK_INIT, don't change in other status.
	                    //==8 or ==24
						// only available when JPG_CALLBACK_INIT and JPG_CALLBACK_RETURNIMGDATA has been setted to lStatus

	MLong lUserParam ;  //the user parameter specified by caller 

} JPG_CALLBACK_PARAM , * LPJPG_CALLBACK_PARAM ; 


typedef MBool ( *ARCSOFT_JPEG_CALLBACK_PROC )( LPJPG_CALLBACK_PARAM pCallBackParam ) ;


typedef struct tagJpegInfo
{
	MLong	lWidth;			//jpeg image width.
	MLong	lHeight;			//jpeg image height.
	
	MLong	colorBits;			//==8 or ==24

	MLong   lSubFormat;         // EIXF or JPEG2000 and so on, 
								// NOTES: this parameter is available only 
								//in the JPG_VERSION_RE and JPG_VERSION_RWE version.
						  
} JPG_INFO, * LPJPG_INFO;

//===========================================================================================
//interface functions 

/*
	This function is used for decompress a specified dimension DIB from a specified JPEG file. 
	This function use the callback function to feedback the image data
Parameter:
	stream_handle: 	in, the jpeg image stream.
	lOutWidth :        in, the expected width of out image, Zero value to return the real width 
	lOutHeight:        in, the expected height of out image, Zero value to return the real height
	lpProc:			in, the call back function, written by application.
	bReadThumbnail: in, try to read the image from thumbnail data in the file
					    NOTES: this parameter is available only in the JPG_VERSION_RE and JPG_VERSION_RWE version.

	lUserParam:		in, the user data used by lpProc function.
Return:
	if the decompress success, this function return 0, other value is a error code of failure.
*/
MLong JPG_Decompress( HMSTREAM stream_handle, MLong lOutWidth, MLong lOutHeight, 
					 ARCSOFT_JPEG_CALLBACK_PROC lpProc,MBool bReadThumbnail, MLong lUserParam);


/*
	This function is used for getting the information of specified JPEG file
Parameter
	stream_handle: 	in, the jpeg image stream.
	pJpgInfo: 		out,if the imageData is a jpeg image, so this structure save width and height of the jpeg, 
Return:
	if the decompress success, this function return 0, other value is a error code of failure.    				
*/
MLong	JPG_GetInfo( HMSTREAM stream_handle, LPJPG_INFO pJpgInfo ) ;

#ifdef __cplusplus
}
#endif

#endif /* _JPEG_EXP_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -