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

Side by Side Diff: core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 2149903002: Use smart pointers for various Jbig2 decoding contexts (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/fpdfapi/fpdf_render/render_int.h" 7 #include "core/fpdfapi/fpdf_render/render_int.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 m_bLoadMask(FALSE), 106 m_bLoadMask(FALSE),
107 m_bDefaultDecode(TRUE), 107 m_bDefaultDecode(TRUE),
108 m_bImageMask(FALSE), 108 m_bImageMask(FALSE),
109 m_bDoBpcCheck(TRUE), 109 m_bDoBpcCheck(TRUE),
110 m_bColorKey(FALSE), 110 m_bColorKey(FALSE),
111 m_bHasMask(FALSE), 111 m_bHasMask(FALSE),
112 m_bStdCS(FALSE), 112 m_bStdCS(FALSE),
113 m_pCompData(nullptr), 113 m_pCompData(nullptr),
114 m_pLineBuf(nullptr), 114 m_pLineBuf(nullptr),
115 m_pMaskedLine(nullptr), 115 m_pMaskedLine(nullptr),
116 m_pJbig2Context(nullptr),
117 m_pMask(nullptr), 116 m_pMask(nullptr),
118 m_pMaskStream(nullptr), 117 m_pMaskStream(nullptr),
119 m_Status(0) {} 118 m_Status(0) {}
120 119
121 CPDF_DIBSource::~CPDF_DIBSource() { 120 CPDF_DIBSource::~CPDF_DIBSource() {
122 FX_Free(m_pMaskedLine); 121 FX_Free(m_pMaskedLine);
123 FX_Free(m_pLineBuf); 122 FX_Free(m_pLineBuf);
124 m_pCachedBitmap.reset(); 123 m_pCachedBitmap.reset();
125 FX_Free(m_pCompData); 124 FX_Free(m_pCompData);
126 CPDF_ColorSpace* pCS = m_pColorSpace; 125 CPDF_ColorSpace* pCS = m_pColorSpace;
127 if (pCS && m_pDocument) { 126 if (pCS && m_pDocument) {
128 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); 127 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
129 } 128 }
130 if (m_pJbig2Context) {
131 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module();
132 pJbig2Module->DestroyJbig2Context(m_pJbig2Context);
133 }
134 } 129 }
135 130
136 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const { 131 CFX_DIBitmap* CPDF_DIBSource::GetBitmap() const {
137 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone(); 132 return m_pCachedBitmap ? m_pCachedBitmap.get() : Clone();
138 } 133 }
139 134
140 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const { 135 void CPDF_DIBSource::ReleaseBitmap(CFX_DIBitmap* pBitmap) const {
141 if (pBitmap && pBitmap != m_pCachedBitmap.get()) { 136 if (pBitmap && pBitmap != m_pCachedBitmap.get()) {
142 delete pBitmap; 137 delete pBitmap;
143 } 138 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 333
339 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) { 334 int CPDF_DIBSource::ContinueLoadDIBSource(IFX_Pause* pPause) {
340 FXCODEC_STATUS ret; 335 FXCODEC_STATUS ret;
341 if (m_Status == 1) { 336 if (m_Status == 1) {
342 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 337 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
343 if (decoder == "JPXDecode") { 338 if (decoder == "JPXDecode") {
344 return 0; 339 return 0;
345 } 340 }
346 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module(); 341 CCodec_Jbig2Module* pJbig2Module = CPDF_ModuleMgr::Get()->GetJbig2Module();
347 if (!m_pJbig2Context) { 342 if (!m_pJbig2Context) {
348 m_pJbig2Context = pJbig2Module->CreateJbig2Context(); 343 m_pJbig2Context.reset(new CCodec_Jbig2Context());
349 if (m_pStreamAcc->GetImageParam()) { 344 if (m_pStreamAcc->GetImageParam()) {
350 CPDF_Stream* pGlobals = 345 CPDF_Stream* pGlobals =
351 m_pStreamAcc->GetImageParam()->GetStreamBy("JBIG2Globals"); 346 m_pStreamAcc->GetImageParam()->GetStreamBy("JBIG2Globals");
352 if (pGlobals) { 347 if (pGlobals) {
353 m_pGlobalStream.reset(new CPDF_StreamAcc); 348 m_pGlobalStream.reset(new CPDF_StreamAcc);
354 m_pGlobalStream->LoadAllData(pGlobals, FALSE); 349 m_pGlobalStream->LoadAllData(pGlobals, FALSE);
355 } 350 }
356 } 351 }
357 ret = pJbig2Module->StartDecode( 352 ret = pJbig2Module->StartDecode(
358 m_pJbig2Context, m_pDocument->CodecContext(), m_Width, m_Height, 353 m_pJbig2Context.get(), m_pDocument->CodecContext(), m_Width, m_Height,
359 m_pStreamAcc.get(), m_pGlobalStream.get(), 354 m_pStreamAcc.get(), m_pGlobalStream.get(),
360 m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause); 355 m_pCachedBitmap->GetBuffer(), m_pCachedBitmap->GetPitch(), pPause);
361 if (ret < 0) { 356 if (ret < 0) {
362 m_pCachedBitmap.reset(); 357 m_pCachedBitmap.reset();
363 m_pGlobalStream.reset(); 358 m_pGlobalStream.reset();
364 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); 359 m_pJbig2Context.reset();
365 m_pJbig2Context = nullptr;
366 return 0; 360 return 0;
367 } 361 }
368 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 362 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
369 return 2; 363 return 2;
370 } 364 }
371 int ret1 = 1; 365 int ret1 = 1;
372 if (m_bHasMask) { 366 if (m_bHasMask) {
373 ret1 = ContinueLoadMaskDIB(pPause); 367 ret1 = ContinueLoadMaskDIB(pPause);
374 m_Status = 2; 368 m_Status = 2;
375 } 369 }
376 if (ret1 == 2) { 370 if (ret1 == 2) {
377 return ret1; 371 return ret1;
378 } 372 }
379 if (m_pColorSpace && m_bStdCS) { 373 if (m_pColorSpace && m_bStdCS) {
380 m_pColorSpace->EnableStdConversion(FALSE); 374 m_pColorSpace->EnableStdConversion(FALSE);
381 } 375 }
382 return ret1; 376 return ret1;
383 } 377 }
384 ret = pJbig2Module->ContinueDecode(m_pJbig2Context, pPause); 378 ret = pJbig2Module->ContinueDecode(m_pJbig2Context.get(), pPause);
385 if (ret < 0) { 379 if (ret < 0) {
386 m_pCachedBitmap.reset(); 380 m_pCachedBitmap.reset();
387 m_pGlobalStream.reset(); 381 m_pGlobalStream.reset();
388 pJbig2Module->DestroyJbig2Context(m_pJbig2Context); 382 m_pJbig2Context.reset();
389 m_pJbig2Context = nullptr;
390 return 0; 383 return 0;
391 } 384 }
392 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) { 385 if (ret == FXCODEC_STATUS_DECODE_TOBECONTINUE) {
393 return 2; 386 return 2;
394 } 387 }
395 int ret1 = 1; 388 int ret1 = 1;
396 if (m_bHasMask) { 389 if (m_bHasMask) {
397 ret1 = ContinueLoadMaskDIB(pPause); 390 ret1 = ContinueLoadMaskDIB(pPause);
398 m_Status = 2; 391 m_Status = 2;
399 } 392 }
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 FXSYS_memset(pLineBuf, 0xFF, m_Pitch); 1046 FXSYS_memset(pLineBuf, 0xFF, m_Pitch);
1054 return pLineBuf; 1047 return pLineBuf;
1055 } 1048 }
1056 if (m_bpc * m_nComponents == 1) { 1049 if (m_bpc * m_nComponents == 1) {
1057 if (m_bImageMask && m_bDefaultDecode) { 1050 if (m_bImageMask && m_bDefaultDecode) {
1058 for (uint32_t i = 0; i < src_pitch_value; i++) { 1051 for (uint32_t i = 0; i < src_pitch_value; i++) {
1059 m_pLineBuf[i] = ~pSrcLine[i]; 1052 m_pLineBuf[i] = ~pSrcLine[i];
1060 } 1053 }
1061 } else if (m_bColorKey) { 1054 } else if (m_bColorKey) {
1062 uint32_t reset_argb, set_argb; 1055 uint32_t reset_argb, set_argb;
1063 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000; 1056 reset_argb = m_pPalette ? m_pPalette.get()[0] : 0xFF000000;
1064 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF; 1057 set_argb = m_pPalette ? m_pPalette.get()[1] : 0xFFFFFFFF;
1065 if (m_pCompData[0].m_ColorKeyMin == 0) { 1058 if (m_pCompData[0].m_ColorKeyMin == 0) {
1066 reset_argb = 0; 1059 reset_argb = 0;
1067 } 1060 }
1068 if (m_pCompData[0].m_ColorKeyMax == 1) { 1061 if (m_pCompData[0].m_ColorKeyMax == 1) {
1069 set_argb = 0; 1062 set_argb = 0;
1070 } 1063 }
1071 set_argb = FXARGB_TODIB(set_argb); 1064 set_argb = FXARGB_TODIB(set_argb);
1072 reset_argb = FXARGB_TODIB(reset_argb); 1065 reset_argb = FXARGB_TODIB(reset_argb);
1073 uint32_t* dest_scan = reinterpret_cast<uint32_t*>(m_pMaskedLine); 1066 uint32_t* dest_scan = reinterpret_cast<uint32_t*>(m_pMaskedLine);
1074 for (int col = 0; col < m_Width; col++) { 1067 for (int col = 0; col < m_Width; col++) {
(...skipping 24 matching lines...) Expand all
1099 } 1092 }
1100 m_pLineBuf[col] = color_index; 1093 m_pLineBuf[col] = color_index;
1101 } 1094 }
1102 } 1095 }
1103 if (m_bColorKey) { 1096 if (m_bColorKey) {
1104 uint8_t* pDestPixel = m_pMaskedLine; 1097 uint8_t* pDestPixel = m_pMaskedLine;
1105 const uint8_t* pSrcPixel = m_pLineBuf; 1098 const uint8_t* pSrcPixel = m_pLineBuf;
1106 for (int col = 0; col < m_Width; col++) { 1099 for (int col = 0; col < m_Width; col++) {
1107 uint8_t index = *pSrcPixel++; 1100 uint8_t index = *pSrcPixel++;
1108 if (m_pPalette) { 1101 if (m_pPalette) {
1109 *pDestPixel++ = FXARGB_B(m_pPalette[index]); 1102 *pDestPixel++ = FXARGB_B(m_pPalette.get()[index]);
1110 *pDestPixel++ = FXARGB_G(m_pPalette[index]); 1103 *pDestPixel++ = FXARGB_G(m_pPalette.get()[index]);
1111 *pDestPixel++ = FXARGB_R(m_pPalette[index]); 1104 *pDestPixel++ = FXARGB_R(m_pPalette.get()[index]);
1112 } else { 1105 } else {
1113 *pDestPixel++ = index; 1106 *pDestPixel++ = index;
1114 *pDestPixel++ = index; 1107 *pDestPixel++ = index;
1115 *pDestPixel++ = index; 1108 *pDestPixel++ = index;
1116 } 1109 }
1117 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin || 1110 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin ||
1118 index > m_pCompData[0].m_ColorKeyMax) 1111 index > m_pCompData[0].m_ColorKeyMax)
1119 ? 0xFF 1112 ? 0xFF
1120 : 0; 1113 : 0;
1121 pDestPixel++; 1114 pDestPixel++;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 int clip_left, 1226 int clip_left,
1234 int clip_width) const { 1227 int clip_width) const {
1235 uint32_t set_argb = (uint32_t)-1; 1228 uint32_t set_argb = (uint32_t)-1;
1236 uint32_t reset_argb = 0; 1229 uint32_t reset_argb = 0;
1237 if (m_bImageMask) { 1230 if (m_bImageMask) {
1238 if (m_bDefaultDecode) { 1231 if (m_bDefaultDecode) {
1239 set_argb = 0; 1232 set_argb = 0;
1240 reset_argb = (uint32_t)-1; 1233 reset_argb = (uint32_t)-1;
1241 } 1234 }
1242 } else if (m_bColorKey) { 1235 } else if (m_bColorKey) {
1243 reset_argb = m_pPalette ? m_pPalette[0] : 0xFF000000; 1236 reset_argb = m_pPalette ? m_pPalette.get()[0] : 0xFF000000;
1244 set_argb = m_pPalette ? m_pPalette[1] : 0xFFFFFFFF; 1237 set_argb = m_pPalette ? m_pPalette.get()[1] : 0xFFFFFFFF;
1245 if (m_pCompData[0].m_ColorKeyMin == 0) { 1238 if (m_pCompData[0].m_ColorKeyMin == 0) {
1246 reset_argb = 0; 1239 reset_argb = 0;
1247 } 1240 }
1248 if (m_pCompData[0].m_ColorKeyMax == 1) { 1241 if (m_pCompData[0].m_ColorKeyMax == 1) {
1249 set_argb = 0; 1242 set_argb = 0;
1250 } 1243 }
1251 set_argb = FXARGB_TODIB(set_argb); 1244 set_argb = FXARGB_TODIB(set_argb);
1252 reset_argb = FXARGB_TODIB(reset_argb); 1245 reset_argb = FXARGB_TODIB(reset_argb);
1253 uint32_t* dest_scan_dword = reinterpret_cast<uint32_t*>(dest_scan); 1246 uint32_t* dest_scan_dword = reinterpret_cast<uint32_t*>(dest_scan);
1254 for (int i = 0; i < clip_width; i++) { 1247 for (int i = 0; i < clip_width; i++) {
1255 uint32_t src_x = (clip_left + i) * src_width / dest_width; 1248 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1256 if (bFlipX) { 1249 if (bFlipX) {
1257 src_x = src_width - src_x - 1; 1250 src_x = src_width - src_x - 1;
1258 } 1251 }
1259 src_x %= src_width; 1252 src_x %= src_width;
1260 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) { 1253 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) {
1261 dest_scan_dword[i] = set_argb; 1254 dest_scan_dword[i] = set_argb;
1262 } else { 1255 } else {
1263 dest_scan_dword[i] = reset_argb; 1256 dest_scan_dword[i] = reset_argb;
1264 } 1257 }
1265 } 1258 }
1266 return; 1259 return;
1267 } else { 1260 } else {
1268 if (dest_Bpp == 1) { 1261 if (dest_Bpp == 1) {
1269 } else if (m_pPalette) { 1262 } else if (m_pPalette) {
1270 reset_argb = m_pPalette[0]; 1263 reset_argb = m_pPalette.get()[0];
1271 set_argb = m_pPalette[1]; 1264 set_argb = m_pPalette.get()[1];
1272 } 1265 }
1273 } 1266 }
1274 for (int i = 0; i < clip_width; i++) { 1267 for (int i = 0; i < clip_width; i++) {
1275 uint32_t src_x = (clip_left + i) * src_width / dest_width; 1268 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1276 if (bFlipX) { 1269 if (bFlipX) {
1277 src_x = src_width - src_x - 1; 1270 src_x = src_width - src_x - 1;
1278 } 1271 }
1279 src_x %= src_width; 1272 src_x %= src_width;
1280 int dest_pos = i * dest_Bpp; 1273 int dest_pos = i * dest_Bpp;
1281 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) { 1274 if (pSrcLine[src_x / 8] & (1 << (7 - src_x % 8))) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 if (m_bColorKey) { 1320 if (m_bColorKey) {
1328 for (int i = 0; i < clip_width; i++) { 1321 for (int i = 0; i < clip_width; i++) {
1329 uint32_t src_x = (clip_left + i) * src_width / dest_width; 1322 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1330 if (bFlipX) { 1323 if (bFlipX) {
1331 src_x = src_width - src_x - 1; 1324 src_x = src_width - src_x - 1;
1332 } 1325 }
1333 src_x %= src_width; 1326 src_x %= src_width;
1334 uint8_t* pDestPixel = dest_scan + i * 4; 1327 uint8_t* pDestPixel = dest_scan + i * 4;
1335 uint8_t index = pSrcLine[src_x]; 1328 uint8_t index = pSrcLine[src_x];
1336 if (m_pPalette) { 1329 if (m_pPalette) {
1337 *pDestPixel++ = FXARGB_B(m_pPalette[index]); 1330 *pDestPixel++ = FXARGB_B(m_pPalette.get()[index]);
1338 *pDestPixel++ = FXARGB_G(m_pPalette[index]); 1331 *pDestPixel++ = FXARGB_G(m_pPalette.get()[index]);
1339 *pDestPixel++ = FXARGB_R(m_pPalette[index]); 1332 *pDestPixel++ = FXARGB_R(m_pPalette.get()[index]);
1340 } else { 1333 } else {
1341 *pDestPixel++ = index; 1334 *pDestPixel++ = index;
1342 *pDestPixel++ = index; 1335 *pDestPixel++ = index;
1343 *pDestPixel++ = index; 1336 *pDestPixel++ = index;
1344 } 1337 }
1345 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin || 1338 *pDestPixel = (index < m_pCompData[0].m_ColorKeyMin ||
1346 index > m_pCompData[0].m_ColorKeyMax) 1339 index > m_pCompData[0].m_ColorKeyMax)
1347 ? 0xFF 1340 ? 0xFF
1348 : 0; 1341 : 0;
1349 } 1342 }
1350 return; 1343 return;
1351 } 1344 }
1352 for (int i = 0; i < clip_width; i++) { 1345 for (int i = 0; i < clip_width; i++) {
1353 uint32_t src_x = (clip_left + i) * src_width / dest_width; 1346 uint32_t src_x = (clip_left + i) * src_width / dest_width;
1354 if (bFlipX) { 1347 if (bFlipX) {
1355 src_x = src_width - src_x - 1; 1348 src_x = src_width - src_x - 1;
1356 } 1349 }
1357 src_x %= src_width; 1350 src_x %= src_width;
1358 uint8_t index = pSrcLine[src_x]; 1351 uint8_t index = pSrcLine[src_x];
1359 if (dest_Bpp == 1) { 1352 if (dest_Bpp == 1) {
1360 dest_scan[i] = index; 1353 dest_scan[i] = index;
1361 } else { 1354 } else {
1362 int dest_pos = i * dest_Bpp; 1355 int dest_pos = i * dest_Bpp;
1363 FX_ARGB argb = m_pPalette[index]; 1356 FX_ARGB argb = m_pPalette.get()[index];
1364 dest_scan[dest_pos] = FXARGB_B(argb); 1357 dest_scan[dest_pos] = FXARGB_B(argb);
1365 dest_scan[dest_pos + 1] = FXARGB_G(argb); 1358 dest_scan[dest_pos + 1] = FXARGB_G(argb);
1366 dest_scan[dest_pos + 2] = FXARGB_R(argb); 1359 dest_scan[dest_pos + 2] = FXARGB_R(argb);
1367 } 1360 }
1368 } 1361 }
1369 } 1362 }
1370 1363
1371 void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp, 1364 void CPDF_DIBSource::DownSampleScanline32Bit(int orig_Bpp,
1372 int dest_Bpp, 1365 int dest_Bpp,
1373 uint32_t src_width, 1366 uint32_t src_width,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 IFX_Pause* pPause) { 1563 IFX_Pause* pPause) {
1571 return LoadHandle->Continue(pPause); 1564 return LoadHandle->Continue(pPause);
1572 } 1565 }
1573 1566
1574 CPDF_ImageLoader::~CPDF_ImageLoader() { 1567 CPDF_ImageLoader::~CPDF_ImageLoader() {
1575 if (!m_bCached) { 1568 if (!m_bCached) {
1576 delete m_pBitmap; 1569 delete m_pBitmap;
1577 delete m_pMask; 1570 delete m_pMask;
1578 } 1571 }
1579 } 1572 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698