• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "core/fxge/dib/cfx_bitmapstorer.h"
8 
9 #include <utility>
10 
11 #include "third_party/base/ptr_util.h"
12 
CFX_BitmapStorer()13 CFX_BitmapStorer::CFX_BitmapStorer() {}
14 
~CFX_BitmapStorer()15 CFX_BitmapStorer::~CFX_BitmapStorer() {}
16 
Detach()17 RetainPtr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
18   return std::move(m_pBitmap);
19 }
20 
Replace(RetainPtr<CFX_DIBitmap> && pBitmap)21 void CFX_BitmapStorer::Replace(RetainPtr<CFX_DIBitmap>&& pBitmap) {
22   m_pBitmap = std::move(pBitmap);
23 }
24 
ComposeScanline(int line,const uint8_t * scanline,const uint8_t * scan_extra_alpha)25 void CFX_BitmapStorer::ComposeScanline(int line,
26                                        const uint8_t* scanline,
27                                        const uint8_t* scan_extra_alpha) {
28   uint8_t* dest_buf = const_cast<uint8_t*>(m_pBitmap->GetScanline(line));
29   uint8_t* dest_alpha_buf =
30       m_pBitmap->m_pAlphaMask
31           ? const_cast<uint8_t*>(m_pBitmap->m_pAlphaMask->GetScanline(line))
32           : nullptr;
33   if (dest_buf)
34     memcpy(dest_buf, scanline, m_pBitmap->GetPitch());
35 
36   if (dest_alpha_buf) {
37     memcpy(dest_alpha_buf, scan_extra_alpha,
38            m_pBitmap->m_pAlphaMask->GetPitch());
39   }
40 }
41 
SetInfo(int width,int height,FXDIB_Format src_format,uint32_t * pSrcPalette)42 bool CFX_BitmapStorer::SetInfo(int width,
43                                int height,
44                                FXDIB_Format src_format,
45                                uint32_t* pSrcPalette) {
46   auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
47   if (!pBitmap->Create(width, height, src_format))
48     return false;
49 
50   if (pSrcPalette)
51     pBitmap->SetPalette(pSrcPalette);
52 
53   m_pBitmap = std::move(pBitmap);
54   return true;
55 }
56