| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fxge/include/fx_dib.h" | 7 #include "core/fxge/include/fx_dib.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 | 10 |
| (...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 } | 1584 } |
| 1585 CFX_ImageRenderer::CFX_ImageRenderer() { | 1585 CFX_ImageRenderer::CFX_ImageRenderer() { |
| 1586 m_Status = 0; | 1586 m_Status = 0; |
| 1587 m_pTransformer = NULL; | 1587 m_pTransformer = NULL; |
| 1588 m_bRgbByteOrder = FALSE; | 1588 m_bRgbByteOrder = FALSE; |
| 1589 m_BlendType = FXDIB_BLEND_NORMAL; | 1589 m_BlendType = FXDIB_BLEND_NORMAL; |
| 1590 } | 1590 } |
| 1591 CFX_ImageRenderer::~CFX_ImageRenderer() { | 1591 CFX_ImageRenderer::~CFX_ImageRenderer() { |
| 1592 delete m_pTransformer; | 1592 delete m_pTransformer; |
| 1593 } | 1593 } |
| 1594 |
| 1594 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, | 1595 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, |
| 1595 const CFX_ClipRgn* pClipRgn, | 1596 const CFX_ClipRgn* pClipRgn, |
| 1596 const CFX_DIBSource* pSource, | 1597 const CFX_DIBSource* pSource, |
| 1597 int bitmap_alpha, | 1598 int bitmap_alpha, |
| 1598 uint32_t mask_color, | 1599 uint32_t mask_color, |
| 1599 const CFX_Matrix* pMatrix, | 1600 const CFX_Matrix* pMatrix, |
| 1600 uint32_t dib_flags, | 1601 uint32_t dib_flags, |
| 1601 FX_BOOL bRgbByteOrder, | 1602 FX_BOOL bRgbByteOrder, |
| 1602 int alpha_flag, | 1603 int alpha_flag, |
| 1603 void* pIccTransform, | 1604 void* pIccTransform, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 m_Stretcher.reset(new CFX_ImageStretcher(&m_Composer, pSource, | 1640 m_Stretcher.reset(new CFX_ImageStretcher(&m_Composer, pSource, |
| 1640 dest_height, dest_width, | 1641 dest_height, dest_width, |
| 1641 bitmap_clip, dib_flags)); | 1642 bitmap_clip, dib_flags)); |
| 1642 if (!m_Stretcher->Start()) | 1643 if (!m_Stretcher->Start()) |
| 1643 return FALSE; | 1644 return FALSE; |
| 1644 | 1645 |
| 1645 m_Status = 1; | 1646 m_Status = 1; |
| 1646 return TRUE; | 1647 return TRUE; |
| 1647 } | 1648 } |
| 1648 m_Status = 2; | 1649 m_Status = 2; |
| 1649 m_pTransformer = new CFX_ImageTransformer; | 1650 m_pTransformer = |
| 1650 m_pTransformer->Start(pSource, &m_Matrix, dib_flags, &m_ClipBox); | 1651 new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox); |
| 1652 m_pTransformer->Start(); |
| 1651 return TRUE; | 1653 return TRUE; |
| 1652 } | 1654 } |
| 1653 | 1655 |
| 1654 int dest_width = image_rect.Width(); | 1656 int dest_width = image_rect.Width(); |
| 1655 if (m_Matrix.a < 0) | 1657 if (m_Matrix.a < 0) |
| 1656 dest_width = -dest_width; | 1658 dest_width = -dest_width; |
| 1657 | 1659 |
| 1658 int dest_height = image_rect.Height(); | 1660 int dest_height = image_rect.Height(); |
| 1659 if (m_Matrix.d > 0) | 1661 if (m_Matrix.d > 0) |
| 1660 dest_height = -dest_height; | 1662 dest_height = -dest_height; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1671 m_Stretcher.reset(new CFX_ImageStretcher( | 1673 m_Stretcher.reset(new CFX_ImageStretcher( |
| 1672 &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags)); | 1674 &m_Composer, pSource, dest_width, dest_height, bitmap_clip, dib_flags)); |
| 1673 return m_Stretcher->Start(); | 1675 return m_Stretcher->Start(); |
| 1674 } | 1676 } |
| 1675 | 1677 |
| 1676 FX_BOOL CFX_ImageRenderer::Continue(IFX_Pause* pPause) { | 1678 FX_BOOL CFX_ImageRenderer::Continue(IFX_Pause* pPause) { |
| 1677 if (m_Status == 1) | 1679 if (m_Status == 1) |
| 1678 return m_Stretcher->Continue(pPause); | 1680 return m_Stretcher->Continue(pPause); |
| 1679 | 1681 |
| 1680 if (m_Status == 2) { | 1682 if (m_Status == 2) { |
| 1681 if (m_pTransformer->Continue(pPause)) { | 1683 if (m_pTransformer->Continue(pPause)) |
| 1682 return TRUE; | 1684 return TRUE; |
| 1683 } | 1685 |
| 1684 CFX_DIBitmap* pBitmap = m_pTransformer->m_Storer.Detach(); | 1686 std::unique_ptr<CFX_DIBitmap> pBitmap(m_pTransformer->DetachBitmap()); |
| 1685 if (!pBitmap) { | 1687 if (!pBitmap || !pBitmap->GetBuffer()) |
| 1686 return FALSE; | 1688 return FALSE; |
| 1687 } | 1689 |
| 1688 if (!pBitmap->GetBuffer()) { | |
| 1689 delete pBitmap; | |
| 1690 return FALSE; | |
| 1691 } | |
| 1692 if (pBitmap->IsAlphaMask()) { | 1690 if (pBitmap->IsAlphaMask()) { |
| 1693 if (m_BitmapAlpha != 255) { | 1691 if (m_BitmapAlpha != 255) { |
| 1694 if (m_AlphaFlag >> 8) { | 1692 if (m_AlphaFlag >> 8) { |
| 1695 m_AlphaFlag = | 1693 m_AlphaFlag = |
| 1696 (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) | | 1694 (((uint8_t)((m_AlphaFlag & 0xff) * m_BitmapAlpha / 255)) | |
| 1697 ((m_AlphaFlag >> 8) << 8)); | 1695 ((m_AlphaFlag >> 8) << 8)); |
| 1698 } else { | 1696 } else { |
| 1699 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); | 1697 m_MaskColor = FXARGB_MUL_ALPHA(m_MaskColor, m_BitmapAlpha); |
| 1700 } | 1698 } |
| 1701 } | 1699 } |
| 1702 m_pDevice->CompositeMask(m_pTransformer->m_ResultLeft, | 1700 m_pDevice->CompositeMask( |
| 1703 m_pTransformer->m_ResultTop, pBitmap->GetWidth(), | 1701 m_pTransformer->result().left, m_pTransformer->result().top, |
| 1704 pBitmap->GetHeight(), pBitmap, m_MaskColor, 0, 0, | 1702 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), m_MaskColor, |
| 1705 m_BlendType, m_pClipRgn, m_bRgbByteOrder, | 1703 0, 0, m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_AlphaFlag, |
| 1706 m_AlphaFlag, m_pIccTransform); | 1704 m_pIccTransform); |
| 1707 } else { | 1705 } else { |
| 1708 if (m_BitmapAlpha != 255) { | 1706 if (m_BitmapAlpha != 255) |
| 1709 pBitmap->MultiplyAlpha(m_BitmapAlpha); | 1707 pBitmap->MultiplyAlpha(m_BitmapAlpha); |
| 1710 } | |
| 1711 m_pDevice->CompositeBitmap( | 1708 m_pDevice->CompositeBitmap( |
| 1712 m_pTransformer->m_ResultLeft, m_pTransformer->m_ResultTop, | 1709 m_pTransformer->result().left, m_pTransformer->result().top, |
| 1713 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap, 0, 0, m_BlendType, | 1710 pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap.get(), 0, 0, |
| 1714 m_pClipRgn, m_bRgbByteOrder, m_pIccTransform); | 1711 m_BlendType, m_pClipRgn, m_bRgbByteOrder, m_pIccTransform); |
| 1715 } | 1712 } |
| 1716 delete pBitmap; | |
| 1717 return FALSE; | 1713 return FALSE; |
| 1718 } | 1714 } |
| 1719 return FALSE; | 1715 return FALSE; |
| 1720 } | 1716 } |
| 1717 |
| 1721 CFX_BitmapStorer::CFX_BitmapStorer() { | 1718 CFX_BitmapStorer::CFX_BitmapStorer() { |
| 1722 m_pBitmap = NULL; | |
| 1723 } | 1719 } |
| 1720 |
| 1724 CFX_BitmapStorer::~CFX_BitmapStorer() { | 1721 CFX_BitmapStorer::~CFX_BitmapStorer() { |
| 1725 delete m_pBitmap; | |
| 1726 } | 1722 } |
| 1727 CFX_DIBitmap* CFX_BitmapStorer::Detach() { | 1723 |
| 1728 CFX_DIBitmap* pBitmap = m_pBitmap; | 1724 std::unique_ptr<CFX_DIBitmap> CFX_BitmapStorer::Detach() { |
| 1729 m_pBitmap = NULL; | 1725 return std::move(m_pBitmap); |
| 1730 return pBitmap; | |
| 1731 } | 1726 } |
| 1732 void CFX_BitmapStorer::Replace(CFX_DIBitmap* pBitmap) { | 1727 |
| 1733 delete m_pBitmap; | 1728 void CFX_BitmapStorer::Replace(std::unique_ptr<CFX_DIBitmap> pBitmap) { |
| 1734 m_pBitmap = pBitmap; | 1729 m_pBitmap = std::move(pBitmap); |
| 1735 } | 1730 } |
| 1731 |
| 1736 void CFX_BitmapStorer::ComposeScanline(int line, | 1732 void CFX_BitmapStorer::ComposeScanline(int line, |
| 1737 const uint8_t* scanline, | 1733 const uint8_t* scanline, |
| 1738 const uint8_t* scan_extra_alpha) { | 1734 const uint8_t* scan_extra_alpha) { |
| 1739 uint8_t* dest_buf = (uint8_t*)m_pBitmap->GetScanline(line); | 1735 uint8_t* dest_buf = const_cast<uint8_t*>(m_pBitmap->GetScanline(line)); |
| 1740 uint8_t* dest_alpha_buf = | 1736 uint8_t* dest_alpha_buf = |
| 1741 m_pBitmap->m_pAlphaMask | 1737 m_pBitmap->m_pAlphaMask |
| 1742 ? (uint8_t*)m_pBitmap->m_pAlphaMask->GetScanline(line) | 1738 ? const_cast<uint8_t*>(m_pBitmap->m_pAlphaMask->GetScanline(line)) |
| 1743 : NULL; | 1739 : nullptr; |
| 1744 if (dest_buf) { | 1740 if (dest_buf) |
| 1745 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); | 1741 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); |
| 1746 } | 1742 |
| 1747 if (dest_alpha_buf) { | 1743 if (dest_alpha_buf) { |
| 1748 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, | 1744 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, |
| 1749 m_pBitmap->m_pAlphaMask->GetPitch()); | 1745 m_pBitmap->m_pAlphaMask->GetPitch()); |
| 1750 } | 1746 } |
| 1751 } | 1747 } |
| 1752 FX_BOOL CFX_BitmapStorer::SetInfo(int width, | 1748 FX_BOOL CFX_BitmapStorer::SetInfo(int width, |
| 1753 int height, | 1749 int height, |
| 1754 FXDIB_Format src_format, | 1750 FXDIB_Format src_format, |
| 1755 uint32_t* pSrcPalette) { | 1751 uint32_t* pSrcPalette) { |
| 1756 m_pBitmap = new CFX_DIBitmap; | 1752 m_pBitmap.reset(new CFX_DIBitmap); |
| 1757 if (!m_pBitmap->Create(width, height, src_format)) { | 1753 if (!m_pBitmap->Create(width, height, src_format)) { |
| 1758 delete m_pBitmap; | 1754 m_pBitmap.reset(); |
| 1759 m_pBitmap = NULL; | |
| 1760 return FALSE; | 1755 return FALSE; |
| 1761 } | 1756 } |
| 1762 if (pSrcPalette) { | 1757 if (pSrcPalette) |
| 1763 m_pBitmap->CopyPalette(pSrcPalette); | 1758 m_pBitmap->CopyPalette(pSrcPalette); |
| 1764 } | |
| 1765 return TRUE; | 1759 return TRUE; |
| 1766 } | 1760 } |
| OLD | NEW |