• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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/fpdfapi/page/cpdf_transferfunc.h"
8 
9 #include <stdint.h>
10 
11 #include <utility>
12 
13 #include "core/fpdfapi/page/cpdf_transferfuncdib.h"
14 #include "core/fpdfapi/parser/cpdf_document.h"
15 #include "core/fxcrt/fixed_uninit_data_vector.h"
16 #include "core/fxge/dib/cfx_dibbase.h"
17 #include "third_party/base/check_op.h"
18 
CPDF_TransferFunc(bool bIdentify,FixedUninitDataVector<uint8_t> samples_r,FixedUninitDataVector<uint8_t> samples_g,FixedUninitDataVector<uint8_t> samples_b)19 CPDF_TransferFunc::CPDF_TransferFunc(bool bIdentify,
20                                      FixedUninitDataVector<uint8_t> samples_r,
21                                      FixedUninitDataVector<uint8_t> samples_g,
22                                      FixedUninitDataVector<uint8_t> samples_b)
23     : m_bIdentity(bIdentify),
24       m_SamplesR(std::move(samples_r)),
25       m_SamplesG(std::move(samples_g)),
26       m_SamplesB(std::move(samples_b)) {
27   DCHECK_EQ(m_SamplesR.size(), kChannelSampleSize);
28   DCHECK_EQ(m_SamplesG.size(), kChannelSampleSize);
29   DCHECK_EQ(m_SamplesB.size(), kChannelSampleSize);
30 }
31 
32 CPDF_TransferFunc::~CPDF_TransferFunc() = default;
33 
TranslateColor(FX_COLORREF colorref) const34 FX_COLORREF CPDF_TransferFunc::TranslateColor(FX_COLORREF colorref) const {
35   return FXSYS_BGR(m_SamplesB.span()[FXSYS_GetBValue(colorref)],
36                    m_SamplesG.span()[FXSYS_GetGValue(colorref)],
37                    m_SamplesR.span()[FXSYS_GetRValue(colorref)]);
38 }
39 
TranslateImage(RetainPtr<CFX_DIBBase> pSrc)40 RetainPtr<CFX_DIBBase> CPDF_TransferFunc::TranslateImage(
41     RetainPtr<CFX_DIBBase> pSrc) {
42   return pdfium::MakeRetain<CPDF_TransferFuncDIB>(std::move(pSrc),
43                                                   pdfium::WrapRetain(this));
44 }
45 
GetSamplesR() const46 pdfium::span<const uint8_t> CPDF_TransferFunc::GetSamplesR() const {
47   return m_SamplesR;
48 }
49 
GetSamplesG() const50 pdfium::span<const uint8_t> CPDF_TransferFunc::GetSamplesG() const {
51   return m_SamplesG;
52 }
53 
GetSamplesB() const54 pdfium::span<const uint8_t> CPDF_TransferFunc::GetSamplesB() const {
55   return m_SamplesB;
56 }
57