| 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 "render_int.h" | 7 #include "render_int.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 if (nbits == 1) { | 33 if (nbits == 1) { |
| 34 return (byte >> (7 - bitpos % 8)) & 0x01; | 34 return (byte >> (7 - bitpos % 8)) & 0x01; |
| 35 } | 35 } |
| 36 if (nbits == 16) { | 36 if (nbits == 16) { |
| 37 return byte * 256 + pData[bitpos / 8 + 1]; | 37 return byte * 256 + pData[bitpos / 8 + 1]; |
| 38 } | 38 } |
| 39 return 0; | 39 return 0; |
| 40 } | 40 } |
| 41 | 41 |
| 42 FX_SAFE_DWORD CalculatePitch8(FX_DWORD bpc, | 42 FX_SAFE_DWORD CalculatePitch8(FX_DWORD bpc, FX_DWORD components, int width) { |
| 43 FX_DWORD components, | |
| 44 int width, | |
| 45 int height) { | |
| 46 FX_SAFE_DWORD pitch = bpc; | 43 FX_SAFE_DWORD pitch = bpc; |
| 47 pitch *= components; | 44 pitch *= components; |
| 48 pitch *= width; | 45 pitch *= width; |
| 49 pitch += 7; | 46 pitch += 7; |
| 50 pitch /= 8; | 47 pitch /= 8; |
| 51 pitch *= height; | |
| 52 return pitch; | 48 return pitch; |
| 53 } | 49 } |
| 54 | 50 |
| 55 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) { | 51 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) { |
| 56 FX_SAFE_DWORD pitch = bpp; | 52 FX_SAFE_DWORD pitch = bpp; |
| 57 pitch *= width; | 53 pitch *= width; |
| 58 pitch += 31; | 54 pitch += 31; |
| 59 pitch /= 8; | 55 pitch /= 32; // quantized to number of 32-bit words. |
| 56 pitch *= 4; // and then back to bytes, (not just /8 in one step). |
| 60 return pitch; | 57 return pitch; |
| 61 } | 58 } |
| 62 | 59 |
| 63 // Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder. | 60 // Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder. |
| 64 class JpxBitMapContext { | 61 class JpxBitMapContext { |
| 65 public: | 62 public: |
| 66 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) | 63 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) |
| 67 : jpx_module_(jpx_module), decoder_(nullptr) {} | 64 : jpx_module_(jpx_module), decoder_(nullptr) {} |
| 68 | 65 |
| 69 ~JpxBitMapContext() { | 66 ~JpxBitMapContext() { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 223 } |
| 227 m_GroupFamily = GroupFamily; | 224 m_GroupFamily = GroupFamily; |
| 228 m_bLoadMask = bLoadMask; | 225 m_bLoadMask = bLoadMask; |
| 229 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, | 226 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, |
| 230 pPageResources)) { | 227 pPageResources)) { |
| 231 return FALSE; | 228 return FALSE; |
| 232 } | 229 } |
| 233 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { | 230 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { |
| 234 return FALSE; | 231 return FALSE; |
| 235 } | 232 } |
| 236 FX_SAFE_DWORD src_pitch = | 233 FX_SAFE_DWORD src_size = |
| 237 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); | 234 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; |
| 238 if (!src_pitch.IsValid()) { | 235 if (!src_size.IsValid()) { |
| 239 return FALSE; | 236 return FALSE; |
| 240 } | 237 } |
| 241 m_pStreamAcc = new CPDF_StreamAcc; | 238 m_pStreamAcc = new CPDF_StreamAcc; |
| 242 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); | 239 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE); |
| 243 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { | 240 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { |
| 244 return FALSE; | 241 return FALSE; |
| 245 } | 242 } |
| 246 if (!CreateDecoder()) { | 243 if (!CreateDecoder()) { |
| 247 return FALSE; | 244 return FALSE; |
| 248 } | 245 } |
| 249 if (m_bImageMask) { | 246 if (m_bImageMask) { |
| 250 m_bpp = 1; | 247 m_bpp = 1; |
| 251 m_bpc = 1; | 248 m_bpc = 1; |
| 252 m_nComponents = 1; | 249 m_nComponents = 1; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 343 } |
| 347 m_GroupFamily = GroupFamily; | 344 m_GroupFamily = GroupFamily; |
| 348 m_bLoadMask = bLoadMask; | 345 m_bLoadMask = bLoadMask; |
| 349 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, | 346 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, |
| 350 pPageResources)) { | 347 pPageResources)) { |
| 351 return 0; | 348 return 0; |
| 352 } | 349 } |
| 353 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { | 350 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { |
| 354 return 0; | 351 return 0; |
| 355 } | 352 } |
| 356 FX_SAFE_DWORD src_pitch = | 353 FX_SAFE_DWORD src_size = |
| 357 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); | 354 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height; |
| 358 if (!src_pitch.IsValid()) { | 355 if (!src_size.IsValid()) { |
| 359 return 0; | 356 return 0; |
| 360 } | 357 } |
| 361 m_pStreamAcc = new CPDF_StreamAcc; | 358 m_pStreamAcc = new CPDF_StreamAcc; |
| 362 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); | 359 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE); |
| 363 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { | 360 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { |
| 364 return 0; | 361 return 0; |
| 365 } | 362 } |
| 366 int ret = CreateDecoder(); | 363 int ret = CreateDecoder(); |
| 367 if (ret != 1) { | 364 if (ret != 1) { |
| 368 if (!ret) { | 365 if (!ret) { |
| 369 return ret; | 366 return ret; |
| 370 } | 367 } |
| 371 if (!ContinueToLoadMask()) { | 368 if (!ContinueToLoadMask()) { |
| 372 return 0; | 369 return 0; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 m_pDecoder = CPDF_ModuleMgr::Get() | 655 m_pDecoder = CPDF_ModuleMgr::Get() |
| 659 ->GetCodecModule() | 656 ->GetCodecModule() |
| 660 ->GetBasicModule() | 657 ->GetBasicModule() |
| 661 ->CreateRunLengthDecoder(src_data, src_size, m_Width, | 658 ->CreateRunLengthDecoder(src_data, src_size, m_Width, |
| 662 m_Height, m_nComponents, m_bpc); | 659 m_Height, m_nComponents, m_bpc); |
| 663 } | 660 } |
| 664 if (!m_pDecoder) | 661 if (!m_pDecoder) |
| 665 return 0; | 662 return 0; |
| 666 | 663 |
| 667 FX_SAFE_DWORD requested_pitch = | 664 FX_SAFE_DWORD requested_pitch = |
| 668 CalculatePitch8(m_bpc, m_nComponents, m_Width, 1); | 665 CalculatePitch8(m_bpc, m_nComponents, m_Width); |
| 669 if (!requested_pitch.IsValid()) { | 666 if (!requested_pitch.IsValid()) { |
| 670 return 0; | 667 return 0; |
| 671 } | 668 } |
| 672 FX_SAFE_DWORD provided_pitch = | 669 FX_SAFE_DWORD provided_pitch = CalculatePitch8( |
| 673 CalculatePitch8(m_pDecoder->GetBPC(), m_pDecoder->CountComps(), | 670 m_pDecoder->GetBPC(), m_pDecoder->CountComps(), m_pDecoder->GetWidth()); |
| 674 m_pDecoder->GetWidth(), 1); | |
| 675 if (!provided_pitch.IsValid()) { | 671 if (!provided_pitch.IsValid()) { |
| 676 return 0; | 672 return 0; |
| 677 } | 673 } |
| 678 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { | 674 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { |
| 679 return 0; | 675 return 0; |
| 680 } | 676 } |
| 681 return 1; | 677 return 1; |
| 682 } | 678 } |
| 683 void CPDF_DIBSource::LoadJpxBitmap() { | 679 void CPDF_DIBSource::LoadJpxBitmap() { |
| 684 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); | 680 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 uint8_t* CPDF_DIBSource::GetBuffer() const { | 1077 uint8_t* CPDF_DIBSource::GetBuffer() const { |
| 1082 if (m_pCachedBitmap) { | 1078 if (m_pCachedBitmap) { |
| 1083 return m_pCachedBitmap->GetBuffer(); | 1079 return m_pCachedBitmap->GetBuffer(); |
| 1084 } | 1080 } |
| 1085 return NULL; | 1081 return NULL; |
| 1086 } | 1082 } |
| 1087 const uint8_t* CPDF_DIBSource::GetScanline(int line) const { | 1083 const uint8_t* CPDF_DIBSource::GetScanline(int line) const { |
| 1088 if (m_bpc == 0) { | 1084 if (m_bpc == 0) { |
| 1089 return NULL; | 1085 return NULL; |
| 1090 } | 1086 } |
| 1091 FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1); | 1087 FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); |
| 1092 if (!src_pitch.IsValid()) | 1088 if (!src_pitch.IsValid()) |
| 1093 return NULL; | 1089 return NULL; |
| 1094 FX_DWORD src_pitch_value = src_pitch.ValueOrDie(); | 1090 FX_DWORD src_pitch_value = src_pitch.ValueOrDie(); |
| 1095 const uint8_t* pSrcLine = NULL; | 1091 const uint8_t* pSrcLine = NULL; |
| 1096 if (m_pCachedBitmap) { | 1092 if (m_pCachedBitmap) { |
| 1097 if (line >= m_pCachedBitmap->GetHeight()) { | 1093 if (line >= m_pCachedBitmap->GetHeight()) { |
| 1098 line = m_pCachedBitmap->GetHeight() - 1; | 1094 line = m_pCachedBitmap->GetHeight() - 1; |
| 1099 } | 1095 } |
| 1100 pSrcLine = m_pCachedBitmap->GetScanline(line); | 1096 pSrcLine = m_pCachedBitmap->GetScanline(line); |
| 1101 } else if (m_pDecoder) { | 1097 } else if (m_pDecoder) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 int dest_width, | 1223 int dest_width, |
| 1228 FX_BOOL bFlipX, | 1224 FX_BOOL bFlipX, |
| 1229 int clip_left, | 1225 int clip_left, |
| 1230 int clip_width) const { | 1226 int clip_width) const { |
| 1231 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 || | 1227 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 || |
| 1232 clip_left < 0 || clip_width <= 0) { | 1228 clip_left < 0 || clip_width <= 0) { |
| 1233 return; | 1229 return; |
| 1234 } | 1230 } |
| 1235 | 1231 |
| 1236 FX_DWORD src_width = m_Width; | 1232 FX_DWORD src_width = m_Width; |
| 1237 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1); | 1233 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width); |
| 1238 if (!pitch.IsValid()) | 1234 if (!pitch.IsValid()) |
| 1239 return; | 1235 return; |
| 1240 | 1236 |
| 1241 const uint8_t* pSrcLine = nullptr; | 1237 const uint8_t* pSrcLine = nullptr; |
| 1242 if (m_pCachedBitmap) { | 1238 if (m_pCachedBitmap) { |
| 1243 pSrcLine = m_pCachedBitmap->GetScanline(line); | 1239 pSrcLine = m_pCachedBitmap->GetScanline(line); |
| 1244 } else if (m_pDecoder) { | 1240 } else if (m_pDecoder) { |
| 1245 pSrcLine = m_pDecoder->GetScanline(line); | 1241 pSrcLine = m_pDecoder->GetScanline(line); |
| 1246 } else { | 1242 } else { |
| 1247 FX_DWORD src_pitch = pitch.ValueOrDie(); | 1243 FX_DWORD src_pitch = pitch.ValueOrDie(); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 } | 1641 } |
| 1646 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { | 1642 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { |
| 1647 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); | 1643 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); |
| 1648 } | 1644 } |
| 1649 CPDF_ImageLoader::~CPDF_ImageLoader() { | 1645 CPDF_ImageLoader::~CPDF_ImageLoader() { |
| 1650 if (!m_bCached) { | 1646 if (!m_bCached) { |
| 1651 delete m_pBitmap; | 1647 delete m_pBitmap; |
| 1652 delete m_pMask; | 1648 delete m_pMask; |
| 1653 } | 1649 } |
| 1654 } | 1650 } |
| OLD | NEW |