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

Side by Side Diff: core/fxge/ge/cfx_cliprgn.cpp

Issue 2216853004: Refactor fx_ge part 2 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fixing build, comments Created 4 years, 4 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/ge/cfx_cliprgn.h ('k') | core/fxge/ge/cfx_gemodule.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "core/fxge/ge/cfx_cliprgn.h"
8
9 CFX_ClipRgn::CFX_ClipRgn(int width, int height)
10 : m_Type(RectI), m_Box(0, 0, width, height) {}
11
12 CFX_ClipRgn::CFX_ClipRgn(const CFX_ClipRgn& src) {
13 m_Type = src.m_Type;
14 m_Box = src.m_Box;
15 m_Mask = src.m_Mask;
16 }
17
18 CFX_ClipRgn::~CFX_ClipRgn() {}
19
20 void CFX_ClipRgn::Reset(const FX_RECT& rect) {
21 m_Type = RectI;
22 m_Box = rect;
23 m_Mask.SetNull();
24 }
25
26 void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
27 if (m_Type == RectI) {
28 m_Box.Intersect(rect);
29 return;
30 }
31 if (m_Type == MaskF) {
32 IntersectMaskRect(rect, m_Box, m_Mask);
33 return;
34 }
35 }
36
37 void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
38 FX_RECT mask_rect,
39 CFX_DIBitmapRef Mask) {
40 const CFX_DIBitmap* mask_dib = Mask.GetObject();
41 m_Type = MaskF;
42 m_Box = rect;
43 m_Box.Intersect(mask_rect);
44 if (m_Box.IsEmpty()) {
45 m_Type = RectI;
46 return;
47 }
48 if (m_Box == mask_rect) {
49 m_Mask = Mask;
50 return;
51 }
52 CFX_DIBitmap* new_dib = m_Mask.New();
53 if (!new_dib)
54 return;
55 new_dib->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
56 for (int row = m_Box.top; row < m_Box.bottom; row++) {
57 uint8_t* dest_scan =
58 new_dib->GetBuffer() + new_dib->GetPitch() * (row - m_Box.top);
59 uint8_t* src_scan =
60 mask_dib->GetBuffer() + mask_dib->GetPitch() * (row - mask_rect.top);
61 for (int col = m_Box.left; col < m_Box.right; col++)
62 dest_scan[col - m_Box.left] = src_scan[col - mask_rect.left];
63 }
64 }
65
66 void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
67 const CFX_DIBitmap* mask_dib = Mask.GetObject();
68 ASSERT(mask_dib->GetFormat() == FXDIB_8bppMask);
69 FX_RECT mask_box(left, top, left + mask_dib->GetWidth(),
70 top + mask_dib->GetHeight());
71 if (m_Type == RectI) {
72 IntersectMaskRect(m_Box, mask_box, Mask);
73 return;
74 }
75 if (m_Type == MaskF) {
76 FX_RECT new_box = m_Box;
77 new_box.Intersect(mask_box);
78 if (new_box.IsEmpty()) {
79 m_Type = RectI;
80 m_Mask.SetNull();
81 m_Box = new_box;
82 return;
83 }
84 CFX_DIBitmapRef new_mask;
85 CFX_DIBitmap* new_dib = new_mask.New();
86 if (!new_dib)
87 return;
88 new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask);
89 const CFX_DIBitmap* old_dib = m_Mask.GetObject();
90 for (int row = new_box.top; row < new_box.bottom; row++) {
91 uint8_t* old_scan =
92 old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch();
93 uint8_t* mask_scan =
94 mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch();
95 uint8_t* new_scan =
96 new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch();
97 for (int col = new_box.left; col < new_box.right; col++) {
98 new_scan[col - new_box.left] =
99 old_scan[col - m_Box.left] * mask_scan[col - left] / 255;
100 }
101 }
102 m_Box = new_box;
103 m_Mask = new_mask;
104 return;
105 }
106 ASSERT(FALSE);
107 }
OLDNEW
« no previous file with comments | « core/fxge/ge/cfx_cliprgn.h ('k') | core/fxge/ge/cfx_gemodule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698