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

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

Issue 2136683002: Use smart pointers for class owned member variables (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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
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 <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 *dest_buf++ = m_RampB[*(src_buf++)]; 319 *dest_buf++ = m_RampB[*(src_buf++)];
320 *dest_buf++ = m_RampG[*(src_buf++)]; 320 *dest_buf++ = m_RampG[*(src_buf++)];
321 *dest_buf++ = m_RampR[*(src_buf++)]; 321 *dest_buf++ = m_RampR[*(src_buf++)];
322 *dest_buf++ = *(src_buf++); 322 *dest_buf++ = *(src_buf++);
323 } 323 }
324 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ 324 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
325 } 325 }
326 #endif 326 #endif
327 } 327 }
328 } 328 }
329
329 CPDF_ImageRenderer::CPDF_ImageRenderer() { 330 CPDF_ImageRenderer::CPDF_ImageRenderer() {
330 m_pRenderStatus = nullptr; 331 m_pRenderStatus = nullptr;
331 m_pImageObject = nullptr; 332 m_pImageObject = nullptr;
332 m_Result = TRUE; 333 m_Result = TRUE;
333 m_Status = 0; 334 m_Status = 0;
334 m_pTransformer = nullptr;
335 m_DeviceHandle = nullptr; 335 m_DeviceHandle = nullptr;
336 m_LoadHandle = nullptr;
337 m_pClone = nullptr;
338 m_bStdCS = FALSE; 336 m_bStdCS = FALSE;
339 m_bPatternColor = FALSE; 337 m_bPatternColor = FALSE;
340 m_BlendType = FXDIB_BLEND_NORMAL; 338 m_BlendType = FXDIB_BLEND_NORMAL;
341 m_pPattern = nullptr; 339 m_pPattern = nullptr;
342 m_pObj2Device = nullptr; 340 m_pObj2Device = nullptr;
343 } 341 }
342
344 CPDF_ImageRenderer::~CPDF_ImageRenderer() { 343 CPDF_ImageRenderer::~CPDF_ImageRenderer() {
345 delete m_pTransformer;
346 if (m_DeviceHandle) { 344 if (m_DeviceHandle) {
347 m_pRenderStatus->m_pDevice->CancelDIBits(m_DeviceHandle); 345 m_pRenderStatus->m_pDevice->CancelDIBits(m_DeviceHandle);
348 } 346 }
349 delete m_LoadHandle;
350 delete m_pClone;
351 } 347 }
348
352 FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() { 349 FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() {
353 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); 350 CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect();
354 FX_RECT image_rect = image_rect_f.GetOutterRect(); 351 FX_RECT image_rect = image_rect_f.GetOutterRect();
355 int dest_width = image_rect.Width(); 352 int dest_width = image_rect.Width();
356 int dest_height = image_rect.Height(); 353 int dest_height = image_rect.Height();
357 if (m_ImageMatrix.a < 0) { 354 if (m_ImageMatrix.a < 0) {
358 dest_width = -dest_width; 355 dest_width = -dest_width;
359 } 356 }
360 if (m_ImageMatrix.d > 0) { 357 if (m_ImageMatrix.d > 0) {
361 dest_height = -dest_height; 358 dest_height = -dest_height;
362 } 359 }
363 if (m_Loader.Start(m_pImageObject, 360 if (m_Loader.Start(m_pImageObject,
364 m_pRenderStatus->m_pContext->GetPageCache(), m_LoadHandle, 361 m_pRenderStatus->m_pContext->GetPageCache(), &m_LoadHandle,
365 m_bStdCS, m_pRenderStatus->m_GroupFamily, 362 m_bStdCS, m_pRenderStatus->m_GroupFamily,
366 m_pRenderStatus->m_bLoadMask, m_pRenderStatus, dest_width, 363 m_pRenderStatus->m_bLoadMask, m_pRenderStatus, dest_width,
367 dest_height)) { 364 dest_height)) {
368 if (m_LoadHandle) { 365 if (m_LoadHandle) {
369 m_Status = 4; 366 m_Status = 4;
370 return TRUE; 367 return TRUE;
371 } 368 }
372 } 369 }
373 return FALSE; 370 return FALSE;
374 } 371 }
372
375 FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { 373 FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() {
376 if (!m_Loader.m_pBitmap) { 374 if (!m_Loader.m_pBitmap) {
377 return FALSE; 375 return FALSE;
378 } 376 }
379 m_BitmapAlpha = 255; 377 m_BitmapAlpha = 255;
380 const CPDF_GeneralStateData* pGeneralState = 378 const CPDF_GeneralStateData* pGeneralState =
381 m_pImageObject->m_GeneralState.GetObject(); 379 m_pImageObject->m_GeneralState.GetObject();
382 if (pGeneralState) { 380 if (pGeneralState) {
383 m_BitmapAlpha = FXSYS_round(pGeneralState->m_FillAlpha * 255); 381 m_BitmapAlpha = FXSYS_round(pGeneralState->m_FillAlpha * 255);
384 } 382 }
(...skipping 24 matching lines...) Expand all
409 if (m_pDIBSource->IsAlphaMask()) { 407 if (m_pDIBSource->IsAlphaMask()) {
410 CPDF_Color* pColor = m_pImageObject->m_ColorState.GetFillColor(); 408 CPDF_Color* pColor = m_pImageObject->m_ColorState.GetFillColor();
411 if (pColor && pColor->IsPattern()) { 409 if (pColor && pColor->IsPattern()) {
412 m_pPattern = pColor->GetPattern(); 410 m_pPattern = pColor->GetPattern();
413 if (m_pPattern) { 411 if (m_pPattern) {
414 m_bPatternColor = TRUE; 412 m_bPatternColor = TRUE;
415 } 413 }
416 } 414 }
417 m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject); 415 m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject);
418 } else if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_GRAY) { 416 } else if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_GRAY) {
419 m_pClone = m_pDIBSource->Clone(); 417 m_pClone.reset(m_pDIBSource->Clone());
420 m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor, 418 m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor,
421 m_pRenderStatus->m_Options.m_ForeColor); 419 m_pRenderStatus->m_Options.m_ForeColor);
422 m_pDIBSource = m_pClone; 420 m_pDIBSource = m_pClone.get();
423 } 421 }
424 m_Flags = 0; 422 m_Flags = 0;
425 if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_DOWNSAMPLE) { 423 if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_DOWNSAMPLE) {
426 m_Flags |= RENDER_FORCE_DOWNSAMPLE; 424 m_Flags |= RENDER_FORCE_DOWNSAMPLE;
427 } else if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_HALFTONE) { 425 } else if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_HALFTONE) {
428 m_Flags |= RENDER_FORCE_HALFTONE; 426 m_Flags |= RENDER_FORCE_HALFTONE;
429 } 427 }
430 if (m_pRenderStatus->m_pDevice->GetDeviceClass() != FXDC_DISPLAY) { 428 if (m_pRenderStatus->m_pDevice->GetDeviceClass() != FXDC_DISPLAY) {
431 CPDF_Object* pFilters = 429 CPDF_Object* pFilters =
432 m_pImageObject->m_pImage->GetStream()->GetDict()->GetDirectObjectBy( 430 m_pImageObject->m_pImage->GetStream()->GetDict()->GetDirectObjectBy(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 int format = pColorSpace->GetFamily(); 479 int format = pColorSpace->GetFamily();
482 if (format == PDFCS_DEVICECMYK || format == PDFCS_SEPARATION || 480 if (format == PDFCS_DEVICECMYK || format == PDFCS_SEPARATION ||
483 format == PDFCS_DEVICEN) { 481 format == PDFCS_DEVICEN) {
484 m_BlendType = FXDIB_BLEND_DARKEN; 482 m_BlendType = FXDIB_BLEND_DARKEN;
485 } 483 }
486 pDocument->GetPageData()->ReleaseColorSpace(pCSObj); 484 pDocument->GetPageData()->ReleaseColorSpace(pCSObj);
487 } 485 }
488 } 486 }
489 return StartDIBSource(); 487 return StartDIBSource();
490 } 488 }
489
491 FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, 490 FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
492 const CPDF_PageObject* pObj, 491 const CPDF_PageObject* pObj,
493 const CFX_Matrix* pObj2Device, 492 const CFX_Matrix* pObj2Device,
494 FX_BOOL bStdCS, 493 FX_BOOL bStdCS,
495 int blendType) { 494 int blendType) {
496 m_pRenderStatus = pStatus; 495 m_pRenderStatus = pStatus;
497 m_bStdCS = bStdCS; 496 m_bStdCS = bStdCS;
498 m_pImageObject = pObj->AsImage(); 497 m_pImageObject = pObj->AsImage();
499 m_BlendType = blendType; 498 m_BlendType = blendType;
500 m_pObj2Device = pObj2Device; 499 m_pObj2Device = pObj2Device;
501 CPDF_Dictionary* pOC = m_pImageObject->m_pImage->GetOC(); 500 CPDF_Dictionary* pOC = m_pImageObject->m_pImage->GetOC();
502 if (pOC && m_pRenderStatus->m_Options.m_pOCContext && 501 if (pOC && m_pRenderStatus->m_Options.m_pOCContext &&
503 !m_pRenderStatus->m_Options.m_pOCContext->CheckOCGVisible(pOC)) { 502 !m_pRenderStatus->m_Options.m_pOCContext->CheckOCGVisible(pOC)) {
504 return FALSE; 503 return FALSE;
505 } 504 }
506 m_ImageMatrix = m_pImageObject->m_Matrix; 505 m_ImageMatrix = m_pImageObject->m_Matrix;
507 m_ImageMatrix.Concat(*pObj2Device); 506 m_ImageMatrix.Concat(*pObj2Device);
508 if (StartLoadDIBSource()) { 507 if (StartLoadDIBSource()) {
509 return TRUE; 508 return TRUE;
510 } 509 }
511 return StartRenderDIBSource(); 510 return StartRenderDIBSource();
512 } 511 }
512
513 FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus, 513 FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
514 const CFX_DIBSource* pDIBSource, 514 const CFX_DIBSource* pDIBSource,
515 FX_ARGB bitmap_argb, 515 FX_ARGB bitmap_argb,
516 int bitmap_alpha, 516 int bitmap_alpha,
517 const CFX_Matrix* pImage2Device, 517 const CFX_Matrix* pImage2Device,
518 uint32_t flags, 518 uint32_t flags,
519 FX_BOOL bStdCS, 519 FX_BOOL bStdCS,
520 int blendType) { 520 int blendType) {
521 m_pRenderStatus = pStatus; 521 m_pRenderStatus = pStatus;
522 m_pDIBSource = pDIBSource; 522 m_pDIBSource = pDIBSource;
523 m_FillArgb = bitmap_argb; 523 m_FillArgb = bitmap_argb;
524 m_BitmapAlpha = bitmap_alpha; 524 m_BitmapAlpha = bitmap_alpha;
525 m_ImageMatrix = *pImage2Device; 525 m_ImageMatrix = *pImage2Device;
526 m_Flags = flags; 526 m_Flags = flags;
527 m_bStdCS = bStdCS; 527 m_bStdCS = bStdCS;
528 m_BlendType = blendType; 528 m_BlendType = blendType;
529 return StartDIBSource(); 529 return StartDIBSource();
530 } 530 }
531
531 FX_BOOL CPDF_ImageRenderer::DrawPatternImage(const CFX_Matrix* pObj2Device) { 532 FX_BOOL CPDF_ImageRenderer::DrawPatternImage(const CFX_Matrix* pObj2Device) {
532 if (m_pRenderStatus->m_bPrint && 533 if (m_pRenderStatus->m_bPrint &&
533 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { 534 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) {
534 m_Result = FALSE; 535 m_Result = FALSE;
535 return FALSE; 536 return FALSE;
536 } 537 }
537 FX_RECT rect = m_ImageMatrix.GetUnitRect().GetOutterRect(); 538 FX_RECT rect = m_ImageMatrix.GetUnitRect().GetOutterRect();
538 rect.Intersect(m_pRenderStatus->m_pDevice->GetClipBox()); 539 rect.Intersect(m_pRenderStatus->m_pDevice->GetClipBox());
539 if (rect.IsEmpty()) { 540 if (rect.IsEmpty()) {
540 return FALSE; 541 return FALSE;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 if ((FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || 767 if ((FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) ||
767 (FXSYS_fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { 768 (FXSYS_fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) {
768 if (m_pRenderStatus->m_bPrint && 769 if (m_pRenderStatus->m_bPrint &&
769 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { 770 !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) {
770 m_Result = FALSE; 771 m_Result = FALSE;
771 return FALSE; 772 return FALSE;
772 } 773 }
773 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); 774 FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox();
774 clip_box.Intersect(image_rect); 775 clip_box.Intersect(image_rect);
775 m_Status = 2; 776 m_Status = 2;
776 m_pTransformer = new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix, 777 m_pTransformer.reset(new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix,
777 m_Flags, &clip_box); 778 m_Flags, &clip_box));
778 m_pTransformer->Start(); 779 m_pTransformer->Start();
779 return TRUE; 780 return TRUE;
780 } 781 }
781 if (m_ImageMatrix.a < 0) 782 if (m_ImageMatrix.a < 0)
782 dest_width = -dest_width; 783 dest_width = -dest_width;
783 784
784 if (m_ImageMatrix.d > 0) 785 if (m_ImageMatrix.d > 0)
785 dest_height = -dest_height; 786 dest_height = -dest_height;
786 787
787 int dest_left = dest_width > 0 ? image_rect.left : image_rect.right; 788 int dest_left = dest_width > 0 ? image_rect.left : image_rect.right;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 m_Result = m_pRenderStatus->m_pDevice->SetDIBitsWithBlend( 890 m_Result = m_pRenderStatus->m_pDevice->SetDIBitsWithBlend(
890 pBitmap.get(), m_pTransformer->result().left, 891 pBitmap.get(), m_pTransformer->result().left,
891 m_pTransformer->result().top, m_BlendType); 892 m_pTransformer->result().top, m_BlendType);
892 } 893 }
893 return FALSE; 894 return FALSE;
894 } 895 }
895 if (m_Status == 3) 896 if (m_Status == 3)
896 return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); 897 return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause);
897 898
898 if (m_Status == 4) { 899 if (m_Status == 4) {
899 if (m_Loader.Continue(m_LoadHandle, pPause)) 900 if (m_Loader.Continue(m_LoadHandle.get(), pPause))
900 return TRUE; 901 return TRUE;
901 902
902 if (StartRenderDIBSource()) 903 if (StartRenderDIBSource())
903 return Continue(pPause); 904 return Continue(pPause);
904 } 905 }
905 return FALSE; 906 return FALSE;
906 } 907 }
907 908
908 CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( 909 CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(
909 const uint8_t* src_buf, 910 const uint8_t* src_buf,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 } else if (pFunc) { 1037 } else if (pFunc) {
1037 int size = dest_pitch * height; 1038 int size = dest_pitch * height;
1038 for (int i = 0; i < size; i++) { 1039 for (int i = 0; i < size; i++) {
1039 dest_buf[i] = transfers[src_buf[i]]; 1040 dest_buf[i] = transfers[src_buf[i]];
1040 } 1041 }
1041 } else { 1042 } else {
1042 FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height); 1043 FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height);
1043 } 1044 }
1044 return pMask.release(); 1045 return pMask.release();
1045 } 1046 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/include/cpdf_parser.h ('k') | core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698