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

Side by Side Diff: xfa/fxfa/app/xfa_ffwidget.cpp

Issue 1973913002: Clean up CFX_ImageTransformer. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 7 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 | « core/fxge/include/fx_dib.h ('k') | no next file » | 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 "xfa/fxfa/include/xfa_ffwidget.h" 7 #include "xfa/fxfa/include/xfa_ffwidget.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory>
10 11
11 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h" 12 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobjectholder.h"
12 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h" 13 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h"
13 #include "core/fxcodec/include/fx_codec.h" 14 #include "core/fxcodec/include/fx_codec.h"
14 #include "xfa/fxfa/app/xfa_textlayout.h" 15 #include "xfa/fxfa/app/xfa_textlayout.h"
15 #include "xfa/fxfa/include/xfa_ffapp.h" 16 #include "xfa/fxfa/include/xfa_ffapp.h"
16 #include "xfa/fxfa/include/xfa_ffdoc.h" 17 #include "xfa/fxfa/include/xfa_ffdoc.h"
17 #include "xfa/fxfa/include/xfa_ffdocview.h" 18 #include "xfa/fxfa/include/xfa_ffdocview.h"
18 #include "xfa/fxfa/include/xfa_ffpageview.h" 19 #include "xfa/fxfa/include/xfa_ffpageview.h"
19 #include "xfa/fxfa/parser/cxfa_corner.h" 20 #include "xfa/fxfa/parser/cxfa_corner.h"
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 switch (iLineCap) { 474 switch (iLineCap) {
474 case XFA_ATTRIBUTEENUM_Round: 475 case XFA_ATTRIBUTEENUM_Round:
475 return CFX_GraphStateData::LineCapRound; 476 return CFX_GraphStateData::LineCapRound;
476 case XFA_ATTRIBUTEENUM_Butt: 477 case XFA_ATTRIBUTEENUM_Butt:
477 return CFX_GraphStateData::LineCapButt; 478 return CFX_GraphStateData::LineCapButt;
478 default: 479 default:
479 break; 480 break;
480 } 481 }
481 return CFX_GraphStateData::LineCapSquare; 482 return CFX_GraphStateData::LineCapSquare;
482 } 483 }
484
483 class CXFA_ImageRenderer { 485 class CXFA_ImageRenderer {
484 public: 486 public:
485 CXFA_ImageRenderer(); 487 CXFA_ImageRenderer();
486 ~CXFA_ImageRenderer(); 488 ~CXFA_ImageRenderer();
489
487 FX_BOOL Start(CFX_RenderDevice* pDevice, 490 FX_BOOL Start(CFX_RenderDevice* pDevice,
488 CFX_DIBSource* pDIBSource, 491 CFX_DIBSource* pDIBSource,
489 FX_ARGB bitmap_argb, 492 FX_ARGB bitmap_argb,
490 int bitmap_alpha, 493 int bitmap_alpha,
491 const CFX_Matrix* pImage2Device, 494 const CFX_Matrix* pImage2Device,
492 uint32_t flags, 495 uint32_t flags,
493 int blendType = FXDIB_BLEND_NORMAL); 496 int blendType = FXDIB_BLEND_NORMAL);
494 FX_BOOL Continue(IFX_Pause* pPause); 497 FX_BOOL Continue(IFX_Pause* pPause);
495 498
496 protected: 499 protected:
497 CFX_RenderDevice* m_pDevice; 500 CFX_RenderDevice* m_pDevice;
498 int m_Status; 501 int m_Status;
499 CFX_Matrix m_ImageMatrix; 502 CFX_Matrix m_ImageMatrix;
500 CFX_DIBSource* m_pDIBSource; 503 CFX_DIBSource* m_pDIBSource;
501 CFX_DIBitmap* m_pCloneConvert; 504 CFX_DIBitmap* m_pCloneConvert;
502 int m_BitmapAlpha; 505 int m_BitmapAlpha;
503 FX_ARGB m_FillArgb; 506 FX_ARGB m_FillArgb;
504 uint32_t m_Flags; 507 uint32_t m_Flags;
505 CFX_ImageTransformer* m_pTransformer; 508 std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
506 void* m_DeviceHandle; 509 void* m_DeviceHandle;
507 int32_t m_BlendType; 510 int32_t m_BlendType;
508 FX_BOOL m_Result; 511 FX_BOOL m_Result;
509 FX_BOOL m_bPrint; 512 FX_BOOL m_bPrint;
510 FX_BOOL StartDIBSource(); 513 FX_BOOL StartDIBSource();
511 void CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, 514 void CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
512 int left, 515 int left,
513 int top, 516 int top,
514 FX_ARGB mask_argb, 517 FX_ARGB mask_argb,
515 int bitmap_alpha, 518 int bitmap_alpha,
516 int blend_mode, 519 int blend_mode,
517 int Transparency); 520 int Transparency);
518 }; 521 };
519 CXFA_ImageRenderer::CXFA_ImageRenderer() { 522 CXFA_ImageRenderer::CXFA_ImageRenderer() {
520 m_pDevice = NULL; 523 m_pDevice = NULL;
521 m_Status = 0; 524 m_Status = 0;
522 m_pDIBSource = NULL; 525 m_pDIBSource = NULL;
523 m_pCloneConvert = NULL; 526 m_pCloneConvert = NULL;
524 m_BitmapAlpha = 255; 527 m_BitmapAlpha = 255;
525 m_FillArgb = 0; 528 m_FillArgb = 0;
526 m_Flags = 0; 529 m_Flags = 0;
527 m_pTransformer = NULL;
528 m_DeviceHandle = NULL; 530 m_DeviceHandle = NULL;
529 m_BlendType = FXDIB_BLEND_NORMAL; 531 m_BlendType = FXDIB_BLEND_NORMAL;
530 m_Result = TRUE; 532 m_Result = TRUE;
531 m_bPrint = FALSE; 533 m_bPrint = FALSE;
532 } 534 }
533 535
534 CXFA_ImageRenderer::~CXFA_ImageRenderer() { 536 CXFA_ImageRenderer::~CXFA_ImageRenderer() {
535 delete m_pCloneConvert; 537 delete m_pCloneConvert;
536 delete m_pTransformer;
537 if (m_DeviceHandle) 538 if (m_DeviceHandle)
538 m_pDevice->CancelDIBits(m_DeviceHandle); 539 m_pDevice->CancelDIBits(m_DeviceHandle);
539 } 540 }
540 541
541 FX_BOOL CXFA_ImageRenderer::Start(CFX_RenderDevice* pDevice, 542 FX_BOOL CXFA_ImageRenderer::Start(CFX_RenderDevice* pDevice,
542 CFX_DIBSource* pDIBSource, 543 CFX_DIBSource* pDIBSource,
543 FX_ARGB bitmap_argb, 544 FX_ARGB bitmap_argb,
544 int bitmap_alpha, 545 int bitmap_alpha,
545 const CFX_Matrix* pImage2Device, 546 const CFX_Matrix* pImage2Device,
546 uint32_t flags, 547 uint32_t flags,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 m_pCloneConvert = m_pDIBSource->CloneConvert(FXDIB_Rgb); 582 m_pCloneConvert = m_pDIBSource->CloneConvert(FXDIB_Rgb);
582 if (!m_pCloneConvert) { 583 if (!m_pCloneConvert) {
583 m_Result = FALSE; 584 m_Result = FALSE;
584 return FALSE; 585 return FALSE;
585 } 586 }
586 pDib = m_pCloneConvert; 587 pDib = m_pCloneConvert;
587 } 588 }
588 FX_RECT clip_box = m_pDevice->GetClipBox(); 589 FX_RECT clip_box = m_pDevice->GetClipBox();
589 clip_box.Intersect(image_rect); 590 clip_box.Intersect(image_rect);
590 m_Status = 2; 591 m_Status = 2;
591 m_pTransformer = new CFX_ImageTransformer; 592 m_pTransformer.reset(
592 m_pTransformer->Start(pDib, &m_ImageMatrix, m_Flags, &clip_box); 593 new CFX_ImageTransformer(pDib, &m_ImageMatrix, m_Flags, &clip_box));
594 m_pTransformer->Start();
593 return TRUE; 595 return TRUE;
594 } 596 }
595 if (m_ImageMatrix.a < 0) { 597 if (m_ImageMatrix.a < 0) {
596 dest_width = -dest_width; 598 dest_width = -dest_width;
597 } 599 }
598 if (m_ImageMatrix.d > 0) { 600 if (m_ImageMatrix.d > 0) {
599 dest_height = -dest_height; 601 dest_height = -dest_height;
600 } 602 }
601 int dest_left, dest_top; 603 int dest_left, dest_top;
602 dest_left = dest_width > 0 ? image_rect.left : image_rect.right; 604 dest_left = dest_width > 0 ? image_rect.left : image_rect.right;
(...skipping 16 matching lines...) Expand all
619 if (m_bPrint && !(m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { 621 if (m_bPrint && !(m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) {
620 m_Result = FALSE; 622 m_Result = FALSE;
621 return TRUE; 623 return TRUE;
622 } 624 }
623 FX_RECT clip_box = m_pDevice->GetClipBox(); 625 FX_RECT clip_box = m_pDevice->GetClipBox();
624 FX_RECT dest_rect = clip_box; 626 FX_RECT dest_rect = clip_box;
625 dest_rect.Intersect(image_rect); 627 dest_rect.Intersect(image_rect);
626 FX_RECT dest_clip( 628 FX_RECT dest_clip(
627 dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, 629 dest_rect.left - image_rect.left, dest_rect.top - image_rect.top,
628 dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); 630 dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top);
629 CFX_DIBitmap* pStretched = 631 std::unique_ptr<CFX_DIBitmap> pStretched(
630 m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip); 632 m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip));
631 if (pStretched) { 633 if (pStretched) {
632 CompositeDIBitmap(pStretched, dest_rect.left, dest_rect.top, m_FillArgb, 634 CompositeDIBitmap(pStretched.get(), dest_rect.left, dest_rect.top,
633 m_BitmapAlpha, m_BlendType, FALSE); 635 m_FillArgb, m_BitmapAlpha, m_BlendType, FALSE);
634 delete pStretched;
635 pStretched = NULL;
636 } 636 }
637 return FALSE; 637 return FALSE;
638 } 638 }
639
639 FX_BOOL CXFA_ImageRenderer::Continue(IFX_Pause* pPause) { 640 FX_BOOL CXFA_ImageRenderer::Continue(IFX_Pause* pPause) {
640 if (m_Status == 2) { 641 if (m_Status == 2) {
641 if (m_pTransformer->Continue(pPause)) { 642 if (m_pTransformer->Continue(pPause))
642 return TRUE; 643 return TRUE;
644
645 std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap());
646 if (!pBitmap)
647 return FALSE;
648
649 if (pBitmap->IsAlphaMask()) {
650 if (m_BitmapAlpha != 255)
651 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha);
652 m_Result =
653 m_pDevice->SetBitMask(pBitmap.get(), m_pTransformer->result().left,
654 m_pTransformer->result().top, m_FillArgb);
655 } else {
656 if (m_BitmapAlpha != 255)
657 pBitmap->MultiplyAlpha(m_BitmapAlpha);
658 m_Result =
659 m_pDevice->SetDIBits(pBitmap.get(), m_pTransformer->result().left,
660 m_pTransformer->result().top, m_BlendType);
643 } 661 }
644 CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach();
645 if (pBitmap == NULL) {
646 return FALSE;
647 }
648 if (pBitmap->IsAlphaMask()) {
649 if (m_BitmapAlpha != 255) {
650 m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha);
651 }
652 m_Result = m_pDevice->SetBitMask(pBitmap, m_pTransformer->m_ResultLeft,
653 m_pTransformer->m_ResultTop, m_FillArgb);
654 } else {
655 if (m_BitmapAlpha != 255) {
656 pBitmap->MultiplyAlpha(m_BitmapAlpha);
657 }
658 m_Result = m_pDevice->SetDIBits(pBitmap, m_pTransformer->m_ResultLeft,
659 m_pTransformer->m_ResultTop, m_BlendType);
660 }
661 delete pBitmap;
662 return FALSE; 662 return FALSE;
663 } else if (m_Status == 3) { 663 }
664 if (m_Status == 3)
664 return m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); 665 return m_pDevice->ContinueDIBits(m_DeviceHandle, pPause);
665 } 666
666 return FALSE; 667 return FALSE;
667 } 668 }
669
668 void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap, 670 void CXFA_ImageRenderer::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
669 int left, 671 int left,
670 int top, 672 int top,
671 FX_ARGB mask_argb, 673 FX_ARGB mask_argb,
672 int bitmap_alpha, 674 int bitmap_alpha,
673 int blend_mode, 675 int blend_mode,
674 int Transparency) { 676 int Transparency) {
675 if (pDIBitmap == NULL) { 677 if (pDIBitmap == NULL) {
676 return; 678 return;
677 } 679 }
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 iType != XFA_ELEMENT_Rectangle) { 1961 iType != XFA_ELEMENT_Rectangle) {
1960 return; 1962 return;
1961 } 1963 }
1962 CXFA_StrokeArray strokes; 1964 CXFA_StrokeArray strokes;
1963 if (!(dwFlags & XFA_DRAWBOX_ForceRound) && iType != XFA_ELEMENT_Arc) { 1965 if (!(dwFlags & XFA_DRAWBOX_ForceRound) && iType != XFA_ELEMENT_Arc) {
1964 box.GetStrokes(strokes); 1966 box.GetStrokes(strokes);
1965 } 1967 }
1966 XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags); 1968 XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags);
1967 XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags); 1969 XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags);
1968 } 1970 }
OLDNEW
« no previous file with comments | « core/fxge/include/fx_dib.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698