1 // Copyright 2016 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/fpdfapi/page/cpdf_transferfunc.h"
8
9 #include <utility>
10
11 #include "core/fpdfapi/page/cpdf_transferfuncdib.h"
12 #include "core/fpdfapi/parser/cpdf_document.h"
13 #include "core/fxge/dib/cfx_dibbase.h"
14
CPDF_TransferFunc(CPDF_Document * pDoc,bool bIdentify,std::vector<uint8_t> samples_r,std::vector<uint8_t> samples_g,std::vector<uint8_t> samples_b)15 CPDF_TransferFunc::CPDF_TransferFunc(CPDF_Document* pDoc,
16 bool bIdentify,
17 std::vector<uint8_t> samples_r,
18 std::vector<uint8_t> samples_g,
19 std::vector<uint8_t> samples_b)
20 : m_pPDFDoc(pDoc),
21 m_bIdentity(bIdentify),
22 m_SamplesR(std::move(samples_r)),
23 m_SamplesG(std::move(samples_g)),
24 m_SamplesB(std::move(samples_b)) {
25 ASSERT(m_SamplesR.size() == kChannelSampleSize);
26 ASSERT(m_SamplesG.size() == kChannelSampleSize);
27 ASSERT(m_SamplesB.size() == kChannelSampleSize);
28 }
29
30 CPDF_TransferFunc::~CPDF_TransferFunc() = default;
31
TranslateColor(FX_COLORREF colorref) const32 FX_COLORREF CPDF_TransferFunc::TranslateColor(FX_COLORREF colorref) const {
33 return FXSYS_BGR(m_SamplesB[FXSYS_GetBValue(colorref)],
34 m_SamplesG[FXSYS_GetGValue(colorref)],
35 m_SamplesR[FXSYS_GetRValue(colorref)]);
36 }
37
TranslateImage(const RetainPtr<CFX_DIBBase> & pSrc)38 RetainPtr<CFX_DIBBase> CPDF_TransferFunc::TranslateImage(
39 const RetainPtr<CFX_DIBBase>& pSrc) {
40 RetainPtr<CPDF_TransferFunc> pHolder(this);
41 return pdfium::MakeRetain<CPDF_TransferFuncDIB>(pSrc, pHolder);
42 }
43
GetSamplesR() const44 pdfium::span<const uint8_t> CPDF_TransferFunc::GetSamplesR() const {
45 return m_SamplesR;
46 }
47
GetSamplesG() const48 pdfium::span<const uint8_t> CPDF_TransferFunc::GetSamplesG() const {
49 return m_SamplesG;
50 }
51
GetSamplesB() const52 pdfium::span<const uint8_t> CPDF_TransferFunc::GetSamplesB() const {
53 return m_SamplesB;
54 }
55