Home | History | Annotate | Download | only in page
      1 // Copyright 2017 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_iccprofile.h"
      8 
      9 #include "core/fpdfapi/cpdf_modulemgr.h"
     10 #include "core/fpdfapi/parser/cpdf_stream.h"
     11 #include "core/fxcodec/codec/ccodec_iccmodule.h"
     12 
     13 namespace {
     14 
     15 bool DetectSRGB(const uint8_t* pData, uint32_t dwSize) {
     16   return dwSize == 3144 && memcmp(pData + 0x190, "sRGB IEC61966-2.1", 17) == 0;
     17 }
     18 
     19 }  // namespace
     20 
     21 CPDF_IccProfile::CPDF_IccProfile(CPDF_Stream* pStream,
     22                                  const uint8_t* pData,
     23                                  uint32_t dwSize)
     24     : m_bsRGB(DetectSRGB(pData, dwSize)), m_pStream(pStream) {
     25   if (m_bsRGB) {
     26     m_nSrcComponents = 3;
     27     return;
     28   }
     29 
     30   uint32_t nSrcComps = 0;
     31   auto* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule();
     32   m_Transform = pIccModule->CreateTransform_sRGB(pData, dwSize, &nSrcComps);
     33   if (m_Transform)
     34     m_nSrcComponents = nSrcComps;
     35 }
     36 
     37 CPDF_IccProfile::~CPDF_IccProfile() {}
     38