summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp7
-rw-r--r--core/fpdfapi/render/cpdf_imagerenderer.cpp42
2 files changed, 27 insertions, 22 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index feafde3b36..97969551c6 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -247,8 +247,10 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
bCopyWithoutAlpha = false;
}
- const CFX_DIBitmap* pMaskBitmap =
- pBitmap->HasAlpha() ? pBitmap->GetAlphaMask() : nullptr;
+ std::unique_ptr<CFX_DIBitmap> pMaskBitmap;
+ if (pBitmap->HasAlpha())
+ pMaskBitmap = pBitmap->CloneAlphaMask();
+
if (pMaskBitmap) {
int32_t maskWidth = pMaskBitmap->GetWidth();
int32_t maskHeight = pMaskBitmap->GetHeight();
@@ -275,7 +277,6 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
mask_buf, mask_size, std::move(pMaskDict));
pDict->SetNewFor<CPDF_Reference>("SMask", m_pDocument,
pNewStream->GetObjNum());
- delete pMaskBitmap;
}
uint8_t* src_buf = pBitmap->GetBuffer();
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 5ca7ea842f..a5b1238eaf 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -25,6 +25,7 @@
#include "core/fpdfapi/render/cpdf_transferfunc.h"
#include "core/fpdfapi/render/render_int.h"
#include "core/fpdfdoc/cpdf_occontext.h"
+#include "core/fxcrt/cfx_maybe_owned.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/cfx_fxgedevice.h"
#include "core/fxge/cfx_pathdata.h"
@@ -499,34 +500,37 @@ bool CPDF_ImageRenderer::StartBitmapAlpha() {
FXFILL_WINDING);
return false;
}
- const CFX_DIBSource* pAlphaMask =
- m_pDIBSource->IsAlphaMask() ? m_pDIBSource : m_pDIBSource->GetAlphaMask();
+ CFX_MaybeOwned<CFX_DIBSource> pAlphaMask;
+ if (m_pDIBSource->IsAlphaMask())
+ pAlphaMask = const_cast<CFX_DIBSource*>(m_pDIBSource);
+ else
+ pAlphaMask = m_pDIBSource->CloneAlphaMask();
+
if (FXSYS_fabs(m_ImageMatrix.b) >= 0.5f ||
FXSYS_fabs(m_ImageMatrix.c) >= 0.5f) {
- int left, top;
- std::unique_ptr<CFX_DIBitmap> pTransformed(
- pAlphaMask->TransformTo(&m_ImageMatrix, left, top));
+ int left;
+ int top;
+ std::unique_ptr<CFX_DIBitmap> pTransformed =
+ pAlphaMask->TransformTo(&m_ImageMatrix, left, top);
if (!pTransformed)
return true;
m_pRenderStatus->m_pDevice->SetBitMask(
pTransformed.get(), left, top,
ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
- } else {
- CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect();
- FX_RECT image_rect = image_rect_f.GetOuterRect();
- int dest_width =
- m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width();
- int dest_height =
- m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height();
- int left = dest_width > 0 ? image_rect.left : image_rect.right;
- int top = dest_height > 0 ? image_rect.top : image_rect.bottom;
- m_pRenderStatus->m_pDevice->StretchBitMask(
- pAlphaMask, left, top, dest_width, dest_height,
- ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
+ return false;
}
- if (m_pDIBSource != pAlphaMask)
- delete pAlphaMask;
+ CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect();
+ FX_RECT image_rect = image_rect_f.GetOuterRect();
+ int dest_width =
+ m_ImageMatrix.a > 0 ? image_rect.Width() : -image_rect.Width();
+ int dest_height =
+ m_ImageMatrix.d > 0 ? -image_rect.Height() : image_rect.Height();
+ int left = dest_width > 0 ? image_rect.left : image_rect.right;
+ int top = dest_height > 0 ? image_rect.top : image_rect.bottom;
+ m_pRenderStatus->m_pDevice->StretchBitMask(
+ pAlphaMask.Get(), left, top, dest_width, dest_height,
+ ArgbEncode(0xff, m_BitmapAlpha, m_BitmapAlpha, m_BitmapAlpha));
return false;
}