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/fpdfapi/page/cpdf_iccprofile.h"
8
9 #include <utility>
10
11 #include "core/fpdfapi/parser/cpdf_stream.h"
12 #include "core/fxcodec/icc/icc_transform.h"
13
14 namespace {
15
DetectSRGB(pdfium::span<const uint8_t> span)16 bool DetectSRGB(pdfium::span<const uint8_t> span) {
17 static const char kSRGB[] = "sRGB IEC61966-2.1";
18 return span.size() == 3144 && memcmp(&span[400], kSRGB, strlen(kSRGB)) == 0;
19 }
20
21 } // namespace
22
CPDF_IccProfile(RetainPtr<const CPDF_Stream> pStream,pdfium::span<const uint8_t> span)23 CPDF_IccProfile::CPDF_IccProfile(RetainPtr<const CPDF_Stream> pStream,
24 pdfium::span<const uint8_t> span)
25 : m_bsRGB(DetectSRGB(span)), m_pStream(std::move(pStream)) {
26 if (m_bsRGB) {
27 m_nSrcComponents = 3;
28 return;
29 }
30
31 m_Transform = fxcodec::IccTransform::CreateTransformSRGB(span);
32 if (m_Transform)
33 m_nSrcComponents = m_Transform->components();
34 }
35
36 CPDF_IccProfile::~CPDF_IccProfile() = default;
37
IsNormal() const38 bool CPDF_IccProfile::IsNormal() const {
39 return m_Transform->IsNormal();
40 }
41
Translate(pdfium::span<const float> pSrcValues,pdfium::span<float> pDestValues)42 void CPDF_IccProfile::Translate(pdfium::span<const float> pSrcValues,
43 pdfium::span<float> pDestValues) {
44 m_Transform->Translate(pSrcValues, pDestValues);
45 }
46
TranslateScanline(pdfium::span<uint8_t> pDest,pdfium::span<const uint8_t> pSrc,int pixels)47 void CPDF_IccProfile::TranslateScanline(pdfium::span<uint8_t> pDest,
48 pdfium::span<const uint8_t> pSrc,
49 int pixels) {
50 m_Transform->TranslateScanline(pDest, pSrc, pixels);
51 }
52