Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_color.cpp

Issue 1965243002: Clean up CPDF_Color and some related code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_colorspace.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/fpdf_page/include/cpdf_color.h" 7 #include "core/fpdfapi/fpdf_page/include/cpdf_color.h"
8 8
9 #include "core/fpdfapi/fpdf_page/pageint.h" 9 #include "core/fpdfapi/fpdf_page/pageint.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
12 #include "core/fxcrt/include/fx_system.h" 12 #include "core/fxcrt/include/fx_system.h"
13 13
14 CPDF_Color::CPDF_Color(int family) { 14 CPDF_Color::CPDF_Color() : m_pCS(nullptr), m_pBuffer(nullptr) {}
15 m_pCS = CPDF_ColorSpace::GetStockCS(family);
16 int nComps = 3;
17 if (family == PDFCS_DEVICEGRAY)
18 nComps = 1;
19 else if (family == PDFCS_DEVICECMYK)
20 nComps = 4;
21
22 m_pBuffer = FX_Alloc(FX_FLOAT, nComps);
23 for (int i = 0; i < nComps; i++)
24 m_pBuffer[i] = 0;
25 }
26 15
27 CPDF_Color::~CPDF_Color() { 16 CPDF_Color::~CPDF_Color() {
28 ReleaseBuffer(); 17 ReleaseBuffer();
29 ReleaseColorSpace(); 18 ReleaseColorSpace();
30 } 19 }
31 20
21 bool CPDF_Color::IsPattern() const {
22 return m_pCS && m_pCS->GetFamily() == PDFCS_PATTERN;
23 }
24
32 void CPDF_Color::ReleaseBuffer() { 25 void CPDF_Color::ReleaseBuffer() {
33 if (!m_pBuffer) 26 if (!m_pBuffer)
34 return; 27 return;
35 28
36 if (m_pCS->GetFamily() == PDFCS_PATTERN) { 29 if (m_pCS->GetFamily() == PDFCS_PATTERN) {
37 PatternValue* pvalue = (PatternValue*)m_pBuffer; 30 PatternValue* pvalue = (PatternValue*)m_pBuffer;
38 CPDF_Pattern* pPattern = 31 CPDF_Pattern* pPattern =
39 pvalue->m_pCountedPattern ? pvalue->m_pCountedPattern->get() : nullptr; 32 pvalue->m_pCountedPattern ? pvalue->m_pCountedPattern->get() : nullptr;
40 if (pPattern && pPattern->document()) { 33 if (pPattern && pPattern->document()) {
41 CPDF_DocPageData* pPageData = pPattern->document()->GetPageData(); 34 CPDF_DocPageData* pPageData = pPattern->document()->GetPageData();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (!m_pBuffer) 70 if (!m_pBuffer)
78 return; 71 return;
79 if (m_pCS->GetFamily() != PDFCS_PATTERN) 72 if (m_pCS->GetFamily() != PDFCS_PATTERN)
80 FXSYS_memcpy(m_pBuffer, comps, m_pCS->CountComponents() * sizeof(FX_FLOAT)); 73 FXSYS_memcpy(m_pBuffer, comps, m_pCS->CountComponents() * sizeof(FX_FLOAT));
81 } 74 }
82 75
83 void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) { 76 void CPDF_Color::SetValue(CPDF_Pattern* pPattern, FX_FLOAT* comps, int ncomps) {
84 if (ncomps > MAX_PATTERN_COLORCOMPS) 77 if (ncomps > MAX_PATTERN_COLORCOMPS)
85 return; 78 return;
86 79
87 if (!m_pCS || m_pCS->GetFamily() != PDFCS_PATTERN) { 80 if (!IsPattern()) {
88 FX_Free(m_pBuffer); 81 FX_Free(m_pBuffer);
89 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN); 82 m_pCS = CPDF_ColorSpace::GetStockCS(PDFCS_PATTERN);
90 m_pBuffer = m_pCS->CreateBuf(); 83 m_pBuffer = m_pCS->CreateBuf();
91 } 84 }
92 85
93 CPDF_DocPageData* pDocPageData = nullptr; 86 CPDF_DocPageData* pDocPageData = nullptr;
94 PatternValue* pvalue = (PatternValue*)m_pBuffer; 87 PatternValue* pvalue = (PatternValue*)m_pBuffer;
95 if (pvalue->m_pPattern && pvalue->m_pPattern->document()) { 88 if (pvalue->m_pPattern && pvalue->m_pPattern->document()) {
96 pDocPageData = pvalue->m_pPattern->document()->GetPageData(); 89 pDocPageData = pvalue->m_pPattern->document()->GetPageData();
97 if (pDocPageData) 90 if (pDocPageData)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 return TRUE; 145 return TRUE;
153 } 146 }
154 147
155 CPDF_Pattern* CPDF_Color::GetPattern() const { 148 CPDF_Pattern* CPDF_Color::GetPattern() const {
156 if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN) 149 if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN)
157 return nullptr; 150 return nullptr;
158 151
159 PatternValue* pvalue = (PatternValue*)m_pBuffer; 152 PatternValue* pvalue = (PatternValue*)m_pBuffer;
160 return pvalue->m_pPattern; 153 return pvalue->m_pPattern;
161 } 154 }
162
163 CPDF_ColorSpace* CPDF_Color::GetPatternCS() const {
164 if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN)
165 return nullptr;
166 return m_pCS->GetBaseCS();
167 }
168
169 FX_FLOAT* CPDF_Color::GetPatternColor() const {
170 if (!m_pBuffer || m_pCS->GetFamily() != PDFCS_PATTERN)
171 return nullptr;
172
173 PatternValue* pvalue = (PatternValue*)m_pBuffer;
174 return pvalue->m_nComps ? pvalue->m_Comps : nullptr;
175 }
176
177 FX_BOOL CPDF_Color::IsEqual(const CPDF_Color& other) const {
178 return m_pCS && m_pCS == other.m_pCS &&
179 FXSYS_memcmp(m_pBuffer, other.m_pBuffer, m_pCS->GetBufSize()) == 0;
180 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_page/cpdf_colorspace.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698