summaryrefslogtreecommitdiff
path: root/core/fpdfapi/render/fpdf_render_image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/render/fpdf_render_image.cpp')
-rw-r--r--core/fpdfapi/render/fpdf_render_image.cpp263
1 files changed, 1 insertions, 262 deletions
diff --git a/core/fpdfapi/render/fpdf_render_image.cpp b/core/fpdfapi/render/fpdf_render_image.cpp
index 560af06842..0c89a7521c 100644
--- a/core/fpdfapi/render/fpdf_render_image.cpp
+++ b/core/fpdfapi/render/fpdf_render_image.cpp
@@ -24,6 +24,7 @@
#include "core/fpdfapi/render/cpdf_pagerendercache.h"
#include "core/fpdfapi/render/cpdf_rendercontext.h"
#include "core/fpdfapi/render/cpdf_renderoptions.h"
+#include "core/fpdfapi/render/cpdf_renderstatus.h"
#include "core/fpdfdoc/cpdf_occontext.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -34,134 +35,6 @@
#include "core/fxge/skia/fx_skia_device.h"
#endif
-bool CPDF_RenderStatus::ProcessImage(CPDF_ImageObject* pImageObj,
- const CFX_Matrix* pObj2Device) {
- CPDF_ImageRenderer render;
- if (render.Start(this, pImageObj, pObj2Device, m_bStdCS, m_curBlend)) {
- render.Continue(nullptr);
- }
- return render.m_Result;
-}
-void CPDF_RenderStatus::CompositeDIBitmap(CFX_DIBitmap* pDIBitmap,
- int left,
- int top,
- FX_ARGB mask_argb,
- int bitmap_alpha,
- int blend_mode,
- int Transparency) {
- if (!pDIBitmap) {
- return;
- }
- if (blend_mode == FXDIB_BLEND_NORMAL) {
- if (!pDIBitmap->IsAlphaMask()) {
- if (bitmap_alpha < 255) {
-#ifdef _SKIA_SUPPORT_
- void* dummy;
- CFX_Matrix m(pDIBitmap->GetWidth(), 0, 0, -pDIBitmap->GetHeight(), left,
- top + pDIBitmap->GetHeight());
- m_pDevice->StartDIBits(pDIBitmap, bitmap_alpha, 0, &m, 0, dummy);
- return;
-#else
- pDIBitmap->MultiplyAlpha(bitmap_alpha);
-#endif
- }
-#ifdef _SKIA_SUPPORT_
- CFX_SkiaDeviceDriver::PreMultiply(pDIBitmap);
-#endif
- if (m_pDevice->SetDIBits(pDIBitmap, left, top)) {
- return;
- }
- } else {
- uint32_t fill_argb = m_Options.TranslateColor(mask_argb);
- if (bitmap_alpha < 255) {
- ((uint8_t*)&fill_argb)[3] =
- ((uint8_t*)&fill_argb)[3] * bitmap_alpha / 255;
- }
- if (m_pDevice->SetBitMask(pDIBitmap, left, top, fill_argb)) {
- return;
- }
- }
- }
- bool bIsolated = !!(Transparency & PDFTRANS_ISOLATED);
- bool bGroup = !!(Transparency & PDFTRANS_GROUP);
- bool bBackAlphaRequired = blend_mode && bIsolated && !m_bDropObjects;
- bool bGetBackGround =
- ((m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT)) ||
- (!(m_pDevice->GetRenderCaps() & FXRC_ALPHA_OUTPUT) &&
- (m_pDevice->GetRenderCaps() & FXRC_GET_BITS) && !bBackAlphaRequired);
- if (bGetBackGround) {
- if (bIsolated || !bGroup) {
- if (pDIBitmap->IsAlphaMask()) {
- return;
- }
- m_pDevice->SetDIBitsWithBlend(pDIBitmap, left, top, blend_mode);
- } else {
- FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
- top + pDIBitmap->GetHeight());
- rect.Intersect(m_pDevice->GetClipBox());
- CFX_DIBitmap* pClone = nullptr;
- bool bClone = false;
- if (m_pDevice->GetBackDrop() && m_pDevice->GetBitmap()) {
- bClone = true;
- pClone = m_pDevice->GetBackDrop()->Clone(&rect);
- CFX_DIBitmap* pForeBitmap = m_pDevice->GetBitmap();
- pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
- pForeBitmap, rect.left, rect.top);
- left = left >= 0 ? 0 : left;
- top = top >= 0 ? 0 : top;
- if (!pDIBitmap->IsAlphaMask())
- pClone->CompositeBitmap(0, 0, pClone->GetWidth(), pClone->GetHeight(),
- pDIBitmap, left, top, blend_mode);
- else
- pClone->CompositeMask(0, 0, pClone->GetWidth(), pClone->GetHeight(),
- pDIBitmap, mask_argb, left, top, blend_mode);
- } else {
- pClone = pDIBitmap;
- }
- if (m_pDevice->GetBackDrop()) {
- m_pDevice->SetDIBits(pClone, rect.left, rect.top);
- } else {
- if (pDIBitmap->IsAlphaMask()) {
- return;
- }
- m_pDevice->SetDIBitsWithBlend(pDIBitmap, rect.left, rect.top,
- blend_mode);
- }
- if (bClone) {
- delete pClone;
- }
- }
- return;
- }
- int back_left, back_top;
- FX_RECT rect(left, top, left + pDIBitmap->GetWidth(),
- top + pDIBitmap->GetHeight());
- std::unique_ptr<CFX_DIBitmap> pBackdrop(
- GetBackdrop(m_pCurObj, rect, back_left, back_top,
- blend_mode > FXDIB_BLEND_NORMAL && bIsolated));
- if (!pBackdrop)
- return;
-
- if (!pDIBitmap->IsAlphaMask()) {
- pBackdrop->CompositeBitmap(left - back_left, top - back_top,
- pDIBitmap->GetWidth(), pDIBitmap->GetHeight(),
- pDIBitmap, 0, 0, blend_mode);
- } else {
- pBackdrop->CompositeMask(left - back_left, top - back_top,
- pDIBitmap->GetWidth(), pDIBitmap->GetHeight(),
- pDIBitmap, mask_argb, 0, 0, blend_mode);
- }
-
- std::unique_ptr<CFX_DIBitmap> pBackdrop1(new CFX_DIBitmap);
- pBackdrop1->Create(pBackdrop->GetWidth(), pBackdrop->GetHeight(),
- FXDIB_Rgb32);
- pBackdrop1->Clear((uint32_t)-1);
- pBackdrop1->CompositeBitmap(0, 0, pBackdrop->GetWidth(),
- pBackdrop->GetHeight(), pBackdrop.get(), 0, 0);
- pBackdrop = std::move(pBackdrop1);
- m_pDevice->SetDIBits(pBackdrop.get(), back_left, back_top);
-}
-
CPDF_TransferFunc::CPDF_TransferFunc(CPDF_Document* pDoc) : m_pPDFDoc(pDoc) {}
FX_COLORREF CPDF_TransferFunc::TranslateColor(FX_COLORREF rgb) const {
@@ -954,137 +827,3 @@ CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(
int nComps,
int bpc,
const CPDF_Dictionary* pParams);
-
-CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict,
- FX_RECT* pClipRect,
- const CFX_Matrix* pMatrix) {
- if (!pSMaskDict)
- return nullptr;
-
- CPDF_Stream* pGroup = pSMaskDict->GetStreamFor("G");
- if (!pGroup)
- return nullptr;
-
- std::unique_ptr<CPDF_Function> pFunc;
- CPDF_Object* pFuncObj = pSMaskDict->GetDirectObjectFor("TR");
- if (pFuncObj && (pFuncObj->IsDictionary() || pFuncObj->IsStream()))
- pFunc = CPDF_Function::Load(pFuncObj);
-
- CFX_Matrix matrix = *pMatrix;
- matrix.TranslateI(-pClipRect->left, -pClipRect->top);
-
- CPDF_Form form(m_pContext->GetDocument(), m_pContext->GetPageResources(),
- pGroup);
- form.ParseContent(nullptr, nullptr, nullptr);
-
- CFX_FxgeDevice bitmap_device;
- bool bLuminosity = pSMaskDict->GetStringFor("S") != "Alpha";
- int width = pClipRect->right - pClipRect->left;
- int height = pClipRect->bottom - pClipRect->top;
- FXDIB_Format format;
-#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || defined _SKIA_SUPPORT_ || \
- defined _SKIA_SUPPORT_PATHS_
- format = bLuminosity ? FXDIB_Rgb32 : FXDIB_8bppMask;
-#else
- format = bLuminosity ? FXDIB_Rgb : FXDIB_8bppMask;
-#endif
- if (!bitmap_device.Create(width, height, format, nullptr))
- return nullptr;
-
- CFX_DIBitmap& bitmap = *bitmap_device.GetBitmap();
- int color_space_family = 0;
- if (bLuminosity) {
- CPDF_Array* pBC = pSMaskDict->GetArrayFor("BC");
- FX_ARGB back_color = 0xff000000;
- if (pBC) {
- CPDF_Object* pCSObj = nullptr;
- CPDF_Dictionary* pDict = pGroup->GetDict();
- if (pDict && pDict->GetDictFor("Group")) {
- pCSObj = pDict->GetDictFor("Group")->GetDirectObjectFor("CS");
- }
- const CPDF_ColorSpace* pCS =
- m_pContext->GetDocument()->LoadColorSpace(pCSObj);
- if (pCS) {
- // Store Color Space Family to use in CPDF_RenderStatus::Initialize.
- color_space_family = pCS->GetFamily();
-
- FX_FLOAT R, G, B;
- uint32_t comps = 8;
- if (pCS->CountComponents() > comps) {
- comps = pCS->CountComponents();
- }
- CFX_FixedBufGrow<FX_FLOAT, 8> float_array(comps);
- FX_FLOAT* pFloats = float_array;
- FX_SAFE_UINT32 num_floats = comps;
- num_floats *= sizeof(FX_FLOAT);
- if (!num_floats.IsValid()) {
- return nullptr;
- }
- FXSYS_memset(pFloats, 0, num_floats.ValueOrDie());
- size_t count = pBC->GetCount() > 8 ? 8 : pBC->GetCount();
- for (size_t i = 0; i < count; i++) {
- pFloats[i] = pBC->GetNumberAt(i);
- }
- pCS->GetRGB(pFloats, R, G, B);
- back_color = 0xff000000 | ((int32_t)(R * 255) << 16) |
- ((int32_t)(G * 255) << 8) | (int32_t)(B * 255);
- m_pContext->GetDocument()->GetPageData()->ReleaseColorSpace(pCSObj);
- }
- }
- bitmap.Clear(back_color);
- } else {
- bitmap.Clear(0);
- }
- CPDF_Dictionary* pFormResource = nullptr;
- if (form.m_pFormDict) {
- pFormResource = form.m_pFormDict->GetDictFor("Resources");
- }
- CPDF_RenderOptions options;
- options.m_ColorMode = bLuminosity ? RENDER_COLOR_NORMAL : RENDER_COLOR_ALPHA;
- CPDF_RenderStatus status;
- status.Initialize(m_pContext, &bitmap_device, nullptr, nullptr, nullptr,
- nullptr, &options, 0, m_bDropObjects, pFormResource, true,
- nullptr, 0, color_space_family, bLuminosity);
- status.RenderObjectList(&form, &matrix);
- std::unique_ptr<CFX_DIBitmap> pMask(new CFX_DIBitmap);
- if (!pMask->Create(width, height, FXDIB_8bppMask))
- return nullptr;
-
- uint8_t* dest_buf = pMask->GetBuffer();
- int dest_pitch = pMask->GetPitch();
- uint8_t* src_buf = bitmap.GetBuffer();
- int src_pitch = bitmap.GetPitch();
- std::vector<uint8_t> transfers(256);
- if (pFunc) {
- CFX_FixedBufGrow<FX_FLOAT, 16> results(pFunc->CountOutputs());
- for (int i = 0; i < 256; i++) {
- FX_FLOAT input = (FX_FLOAT)i / 255.0f;
- int nresult;
- pFunc->Call(&input, 1, results, nresult);
- transfers[i] = FXSYS_round(results[0] * 255);
- }
- } else {
- for (int i = 0; i < 256; i++) {
- transfers[i] = i;
- }
- }
- if (bLuminosity) {
- int Bpp = bitmap.GetBPP() / 8;
- for (int row = 0; row < height; row++) {
- uint8_t* dest_pos = dest_buf + row * dest_pitch;
- uint8_t* src_pos = src_buf + row * src_pitch;
- for (int col = 0; col < width; col++) {
- *dest_pos++ = transfers[FXRGB2GRAY(src_pos[2], src_pos[1], *src_pos)];
- src_pos += Bpp;
- }
- }
- } else if (pFunc) {
- int size = dest_pitch * height;
- for (int i = 0; i < size; i++) {
- dest_buf[i] = transfers[src_buf[i]];
- }
- } else {
- FXSYS_memcpy(dest_buf, src_buf, dest_pitch * height);
- }
- return pMask.release();
-}