summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_render
diff options
context:
space:
mode:
authorcaryclark <caryclark@google.com>2016-08-15 10:09:46 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-15 10:09:46 -0700
commitc4f3c0f183c9ce472cd22e831075c3897e14c3af (patch)
tree1dbc77920dc04eac93ba031dd552ee712c6a1afc /core/fpdfapi/fpdf_render
parent845cac29d76e03960e1de9a019bba67ced84792a (diff)
downloadpdfium-c4f3c0f183c9ce472cd22e831075c3897e14c3af.tar.xz
add native draw bitmap with alpha mask
PDFs draw bitmaps with alpha by supplying an image alpha mask along side the image color data. The alpha mask may not be the same scale as the image data. Skia doesn't have a direct mapping for this draw call, but can come close by using the internal SkCompositeShader class. This scales the alpha mask to match the size of the image data, then puts both in the composite shader to draw. There are more things to do: - Allow Alpha8 or Gray8 to draw scaled to a matching device (blit doesn't work today) Temporary code marked with a TODO implements this functionality. - Refactor PDFium to allow SkComposeShader's components to take a matrix. The latter goal will defer drawing so that PDFium doesn't resize the mask, discarding resolution, before Skia has a chance to record it. Additionally fix drawing text with a negative font size. R=reed@google.com,dsinclair@chromium.org,herb@chromium.org Review-Url: https://codereview.chromium.org/2182763002
Diffstat (limited to 'core/fpdfapi/fpdf_render')
-rw-r--r--core/fpdfapi/fpdf_render/fpdf_render_image.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
index c93600f2a1..8d638f62f8 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
@@ -646,6 +646,7 @@ FX_BOOL CPDF_ImageRenderer::DrawPatternImage(const CFX_Matrix* pObj2Device) {
bitmap_device1.GetBitmap(), rect.left, rect.top, m_BlendType);
return FALSE;
}
+
FX_BOOL CPDF_ImageRenderer::DrawMaskedImage() {
if (m_pRenderStatus->m_bPrint &&
!(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) {
@@ -665,7 +666,11 @@ FX_BOOL CPDF_ImageRenderer::DrawMaskedImage() {
if (!bitmap_device1.Create(width, height, FXDIB_Rgb32, nullptr))
return TRUE;
+#if defined _SKIA_SUPPORT_
+ bitmap_device1.Clear(0xffffff);
+#else
bitmap_device1.GetBitmap()->Clear(0xffffff);
+#endif
{
CPDF_RenderStatus bitmap_render;
bitmap_render.Initialize(m_pRenderStatus->m_pContext, &bitmap_device1,
@@ -682,7 +687,11 @@ FX_BOOL CPDF_ImageRenderer::DrawMaskedImage() {
if (!bitmap_device2.Create(width, height, FXDIB_8bppRgb, nullptr))
return TRUE;
+#if defined _SKIA_SUPPORT_
+ bitmap_device2.Clear(0);
+#else
bitmap_device2.GetBitmap()->Clear(0);
+#endif
CPDF_RenderStatus bitmap_render;
bitmap_render.Initialize(m_pRenderStatus->m_pContext, &bitmap_device2,
nullptr, nullptr, nullptr, nullptr, nullptr, 0,
@@ -731,17 +740,21 @@ FX_BOOL CPDF_ImageRenderer::DrawMaskedImage() {
}
}
}
+#ifdef _SKIA_SUPPORT_
+ m_pRenderStatus->m_pDevice->SetBitsWithMask(
+ bitmap_device1.GetBitmap(), bitmap_device2.GetBitmap(), rect.left,
+ rect.top, m_BitmapAlpha, m_BlendType);
+ }
+#else
bitmap_device2.GetBitmap()->ConvertFormat(FXDIB_8bppMask);
bitmap_device1.GetBitmap()->MultiplyAlpha(bitmap_device2.GetBitmap());
-#ifdef _SKIA_SUPPORT_
- CFX_SkiaDeviceDriver::PreMultiply(bitmap_device1.GetBitmap());
-#endif
if (m_BitmapAlpha < 255) {
bitmap_device1.GetBitmap()->MultiplyAlpha(m_BitmapAlpha);
}
}
m_pRenderStatus->m_pDevice->SetDIBitsWithBlend(
bitmap_device1.GetBitmap(), rect.left, rect.top, m_BlendType);
+#endif // _SKIA_SUPPORT_
return FALSE;
}
@@ -756,7 +769,8 @@ FX_BOOL CPDF_ImageRenderer::StartDIBSource() {
}
#ifdef _SKIA_SUPPORT_
CFX_DIBitmap* premultiplied = m_pDIBSource->Clone();
- CFX_SkiaDeviceDriver::PreMultiply(premultiplied);
+ if (m_pDIBSource->HasAlpha())
+ CFX_SkiaDeviceDriver::PreMultiply(premultiplied);
if (m_pRenderStatus->m_pDevice->StartDIBitsWithBlend(
premultiplied, m_BitmapAlpha, m_FillArgb, &m_ImageMatrix, m_Flags,
m_DeviceHandle, m_BlendType)) {