| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 void CWeightTable::Calc(int dest_len, | 35 void CWeightTable::Calc(int dest_len, |
| 36 int dest_min, | 36 int dest_min, |
| 37 int dest_max, | 37 int dest_max, |
| 38 int src_len, | 38 int src_len, |
| 39 int src_min, | 39 int src_min, |
| 40 int src_max, | 40 int src_max, |
| 41 int flags) { | 41 int flags) { |
| 42 FX_Free(m_pWeightTables); | 42 FX_Free(m_pWeightTables); |
| 43 m_pWeightTables = NULL; | 43 m_pWeightTables = nullptr; |
| 44 double scale, base; | 44 double scale, base; |
| 45 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; | 45 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; |
| 46 if (dest_len < 0) { | 46 if (dest_len < 0) { |
| 47 base = (FX_FLOAT)(src_len); | 47 base = (FX_FLOAT)(src_len); |
| 48 } else { | 48 } else { |
| 49 base = 0; | 49 base = 0; |
| 50 } | 50 } |
| 51 int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1; | 51 int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1; |
| 52 m_ItemSize = | 52 m_ItemSize = |
| 53 sizeof(int) * 2 + | 53 sizeof(int) * 2 + |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 int flags) { | 242 int flags) { |
| 243 m_State = 0; | 243 m_State = 0; |
| 244 m_DestFormat = dest_format; | 244 m_DestFormat = dest_format; |
| 245 m_DestBpp = dest_format & 0xff; | 245 m_DestBpp = dest_format & 0xff; |
| 246 m_SrcBpp = pSrcBitmap->GetFormat() & 0xff; | 246 m_SrcBpp = pSrcBitmap->GetFormat() & 0xff; |
| 247 m_bHasAlpha = pSrcBitmap->GetFormat() & 0x200; | 247 m_bHasAlpha = pSrcBitmap->GetFormat() & 0x200; |
| 248 m_pSrcPalette = pSrcBitmap->GetPalette(); | 248 m_pSrcPalette = pSrcBitmap->GetPalette(); |
| 249 m_pDestBitmap = pDestBitmap; | 249 m_pDestBitmap = pDestBitmap; |
| 250 m_DestWidth = dest_width; | 250 m_DestWidth = dest_width; |
| 251 m_DestHeight = dest_height; | 251 m_DestHeight = dest_height; |
| 252 m_pInterBuf = NULL; | 252 m_pInterBuf = nullptr; |
| 253 m_pExtraAlphaBuf = NULL; | 253 m_pExtraAlphaBuf = nullptr; |
| 254 m_pDestMaskScanline = NULL; | 254 m_pDestMaskScanline = nullptr; |
| 255 m_DestClip = clip_rect; | 255 m_DestClip = clip_rect; |
| 256 uint32_t size = clip_rect.Width(); | 256 uint32_t size = clip_rect.Width(); |
| 257 if (size && m_DestBpp > (int)(INT_MAX / size)) { | 257 if (size && m_DestBpp > (int)(INT_MAX / size)) { |
| 258 return; | 258 return; |
| 259 } | 259 } |
| 260 size *= m_DestBpp; | 260 size *= m_DestBpp; |
| 261 if (size > INT_MAX - 31) { | 261 if (size > INT_MAX - 31) { |
| 262 return; | 262 return; |
| 263 } | 263 } |
| 264 size += 31; | 264 size += 31; |
| 265 size = size / 32 * 4; | 265 size = size / 32 * 4; |
| 266 m_pDestScanline = FX_TryAlloc(uint8_t, size); | 266 m_pDestScanline = FX_TryAlloc(uint8_t, size); |
| 267 if (!m_pDestScanline) { | 267 if (!m_pDestScanline) { |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 if (dest_format == FXDIB_Rgb32) { | 270 if (dest_format == FXDIB_Rgb32) { |
| 271 FXSYS_memset(m_pDestScanline, 255, size); | 271 FXSYS_memset(m_pDestScanline, 255, size); |
| 272 } | 272 } |
| 273 m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4; | 273 m_InterPitch = (m_DestClip.Width() * m_DestBpp + 31) / 32 * 4; |
| 274 m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4; | 274 m_ExtraMaskPitch = (m_DestClip.Width() * 8 + 31) / 32 * 4; |
| 275 m_pInterBuf = NULL; | 275 m_pInterBuf = nullptr; |
| 276 m_pSource = pSrcBitmap; | 276 m_pSource = pSrcBitmap; |
| 277 m_SrcWidth = pSrcBitmap->GetWidth(); | 277 m_SrcWidth = pSrcBitmap->GetWidth(); |
| 278 m_SrcHeight = pSrcBitmap->GetHeight(); | 278 m_SrcHeight = pSrcBitmap->GetHeight(); |
| 279 m_SrcPitch = (m_SrcWidth * m_SrcBpp + 31) / 32 * 4; | 279 m_SrcPitch = (m_SrcWidth * m_SrcBpp + 31) / 32 * 4; |
| 280 if ((flags & FXDIB_NOSMOOTH) == 0) { | 280 if ((flags & FXDIB_NOSMOOTH) == 0) { |
| 281 FX_BOOL bInterpol = | 281 FX_BOOL bInterpol = |
| 282 flags & FXDIB_INTERPOL || flags & FXDIB_BICUBIC_INTERPOL; | 282 flags & FXDIB_INTERPOL || flags & FXDIB_BICUBIC_INTERPOL; |
| 283 if (!bInterpol && FXSYS_abs(dest_width) != 0 && | 283 if (!bInterpol && FXSYS_abs(dest_width) != 0 && |
| 284 FXSYS_abs(dest_height) < | 284 FXSYS_abs(dest_height) < |
| 285 m_SrcWidth * m_SrcHeight * 8 / FXSYS_abs(dest_width)) { | 285 m_SrcWidth * m_SrcHeight * 8 / FXSYS_abs(dest_width)) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 for (; m_CurRow < m_SrcClip.bottom; m_CurRow++) { | 401 for (; m_CurRow < m_SrcClip.bottom; m_CurRow++) { |
| 402 if (rows_to_go == 0) { | 402 if (rows_to_go == 0) { |
| 403 if (pPause && pPause->NeedToPauseNow()) { | 403 if (pPause && pPause->NeedToPauseNow()) { |
| 404 return TRUE; | 404 return TRUE; |
| 405 } | 405 } |
| 406 rows_to_go = FX_STRECH_PAUSE_ROWS; | 406 rows_to_go = FX_STRECH_PAUSE_ROWS; |
| 407 } | 407 } |
| 408 const uint8_t* src_scan = m_pSource->GetScanline(m_CurRow); | 408 const uint8_t* src_scan = m_pSource->GetScanline(m_CurRow); |
| 409 uint8_t* dest_scan = | 409 uint8_t* dest_scan = |
| 410 m_pInterBuf + (m_CurRow - m_SrcClip.top) * m_InterPitch; | 410 m_pInterBuf + (m_CurRow - m_SrcClip.top) * m_InterPitch; |
| 411 const uint8_t* src_scan_mask = NULL; | 411 const uint8_t* src_scan_mask = nullptr; |
| 412 uint8_t* dest_scan_mask = NULL; | 412 uint8_t* dest_scan_mask = nullptr; |
| 413 if (m_pExtraAlphaBuf) { | 413 if (m_pExtraAlphaBuf) { |
| 414 src_scan_mask = m_pSource->m_pAlphaMask->GetScanline(m_CurRow); | 414 src_scan_mask = m_pSource->m_pAlphaMask->GetScanline(m_CurRow); |
| 415 dest_scan_mask = | 415 dest_scan_mask = |
| 416 m_pExtraAlphaBuf + (m_CurRow - m_SrcClip.top) * m_ExtraMaskPitch; | 416 m_pExtraAlphaBuf + (m_CurRow - m_SrcClip.top) * m_ExtraMaskPitch; |
| 417 } | 417 } |
| 418 switch (m_TransMethod) { | 418 switch (m_TransMethod) { |
| 419 case 1: | 419 case 1: |
| 420 case 2: { | 420 case 2: { |
| 421 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { | 421 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { |
| 422 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); | 422 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 dest_scan[2] = (uint8_t)((dest_r_y) >> 16); | 711 dest_scan[2] = (uint8_t)((dest_r_y) >> 16); |
| 712 dest_scan += DestBpp; | 712 dest_scan += DestBpp; |
| 713 } | 713 } |
| 714 break; | 714 break; |
| 715 } | 715 } |
| 716 case 6: | 716 case 6: |
| 717 case 8: { | 717 case 8: { |
| 718 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { | 718 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { |
| 719 unsigned char* src_scan = | 719 unsigned char* src_scan = |
| 720 m_pInterBuf + (col - m_DestClip.left) * DestBpp; | 720 m_pInterBuf + (col - m_DestClip.left) * DestBpp; |
| 721 unsigned char* src_scan_mask = NULL; | 721 unsigned char* src_scan_mask = nullptr; |
| 722 if (m_DestFormat != FXDIB_Argb) { | 722 if (m_DestFormat != FXDIB_Argb) { |
| 723 src_scan_mask = m_pExtraAlphaBuf + (col - m_DestClip.left); | 723 src_scan_mask = m_pExtraAlphaBuf + (col - m_DestClip.left); |
| 724 } | 724 } |
| 725 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; | 725 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; |
| 726 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; | 726 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; |
| 727 j++) { | 727 j++) { |
| 728 int pixel_weight = | 728 int pixel_weight = |
| 729 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; | 729 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; |
| 730 const uint8_t* src_pixel = | 730 const uint8_t* src_pixel = |
| 731 src_scan + (j - m_SrcClip.top) * m_InterPitch; | 731 src_scan + (j - m_SrcClip.top) * m_InterPitch; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 result_width); | 920 result_width); |
| 921 if (m_pMaskScanline) { | 921 if (m_pMaskScanline) { |
| 922 m_pSource->m_pAlphaMask->DownSampleScanline( | 922 m_pSource->m_pAlphaMask->DownSampleScanline( |
| 923 src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX, | 923 src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX, |
| 924 m_ClipRect.left, result_width); | 924 m_ClipRect.left, result_width); |
| 925 } | 925 } |
| 926 m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get()); | 926 m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get()); |
| 927 } | 927 } |
| 928 return FALSE; | 928 return FALSE; |
| 929 } | 929 } |
| OLD | NEW |