FX_BOOL CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { if (m_Status == 1) { if (m_pQuickStretcher->Continue(pPause)) { return TRUE; } if (m_pQuickStretcher->m_pBitmap->IsAlphaMask()) m_pRenderStatus->m_pDevice->SetBitMask( m_pQuickStretcher->m_pBitmap, m_pQuickStretcher->m_ResultLeft, m_pQuickStretcher->m_ResultTop, m_FillArgb); else m_pRenderStatus->m_pDevice->SetDIBits( m_pQuickStretcher->m_pBitmap, m_pQuickStretcher->m_ResultLeft, m_pQuickStretcher->m_ResultTop, m_BlendType); return FALSE; } if (m_Status == 2) { if (m_pTransformer->Continue(pPause)) { return TRUE; } CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach(); if (pBitmap == NULL) { return FALSE; } if (pBitmap->IsAlphaMask()) { if (m_BitmapAlpha != 255) { m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); } m_Result = m_pRenderStatus->m_pDevice->SetBitMask( pBitmap, m_pTransformer->m_ResultLeft, m_pTransformer->m_ResultTop, m_FillArgb); } else { if (m_BitmapAlpha != 255) { pBitmap->MultiplyAlpha(m_BitmapAlpha); } m_Result = m_pRenderStatus->m_pDevice->SetDIBits( pBitmap, m_pTransformer->m_ResultLeft, m_pTransformer->m_ResultTop, m_BlendType); } delete pBitmap; return FALSE; } if (m_Status == 3) { return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); } if (m_Status == 4) { if (m_Loader.Continue(m_LoadHandle, pPause)) { return TRUE; } if (StartRenderDIBSource()) { return Continue(pPause); } } return FALSE; }
bool CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { if (m_Status == 2) { if (m_pTransformer->Continue(pPause)) return true; std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); if (!pBitmap) return false; if (pBitmap->IsAlphaMask()) { if (m_BitmapAlpha != 255) m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); m_Result = m_pRenderStatus->m_pDevice->SetBitMask( pBitmap.get(), m_pTransformer->result().left, m_pTransformer->result().top, m_FillArgb); } else { if (m_BitmapAlpha != 255) pBitmap->MultiplyAlpha(m_BitmapAlpha); m_Result = m_pRenderStatus->m_pDevice->SetDIBitsWithBlend( pBitmap.get(), m_pTransformer->result().left, m_pTransformer->result().top, m_BlendType); } return false; } if (m_Status == 3) return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); if (m_Status == 4) { if (m_Loader.Continue(pPause)) return true; if (StartRenderDIBSource()) return Continue(pPause); } return false; }
bool CPDF_ImageRenderer::StartDIBSource() { if (!(m_Flags & RENDER_FORCE_DOWNSAMPLE) && m_pDIBSource->GetBPP() > 1) { FX_SAFE_SIZE_T image_size = m_pDIBSource->GetBPP(); image_size /= 8; image_size *= m_pDIBSource->GetWidth(); image_size *= m_pDIBSource->GetHeight(); if (!image_size.IsValid()) return false; if (image_size.ValueOrDie() > FPDF_HUGE_IMAGE_SIZE && !(m_Flags & RENDER_FORCE_HALFTONE)) { m_Flags |= RENDER_FORCE_DOWNSAMPLE; } } #ifdef _SKIA_SUPPORT_ CFX_DIBitmap* premultiplied = m_pDIBSource->Clone().release(); 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)) { if (m_DeviceHandle) { m_Status = 3; return true; } return false; } #else if (m_pRenderStatus->m_pDevice->StartDIBitsWithBlend( m_pDIBSource, m_BitmapAlpha, m_FillArgb, &m_ImageMatrix, m_Flags, m_DeviceHandle, m_BlendType)) { if (m_DeviceHandle) { m_Status = 3; return true; } return false; } #endif CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); FX_RECT image_rect = image_rect_f.GetOuterRect(); int dest_width = image_rect.Width(); int dest_height = image_rect.Height(); if ((FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || (FXSYS_fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { if (NotDrawing()) { m_Result = false; return false; } FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); clip_box.Intersect(image_rect); m_Status = 2; m_pTransformer = pdfium::MakeUnique<CFX_ImageTransformer>( m_pDIBSource, &m_ImageMatrix, m_Flags, &clip_box); m_pTransformer->Start(); return true; } if (m_ImageMatrix.a < 0) dest_width = -dest_width; if (m_ImageMatrix.d > 0) dest_height = -dest_height; int dest_left = dest_width > 0 ? image_rect.left : image_rect.right; int dest_top = dest_height > 0 ? image_rect.top : image_rect.bottom; if (m_pDIBSource->IsOpaqueImage() && m_BitmapAlpha == 255) { if (m_pRenderStatus->m_pDevice->StretchDIBitsWithFlagsAndBlend( m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_Flags, m_BlendType)) { return false; } } if (m_pDIBSource->IsAlphaMask()) { if (m_BitmapAlpha != 255) m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); if (m_pRenderStatus->m_pDevice->StretchBitMaskWithFlags( m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_FillArgb, m_Flags)) { return false; } } if (NotDrawing()) { m_Result = false; return true; } FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); FX_RECT dest_rect = clip_box; dest_rect.Intersect(image_rect); FX_RECT dest_clip( dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); std::unique_ptr<CFX_DIBitmap> pStretched( m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip)); if (pStretched) { m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left, dest_rect.top, m_FillArgb, m_BitmapAlpha, m_BlendType, false); } return false; }
FX_BOOL CPDF_ImageRenderer::StartDIBSource() { if (!(m_Flags & RENDER_FORCE_DOWNSAMPLE) && m_pDIBSource->GetBPP() > 1) { int image_size = m_pDIBSource->GetBPP() / 8 * m_pDIBSource->GetWidth() * m_pDIBSource->GetHeight(); if (image_size > FPDF_HUGE_IMAGE_SIZE && !(m_Flags & RENDER_FORCE_HALFTONE)) { m_Flags |= RENDER_FORCE_DOWNSAMPLE; } } if (m_pRenderStatus->m_pDevice->StartDIBits( m_pDIBSource, m_BitmapAlpha, m_FillArgb, &m_ImageMatrix, m_Flags, m_DeviceHandle, 0, NULL, m_BlendType)) { if (m_DeviceHandle != NULL) { m_Status = 3; return TRUE; } return FALSE; } CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect(); FX_RECT image_rect = image_rect_f.GetOutterRect(); int dest_width = image_rect.Width(); int dest_height = image_rect.Height(); if ((FXSYS_fabs(m_ImageMatrix.b) >= 0.5f || m_ImageMatrix.a == 0) || (FXSYS_fabs(m_ImageMatrix.c) >= 0.5f || m_ImageMatrix.d == 0)) { if (m_pRenderStatus->m_bPrint && !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { m_Result = FALSE; return FALSE; } FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); clip_box.Intersect(image_rect); m_Status = 2; m_pTransformer = new CFX_ImageTransformer; m_pTransformer->Start(m_pDIBSource, &m_ImageMatrix, m_Flags, &clip_box); return TRUE; } if (m_ImageMatrix.a < 0) { dest_width = -dest_width; } if (m_ImageMatrix.d > 0) { dest_height = -dest_height; } int dest_left, dest_top; dest_left = dest_width > 0 ? image_rect.left : image_rect.right; dest_top = dest_height > 0 ? image_rect.top : image_rect.bottom; if (m_pDIBSource->IsOpaqueImage() && m_BitmapAlpha == 255) { if (m_pRenderStatus->m_pDevice->StretchDIBits( m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_Flags, NULL, m_BlendType)) { return FALSE; } } if (m_pDIBSource->IsAlphaMask()) { if (m_BitmapAlpha != 255) { m_FillArgb = FXARGB_MUL_ALPHA(m_FillArgb, m_BitmapAlpha); } if (m_pRenderStatus->m_pDevice->StretchBitMask( m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_FillArgb, m_Flags)) { return FALSE; } } if (m_pRenderStatus->m_bPrint && !(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) { m_Result = FALSE; return TRUE; } FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox(); FX_RECT dest_rect = clip_box; dest_rect.Intersect(image_rect); FX_RECT dest_clip( dest_rect.left - image_rect.left, dest_rect.top - image_rect.top, dest_rect.right - image_rect.left, dest_rect.bottom - image_rect.top); nonstd::unique_ptr<CFX_DIBitmap> pStretched( m_pDIBSource->StretchTo(dest_width, dest_height, m_Flags, &dest_clip)); if (pStretched) { m_pRenderStatus->CompositeDIBitmap(pStretched.get(), dest_rect.left, dest_rect.top, m_FillArgb, m_BitmapAlpha, m_BlendType, FALSE); } return FALSE; }