#include "jpegDecoder.h"
#include "decolor.h"
#include "deHuffman.h"
#include "idct.h"
#include "sample.h"
// for test
#ifndef RELEASE_VERSION
#include <windows.h>
int CT_List[16] ;
int CT_Temp ;
int nIndex = 0 ;
#define CountTime_Start() { \
CT_Temp = GetTickCount() ; \
}
#define CountTime_End(nIndex) { \
CT_List[nIndex] += GetTickCount()-CT_Temp ; \
}
#else
#define CountTime_Start()
#define CountTime_End(nIndex)
#endif
/////////////////////////////////////////////
/////////////////////////////////////////////
#ifdef _PALM_OS_
#include "CallBack.h"
extern EmulStateRef g_emulStateP ;
#define CALL_CALLBACK_FUNCTION( lpProc , pCallbackParam ) Call68KFunction( g_emulStateP, lpProc , pCallbackParam )
#else
#define CALL_CALLBACK_FUNCTION( lpProc , pCallbackParam ) lpProc( pCallbackParam )
#endif
#ifdef __WIN32__
#define BitsRoundTo4Bytes(bits) (((bits) + 31) / 32 * 4)
#endif
/////////
int GetInfo(JPEG_HANDLE *hJpeg, HMSTREAM pStream, LPJPG_INFO pJpgInfo) ;
int OpenFileAndGetInfo( JPEG_HANDLE *hJpeg, HMSTREAM stream_handle );
int getColorLimitTable( JPEG_HANDLE *hJpeg ) ;
void InitHuffmanVar( JPEG_HANDLE *hJpeg ) ;
int InitResampleVar( JPEG_HANDLE *hJpeg, int lWidth, int lHeight ) ;
int hJpegInit( JPEG_HANDLE **hJpeg, HMSTREAM stream_handle, MLong *lWidth, MLong *lHeight ) ;
int huffmanDecodeInfoInit( JPEG_HANDLE *hJpeg, HUFFMAN_QT_DECODER_INFO ** pDecoderInfo ) ;
int colorInfoInit( JPEG_HANDLE *hJpeg, DECOLOR_PARAM ** pDecolorParam, JPG_CALLBACK_PARAM *pCallbackParam, int lWidth ) ;
int callbackInfoInit(JPG_CALLBACK_PARAM **pCallbackParam, JPEG_HANDLE *hJpeg, int lWidth, int lHeight, MLong lUserParam ) ;
#define Resample( addrW, addrH, inData, outData, lineBytes, LineCount, lWidth ) {\
{\
if ( LineCount >= 0 ) {\
int i = LineCount ;\
MByte * inDatax = inData ;\
MByte * outDatax = outData ;\
MShort * addrHx = addrH ;\
while (-- i >= 0 ) {\
register MByte * out = outDatax ;\
register MByte * in = inDatax + ( * addrHx ++ ) * lineBytes;\
register MShort * addrWx = addrW ;\
register int j = lWidth ; \
while( --j >= 0 )\
* out ++ = in[ * addrWx ++ ] ;\
outDatax += lWidth ;\
}\
}\
}\
}
/////////
MLong JPG_GetInfo( HMSTREAM stream_handle, LPJPG_INFO pJpgInfo ) {
JPEG_HANDLE *hJpeg ;
int releaseReturn = READ_JPEG_OK ;
hJpeg = ( JPEG_HANDLE * ) AMMemAlloc ( MNull, sizeof ( JPEG_HANDLE ) ) ;
if ( !hJpeg )
return NO_ENOUGH_MEMORY ;
AMMemSet( hJpeg, 0 , sizeof ( JPEG_HANDLE ) ) ;
if ( !stream_handle ) {
releaseReturn = READ_IMAGE_ERROR ;
goto releaseBuffer1 ;
}
if ( ( hJpeg -> fileSize = AMStreamGetSize(stream_handle) ) <= 0 ) {
releaseReturn = READ_IMAGE_ERROR ;
goto releaseBuffer1 ;
}
releaseReturn = GetInfo(hJpeg, stream_handle, pJpgInfo) ;
releaseBuffer1:
releaseJpegHandle( hJpeg ) ;
return releaseReturn ;
}
///////////////////////////////////////////////////
MLong JPG_Decompress(HMSTREAM stream_handle, MLong lOutWidth, MLong lOutHeight,
ARCSOFT_JPEG_CALLBACK_PROC lpProc, MBool bReadThumbnail, MLong lUserParam) {
int releaseReturn = READ_JPEG_OK ;
MLong lWidth = lOutWidth ;
MLong lHeight = lOutHeight ;
/***************** used by hJpegInit *****************/
JPEG_HANDLE *hJpeg = MNull ;
/*********** used by huffmanDecodeInfoInit ***********/
HUFFMAN_QT_DECODER_INFO * pDecoderInfo = MNull ;
/************** used by callbackInfoInit *************/
LPJPG_CALLBACK_PARAM pCallbackParam = MNull ;
/**************** used by colorInfoInit **************/
LPDECOLOR_PARAM pDecolorParam = MNull ;
int StripsForCallback = 0 ;
if (stream_handle == MNull)
return READ_IMAGE_ERROR ;
if ( ( releaseReturn = hJpegInit( &hJpeg, stream_handle, &lWidth, &lHeight ) ) != READ_JPEG_OK )
goto releaseReturn3 ;
if ( ( releaseReturn = huffmanDecodeInfoInit( hJpeg, &pDecoderInfo ) ) != READ_JPEG_OK )
goto releaseReturn3 ;
if ( ( releaseReturn = callbackInfoInit(&pCallbackParam, hJpeg, lWidth, lHeight, lUserParam ) ) != READ_JPEG_OK )
goto releaseReturn3 ;
if ( !CALL_CALLBACK_FUNCTION( lpProc , pCallbackParam ) ) {
releaseReturn = NO_ENOUGH_MEMORY;
goto releaseReturn3;
}
if ( ( releaseReturn = colorInfoInit( hJpeg, &pDecolorParam, pCallbackParam, lWidth ) ) != READ_JPEG_OK )
goto releaseReturn3 ;
{
int stripsCount = 0 ;
int offset = 0 ;
int lastHeight = 0 ;
int runx = READ_JPEG_OK ;
int nResampledSize, nValidHigh, nDecodedWidth[3] ;
int nCurWidth = 0 ;
int nCurHeight = 0 ;
int YinHigh = 0 ;
int CinHigh = 0 ;
int Height = hJpeg -> pInfo -> Height ;
int Width = hJpeg -> pInfo -> Width ;
MShort * CresamleAddrH ;
MShort * CresamleAddrW ;
MShort * CnewHBegin ;
MShort * CnewHEnd ;
int *WideSamp = &( hJpeg -> pInfo -> WideSamp[0] ) ;
int *HighSamp = &( hJpeg -> pInfo -> HighSamp[0] ) ;
int oneMcuWidth = WideSamp[0] << 3 ;
int oneMcuHigh = HighSamp[0] << 3 ;
int nLineMCUCount = ( Width + oneMcuWidth - 1 ) >> (WideSamp[0]+2) ;
MBool bTerminated = MFalse ;
MByte *pYBuf, *pCbBuf, *pCrBuf, *pYResampled, *pCbResampled, *pCrResampled ;
MByte *index[3] ;
int YOneMcuBlockNumber = ( WideSamp[0] * HighSamp[0] ) << 6 ;
int COneMcuBlockNumber = ( WideSamp[1] * HighSamp[1] ) << 6 ;
int OneMcuBufferLen = ( YOneMcuBlockNumber + (COneMcuBlockNumber<<1) ) * sizeof(int) ;
int imageNewSize = 3 * lWidth * lHeight ;
int resetCount = hJpeg->pInfo->ResetLen;
#ifdef __WIN32__
int nExtra = BitsRoundTo4Bytes(lWidth*24) - lWidth*3 ;
#endif
float rateW = (float)Width/(float)lWidth;
float rateH = (float)Height/(float)lHeight;
int idctTag;
if (rateW < rateH)
rateW = rateH;
if (rateW < 1.7)
idctTag = 0;
else if (rateW < 3.5)
idctTag = 1;
else if (rateW < 7.0)
idctTag = 2;
else
idctTag = 3;
if (pCallbackParam->nextBufferSize >= imageNewSize ) {
StripsForCallback = Height / oneMcuHigh;
}
else {
StripsForCallback = (Height * pCallbackParam->nextBufferSize) / (oneMcuHigh * imageNewSize);
{
long l = oneMcuHigh * lHeight;
long n = (l * 1000) / Height;
long m = n / 1000;
if ((n - m * 1000) > 0) {
if (m > 0)
StripsForCallback -= 2 ;
else
StripsForCallback -= (Height +l - 1) / l + 1 ;
}
}
}
if (StripsForCallback <= 0) {
if (oneMcuHigh > lHeight) {
if (pCallbackParam->nextBufferSize >= ((lHeight * imageNewSize + Height - 1) / Height))
StripsForCallback = 1 ;
else {
releaseReturn = IMAGE_BUFFER_TOO_SMALL;
goto releaseReturn3;
}
}
else if (pCallbackParam->nextBufferSize >= ((oneMcuHigh * imageNewSize + Height - 1) / Height))
StripsForCallback = 1 ;
else {
releaseReturn = IMAGE_BUFFER_TOO_SMALL;
goto releaseReturn3;
}
}
pDecolorParam -> outRGB = pCallbackParam -> pBuffer ;
nDecodedWidth[0] = ((Width + (WideSamp[0]<<3)-1) >> (WideSamp[0]+2)) << (WideSamp[0]+2) ;
nDecodedWidth[2] = nDecodedWidth[1] = nDecodedWidth[0]>>(WideSamp[0]-1) ;
if ( HighSamp[0] == 2 ) {
CnewHBegin = hJpeg -> newH2Begin ;
CnewHEnd = hJpeg -> newH2End ;
CresamleAddrH = hJpeg -> resamleAddrH2 ;
}
else {
CnewHBegin = hJpeg -> newHBegin ;
CnewHEnd = hJpeg -> newHEnd ;
CresamleAddrH = hJpeg -> resamleAddrH ;
}
if ( WideSamp[0] == 2 )
CresamleAddrW = hJpeg -> resamleAddrW2 ;
else
CresamleAddrW = hJpeg -> resamleAddrW ;
pYBuf = ( MByte * )AMMemAlloc(MNull, YOneMcuBlockNumber * nLineMCUCount ) ;
pCbBuf = ( MByte * )AMMemAlloc(MNull, COneMcuBlockNumber * nLineMCUCount ) ;
pCrBuf = ( MByte * )AMMemAlloc(MNull, COneMcuBlockNumber * nLineMCUCount ) ;
nResampledSize = lWidth * oneMcuHigh;
pYResampled = (MByte*)AMMemAllo
JPEG.rar_jpeg解压
版权申诉
74 浏览量
2022-09-24
13:54:40
上传
评论
收藏 138KB RAR 举报
JaniceLu
- 粉丝: 79
- 资源: 1万+
最新资源
- Picasso_v3.1 2.ipa
- chromedriver-mac-arm64.zip
- 蓝zapro.apk
- chromedriver-linux64.zip
- UCAS研一深度学习实验-MNIST手写数字识别python源码+详细注释(高分项目)
- 基于Python和PyTorch框架完成的一个手写数字识别实验源码(带MINIST手写数字数据集)+详细注释(高分项目)
- 基于Matlab在MNIST数据集上利用CNN完成手写体数字识别任务,并实现单层CNN反向传播算法+源代码+文档说明(高分项目)
- NVIDIA驱动、CUDA和Pytorch及其依赖
- 基于SVM多特征融合的微表情识别python源码+项目说明+详细注释(高分课程设计)
- html动态爱心代码一(附源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈