summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.cpp114
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.h10
2 files changed, 49 insertions, 75 deletions
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.cpp b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
index 280b647ebd..f7c9f6544d 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.cpp
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.cpp
@@ -708,8 +708,8 @@ void CCodec_ProgressiveDecoder::ResampleVertBT(
}
}
-bool CCodec_ProgressiveDecoder::BmpDetectImageType(CFX_DIBAttribute* pAttribute,
- uint32_t size) {
+bool CCodec_ProgressiveDecoder::BmpDetectImageTypeInBuffer(
+ CFX_DIBAttribute* pAttribute) {
CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
if (!pBmpModule) {
m_status = FXCODEC_STATUS_ERR_MEMORY;
@@ -718,18 +718,8 @@ bool CCodec_ProgressiveDecoder::BmpDetectImageType(CFX_DIBAttribute* pAttribute,
std::unique_ptr<CCodec_BmpModule::Context> pBmpContext =
pBmpModule->Start(this);
- if (!pBmpContext) {
- m_status = FXCODEC_STATUS_ERR_MEMORY;
- return false;
- }
+ pBmpModule->Input(pBmpContext.get(), {m_pSrcBuf.get(), m_SrcSize});
- if (!m_pFile->ReadBlock(m_pSrcBuf.get(), 0, size)) {
- m_status = FXCODEC_STATUS_ERR_READ;
- return false;
- }
-
- m_offSet += size;
- pBmpModule->Input(pBmpContext.get(), {m_pSrcBuf.get(), size});
std::vector<uint32_t> palette;
int32_t readResult = pBmpModule->ReadHeader(
pBmpContext.get(), &m_SrcWidth, &m_SrcHeight, &m_BmpIsTopBottom,
@@ -936,21 +926,15 @@ bool CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
return true;
}
-bool CCodec_ProgressiveDecoder::GifDetectImageType(CFX_DIBAttribute* pAttribute,
- uint32_t size) {
+bool CCodec_ProgressiveDecoder::GifDetectImageTypeInBuffer(
+ CFX_DIBAttribute* pAttribute) {
CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
if (!pGifModule) {
m_status = FXCODEC_STATUS_ERR_MEMORY;
return false;
}
m_pGifContext = pGifModule->Start(this);
- bool bResult = m_pFile->ReadBlock(m_pSrcBuf.get(), 0, size);
- if (!bResult) {
- m_status = FXCODEC_STATUS_ERR_READ;
- return false;
- }
- m_offSet += size;
- pGifModule->Input(m_pGifContext.get(), {m_pSrcBuf.get(), size});
+ pGifModule->Input(m_pGifContext.get(), {m_pSrcBuf.get(), m_SrcSize});
m_SrcComponents = 1;
CFX_GifDecodeStatus readResult = pGifModule->ReadHeader(
m_pGifContext.get(), &m_SrcWidth, &m_SrcHeight, &m_GifPltNumber,
@@ -1158,21 +1142,15 @@ bool CCodec_ProgressiveDecoder::JpegReadMoreData(CCodec_JpegModule* pJpegModule,
return true;
}
-bool CCodec_ProgressiveDecoder::JpegDetectImageType(
- CFX_DIBAttribute* pAttribute,
- uint32_t size) {
+bool CCodec_ProgressiveDecoder::JpegDetectImageTypeInBuffer(
+ CFX_DIBAttribute* pAttribute) {
CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
m_pJpegContext = pJpegModule->Start();
if (!m_pJpegContext) {
m_status = FXCODEC_STATUS_ERR_MEMORY;
return false;
}
- if (!m_pFile->ReadBlock(m_pSrcBuf.get(), 0, size)) {
- m_status = FXCODEC_STATUS_ERR_READ;
- return false;
- }
- m_offSet += size;
- pJpegModule->Input(m_pJpegContext.get(), m_pSrcBuf.get(), size);
+ pJpegModule->Input(m_pJpegContext.get(), m_pSrcBuf.get(), m_SrcSize);
// Setting jump marker before calling ReadHeader, since a longjmp to
// the marker indicates a fatal error.
if (setjmp(*m_pJpegContext->GetJumpMark()) == -1) {
@@ -1370,8 +1348,8 @@ void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz(
}
}
-bool CCodec_ProgressiveDecoder::PngDetectImageType(CFX_DIBAttribute* pAttribute,
- uint32_t size) {
+bool CCodec_ProgressiveDecoder::PngDetectImageTypeInBuffer(
+ CFX_DIBAttribute* pAttribute) {
CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
if (!pPngModule) {
m_status = FXCODEC_STATUS_ERR_MEMORY;
@@ -1382,15 +1360,8 @@ bool CCodec_ProgressiveDecoder::PngDetectImageType(CFX_DIBAttribute* pAttribute,
m_status = FXCODEC_STATUS_ERR_MEMORY;
return false;
}
- bool bResult = m_pFile->ReadBlock(m_pSrcBuf.get(), 0, size);
- if (!bResult) {
- m_status = FXCODEC_STATUS_ERR_READ;
- return false;
- }
-
- m_offSet += size;
- bResult =
- pPngModule->Input(m_pPngContext.get(), m_pSrcBuf.get(), size, pAttribute);
+ bool bResult = pPngModule->Input(m_pPngContext.get(), m_pSrcBuf.get(),
+ m_SrcSize, pAttribute);
while (bResult) {
uint32_t remain_size = static_cast<uint32_t>(m_pFile->GetSize()) - m_offSet;
uint32_t input_size =
@@ -1414,7 +1385,6 @@ bool CCodec_ProgressiveDecoder::PngDetectImageType(CFX_DIBAttribute* pAttribute,
bResult = pPngModule->Input(m_pPngContext.get(), m_pSrcBuf.get(),
input_size, pAttribute);
}
- ASSERT(!bResult);
m_pPngContext.reset();
if (m_SrcPassNumber == 0) {
m_status = FXCODEC_STATUS_ERR_FORMAT;
@@ -1515,9 +1485,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::PngContinueDecode() {
#endif // PDF_ENABLE_XFA_PNG
#ifdef PDF_ENABLE_XFA_TIFF
-bool CCodec_ProgressiveDecoder::TiffDetectImageType(
- CFX_DIBAttribute* pAttribute,
- uint32_t size) {
+bool CCodec_ProgressiveDecoder::TiffDetectImageTypeFromFile(
+ CFX_DIBAttribute* pAttribute) {
CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
if (!pTiffModule) {
m_status = FXCODEC_STATUS_ERR_FORMAT;
@@ -1684,37 +1653,42 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::TiffContinueDecode() {
bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType,
CFX_DIBAttribute* pAttribute) {
+#ifdef PDF_ENABLE_XFA_TIFF
+ if (imageType == FXCODEC_IMAGE_TIFF)
+ return TiffDetectImageTypeFromFile(pAttribute);
+#endif // PDF_ENABLE_XFA_TIFF
+
+ size_t size = std::min<size_t>(m_pFile->GetSize(), FXCODEC_BLOCK_SIZE);
+ m_SrcSize = static_cast<uint32_t>(size);
+ m_pSrcBuf.reset(FX_Alloc(uint8_t, m_SrcSize));
+
m_offSet = 0;
- uint32_t size = (uint32_t)m_pFile->GetSize();
- if (size > FXCODEC_BLOCK_SIZE) {
- size = FXCODEC_BLOCK_SIZE;
- }
- m_pSrcBuf.reset(FX_Alloc(uint8_t, size));
- memset(m_pSrcBuf.get(), 0, size);
- m_SrcSize = size;
- switch (imageType) {
- case FXCODEC_IMAGE_JPG:
- return JpegDetectImageType(pAttribute, size);
+ if (!m_pFile->ReadBlock(m_pSrcBuf.get(), m_offSet, m_SrcSize)) {
+ m_status = FXCODEC_STATUS_ERR_READ;
+ return false;
+ }
+ m_offSet += m_SrcSize;
+
+ if (imageType == FXCODEC_IMAGE_JPG)
+ return JpegDetectImageTypeInBuffer(pAttribute);
+
#ifdef PDF_ENABLE_XFA_BMP
- case FXCODEC_IMAGE_BMP:
- return BmpDetectImageType(pAttribute, size);
+ if (imageType == FXCODEC_IMAGE_BMP)
+ return BmpDetectImageTypeInBuffer(pAttribute);
#endif // PDF_ENABLE_XFA_BMP
+
#ifdef PDF_ENABLE_XFA_GIF
- case FXCODEC_IMAGE_GIF:
- return GifDetectImageType(pAttribute, size);
+ if (imageType == FXCODEC_IMAGE_GIF)
+ return GifDetectImageTypeInBuffer(pAttribute);
#endif // PDF_ENABLE_XFA_GIF
+
#ifdef PDF_ENABLE_XFA_PNG
- case FXCODEC_IMAGE_PNG:
- return PngDetectImageType(pAttribute, size);
+ if (imageType == FXCODEC_IMAGE_PNG)
+ return PngDetectImageTypeInBuffer(pAttribute);
#endif // PDF_ENABLE_XFA_PNG
-#ifdef PDF_ENABLE_XFA_TIFF
- case FXCODEC_IMAGE_TIFF:
- return TiffDetectImageType(pAttribute, size);
-#endif // PDF_ENABLE_XFA_TIFF
- default:
- m_status = FXCODEC_STATUS_ERR_FORMAT;
- return false;
- }
+
+ m_status = FXCODEC_STATUS_ERR_FORMAT;
+ return false;
}
FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h
index 1f72d9f044..87bf18411d 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.h
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.h
@@ -184,7 +184,7 @@ class CCodec_ProgressiveDecoder :
bool BmpReadMoreData(CCodec_BmpModule* pBmpModule,
CCodec_BmpModule::Context* pBmpContext,
FXCODEC_STATUS& err_status);
- bool BmpDetectImageType(CFX_DIBAttribute* pAttribute, uint32_t size);
+ bool BmpDetectImageTypeInBuffer(CFX_DIBAttribute* pAttribute);
FXCODEC_STATUS BmpStartDecode(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
FXCODEC_STATUS BmpContinueDecode();
#endif // PDF_ENABLE_XFA_BMP
@@ -192,7 +192,7 @@ class CCodec_ProgressiveDecoder :
#ifdef PDF_ENABLE_XFA_GIF
bool GifReadMoreData(CCodec_GifModule* pGifModule,
FXCODEC_STATUS& err_status);
- bool GifDetectImageType(CFX_DIBAttribute* pAttribute, uint32_t size);
+ bool GifDetectImageTypeInBuffer(CFX_DIBAttribute* pAttribute);
FXCODEC_STATUS GifStartDecode(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
FXCODEC_STATUS GifContinueDecode();
void GifDoubleLineResampleVert(const RetainPtr<CFX_DIBitmap>& pDeviceBitmap,
@@ -202,7 +202,7 @@ class CCodec_ProgressiveDecoder :
bool JpegReadMoreData(CCodec_JpegModule* pJpegModule,
FXCODEC_STATUS& err_status);
- bool JpegDetectImageType(CFX_DIBAttribute* pAttribute, uint32_t size);
+ bool JpegDetectImageTypeInBuffer(CFX_DIBAttribute* pAttribute);
FXCODEC_STATUS JpegStartDecode(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
FXCODEC_STATUS JpegContinueDecode();
@@ -211,13 +211,13 @@ class CCodec_ProgressiveDecoder :
int32_t dest_line,
uint8_t* src_scan,
FXCodec_Format src_format);
- bool PngDetectImageType(CFX_DIBAttribute* pAttribute, uint32_t size);
+ bool PngDetectImageTypeInBuffer(CFX_DIBAttribute* pAttribute);
FXCODEC_STATUS PngStartDecode(const RetainPtr<CFX_DIBitmap>& pDIBitmap);
FXCODEC_STATUS PngContinueDecode();
#endif // PDF_ENABLE_XFA_PNG
#ifdef PDF_ENABLE_XFA_TIFF
- bool TiffDetectImageType(CFX_DIBAttribute* pAttribute, uint32_t size);
+ bool TiffDetectImageTypeFromFile(CFX_DIBAttribute* pAttribute);
FXCODEC_STATUS TiffContinueDecode();
#endif // PDF_ENABLE_XFA_TIFF