xref: /aosp_15_r20/external/pdfium/core/fxge/dib/cfx_bitmapstorer.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2017 The PDFium Authors
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 <string.h>
10 
11 #include <utility>
12 
13 #include "core/fxcrt/span_util.h"
14 #include "core/fxge/dib/cfx_dibitmap.h"
15 #include "third_party/base/check_op.h"
16 
17 CFX_BitmapStorer::CFX_BitmapStorer() = default;
18 
19 CFX_BitmapStorer::~CFX_BitmapStorer() = default;
20 
Detach()21 RetainPtr<CFX_DIBitmap> CFX_BitmapStorer::Detach() {
22   return std::move(m_pBitmap);
23 }
24 
Replace(RetainPtr<CFX_DIBitmap> && pBitmap)25 void CFX_BitmapStorer::Replace(RetainPtr<CFX_DIBitmap>&& pBitmap) {
26   m_pBitmap = std::move(pBitmap);
27 }
28 
ComposeScanline(int line,pdfium::span<const uint8_t> scanline)29 void CFX_BitmapStorer::ComposeScanline(int line,
30                                        pdfium::span<const uint8_t> scanline) {
31   pdfium::span<uint8_t> dest_buf = m_pBitmap->GetWritableScanline(line);
32   if (!dest_buf.empty())
33     fxcrt::spancpy(dest_buf, scanline);
34 }
35 
SetInfo(int width,int height,FXDIB_Format src_format,pdfium::span<const uint32_t> src_palette)36 bool CFX_BitmapStorer::SetInfo(int width,
37                                int height,
38                                FXDIB_Format src_format,
39                                pdfium::span<const uint32_t> src_palette) {
40   DCHECK_NE(src_format, FXDIB_Format::k1bppMask);
41   DCHECK_NE(src_format, FXDIB_Format::k1bppRgb);
42   auto pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
43   if (!pBitmap->Create(width, height, src_format))
44     return false;
45 
46   if (!src_palette.empty())
47     pBitmap->SetPalette(src_palette);
48 
49   m_pBitmap = std::move(pBitmap);
50   return true;
51 }
52