aboutsummaryrefslogtreecommitdiff
path: root/core/fxge/dib/cfx_dibextractor.cpp
blob: 9dcfbec52589733761b789696cfb4868ec31296a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "core/fxge/dib/cfx_dibextractor.h"

#include "core/fxge/dib/cfx_dibbase.h"
#include "core/fxge/dib/cfx_dibitmap.h"

CFX_DIBExtractor::CFX_DIBExtractor(const RetainPtr<CFX_DIBBase>& pSrc) {
  if (pSrc->GetBuffer().empty()) {
    m_pBitmap = pSrc->Realize();
    return;
  }
  m_pBitmap = pdfium::MakeRetain<CFX_DIBitmap>();
  if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), pSrc->GetFormat(),
                         pSrc->GetBuffer().data(),
                         /*pitch=*/0)) {
    m_pBitmap.Reset();
    return;
  }

  m_pBitmap->SetPalette(pSrc->GetPaletteSpan());
}

CFX_DIBExtractor::~CFX_DIBExtractor() = default;