diff options
author | thestig <thestig@chromium.org> | 2016-05-12 15:35:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-12 15:35:00 -0700 |
commit | 39fbb7e1c2282a46d9bd3adfd030916dcb0155ef (patch) | |
tree | 096b3687e8641d73c8513b4805f046b59b0102eb /core/fpdfapi/fpdf_render | |
parent | a0a3bc3482e78a545e8f8290f7d35f42aa968814 (diff) | |
download | pdfium-39fbb7e1c2282a46d9bd3adfd030916dcb0155ef.tar.xz |
Clean up CFX_ImageTransformer.
Review-Url: https://codereview.chromium.org/1973913002
Diffstat (limited to 'core/fpdfapi/fpdf_render')
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_image.cpp | 66 | ||||
-rw-r--r-- | core/fpdfapi/fpdf_render/fpdf_render_text.cpp | 31 |
2 files changed, 48 insertions, 49 deletions
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp index 17851b8b4b..53c40b66ee 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -699,6 +699,7 @@ FX_BOOL CPDF_ImageRenderer::DrawMaskedImage() { rect.top, m_BlendType); 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() * @@ -710,7 +711,7 @@ FX_BOOL CPDF_ImageRenderer::StartDIBSource() { } if (m_pRenderStatus->m_pDevice->StartDIBits( m_pDIBSource, m_BitmapAlpha, m_FillArgb, &m_ImageMatrix, m_Flags, - m_DeviceHandle, 0, NULL, m_BlendType)) { + m_DeviceHandle, 0, nullptr, m_BlendType)) { if (m_DeviceHandle) { m_Status = 3; return TRUE; @@ -731,30 +732,29 @@ FX_BOOL CPDF_ImageRenderer::StartDIBSource() { 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); + m_pTransformer = new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix, + m_Flags, &clip_box); + m_pTransformer->Start(); return TRUE; } - if (m_ImageMatrix.a < 0) { + if (m_ImageMatrix.a < 0) dest_width = -dest_width; - } - if (m_ImageMatrix.d > 0) { + + 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; + + 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->StretchDIBits( m_pDIBSource, dest_left, dest_top, dest_width, dest_height, m_Flags, - NULL, m_BlendType)) { + nullptr, m_BlendType)) { return FALSE; } } if (m_pDIBSource->IsAlphaMask()) { - if (m_BitmapAlpha != 255) { + 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)) { @@ -766,6 +766,7 @@ FX_BOOL CPDF_ImageRenderer::StartDIBSource() { 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); @@ -781,6 +782,7 @@ FX_BOOL CPDF_ImageRenderer::StartDIBSource() { } return FALSE; } + FX_BOOL CPDF_ImageRenderer::StartBitmapAlpha() { if (m_pDIBSource->IsOpaqueImage()) { CFX_PathData path; @@ -824,46 +826,44 @@ FX_BOOL CPDF_ImageRenderer::StartBitmapAlpha() { } return FALSE; } + FX_BOOL CPDF_ImageRenderer::Continue(IFX_Pause* pPause) { if (m_Status == 2) { - if (m_pTransformer->Continue(pPause)) { + if (m_pTransformer->Continue(pPause)) return TRUE; - } - CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach(); - if (!pBitmap) { + + std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); + if (!pBitmap) return FALSE; - } + if (pBitmap->IsAlphaMask()) { - if (m_BitmapAlpha != 255) { + 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); + pBitmap.get(), m_pTransformer->result().left, + m_pTransformer->result().top, m_FillArgb); } else { - if (m_BitmapAlpha != 255) { + 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); + pBitmap.get(), m_pTransformer->result().left, + m_pTransformer->result().top, m_BlendType); } - delete pBitmap; return FALSE; } - if (m_Status == 3) { + if (m_Status == 3) return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause); - } + if (m_Status == 4) { - if (m_Loader.Continue(m_LoadHandle, pPause)) { + if (m_Loader.Continue(m_LoadHandle, pPause)) return TRUE; - } - if (StartRenderDIBSource()) { + + if (StartRenderDIBSource()) return Continue(pPause); - } } return FALSE; } + CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( const uint8_t* src_buf, uint32_t src_size, diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp index acc70c001e..33ad21351e 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -149,6 +149,7 @@ static int _DetectFirstLastScan(const CFX_DIBitmap* pBitmap, FX_BOOL bFirst) { } return -1; } + CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, uint32_t charcode, const CFX_Matrix* pMatrix, @@ -158,12 +159,12 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, if (!pChar || !pChar->m_pBitmap) return nullptr; - CFX_DIBitmap* pBitmap = pChar->m_pBitmap; + CFX_DIBitmap* pBitmap = pChar->m_pBitmap.get(); CFX_Matrix image_matrix, text_matrix; image_matrix = pChar->m_ImageMatrix; text_matrix.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d, 0, 0); image_matrix.Concat(text_matrix); - CFX_DIBitmap* pResBitmap = NULL; + std::unique_ptr<CFX_DIBitmap> pResBitmap; int left = 0; int top = 0; if (FXSYS_fabs(image_matrix.b) < FXSYS_fabs(image_matrix.a) / 100 && @@ -180,10 +181,10 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, bottom_y = temp; } pSize->AdjustBlue(top_y, bottom_y, top_line, bottom_line); - pResBitmap = pBitmap->StretchTo( + pResBitmap.reset(pBitmap->StretchTo( (int)(FXSYS_round(image_matrix.a) * retinaScaleX), (int)((bFlipped ? top_line - bottom_line : bottom_line - top_line) * - retinaScaleY)); + retinaScaleY))); top = top_line; if (image_matrix.a < 0) { image_matrix.Scale(retinaScaleX, retinaScaleY); @@ -195,16 +196,15 @@ CFX_GlyphBitmap* CPDF_Type3Cache::RenderGlyph(CPDF_Type3Glyphs* pSize, } if (!pResBitmap) { image_matrix.Scale(retinaScaleX, retinaScaleY); - pResBitmap = pBitmap->TransformTo(&image_matrix, left, top); - } - if (!pResBitmap) { - return NULL; + pResBitmap.reset(pBitmap->TransformTo(&image_matrix, left, top)); } + if (!pResBitmap) + return nullptr; + CFX_GlyphBitmap* pGlyph = new CFX_GlyphBitmap; pGlyph->m_Left = left; pGlyph->m_Top = -top; - pGlyph->m_Bitmap.TakeOver(pResBitmap); - delete pResBitmap; + pGlyph->m_Bitmap.TakeOver(pResBitmap.get()); return pGlyph; } @@ -423,7 +423,7 @@ FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, status.m_Type3FontCache.Append(m_Type3FontCache); status.m_Type3FontCache.Add(pType3Font); m_pDevice->SaveState(); - status.RenderObjectList(pType3Char->m_pForm, &matrix); + status.RenderObjectList(pType3Char->m_pForm.get(), &matrix); m_pDevice->RestoreState(); } else { CFX_FloatRect rect_f = pType3Char->m_pForm->CalcBoundingBox(); @@ -444,7 +444,7 @@ FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, status.m_Type3FontCache.Add(pType3Font); matrix.TranslateI(-rect.left, -rect.top); matrix.Scale(sa, sd); - status.RenderObjectList(pType3Char->m_pForm, &matrix); + status.RenderObjectList(pType3Char->m_pForm.get(), &matrix); m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top); } delete pStates; @@ -470,13 +470,12 @@ FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, CFX_Matrix image_matrix = pType3Char->m_ImageMatrix; image_matrix.Concat(matrix); CPDF_ImageRenderer renderer; - if (renderer.Start(this, pType3Char->m_pBitmap, fill_argb, 255, + if (renderer.Start(this, pType3Char->m_pBitmap.get(), fill_argb, 255, &image_matrix, 0, FALSE)) { - renderer.Continue(NULL); + renderer.Continue(nullptr); } - if (!renderer.m_Result) { + if (!renderer.m_Result) return FALSE; - } } } } |