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 "core/fxge/dib/dib_int.h" | 9 #include "core/fxge/dib/dib_int.h" |
10 #include "core/include/fxge/fx_dib.h" | 10 #include "core/include/fxge/fx_dib.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 m_SrcBpp = pSrcBitmap->GetFormat() & 0xff; | 224 m_SrcBpp = pSrcBitmap->GetFormat() & 0xff; |
225 m_bHasAlpha = pSrcBitmap->GetFormat() & 0x200; | 225 m_bHasAlpha = pSrcBitmap->GetFormat() & 0x200; |
226 m_pSrcPalette = pSrcBitmap->GetPalette(); | 226 m_pSrcPalette = pSrcBitmap->GetPalette(); |
227 m_pDestBitmap = pDestBitmap; | 227 m_pDestBitmap = pDestBitmap; |
228 m_DestWidth = dest_width; | 228 m_DestWidth = dest_width; |
229 m_DestHeight = dest_height; | 229 m_DestHeight = dest_height; |
230 m_pInterBuf = NULL; | 230 m_pInterBuf = NULL; |
231 m_pExtraAlphaBuf = NULL; | 231 m_pExtraAlphaBuf = NULL; |
232 m_pDestMaskScanline = NULL; | 232 m_pDestMaskScanline = NULL; |
233 m_DestClip = clip_rect; | 233 m_DestClip = clip_rect; |
234 FX_DWORD size = clip_rect.Width(); | 234 uint32_t size = clip_rect.Width(); |
235 if (size && m_DestBpp > (int)(INT_MAX / size)) { | 235 if (size && m_DestBpp > (int)(INT_MAX / size)) { |
236 return; | 236 return; |
237 } | 237 } |
238 size *= m_DestBpp; | 238 size *= m_DestBpp; |
239 if (size > INT_MAX - 31) { | 239 if (size > INT_MAX - 31) { |
240 return; | 240 return; |
241 } | 241 } |
242 size += 31; | 242 size += 31; |
243 size = size / 32 * 4; | 243 size = size / 32 * 4; |
244 m_pDestScanline = FX_TryAlloc(uint8_t, size); | 244 m_pDestScanline = FX_TryAlloc(uint8_t, size); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 m_SrcClip.Height() == 0) { | 344 m_SrcClip.Height() == 0) { |
345 return FALSE; | 345 return FALSE; |
346 } | 346 } |
347 m_pInterBuf = FX_TryAlloc(unsigned char, m_SrcClip.Height() * m_InterPitch); | 347 m_pInterBuf = FX_TryAlloc(unsigned char, m_SrcClip.Height() * m_InterPitch); |
348 if (!m_pInterBuf) { | 348 if (!m_pInterBuf) { |
349 return FALSE; | 349 return FALSE; |
350 } | 350 } |
351 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) { | 351 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) { |
352 m_pExtraAlphaBuf = | 352 m_pExtraAlphaBuf = |
353 FX_Alloc2D(unsigned char, m_SrcClip.Height(), m_ExtraMaskPitch); | 353 FX_Alloc2D(unsigned char, m_SrcClip.Height(), m_ExtraMaskPitch); |
354 FX_DWORD size = (m_DestClip.Width() * 8 + 31) / 32 * 4; | 354 uint32_t size = (m_DestClip.Width() * 8 + 31) / 32 * 4; |
355 m_pDestMaskScanline = FX_TryAlloc(unsigned char, size); | 355 m_pDestMaskScanline = FX_TryAlloc(unsigned char, size); |
356 if (!m_pDestMaskScanline) { | 356 if (!m_pDestMaskScanline) { |
357 return FALSE; | 357 return FALSE; |
358 } | 358 } |
359 } | 359 } |
360 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidth, | 360 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidth, |
361 m_SrcClip.left, m_SrcClip.right, m_Flags); | 361 m_SrcClip.left, m_SrcClip.right, m_Flags); |
362 if (!m_WeightTable.m_pWeightTables) { | 362 if (!m_WeightTable.m_pWeightTables) { |
363 return FALSE; | 363 return FALSE; |
364 } | 364 } |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { | 723 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { |
724 dest_r_y = | 724 dest_r_y = |
725 dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y; | 725 dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y; |
726 dest_g_m = | 726 dest_g_m = |
727 dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m; | 727 dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m; |
728 dest_b_c = | 728 dest_b_c = |
729 dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c; | 729 dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c; |
730 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a; | 730 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a; |
731 } | 731 } |
732 if (dest_a) { | 732 if (dest_a) { |
733 int r = ((FX_DWORD)dest_r_y) * 255 / dest_a; | 733 int r = ((uint32_t)dest_r_y) * 255 / dest_a; |
734 int g = ((FX_DWORD)dest_g_m) * 255 / dest_a; | 734 int g = ((uint32_t)dest_g_m) * 255 / dest_a; |
735 int b = ((FX_DWORD)dest_b_c) * 255 / dest_a; | 735 int b = ((uint32_t)dest_b_c) * 255 / dest_a; |
736 dest_scan[0] = b > 255 ? 255 : b < 0 ? 0 : b; | 736 dest_scan[0] = b > 255 ? 255 : b < 0 ? 0 : b; |
737 dest_scan[1] = g > 255 ? 255 : g < 0 ? 0 : g; | 737 dest_scan[1] = g > 255 ? 255 : g < 0 ? 0 : g; |
738 dest_scan[2] = r > 255 ? 255 : r < 0 ? 0 : r; | 738 dest_scan[2] = r > 255 ? 255 : r < 0 ? 0 : r; |
739 } | 739 } |
740 if (m_DestFormat == FXDIB_Argb) { | 740 if (m_DestFormat == FXDIB_Argb) { |
741 dest_scan[3] = (uint8_t)((dest_a) >> 16); | 741 dest_scan[3] = (uint8_t)((dest_a) >> 16); |
742 } else { | 742 } else { |
743 *dest_sacn_mask = (uint8_t)((dest_a) >> 16); | 743 *dest_sacn_mask = (uint8_t)((dest_a) >> 16); |
744 } | 744 } |
745 dest_scan += DestBpp; | 745 dest_scan += DestBpp; |
(...skipping 29 matching lines...) Expand all Loading... |
775 format = FXDIB_Rgb; | 775 format = FXDIB_Rgb; |
776 } | 776 } |
777 } | 777 } |
778 return format; | 778 return format; |
779 } | 779 } |
780 FX_BOOL CFX_ImageStretcher::Start(IFX_ScanlineComposer* pDest, | 780 FX_BOOL CFX_ImageStretcher::Start(IFX_ScanlineComposer* pDest, |
781 const CFX_DIBSource* pSource, | 781 const CFX_DIBSource* pSource, |
782 int dest_width, | 782 int dest_width, |
783 int dest_height, | 783 int dest_height, |
784 const FX_RECT& rect, | 784 const FX_RECT& rect, |
785 FX_DWORD flags) { | 785 uint32_t flags) { |
786 m_DestFormat = _GetStretchedFormat(pSource); | 786 m_DestFormat = _GetStretchedFormat(pSource); |
787 m_DestBPP = m_DestFormat & 0xff; | 787 m_DestBPP = m_DestFormat & 0xff; |
788 m_pDest = pDest; | 788 m_pDest = pDest; |
789 m_pSource = pSource; | 789 m_pSource = pSource; |
790 m_DestWidth = dest_width; | 790 m_DestWidth = dest_width; |
791 m_DestHeight = dest_height; | 791 m_DestHeight = dest_height; |
792 m_ClipRect = rect; | 792 m_ClipRect = rect; |
793 m_Flags = flags; | 793 m_Flags = flags; |
794 if (pSource->GetFormat() == FXDIB_1bppRgb && pSource->GetPalette()) { | 794 if (pSource->GetFormat() == FXDIB_1bppRgb && pSource->GetPalette()) { |
795 FX_ARGB pal[256]; | 795 FX_ARGB pal[256]; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 m_bFlipY = FALSE; | 856 m_bFlipY = FALSE; |
857 if (m_DestWidth < 0) { | 857 if (m_DestWidth < 0) { |
858 m_bFlipX = TRUE; | 858 m_bFlipX = TRUE; |
859 m_DestWidth = -m_DestWidth; | 859 m_DestWidth = -m_DestWidth; |
860 } | 860 } |
861 if (m_DestHeight < 0) { | 861 if (m_DestHeight < 0) { |
862 m_bFlipY = TRUE; | 862 m_bFlipY = TRUE; |
863 m_DestHeight = -m_DestHeight; | 863 m_DestHeight = -m_DestHeight; |
864 } | 864 } |
865 m_LineIndex = 0; | 865 m_LineIndex = 0; |
866 FX_DWORD size = m_ClipRect.Width(); | 866 uint32_t size = m_ClipRect.Width(); |
867 if (size && m_DestBPP > (int)(INT_MAX / size)) { | 867 if (size && m_DestBPP > (int)(INT_MAX / size)) { |
868 return FALSE; | 868 return FALSE; |
869 } | 869 } |
870 size *= m_DestBPP; | 870 size *= m_DestBPP; |
871 m_pScanline = FX_Alloc(uint8_t, (size / 8 + 3) / 4 * 4); | 871 m_pScanline = FX_Alloc(uint8_t, (size / 8 + 3) / 4 * 4); |
872 if (m_pSource->m_pAlphaMask) { | 872 if (m_pSource->m_pAlphaMask) { |
873 m_pMaskScanline = FX_Alloc(uint8_t, (m_ClipRect.Width() + 3) / 4 * 4); | 873 m_pMaskScanline = FX_Alloc(uint8_t, (m_ClipRect.Width() + 3) / 4 * 4); |
874 } | 874 } |
875 if (m_pSource->GetWidth() * m_pSource->GetHeight() < | 875 if (m_pSource->GetWidth() * m_pSource->GetHeight() < |
876 MAX_PROGRESSIVE_STRETCH_PIXELS) { | 876 MAX_PROGRESSIVE_STRETCH_PIXELS) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 m_bFlipX, m_ClipRect.left, result_width); | 908 m_bFlipX, m_ClipRect.left, result_width); |
909 if (m_pMaskScanline) { | 909 if (m_pMaskScanline) { |
910 m_pSource->m_pAlphaMask->DownSampleScanline( | 910 m_pSource->m_pAlphaMask->DownSampleScanline( |
911 src_y, m_pMaskScanline, 1, m_DestWidth, m_bFlipX, m_ClipRect.left, | 911 src_y, m_pMaskScanline, 1, m_DestWidth, m_bFlipX, m_ClipRect.left, |
912 result_width); | 912 result_width); |
913 } | 913 } |
914 m_pDest->ComposeScanline(dest_y, m_pScanline, m_pMaskScanline); | 914 m_pDest->ComposeScanline(dest_y, m_pScanline, m_pMaskScanline); |
915 } | 915 } |
916 return FALSE; | 916 return FALSE; |
917 } | 917 } |
OLD | NEW |