| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fxge/ge/cfx_cliprgn.h" | 7 #include "core/fxge/ge/cfx_cliprgn.h" |
| 8 | 8 |
| 9 CFX_ClipRgn::CFX_ClipRgn(int width, int height) | 9 CFX_ClipRgn::CFX_ClipRgn(int width, int height) |
| 10 : m_Type(RectI), m_Box(0, 0, width, height) {} | 10 : m_Type(RectI), m_Box(0, 0, width, height) {} |
| 11 | 11 |
| 12 CFX_ClipRgn::CFX_ClipRgn(const CFX_ClipRgn& src) { | 12 CFX_ClipRgn::CFX_ClipRgn(const CFX_ClipRgn& src) { |
| 13 m_Type = src.m_Type; | 13 m_Type = src.m_Type; |
| 14 m_Box = src.m_Box; | 14 m_Box = src.m_Box; |
| 15 m_Mask = src.m_Mask; | 15 m_Mask = src.m_Mask; |
| 16 } | 16 } |
| 17 | 17 |
| 18 CFX_ClipRgn::~CFX_ClipRgn() {} | 18 CFX_ClipRgn::~CFX_ClipRgn() {} |
| 19 | 19 |
| 20 void CFX_ClipRgn::Reset(const FX_RECT& rect) { | 20 void CFX_ClipRgn::Reset(const FX_RECT& rect) { |
| 21 m_Type = RectI; | 21 m_Type = RectI; |
| 22 m_Box = rect; | 22 m_Box = rect; |
| 23 m_Mask.SetNull(); | 23 m_Mask.Clear(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) { | 26 void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) { |
| 27 if (m_Type == RectI) { | 27 if (m_Type == RectI) { |
| 28 m_Box.Intersect(rect); | 28 m_Box.Intersect(rect); |
| 29 return; | 29 return; |
| 30 } | 30 } |
| 31 if (m_Type == MaskF) { | 31 if (m_Type == MaskF) { |
| 32 IntersectMaskRect(rect, m_Box, m_Mask); | 32 IntersectMaskRect(rect, m_Box, m_Mask); |
| 33 return; | 33 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 top + mask_dib->GetHeight()); | 70 top + mask_dib->GetHeight()); |
| 71 if (m_Type == RectI) { | 71 if (m_Type == RectI) { |
| 72 IntersectMaskRect(m_Box, mask_box, Mask); | 72 IntersectMaskRect(m_Box, mask_box, Mask); |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 if (m_Type == MaskF) { | 75 if (m_Type == MaskF) { |
| 76 FX_RECT new_box = m_Box; | 76 FX_RECT new_box = m_Box; |
| 77 new_box.Intersect(mask_box); | 77 new_box.Intersect(mask_box); |
| 78 if (new_box.IsEmpty()) { | 78 if (new_box.IsEmpty()) { |
| 79 m_Type = RectI; | 79 m_Type = RectI; |
| 80 m_Mask.SetNull(); | 80 m_Mask.Clear(); |
| 81 m_Box = new_box; | 81 m_Box = new_box; |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 CFX_DIBitmapRef new_mask; | 84 CFX_DIBitmapRef new_mask; |
| 85 CFX_DIBitmap* new_dib = new_mask.New(); | 85 CFX_DIBitmap* new_dib = new_mask.New(); |
| 86 if (!new_dib) | 86 if (!new_dib) |
| 87 return; | 87 return; |
| 88 new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask); | 88 new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask); |
| 89 const CFX_DIBitmap* old_dib = m_Mask.GetObject(); | 89 const CFX_DIBitmap* old_dib = m_Mask.GetObject(); |
| 90 for (int row = new_box.top; row < new_box.bottom; row++) { | 90 for (int row = new_box.top; row < new_box.bottom; row++) { |
| 91 uint8_t* old_scan = | 91 uint8_t* old_scan = |
| 92 old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch(); | 92 old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch(); |
| 93 uint8_t* mask_scan = | 93 uint8_t* mask_scan = |
| 94 mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch(); | 94 mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch(); |
| 95 uint8_t* new_scan = | 95 uint8_t* new_scan = |
| 96 new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch(); | 96 new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch(); |
| 97 for (int col = new_box.left; col < new_box.right; col++) { | 97 for (int col = new_box.left; col < new_box.right; col++) { |
| 98 new_scan[col - new_box.left] = | 98 new_scan[col - new_box.left] = |
| 99 old_scan[col - m_Box.left] * mask_scan[col - left] / 255; | 99 old_scan[col - m_Box.left] * mask_scan[col - left] / 255; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 m_Box = new_box; | 102 m_Box = new_box; |
| 103 m_Mask = new_mask; | 103 m_Mask = new_mask; |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 ASSERT(FALSE); | 106 ASSERT(FALSE); |
| 107 } | 107 } |
| OLD | NEW |