Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Unified Diff: core/fxcodec/codec/fx_codec_progress.cpp

Issue 2053573003: Clean up fx_codec_tiff.cpp. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: CCodec_ProgressiveDecoder cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fxcodec/codec/ccodec_tiffmodule.h ('k') | core/fxcodec/codec/fx_codec_tiff.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcodec/codec/fx_codec_progress.cpp
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index ec3347cdaac544c1a3904d1d947e82eb7bf335c2..088e75816410449b98d258b502fffaf040c9b075 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -17,6 +17,23 @@
#define FXCODEC_PNG_GAMMA 1.7
#endif
+namespace {
+
+void RGB2BGR(uint8_t* buffer, int width = 1) {
+ if (buffer && width > 0) {
+ uint8_t temp;
+ int i = 0;
+ int j = 0;
+ for (; i < width; i++, j += 3) {
+ temp = buffer[j];
+ buffer[j] = buffer[j + 2];
+ buffer[j + 2] = temp;
+ }
+ }
+}
+
+} // namespace
+
void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len,
int dest_min,
int dest_max,
@@ -24,9 +41,6 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len,
int src_min,
int src_max,
FX_BOOL bInterpol) {
- if (m_pWeightTables) {
- FX_Free(m_pWeightTables);
- }
double scale, base;
scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len;
if (dest_len < 0) {
@@ -38,6 +52,7 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len,
(int)(sizeof(int) * 2 +
sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1));
m_DestMin = dest_min;
+ FX_Free(m_pWeightTables);
m_pWeightTables = FX_Alloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4);
if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) {
@@ -118,15 +133,14 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len,
}
}
}
+
void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len,
int src_len,
FX_BOOL bInterpol) {
- if (m_pWeightTables) {
- FX_Free(m_pWeightTables);
- }
double scale = (double)dest_len / (double)src_len;
m_ItemSize = sizeof(int) * 4;
int size = dest_len * m_ItemSize + 4;
+ FX_Free(m_pWeightTables);
m_pWeightTables = FX_Alloc(uint8_t, size);
FXSYS_memset(m_pWeightTables, 0, size);
if (scale > 1) {
@@ -177,65 +191,66 @@ void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len,
pWeight->m_Weights[1] = 0;
}
}
+
void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len,
int src_len) {
- if (m_pWeightTables) {
- FX_Free(m_pWeightTables);
- }
double scale = (double)dest_len / (double)src_len;
m_ItemSize = sizeof(int) * 4;
int size = dest_len * m_ItemSize + 4;
+ FX_Free(m_pWeightTables);
m_pWeightTables = FX_Alloc(uint8_t, size);
FXSYS_memset(m_pWeightTables, 0, size);
- if (scale > 1) {
- double step = 0.0;
- int src_row = 0;
- while (step < (double)dest_len) {
- int start_step = (int)step;
- step = scale * (++src_row);
- int end_step = (int)step;
- if (end_step >= dest_len) {
- end_step = dest_len;
- for (int des_row = start_step; des_row < end_step; des_row++) {
- PixelWeight* pWeight =
- (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
- pWeight->m_SrcStart = start_step;
- pWeight->m_SrcEnd = start_step;
- pWeight->m_Weights[0] = 65536;
- pWeight->m_Weights[1] = 0;
- }
- return;
- }
- int length = end_step - start_step;
- {
+ if (scale <= 1) {
+ for (int des_row = 0; des_row < dest_len; des_row++) {
+ PixelWeight* pWeight =
+ (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
+ pWeight->m_SrcStart = des_row;
+ pWeight->m_SrcEnd = des_row;
+ pWeight->m_Weights[0] = 65536;
+ pWeight->m_Weights[1] = 0;
+ }
+ return;
+ }
+
+ double step = 0.0;
+ int src_row = 0;
+ while (step < (double)dest_len) {
+ int start_step = (int)step;
+ step = scale * (++src_row);
+ int end_step = (int)step;
+ if (end_step >= dest_len) {
+ end_step = dest_len;
+ for (int des_row = start_step; des_row < end_step; des_row++) {
PixelWeight* pWeight =
- (PixelWeight*)(m_pWeightTables + start_step * m_ItemSize);
+ (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
pWeight->m_SrcStart = start_step;
pWeight->m_SrcEnd = start_step;
pWeight->m_Weights[0] = 65536;
pWeight->m_Weights[1] = 0;
}
- for (int des_row = start_step + 1; des_row < end_step; des_row++) {
- PixelWeight* pWeight =
- (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
- pWeight->m_SrcStart = start_step;
- pWeight->m_SrcEnd = end_step;
- pWeight->m_Weights[0] = FXSYS_round((FX_FLOAT)(end_step - des_row) /
- (FX_FLOAT)length * 65536);
- pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
- }
+ return;
}
- } else {
- for (int des_row = 0; des_row < dest_len; des_row++) {
+ int length = end_step - start_step;
+ {
PixelWeight* pWeight =
- (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
- pWeight->m_SrcStart = des_row;
- pWeight->m_SrcEnd = des_row;
+ (PixelWeight*)(m_pWeightTables + start_step * m_ItemSize);
+ pWeight->m_SrcStart = start_step;
+ pWeight->m_SrcEnd = start_step;
pWeight->m_Weights[0] = 65536;
pWeight->m_Weights[1] = 0;
}
+ for (int des_row = start_step + 1; des_row < end_step; des_row++) {
+ PixelWeight* pWeight =
+ (PixelWeight*)(m_pWeightTables + des_row * m_ItemSize);
+ pWeight->m_SrcStart = start_step;
+ pWeight->m_SrcEnd = end_step;
+ pWeight->m_Weights[0] = FXSYS_round((FX_FLOAT)(end_step - des_row) /
+ (FX_FLOAT)length * 65536);
+ pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
+ }
}
}
+
CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder(
CCodec_ModuleMgr* pCodecMgr) {
m_pFile = nullptr;
@@ -253,7 +268,8 @@ CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder(
m_offSet = 0;
m_SrcSize = 0;
m_ScanlineSize = 0;
- m_SrcWidth = m_SrcHeight = 0;
+ m_SrcWidth = 0;
+ m_SrcHeight = 0;
m_SrcComponents = 0;
m_SrcBPC = 0;
m_SrcPassNumber = 0;
@@ -274,27 +290,24 @@ CCodec_ProgressiveDecoder::CCodec_ProgressiveDecoder(
m_GifFrameRect = FX_RECT(0, 0, 0, 0);
m_BmpIsTopBottom = FALSE;
}
+
CCodec_ProgressiveDecoder::~CCodec_ProgressiveDecoder() {
m_pFile = nullptr;
- if (m_pJpegContext) {
+ if (m_pJpegContext)
m_pCodecMgr->GetJpegModule()->Finish(m_pJpegContext);
- }
- if (m_pPngContext) {
+ if (m_pPngContext)
m_pCodecMgr->GetPngModule()->Finish(m_pPngContext);
- }
- if (m_pGifContext) {
+ if (m_pGifContext)
m_pCodecMgr->GetGifModule()->Finish(m_pGifContext);
- }
- if (m_pBmpContext) {
+ if (m_pBmpContext)
m_pCodecMgr->GetBmpModule()->Finish(m_pBmpContext);
- }
- if (m_pTiffContext) {
+ if (m_pTiffContext)
m_pCodecMgr->GetTiffModule()->DestroyDecoder(m_pTiffContext);
- }
FX_Free(m_pSrcBuf);
FX_Free(m_pDecodeBuf);
FX_Free(m_pSrcPalette);
}
+
FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData(
CCodec_JpegModule* pJpegModule,
FXCODEC_STATUS& err_status) {
@@ -332,6 +345,7 @@ FX_BOOL CCodec_ProgressiveDecoder::JpegReadMoreData(
pJpegModule->Input(m_pJpegContext, m_pSrcBuf, dwSize + dwAvail);
return TRUE;
}
+
FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule,
int width,
int height,
@@ -380,6 +394,7 @@ FX_BOOL CCodec_ProgressiveDecoder::PngReadHeaderFunc(void* pModule,
*gamma = FXCODEC_PNG_GAMMA;
return TRUE;
}
+
FX_BOOL CCodec_ProgressiveDecoder::PngAskScanlineBufFunc(void* pModule,
int line,
uint8_t*& src_buf) {
@@ -454,6 +469,7 @@ FX_BOOL CCodec_ProgressiveDecoder::PngAskScanlineBufFunc(void* pModule,
}
return TRUE;
}
+
void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz(
CFX_DIBitmap* pDeviceBitmap,
int32_t des_line,
@@ -525,6 +541,7 @@ void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz(
}
}
}
+
void CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc(void* pModule,
int pass,
int line) {
@@ -554,6 +571,7 @@ void CCodec_ProgressiveDecoder::PngFillScanlineBufCompletedFunc(void* pModule,
}
}
}
+
FX_BOOL CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
FXCODEC_STATUS& err_status) {
uint32_t dwSize = (uint32_t)m_pFile->GetSize();
@@ -590,6 +608,7 @@ FX_BOOL CCodec_ProgressiveDecoder::GifReadMoreData(CCodec_GifModule* pGifModule,
pGifModule->Input(m_pGifContext, m_pSrcBuf, dwSize + dwAvail);
return TRUE;
}
+
void CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback(
void* pModule,
uint32_t& cur_pos) {
@@ -598,12 +617,14 @@ void CCodec_ProgressiveDecoder::GifRecordCurrentPositionCallback(
pCodec->m_pCodecMgr->GetGifModule()->GetAvailInput(pCodec->m_pGifContext);
cur_pos = pCodec->m_offSet - remain_size;
}
+
uint8_t* CCodec_ProgressiveDecoder::GifAskLocalPaletteBufCallback(
void* pModule,
int32_t frame_num,
int32_t pal_size) {
return FX_Alloc(uint8_t, pal_size);
}
+
FX_BOOL CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback(
void* pModule,
uint32_t rcd_pos,
@@ -693,6 +714,7 @@ FX_BOOL CCodec_ProgressiveDecoder::GifInputRecordPositionBufCallback(
}
return TRUE;
}
+
void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule,
int32_t row_num,
uint8_t* row_buf) {
@@ -723,41 +745,42 @@ void CCodec_ProgressiveDecoder::GifReadScanlineCallback(void* pModule,
int des_top = pCodec->m_startY;
int src_hei = pCodec->m_clipBox.Height();
int des_hei = pCodec->m_sizeY;
- if (line >= src_top && line < src_bottom) {
- double scale_y = (double)des_hei / (double)src_hei;
- int src_row = line - src_top;
- int des_row = (int)(src_row * scale_y) + des_top;
- if (des_row >= des_top + des_hei) {
- return;
- }
- pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
- pCodec->m_SrcFormat);
- if (scale_y > 1.0 &&
- (!pCodec->m_bInterpol || pCodec->m_SrcPassNumber == 1)) {
- pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
- return;
- }
- if (scale_y > 1.0) {
- int des_bottom = des_top + pCodec->m_sizeY;
- int des_Bpp = pDIBitmap->GetBPP() >> 3;
- uint32_t des_ScanOffet = pCodec->m_startX * des_Bpp;
- if (des_row + (int)scale_y >= des_bottom - 1) {
- uint8_t* scan_src =
- (uint8_t*)pDIBitmap->GetScanline(des_row) + des_ScanOffet;
- int cur_row = des_row;
- while (++cur_row < des_bottom) {
- uint8_t* scan_des =
- (uint8_t*)pDIBitmap->GetScanline(cur_row) + des_ScanOffet;
- uint32_t size = pCodec->m_sizeX * des_Bpp;
- FXSYS_memcpy(scan_des, scan_src, size);
- }
- }
- if (bLastPass) {
- pCodec->GifDoubleLineResampleVert(pDIBitmap, scale_y, des_row);
- }
+ if (line < src_top || line >= src_bottom)
+ return;
+
+ double scale_y = (double)des_hei / (double)src_hei;
+ int src_row = line - src_top;
+ int des_row = (int)(src_row * scale_y) + des_top;
+ if (des_row >= des_top + des_hei)
+ return;
+
+ pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
+ pCodec->m_SrcFormat);
+ if (scale_y > 1.0 && (!pCodec->m_bInterpol || pCodec->m_SrcPassNumber == 1)) {
+ pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
+ return;
+ }
+ if (scale_y <= 1.0)
+ return;
+
+ int des_bottom = des_top + pCodec->m_sizeY;
+ int des_Bpp = pDIBitmap->GetBPP() >> 3;
+ uint32_t des_ScanOffet = pCodec->m_startX * des_Bpp;
+ if (des_row + (int)scale_y >= des_bottom - 1) {
+ uint8_t* scan_src =
+ (uint8_t*)pDIBitmap->GetScanline(des_row) + des_ScanOffet;
+ int cur_row = des_row;
+ while (++cur_row < des_bottom) {
+ uint8_t* scan_des =
+ (uint8_t*)pDIBitmap->GetScanline(cur_row) + des_ScanOffet;
+ uint32_t size = pCodec->m_sizeX * des_Bpp;
+ FXSYS_memcpy(scan_des, scan_src, size);
}
}
+ if (bLastPass)
+ pCodec->GifDoubleLineResampleVert(pDIBitmap, scale_y, des_row);
}
+
void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert(
CFX_DIBitmap* pDeviceBitmap,
double scale_y,
@@ -836,12 +859,13 @@ void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert(
GifDoubleLineResampleVert(pDeviceBitmap, scale_y, des_row + (int)scale_y);
}
}
+
FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule,
FXCODEC_STATUS& err_status) {
uint32_t dwSize = (uint32_t)m_pFile->GetSize();
- if (dwSize <= m_offSet) {
+ if (dwSize <= m_offSet)
return FALSE;
- }
+
dwSize = dwSize - m_offSet;
uint32_t dwAvail = pBmpModule->GetAvailInput(m_pBmpContext, nullptr);
if (dwAvail == m_SrcSize) {
@@ -872,18 +896,17 @@ FX_BOOL CCodec_ProgressiveDecoder::BmpReadMoreData(CCodec_BmpModule* pBmpModule,
pBmpModule->Input(m_pBmpContext, m_pSrcBuf, dwSize + dwAvail);
return TRUE;
}
+
FX_BOOL CCodec_ProgressiveDecoder::BmpInputImagePositionBufCallback(
void* pModule,
uint32_t rcd_pos) {
CCodec_ProgressiveDecoder* pCodec = (CCodec_ProgressiveDecoder*)pModule;
pCodec->m_offSet = rcd_pos;
FXCODEC_STATUS error_status = FXCODEC_STATUS_ERROR;
- if (!pCodec->BmpReadMoreData(pCodec->m_pCodecMgr->GetBmpModule(),
- error_status)) {
- return FALSE;
- }
- return TRUE;
+ return pCodec->BmpReadMoreData(pCodec->m_pCodecMgr->GetBmpModule(),
+ error_status);
}
+
void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule,
int32_t row_num,
uint8_t* row_buf) {
@@ -896,25 +919,27 @@ void CCodec_ProgressiveDecoder::BmpReadScanlineCallback(void* pModule,
int des_top = pCodec->m_startY;
int src_hei = pCodec->m_clipBox.Height();
int des_hei = pCodec->m_sizeY;
- if (row_num >= src_top && row_num < src_bottom) {
- double scale_y = (double)des_hei / (double)src_hei;
- int src_row = row_num - src_top;
- int des_row = (int)(src_row * scale_y) + des_top;
- if (des_row >= des_top + des_hei) {
- return;
- }
- pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
- pCodec->m_SrcFormat);
- if (scale_y > 1.0) {
- if (pCodec->m_BmpIsTopBottom || !pCodec->m_bInterpol) {
- pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
- return;
- } else {
- pCodec->ResampleVertBT(pDIBitmap, scale_y, des_row);
- }
- }
+ if (row_num < src_top || row_num >= src_bottom)
+ return;
+
+ double scale_y = (double)des_hei / (double)src_hei;
+ int src_row = row_num - src_top;
+ int des_row = (int)(src_row * scale_y) + des_top;
+ if (des_row >= des_top + des_hei)
+ return;
+
+ pCodec->ReSampleScanline(pDIBitmap, des_row, pCodec->m_pDecodeBuf,
+ pCodec->m_SrcFormat);
+ if (scale_y <= 1.0)
+ return;
+
+ if (pCodec->m_BmpIsTopBottom || !pCodec->m_bInterpol) {
+ pCodec->ResampleVert(pDIBitmap, scale_y, des_row);
+ return;
}
+ pCodec->ResampleVertBT(pDIBitmap, scale_y, des_row);
}
+
void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap,
double scale_y,
int des_row) {
@@ -996,6 +1021,7 @@ void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap,
}
}
}
+
FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
FXCODEC_IMAGE_TYPE imageType,
CFX_DIBAttribute* pAttribute) {
@@ -1063,7 +1089,7 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
}
m_status = FXCODEC_STATUS_ERR_FORMAT;
return FALSE;
- } break;
+ }
case FXCODEC_IMAGE_JPG: {
CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
if (!pJpegModule) {
@@ -1106,7 +1132,7 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
}
m_status = FXCODEC_STATUS_ERR_FORMAT;
return FALSE;
- } break;
+ }
case FXCODEC_IMAGE_PNG: {
CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
if (!pPngModule) {
@@ -1167,7 +1193,7 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
m_status = FXCODEC_STATUS_ERR_FORMAT;
return FALSE;
}
- } break;
+ }
Tom Sepez 2016/06/09 17:53:16 still need a break here, the return above is condi
Lei Zhang 2016/06/09 22:00:40 Whoops.
case FXCODEC_IMAGE_GIF: {
CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
if (!pGifModule) {
@@ -1219,7 +1245,7 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
}
m_status = FXCODEC_STATUS_ERR_FORMAT;
return FALSE;
- } break;
+ }
case FXCODEC_IMAGE_TIF: {
CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
if (!pTiffModule) {
@@ -1231,27 +1257,26 @@ FX_BOOL CCodec_ProgressiveDecoder::DetectImageType(
m_status = FXCODEC_STATUS_ERR_FORMAT;
return FALSE;
}
- int32_t frames = 0;
- pTiffModule->GetFrames(m_pTiffContext, frames);
- uint32_t bpc;
- FX_BOOL ret = pTiffModule->LoadFrameInfo(
- m_pTiffContext, 0, (uint32_t&)m_SrcWidth, (uint32_t&)m_SrcHeight,
- (uint32_t&)m_SrcComponents, bpc, pAttribute);
+ int32_t dummy_bpc;
+ FX_BOOL ret = pTiffModule->LoadFrameInfo(m_pTiffContext, 0, &m_SrcWidth,
+ &m_SrcHeight, &m_SrcComponents,
+ &dummy_bpc, pAttribute);
m_SrcComponents = 4;
m_clipBox = FX_RECT(0, 0, m_SrcWidth, m_SrcHeight);
if (!ret) {
pTiffModule->DestroyDecoder(m_pTiffContext);
- (m_pTiffContext = nullptr);
- (m_status = FXCODEC_STATUS_ERR_FORMAT);
+ m_pTiffContext = nullptr;
+ m_status = FXCODEC_STATUS_ERR_FORMAT;
return FALSE;
}
- } break;
+ return TRUE;
+ }
default:
m_status = FXCODEC_STATUS_ERR_FORMAT;
return FALSE;
}
- return TRUE;
}
+
FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
IFX_FileRead* pFile,
FXCODEC_IMAGE_TYPE imageType,
@@ -1295,32 +1320,26 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
m_pFile = nullptr;
return m_status;
}
+
void CCodec_ProgressiveDecoder::SetClipBox(FX_RECT* clip) {
- if (m_status != FXCODEC_STATUS_FRAME_READY) {
+ if (m_status != FXCODEC_STATUS_FRAME_READY)
return;
- }
+
if (clip->IsEmpty()) {
m_clipBox = FX_RECT(0, 0, 0, 0);
return;
}
- if (clip->left < 0) {
- clip->left = 0;
- }
- if (clip->right > m_SrcWidth) {
- clip->right = m_SrcWidth;
- }
- if (clip->top < 0) {
- clip->top = 0;
- }
- if (clip->bottom > m_SrcHeight) {
- clip->bottom = m_SrcHeight;
- }
+ clip->left = std::max(clip->left, 0);
+ clip->right = std::min(clip->right, m_SrcWidth);
+ clip->top = std::max(clip->top, 0);
+ clip->bottom = std::min(clip->bottom, m_SrcHeight);
if (clip->IsEmpty()) {
m_clipBox = FX_RECT(0, 0, 0, 0);
return;
}
m_clipBox = *clip;
}
+
void CCodec_ProgressiveDecoder::GetDownScale(int& down_scale) {
down_scale = 1;
int ratio_w = m_clipBox.Width() / m_sizeX;
@@ -1344,6 +1363,7 @@ void CCodec_ProgressiveDecoder::GetDownScale(int& down_scale) {
m_clipBox.bottom = m_clipBox.top + 1;
}
}
+
void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format,
FXCodec_Format src_format) {
switch (des_format) {
@@ -1441,18 +1461,7 @@ void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format,
m_TransMethod = -1;
}
}
-void _RGB2BGR(uint8_t* buffer, int width = 1) {
- if (buffer && width > 0) {
- uint8_t temp;
- int i = 0;
- int j = 0;
- for (; i < width; i++, j += 3) {
- temp = buffer[j];
- buffer[j] = buffer[j + 2];
- buffer[j + 2] = temp;
- }
- }
-}
+
void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
int des_line,
uint8_t* src_scan,
@@ -1654,6 +1663,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap,
}
}
}
+
void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap,
double scale_y,
int des_row) {
@@ -1766,6 +1776,7 @@ void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap,
}
}
}
+
void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap,
int32_t src_line,
uint8_t* src_scan,
@@ -1787,6 +1798,7 @@ void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap,
}
}
}
+
FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames,
IFX_Pause* pPause) {
if (!(m_status == FXCODEC_STATUS_FRAME_READY ||
@@ -1799,10 +1811,11 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames,
case FXCODEC_IMAGE_PNG:
case FXCODEC_IMAGE_TIF:
frames = m_FrameNumber = 1;
- return m_status = FXCODEC_STATUS_DECODE_READY;
+ m_status = FXCODEC_STATUS_DECODE_READY;
+ return m_status;
case FXCODEC_IMAGE_GIF: {
CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
- while (TRUE) {
+ while (true) {
int32_t readResult =
pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
while (readResult == 2) {
@@ -1811,26 +1824,29 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames,
return error_status;
}
if (pPause && pPause->NeedToPauseNow()) {
- return m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE;
+ m_status = FXCODEC_STATUS_FRAME_TOBECONTINUE;
+ return m_status;
}
readResult = pGifModule->LoadFrameInfo(m_pGifContext, &m_FrameNumber);
}
if (readResult == 1) {
frames = m_FrameNumber;
- return m_status = FXCODEC_STATUS_DECODE_READY;
+ m_status = FXCODEC_STATUS_DECODE_READY;
+ return m_status;
}
if (m_pGifContext) {
pGifModule->Finish(m_pGifContext);
m_pGifContext = nullptr;
}
- return m_status = FXCODEC_STATUS_ERROR;
+ m_status = FXCODEC_STATUS_ERROR;
+ return m_status;
}
- } break;
+ }
default:
- break;
+ return FXCODEC_STATUS_ERROR;
}
- return FXCODEC_STATUS_ERROR;
}
+
FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
int start_x,
int start_y,
@@ -1846,21 +1862,20 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
return FXCODEC_STATUS_ERR_PARAMS;
}
m_pDeviceBitmap = pDIBitmap;
- if (m_clipBox.IsEmpty()) {
+ if (m_clipBox.IsEmpty())
return FXCODEC_STATUS_ERR_PARAMS;
- }
- if (size_x <= 0 || size_x > 65535 || size_y <= 0 || size_y > 65535) {
+ if (size_x <= 0 || size_x > 65535 || size_y <= 0 || size_y > 65535)
return FXCODEC_STATUS_ERR_PARAMS;
- }
+
FX_RECT device_rc =
FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y);
int32_t out_range_x = device_rc.right - pDIBitmap->GetWidth();
int32_t out_range_y = device_rc.bottom - pDIBitmap->GetHeight();
device_rc.Intersect(
FX_RECT(0, 0, pDIBitmap->GetWidth(), pDIBitmap->GetHeight()));
- if (device_rc.IsEmpty()) {
+ if (device_rc.IsEmpty())
return FXCODEC_STATUS_ERR_PARAMS;
- }
+
m_startX = device_rc.left;
m_startY = device_rc.top;
m_sizeX = device_rc.Width();
@@ -1899,7 +1914,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
if (!JpegReadMoreData(pJpegModule, error_status)) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = error_status;
+ m_status = error_status;
+ return m_status;
}
bStart = pJpegModule->StartScanline(m_pJpegContext, down_scale);
}
@@ -1923,14 +1939,16 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
break;
}
GetTransMethod(pDIBitmap->GetFormat(), m_SrcFormat);
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
- } break;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
+ }
case FXCODEC_IMAGE_PNG: {
CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
if (!pPngModule) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
}
if (m_pPngContext) {
pPngModule->Finish(m_pPngContext);
@@ -1940,7 +1958,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
if (!m_pPngContext) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
}
m_offSet = 0;
switch (m_pDeviceBitmap->GetFormat()) {
@@ -1961,7 +1980,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
default: {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_PARAMS;
+ m_status = FXCODEC_STATUS_ERR_PARAMS;
+ return m_status;
}
}
GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
@@ -1971,14 +1991,16 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
FXSYS_memset(m_pDecodeBuf, 0, scanline_size);
m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol);
m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
- } break;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
+ }
case FXCODEC_IMAGE_GIF: {
CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
if (!pGifModule) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
}
m_SrcFormat = FXCodec_8bppRgb;
GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
@@ -1990,14 +2012,16 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
m_clipBox.Width(), m_bInterpol);
m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
m_FrameCur = frames;
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
- } break;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
+ }
case FXCODEC_IMAGE_BMP: {
CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
if (!pBmpModule) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
}
switch (m_SrcComponents) {
case 1:
@@ -2018,23 +2042,25 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap,
m_WeightHorz.Calc(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
m_clipBox.Width(), m_bInterpol);
m_WeightVert.Calc(m_sizeY, m_clipBox.Height());
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
- } break;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
+ }
case FXCODEC_IMAGE_TIF:
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
default:
- break;
+ return FXCODEC_STATUS_ERROR;
}
- return FXCODEC_STATUS_ERROR;
}
+
FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
- if (m_status != FXCODEC_STATUS_DECODE_TOBECONTINUE) {
+ if (m_status != FXCODEC_STATUS_DECODE_TOBECONTINUE)
return FXCODEC_STATUS_ERROR;
- }
+
switch (m_imagType) {
case FXCODEC_IMAGE_JPG: {
CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
- while (TRUE) {
+ while (true) {
FX_BOOL readRes =
pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
while (!readRes) {
@@ -2042,29 +2068,32 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
if (!JpegReadMoreData(pJpegModule, error_status)) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = error_status;
+ m_status = error_status;
+ return m_status;
}
readRes = pJpegModule->ReadScanline(m_pJpegContext, m_pDecodeBuf);
}
if (m_SrcFormat == FXCodec_Rgb) {
int src_Bpp = (m_SrcFormat & 0xff) >> 3;
- _RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width());
+ RGB2BGR(m_pDecodeBuf + m_clipBox.left * src_Bpp, m_clipBox.Width());
}
if (m_SrcRow >= m_clipBox.bottom) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_DECODE_FINISH;
+ m_status = FXCODEC_STATUS_DECODE_FINISH;
+ return m_status;
}
Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf, m_SrcFormat);
m_SrcRow++;
if (pPause && pPause->NeedToPauseNow()) {
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
}
}
- } break;
+ }
case FXCODEC_IMAGE_PNG: {
CCodec_PngModule* pPngModule = m_pCodecMgr->GetPngModule();
- while (TRUE) {
+ while (true) {
uint32_t remain_size = (uint32_t)m_pFile->GetSize() - m_offSet;
uint32_t input_size =
remain_size > FXCODEC_BLOCK_SIZE ? FXCODEC_BLOCK_SIZE : remain_size;
@@ -2075,7 +2104,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
m_pPngContext = nullptr;
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_DECODE_FINISH;
+ m_status = FXCODEC_STATUS_DECODE_FINISH;
+ return m_status;
}
if (m_pSrcBuf && input_size > m_SrcSize) {
FX_Free(m_pSrcBuf);
@@ -2087,7 +2117,8 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
if (!bResult) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_READ;
+ m_status = FXCODEC_STATUS_ERR_READ;
+ return m_status;
}
m_offSet += input_size;
bResult =
@@ -2095,16 +2126,18 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
if (!bResult) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERROR;
+ m_status = FXCODEC_STATUS_ERROR;
+ return m_status;
}
if (pPause && pPause->NeedToPauseNow()) {
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
}
}
- } break;
+ }
case FXCODEC_IMAGE_GIF: {
CCodec_GifModule* pGifModule = m_pCodecMgr->GetGifModule();
- while (TRUE) {
+ while (true) {
int32_t readRes =
pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
while (readRes == 2) {
@@ -2112,49 +2145,57 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
if (!GifReadMoreData(pGifModule, error_status)) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = error_status;
+ m_status = error_status;
+ return m_status;
}
if (pPause && pPause->NeedToPauseNow()) {
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
}
readRes = pGifModule->LoadFrame(m_pGifContext, m_FrameCur, nullptr);
}
if (readRes == 1) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_DECODE_FINISH;
+ m_status = FXCODEC_STATUS_DECODE_FINISH;
+ return m_status;
}
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERROR;
+ m_status = FXCODEC_STATUS_ERROR;
+ return m_status;
}
- } break;
+ }
case FXCODEC_IMAGE_BMP: {
CCodec_BmpModule* pBmpModule = m_pCodecMgr->GetBmpModule();
- while (TRUE) {
+ while (true) {
int32_t readRes = pBmpModule->LoadImage(m_pBmpContext);
while (readRes == 2) {
FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
if (!BmpReadMoreData(pBmpModule, error_status)) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = error_status;
+ m_status = error_status;
+ return m_status;
}
if (pPause && pPause->NeedToPauseNow()) {
- return m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
+ return m_status;
}
readRes = pBmpModule->LoadImage(m_pBmpContext);
}
if (readRes == 1) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_DECODE_FINISH;
+ m_status = FXCODEC_STATUS_DECODE_FINISH;
+ return m_status;
}
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERROR;
+ m_status = FXCODEC_STATUS_ERROR;
+ return m_status;
}
- } break;
+ };
case FXCODEC_IMAGE_TIF: {
CCodec_TiffModule* pTiffModule = m_pCodecMgr->GetTiffModule();
FX_BOOL ret = FALSE;
@@ -2168,136 +2209,143 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
if (!ret) {
- return m_status = FXCODEC_STATUS_ERROR;
+ m_status = FXCODEC_STATUS_ERROR;
+ return m_status;
}
- return m_status = FXCODEC_STATUS_DECODE_FINISH;
- } else {
- CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
- pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb);
- if (!pDIBitmap->GetBuffer()) {
- delete pDIBitmap;
- m_pDeviceBitmap = nullptr;
- m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
- }
- ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
- if (!ret) {
- delete pDIBitmap;
- m_pDeviceBitmap = nullptr;
- m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERROR;
- }
- CFX_DIBitmap* pClipBitmap =
- (m_clipBox.left == 0 && m_clipBox.top == 0 &&
- m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
- ? pDIBitmap
- : pDIBitmap->Clone(&m_clipBox);
- if (pDIBitmap != pClipBitmap) {
- delete pDIBitmap;
- }
- if (!pClipBitmap) {
- m_pDeviceBitmap = nullptr;
- m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
- }
- CFX_DIBitmap* pFormatBitmap = nullptr;
- switch (m_pDeviceBitmap->GetFormat()) {
- case FXDIB_8bppRgb:
- pFormatBitmap = new CFX_DIBitmap;
- pFormatBitmap->Create(pClipBitmap->GetWidth(),
- pClipBitmap->GetHeight(), FXDIB_8bppRgb);
- break;
- case FXDIB_8bppMask:
- pFormatBitmap = new CFX_DIBitmap;
- pFormatBitmap->Create(pClipBitmap->GetWidth(),
- pClipBitmap->GetHeight(), FXDIB_8bppMask);
- break;
- case FXDIB_Rgb:
- pFormatBitmap = new CFX_DIBitmap;
- pFormatBitmap->Create(pClipBitmap->GetWidth(),
- pClipBitmap->GetHeight(), FXDIB_Rgb);
- break;
- case FXDIB_Rgb32:
- pFormatBitmap = new CFX_DIBitmap;
- pFormatBitmap->Create(pClipBitmap->GetWidth(),
- pClipBitmap->GetHeight(), FXDIB_Rgb32);
- break;
- case FXDIB_Argb:
- pFormatBitmap = pClipBitmap;
- break;
- default:
- break;
- }
- switch (m_pDeviceBitmap->GetFormat()) {
- case FXDIB_8bppRgb:
- case FXDIB_8bppMask: {
- for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
- uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
- uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
- for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
- uint8_t _a = 255 - src_line[3];
- uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
- uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
- uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
- *des_line++ = FXRGB2GRAY(r, g, b);
- src_line += 4;
- }
+ m_status = FXCODEC_STATUS_DECODE_FINISH;
+ return m_status;
+ }
+
+ CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap;
+ pDIBitmap->Create(m_SrcWidth, m_SrcHeight, FXDIB_Argb);
+ if (!pDIBitmap->GetBuffer()) {
+ delete pDIBitmap;
+ m_pDeviceBitmap = nullptr;
+ m_pFile = nullptr;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
+ }
+ ret = pTiffModule->Decode(m_pTiffContext, pDIBitmap);
+ if (!ret) {
+ delete pDIBitmap;
+ m_pDeviceBitmap = nullptr;
+ m_pFile = nullptr;
+ m_status = FXCODEC_STATUS_ERROR;
+ return m_status;
+ }
+ CFX_DIBitmap* pClipBitmap =
+ (m_clipBox.left == 0 && m_clipBox.top == 0 &&
+ m_clipBox.right == m_SrcWidth && m_clipBox.bottom == m_SrcHeight)
+ ? pDIBitmap
+ : pDIBitmap->Clone(&m_clipBox);
+ if (pDIBitmap != pClipBitmap) {
+ delete pDIBitmap;
+ }
+ if (!pClipBitmap) {
+ m_pDeviceBitmap = nullptr;
+ m_pFile = nullptr;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
+ }
+ CFX_DIBitmap* pFormatBitmap = nullptr;
+ switch (m_pDeviceBitmap->GetFormat()) {
+ case FXDIB_8bppRgb:
+ pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap->Create(pClipBitmap->GetWidth(),
+ pClipBitmap->GetHeight(), FXDIB_8bppRgb);
+ break;
+ case FXDIB_8bppMask:
+ pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap->Create(pClipBitmap->GetWidth(),
+ pClipBitmap->GetHeight(), FXDIB_8bppMask);
+ break;
+ case FXDIB_Rgb:
+ pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap->Create(pClipBitmap->GetWidth(),
+ pClipBitmap->GetHeight(), FXDIB_Rgb);
+ break;
+ case FXDIB_Rgb32:
+ pFormatBitmap = new CFX_DIBitmap;
+ pFormatBitmap->Create(pClipBitmap->GetWidth(),
+ pClipBitmap->GetHeight(), FXDIB_Rgb32);
+ break;
+ case FXDIB_Argb:
+ pFormatBitmap = pClipBitmap;
+ break;
+ default:
+ break;
+ }
+ switch (m_pDeviceBitmap->GetFormat()) {
+ case FXDIB_8bppRgb:
+ case FXDIB_8bppMask: {
+ for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
+ uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
+ uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
+ for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
+ uint8_t _a = 255 - src_line[3];
+ uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
+ uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
+ uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
+ *des_line++ = FXRGB2GRAY(r, g, b);
+ src_line += 4;
}
- } break;
- case FXDIB_Rgb:
- case FXDIB_Rgb32: {
- int32_t desBpp =
- (m_pDeviceBitmap->GetFormat() == FXDIB_Rgb) ? 3 : 4;
- for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
- uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
- uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
- for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
- uint8_t _a = 255 - src_line[3];
- uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
- uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
- uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
- *des_line++ = b;
- *des_line++ = g;
- *des_line++ = r;
- des_line += desBpp - 3;
- src_line += 4;
- }
+ }
+ } break;
+ case FXDIB_Rgb:
+ case FXDIB_Rgb32: {
+ int32_t desBpp = (m_pDeviceBitmap->GetFormat() == FXDIB_Rgb) ? 3 : 4;
+ for (int32_t row = 0; row < pClipBitmap->GetHeight(); row++) {
+ uint8_t* src_line = (uint8_t*)pClipBitmap->GetScanline(row);
+ uint8_t* des_line = (uint8_t*)pFormatBitmap->GetScanline(row);
+ for (int32_t col = 0; col < pClipBitmap->GetWidth(); col++) {
+ uint8_t _a = 255 - src_line[3];
+ uint8_t b = (src_line[0] * src_line[3] + 0xFF * _a) / 255;
+ uint8_t g = (src_line[1] * src_line[3] + 0xFF * _a) / 255;
+ uint8_t r = (src_line[2] * src_line[3] + 0xFF * _a) / 255;
+ *des_line++ = b;
+ *des_line++ = g;
+ *des_line++ = r;
+ des_line += desBpp - 3;
+ src_line += 4;
}
- } break;
- default:
- break;
- }
- if (pClipBitmap != pFormatBitmap) {
- delete pClipBitmap;
- }
- if (!pFormatBitmap) {
- m_pDeviceBitmap = nullptr;
- m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
- }
- CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo(
- m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
- delete pFormatBitmap;
- pFormatBitmap = nullptr;
- if (!pStrechBitmap) {
- m_pDeviceBitmap = nullptr;
- m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_ERR_MEMORY;
- }
- m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
- pStrechBitmap, 0, 0);
- delete pStrechBitmap;
- pStrechBitmap = nullptr;
+ }
+ } break;
+ default:
+ break;
+ }
+ if (pClipBitmap != pFormatBitmap) {
+ delete pClipBitmap;
+ }
+ if (!pFormatBitmap) {
m_pDeviceBitmap = nullptr;
m_pFile = nullptr;
- return m_status = FXCODEC_STATUS_DECODE_FINISH;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
}
- } break;
+ CFX_DIBitmap* pStrechBitmap = pFormatBitmap->StretchTo(
+ m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE);
+ delete pFormatBitmap;
+ pFormatBitmap = nullptr;
+ if (!pStrechBitmap) {
+ m_pDeviceBitmap = nullptr;
+ m_pFile = nullptr;
+ m_status = FXCODEC_STATUS_ERR_MEMORY;
+ return m_status;
+ }
+ m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY,
+ pStrechBitmap, 0, 0);
+ delete pStrechBitmap;
+ pStrechBitmap = nullptr;
+ m_pDeviceBitmap = nullptr;
+ m_pFile = nullptr;
+ m_status = FXCODEC_STATUS_DECODE_FINISH;
+ return m_status;
+ }
default:
- break;
+ return FXCODEC_STATUS_ERROR;
}
- return FXCODEC_STATUS_ERROR;
}
+
CCodec_ProgressiveDecoder* CCodec_ModuleMgr::CreateProgressiveDecoder() {
return new CCodec_ProgressiveDecoder(this);
}
« no previous file with comments | « core/fxcodec/codec/ccodec_tiffmodule.h ('k') | core/fxcodec/codec/fx_codec_tiff.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698