diff options
Diffstat (limited to 'chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp')
-rw-r--r-- | chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp | 207 |
1 files changed, 100 insertions, 107 deletions
diff --git a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp index 1f2f50c29e1..79f0bed4159 100644 --- a/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp +++ b/chromium/third_party/pdfium/core/fxcodec/codec/fx_codec_progress.cpp @@ -10,6 +10,7 @@ #include <memory> #include "core/fxcodec/fx_codec.h" +#include "core/fxge/dib/cfx_dibitmap.h" #include "core/fxge/fx_dib.h" #include "third_party/base/numerics/safe_math.h" #include "third_party/base/ptr_util.h" @@ -51,25 +52,23 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len, int src_max, bool bInterpol) { double scale, base; - scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; + scale = (float)src_len / (float)dest_len; if (dest_len < 0) { - base = (FX_FLOAT)(src_len); + base = (float)(src_len); } else { base = 0.0f; } m_ItemSize = - (int)(sizeof(int) * 2 + - sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + 1)); + (int)(sizeof(int) * 2 + sizeof(int) * (ceil(fabs((float)scale)) + 1)); m_DestMin = dest_min; m_pWeightTables.resize((dest_max - dest_min) * m_ItemSize + 4); - if (FXSYS_fabs((FX_FLOAT)scale) < 1.0f) { + if (fabs((float)scale) < 1.0f) { for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) { PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel); double src_pos = dest_pixel * scale + scale / 2 + base; if (bInterpol) { - pixel_weights.m_SrcStart = - (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2); - pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2); + pixel_weights.m_SrcStart = (int)floor((float)src_pos - 1.0f / 2); + pixel_weights.m_SrcEnd = (int)floor((float)src_pos + 1.0f / 2); if (pixel_weights.m_SrcStart < src_min) { pixel_weights.m_SrcStart = src_min; } @@ -80,13 +79,12 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len, pixel_weights.m_Weights[0] = 65536; } else { pixel_weights.m_Weights[1] = FXSYS_round( - (FX_FLOAT)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * - 65536); + (float)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * 65536); pixel_weights.m_Weights[0] = 65536 - pixel_weights.m_Weights[1]; } } else { pixel_weights.m_SrcStart = pixel_weights.m_SrcEnd = - (int)FXSYS_floor((FX_FLOAT)src_pos); + (int)floor((float)src_pos); pixel_weights.m_Weights[0] = 65536; } } @@ -98,11 +96,11 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len, double src_end = src_start + scale; int start_i, end_i; if (src_start < src_end) { - start_i = (int)FXSYS_floor((FX_FLOAT)src_start); - end_i = (int)FXSYS_ceil((FX_FLOAT)src_end); + start_i = (int)floor((float)src_start); + end_i = (int)ceil((float)src_end); } else { - start_i = (int)FXSYS_floor((FX_FLOAT)src_end); - end_i = (int)FXSYS_ceil((FX_FLOAT)src_start); + start_i = (int)floor((float)src_end); + end_i = (int)ceil((float)src_start); } if (start_i < src_min) { start_i = src_min; @@ -118,18 +116,17 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len, pixel_weights.m_SrcStart = start_i; pixel_weights.m_SrcEnd = end_i; for (int j = start_i; j <= end_i; j++) { - double dest_start = ((FX_FLOAT)j - base) / scale; - double dest_end = ((FX_FLOAT)(j + 1) - base) / scale; + double dest_start = ((float)j - base) / scale; + double dest_end = ((float)(j + 1) - base) / scale; if (dest_start > dest_end) { double temp = dest_start; dest_start = dest_end; dest_end = temp; } - double area_start = dest_start > (FX_FLOAT)(dest_pixel) - ? dest_start - : (FX_FLOAT)(dest_pixel); - double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1) - ? (FX_FLOAT)(dest_pixel + 1) + double area_start = + dest_start > (float)(dest_pixel) ? dest_start : (float)(dest_pixel); + double area_end = dest_end > (float)(dest_pixel + 1) + ? (float)(dest_pixel + 1) : dest_end; double weight = area_start >= area_end ? 0.0f : area_end - area_start; if (weight == 0 && j == end_i) { @@ -137,7 +134,7 @@ void CCodec_ProgressiveDecoder::CFXCODEC_WeightTable::Calc(int dest_len, break; } pixel_weights.m_Weights[j - start_i] = - FXSYS_round((FX_FLOAT)(weight * 65536)); + FXSYS_round((float)(weight * 65536)); } } } @@ -157,7 +154,7 @@ void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len, int pre_des_col = 0; for (int src_col = 0; src_col < src_len; src_col++) { double des_col_f = src_col * scale; - int des_col = FXSYS_round((FX_FLOAT)des_col_f); + int des_col = FXSYS_round((float)des_col_f); PixelWeight* pWeight = GetPixelWeight(des_col); pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; pWeight->m_Weights[0] = 65536; @@ -179,10 +176,10 @@ void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len, pWeight->m_SrcStart = src_col - 1; pWeight->m_SrcEnd = src_col; pWeight->m_Weights[0] = - bInterpol ? FXSYS_round((FX_FLOAT)( - ((FX_FLOAT)des_col - (FX_FLOAT)des_col_index) / - (FX_FLOAT)des_col_len * 65536)) - : 65536; + bInterpol + ? FXSYS_round((float)(((float)des_col - (float)des_col_index) / + (float)des_col_len * 65536)) + : 65536; pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0]; } pre_des_col = des_col; @@ -191,7 +188,7 @@ void CCodec_ProgressiveDecoder::CFXCODEC_HorzTable::Calc(int dest_len, } for (int des_col = 0; des_col < dest_len; des_col++) { double src_col_f = des_col / scale; - int src_col = FXSYS_round((FX_FLOAT)src_col_f); + int src_col = FXSYS_round((float)src_col_f); PixelWeight* pWeight = GetPixelWeight(des_col); pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col; pWeight->m_Weights[0] = 65536; @@ -249,8 +246,8 @@ void CCodec_ProgressiveDecoder::CFXCODEC_VertTable::Calc(int dest_len, PixelWeight* pWeight = GetPixelWeight(des_row); 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[0] = + FXSYS_round((float)(end_step - des_row) / (float)length * 65536); pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0]; } } @@ -335,7 +332,7 @@ bool CCodec_ProgressiveDecoder::JpegReadMoreData(CCodec_JpegModule* pJpegModule, } else { uint32_t dwConsume = m_SrcSize - dwAvail; if (dwAvail) { - FXSYS_memmove(m_pSrcBuf, m_pSrcBuf + dwConsume, dwAvail); + memmove(m_pSrcBuf, m_pSrcBuf + dwConsume, dwAvail); } if (dwSize > dwConsume) { dwSize = dwConsume; @@ -408,7 +405,7 @@ bool CCodec_ProgressiveDecoder::PngReadHeader(int width, } bool CCodec_ProgressiveDecoder::PngAskScanlineBuf(int line, uint8_t*& src_buf) { - CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; + CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap; if (!pDIBitmap) { ASSERT(false); return false; @@ -477,7 +474,7 @@ bool CCodec_ProgressiveDecoder::PngAskScanlineBuf(int line, uint8_t*& src_buf) { } void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz( - CFX_DIBitmap* pDeviceBitmap, + const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap, int32_t des_line, uint8_t* src_scan, FXCodec_Format src_format) { @@ -550,7 +547,7 @@ void CCodec_ProgressiveDecoder::PngOneOneMapResampleHorz( void CCodec_ProgressiveDecoder::PngFillScanlineBufCompleted(int pass, int line) { - CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; + CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); int src_top = m_clipBox.top; int src_bottom = m_clipBox.bottom; @@ -597,7 +594,7 @@ bool CCodec_ProgressiveDecoder::GifReadMoreData(ICodec_GifModule* pGifModule, } else { uint32_t dwConsume = m_SrcSize - dwAvail; if (dwAvail) { - FXSYS_memmove(m_pSrcBuf, m_pSrcBuf + dwConsume, dwAvail); + memmove(m_pSrcBuf, m_pSrcBuf + dwConsume, dwAvail); } if (dwSize > dwConsume) { dwSize = dwConsume; @@ -662,7 +659,7 @@ bool CCodec_ProgressiveDecoder::GifInputRecordPositionBuf( m_GifFrameRect = img_rc; m_SrcPassNumber = interlace ? 4 : 1; int32_t pal_index = m_GifBgIndex; - CFX_DIBitmap* pDevice = m_pDeviceBitmap; + CFX_RetainPtr<CFX_DIBitmap> pDevice = m_pDeviceBitmap; if (trans_index >= pal_num) trans_index = -1; if (trans_index != -1) { @@ -686,7 +683,7 @@ bool CCodec_ProgressiveDecoder::GifInputRecordPositionBuf( case 3: { uint8_t gray = FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); - FXSYS_memset(pScanline, gray, sizeX); + memset(pScanline, gray, sizeX); break; } case 8: { @@ -712,7 +709,7 @@ bool CCodec_ProgressiveDecoder::GifInputRecordPositionBuf( void CCodec_ProgressiveDecoder::GifReadScanline(int32_t row_num, uint8_t* row_buf) { - CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; + CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); int32_t img_width = m_GifFrameRect.Width(); if (!pDIBitmap->HasAlpha()) { @@ -728,11 +725,11 @@ void CCodec_ProgressiveDecoder::GifReadScanline(int32_t row_num, if (m_GifTransIndex != -1 && m_pDeviceBitmap->HasAlpha()) { pal_index = m_GifTransIndex; } - FXSYS_memset(m_pDecodeBuf, pal_index, m_SrcWidth); + memset(m_pDecodeBuf, pal_index, m_SrcWidth); bool bLastPass = (row_num % 2) == 1; int32_t line = row_num + m_GifFrameRect.top; int32_t left = m_GifFrameRect.left; - FXSYS_memcpy(m_pDecodeBuf + left, row_buf, img_width); + memcpy(m_pDecodeBuf + left, row_buf, img_width); int src_top = m_clipBox.top; int src_bottom = m_clipBox.bottom; int des_top = m_startY; @@ -766,7 +763,7 @@ void CCodec_ProgressiveDecoder::GifReadScanline(int32_t row_num, uint8_t* scan_des = (uint8_t*)pDIBitmap->GetScanline(cur_row) + des_ScanOffet; uint32_t size = m_sizeX * des_Bpp; - FXSYS_memmove(scan_des, scan_src, size); + memmove(scan_des, scan_src, size); } } if (bLastPass) @@ -774,7 +771,7 @@ void CCodec_ProgressiveDecoder::GifReadScanline(int32_t row_num, } void CCodec_ProgressiveDecoder::GifDoubleLineResampleVert( - CFX_DIBitmap* pDeviceBitmap, + const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap, double scale_y, int des_row) { int des_Bpp = pDeviceBitmap->GetBPP() >> 3; @@ -876,7 +873,7 @@ bool CCodec_ProgressiveDecoder::BmpReadMoreData(ICodec_BmpModule* pBmpModule, } else { uint32_t dwConsume = m_SrcSize - dwAvail; if (dwAvail) { - FXSYS_memmove(m_pSrcBuf, m_pSrcBuf + dwConsume, dwAvail); + memmove(m_pSrcBuf, m_pSrcBuf + dwConsume, dwAvail); } if (dwSize > dwConsume) { dwSize = dwConsume; @@ -899,9 +896,9 @@ bool CCodec_ProgressiveDecoder::BmpInputImagePositionBuf(uint32_t rcd_pos) { void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num, uint8_t* row_buf) { - CFX_DIBitmap* pDIBitmap = m_pDeviceBitmap; + CFX_RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap; ASSERT(pDIBitmap); - FXSYS_memcpy(m_pDecodeBuf, row_buf, m_ScanlineSize); + memcpy(m_pDecodeBuf, row_buf, m_ScanlineSize); int src_top = m_clipBox.top; int src_bottom = m_clipBox.bottom; int des_top = m_startY; @@ -927,9 +924,10 @@ void CCodec_ProgressiveDecoder::BmpReadScanline(int32_t row_num, ResampleVertBT(pDIBitmap, scale_y, des_row); } -void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, - double scale_y, - int des_row) { +void CCodec_ProgressiveDecoder::ResampleVertBT( + const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap, + double scale_y, + int des_row) { int des_Bpp = pDeviceBitmap->GetBPP() >> 3; uint32_t des_ScanOffet = m_startX * des_Bpp; int des_top = m_startY; @@ -944,7 +942,7 @@ void CCodec_ProgressiveDecoder::ResampleVertBT(CFX_DIBitmap* pDeviceBitmap, uint8_t* scan_des = (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; uint32_t size = m_sizeX * des_Bpp; - FXSYS_memmove(scan_des, scan_src, size); + memmove(scan_des, scan_src, size); } return; } @@ -1020,7 +1018,7 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, } FX_Free(m_pSrcBuf); m_pSrcBuf = FX_Alloc(uint8_t, size); - FXSYS_memset(m_pSrcBuf, 0, size); + memset(m_pSrcBuf, 0, size); m_SrcSize = size; switch (imageType) { case FXCODEC_IMAGE_BMP: { @@ -1062,8 +1060,8 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, FX_Free(m_pSrcPalette); if (m_SrcPaletteNumber) { m_pSrcPalette = FX_Alloc(FX_ARGB, m_SrcPaletteNumber); - FXSYS_memcpy(m_pSrcPalette, pPalette, - m_SrcPaletteNumber * sizeof(uint32_t)); + memcpy(m_pSrcPalette, pPalette, + m_SrcPaletteNumber * sizeof(uint32_t)); } else { m_pSrcPalette = nullptr; } @@ -1153,7 +1151,7 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, if (m_pSrcBuf && input_size > m_SrcSize) { FX_Free(m_pSrcBuf); m_pSrcBuf = FX_Alloc(uint8_t, input_size); - FXSYS_memset(m_pSrcBuf, 0, input_size); + memset(m_pSrcBuf, 0, input_size); m_SrcSize = input_size; } bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size); @@ -1444,10 +1442,11 @@ void CCodec_ProgressiveDecoder::GetTransMethod(FXDIB_Format des_format, } } -void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, - int des_line, - uint8_t* src_scan, - FXCodec_Format src_format) { +void CCodec_ProgressiveDecoder::ReSampleScanline( + const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap, + int des_line, + uint8_t* src_scan, + FXCodec_Format src_format) { int src_left = m_clipBox.left; int des_left = m_startX; uint8_t* des_scan = @@ -1533,7 +1532,7 @@ void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; des_g += pixel_weight * src_scan[j]; } - FXSYS_memset(des_scan, (uint8_t)(des_g >> 16), 3); + memset(des_scan, (uint8_t)(des_g >> 16), 3); des_scan += des_Bpp; } break; case 8: { @@ -1646,9 +1645,10 @@ void CCodec_ProgressiveDecoder::ReSampleScanline(CFX_DIBitmap* pDeviceBitmap, } } -void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap, - double scale_y, - int des_row) { +void CCodec_ProgressiveDecoder::ResampleVert( + const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap, + double scale_y, + int des_row) { int des_Bpp = pDeviceBitmap->GetBPP() >> 3; uint32_t des_ScanOffet = m_startX * des_Bpp; if (m_bInterpol) { @@ -1665,7 +1665,7 @@ void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap, uint8_t* scan_des = (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; uint32_t size = m_sizeX * des_Bpp; - FXSYS_memmove(scan_des, scan_src, size); + memmove(scan_des, scan_src, size); } } return; @@ -1740,12 +1740,12 @@ void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap, uint8_t* scan_des = (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; uint32_t size = m_sizeX * des_Bpp; - FXSYS_memmove(scan_des, scan_src, size); + memmove(scan_des, scan_src, size); } } return; } - int multiple = (int)FXSYS_ceil((FX_FLOAT)scale_y - 1); + int multiple = (int)ceil((float)scale_y - 1); if (multiple > 0) { uint8_t* scan_src = (uint8_t*)pDeviceBitmap->GetScanline(des_row) + des_ScanOffet; @@ -1756,15 +1756,16 @@ void CCodec_ProgressiveDecoder::ResampleVert(CFX_DIBitmap* pDeviceBitmap, uint8_t* scan_des = (uint8_t*)pDeviceBitmap->GetScanline(des_row + i) + des_ScanOffet; uint32_t size = m_sizeX * des_Bpp; - FXSYS_memmove(scan_des, scan_src, size); + memmove(scan_des, scan_src, size); } } } -void CCodec_ProgressiveDecoder::Resample(CFX_DIBitmap* pDeviceBitmap, - int32_t src_line, - uint8_t* src_scan, - FXCodec_Format src_format) { +void CCodec_ProgressiveDecoder::Resample( + const CFX_RetainPtr<CFX_DIBitmap>& pDeviceBitmap, + int32_t src_line, + uint8_t* src_scan, + FXCodec_Format src_format) { int src_top = m_clipBox.top; int des_top = m_startY; int src_hei = m_clipBox.Height(); @@ -1835,13 +1836,14 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::GetFrames(int32_t& frames, } } -FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, - int start_x, - int start_y, - int size_x, - int size_y, - int32_t frames, - bool bInterpol) { +FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode( + const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, + int start_x, + int start_y, + int size_x, + int size_y, + int32_t frames, + bool bInterpol) { if (m_status != FXCODEC_STATUS_DECODE_READY) return FXCODEC_STATUS_ERROR; @@ -1871,21 +1873,21 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_bInterpol = bInterpol; m_FrameCur = 0; if (start_x < 0 || out_range_x > 0) { - FX_FLOAT scaleX = (FX_FLOAT)m_clipBox.Width() / (FX_FLOAT)size_x; + float scaleX = (float)m_clipBox.Width() / (float)size_x; if (start_x < 0) { - m_clipBox.left -= (int32_t)FXSYS_ceil((FX_FLOAT)start_x * scaleX); + m_clipBox.left -= (int32_t)ceil((float)start_x * scaleX); } if (out_range_x > 0) { - m_clipBox.right -= (int32_t)FXSYS_floor((FX_FLOAT)out_range_x * scaleX); + m_clipBox.right -= (int32_t)floor((float)out_range_x * scaleX); } } if (start_y < 0 || out_range_y > 0) { - FX_FLOAT scaleY = (FX_FLOAT)m_clipBox.Height() / (FX_FLOAT)size_y; + float scaleY = (float)m_clipBox.Height() / (float)size_y; if (start_y < 0) { - m_clipBox.top -= (int32_t)FXSYS_ceil((FX_FLOAT)start_y * scaleY); + m_clipBox.top -= (int32_t)ceil((float)start_y * scaleY); } if (out_range_y > 0) { - m_clipBox.bottom -= (int32_t)FXSYS_floor((FX_FLOAT)out_range_y * scaleY); + m_clipBox.bottom -= (int32_t)floor((float)out_range_y * scaleY); } } if (m_clipBox.IsEmpty()) { @@ -1911,7 +1913,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, scanline_size = (scanline_size * m_SrcComponents + 3) / 4 * 4; FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); - FXSYS_memset(m_pDecodeBuf, 0, scanline_size); + memset(m_pDecodeBuf, 0, scanline_size); 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()); @@ -1976,7 +1978,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, int scanline_size = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); - FXSYS_memset(m_pDecodeBuf, 0, scanline_size); + memset(m_pDecodeBuf, 0, scanline_size); m_WeightHorzOO.Calc(m_sizeX, m_clipBox.Width(), m_bInterpol); m_WeightVert.Calc(m_sizeY, m_clipBox.Height()); m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE; @@ -1995,7 +1997,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, int scanline_size = (m_SrcWidth + 3) / 4 * 4; FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, scanline_size); - FXSYS_memset(m_pDecodeBuf, 0, scanline_size); + memset(m_pDecodeBuf, 0, scanline_size); 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()); @@ -2026,7 +2028,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(CFX_DIBitmap* pDIBitmap, m_ScanlineSize = (m_SrcWidth * m_SrcComponents + 3) / 4 * 4; FX_Free(m_pDecodeBuf); m_pDecodeBuf = FX_Alloc(uint8_t, m_ScanlineSize); - FXSYS_memset(m_pDecodeBuf, 0, m_ScanlineSize); + memset(m_pDecodeBuf, 0, m_ScanlineSize); 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()); @@ -2101,7 +2103,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { if (m_pSrcBuf && input_size > m_SrcSize) { FX_Free(m_pSrcBuf); m_pSrcBuf = FX_Alloc(uint8_t, input_size); - FXSYS_memset(m_pSrcBuf, 0, input_size); + memset(m_pSrcBuf, 0, input_size); m_SrcSize = input_size; } bool bResult = m_pFile->ReadBlock(m_pSrcBuf, m_offSet, input_size); @@ -2219,10 +2221,9 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { return m_status; } - CFX_DIBitmap* pDIBitmap = new CFX_DIBitmap; + auto pDIBitmap = pdfium::MakeRetain<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; @@ -2230,45 +2231,41 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { } 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 = + CFX_RetainPtr<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).release(); - if (pDIBitmap != pClipBitmap) { - delete pDIBitmap; - } + : pDIBitmap->Clone(&m_clipBox); if (!pClipBitmap) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; m_status = FXCODEC_STATUS_ERR_MEMORY; return m_status; } - CFX_DIBitmap* pFormatBitmap = nullptr; + CFX_RetainPtr<CFX_DIBitmap> pFormatBitmap; switch (m_pDeviceBitmap->GetFormat()) { case FXDIB_8bppRgb: - pFormatBitmap = new CFX_DIBitmap; + pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); pFormatBitmap->Create(pClipBitmap->GetWidth(), pClipBitmap->GetHeight(), FXDIB_8bppRgb); break; case FXDIB_8bppMask: - pFormatBitmap = new CFX_DIBitmap; + pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); pFormatBitmap->Create(pClipBitmap->GetWidth(), pClipBitmap->GetHeight(), FXDIB_8bppMask); break; case FXDIB_Rgb: - pFormatBitmap = new CFX_DIBitmap; + pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); pFormatBitmap->Create(pClipBitmap->GetWidth(), pClipBitmap->GetHeight(), FXDIB_Rgb); break; case FXDIB_Rgb32: - pFormatBitmap = new CFX_DIBitmap; + pFormatBitmap = pdfium::MakeRetain<CFX_DIBitmap>(); pFormatBitmap->Create(pClipBitmap->GetWidth(), pClipBitmap->GetHeight(), FXDIB_Rgb32); break; @@ -2316,18 +2313,14 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { default: break; } - if (pClipBitmap != pFormatBitmap) { - delete pClipBitmap; - } if (!pFormatBitmap) { m_pDeviceBitmap = nullptr; m_pFile = nullptr; m_status = FXCODEC_STATUS_ERR_MEMORY; return m_status; } - std::unique_ptr<CFX_DIBitmap> pStrechBitmap = pFormatBitmap->StretchTo( + CFX_RetainPtr<CFX_DIBitmap> pStrechBitmap = pFormatBitmap->StretchTo( m_sizeX, m_sizeY, m_bInterpol ? FXDIB_INTERPOL : FXDIB_DOWNSAMPLE); - delete pFormatBitmap; pFormatBitmap = nullptr; if (!pStrechBitmap) { m_pDeviceBitmap = nullptr; @@ -2336,7 +2329,7 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode(IFX_Pause* pPause) { return m_status; } m_pDeviceBitmap->TransferBitmap(m_startX, m_startY, m_sizeX, m_sizeY, - pStrechBitmap.get(), 0, 0); + pStrechBitmap, 0, 0); m_pDeviceBitmap = nullptr; m_pFile = nullptr; m_status = FXCODEC_STATUS_DECODE_FINISH; |