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

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

Issue 1824033002: Split core/include/fpdfapi/fpdf_resource.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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 | « core/fpdfapi/fpdf_page/cpdf_meshstream.h ('k') | core/fpdfapi/fpdf_page/cpdf_page.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/fpdf_page/cpdf_meshstream.h"
8
9 #include "core/fpdfapi/fpdf_page/include/cpdf_colorspace.h"
10 #include "core/fpdfapi/fpdf_page/pageint.h"
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
12
13 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream,
14 CPDF_Function** pFuncs,
15 int nFuncs,
16 CPDF_ColorSpace* pCS) {
17 m_Stream.LoadAllData(pShadingStream);
18 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize());
19 m_pFuncs = pFuncs;
20 m_nFuncs = nFuncs;
21 m_pCS = pCS;
22 CPDF_Dictionary* pDict = pShadingStream->GetDict();
23 m_nCoordBits = pDict->GetIntegerBy("BitsPerCoordinate");
24 m_nCompBits = pDict->GetIntegerBy("BitsPerComponent");
25 m_nFlagBits = pDict->GetIntegerBy("BitsPerFlag");
26 if (!m_nCoordBits || !m_nCompBits)
27 return FALSE;
28
29 FX_DWORD nComps = pCS->CountComponents();
30 if (nComps > 8)
31 return FALSE;
32
33 m_nComps = nFuncs ? 1 : nComps;
34 if (((int)m_nComps < 0) || m_nComps > 8)
35 return FALSE;
36
37 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1;
38 m_CompMax = (1 << m_nCompBits) - 1;
39 CPDF_Array* pDecode = pDict->GetArrayBy("Decode");
40 if (!pDecode || pDecode->GetCount() != 4 + m_nComps * 2)
41 return FALSE;
42
43 m_xmin = pDecode->GetNumberAt(0);
44 m_xmax = pDecode->GetNumberAt(1);
45 m_ymin = pDecode->GetNumberAt(2);
46 m_ymax = pDecode->GetNumberAt(3);
47 for (FX_DWORD i = 0; i < m_nComps; i++) {
48 m_ColorMin[i] = pDecode->GetNumberAt(i * 2 + 4);
49 m_ColorMax[i] = pDecode->GetNumberAt(i * 2 + 5);
50 }
51 return TRUE;
52 }
53
54 FX_DWORD CPDF_MeshStream::GetFlag() {
55 return m_BitStream.GetBits(m_nFlagBits) & 0x03;
56 }
57
58 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) {
59 if (m_nCoordBits == 32) {
60 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) *
61 (m_xmax - m_xmin) / (double)m_CoordMax);
62 y = m_ymin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) *
63 (m_ymax - m_ymin) / (double)m_CoordMax);
64 } else {
65 x = m_xmin +
66 m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_xmin) / m_CoordMax;
67 y = m_ymin +
68 m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ymin) / m_CoordMax;
69 }
70 }
71
72 void CPDF_MeshStream::GetColor(FX_FLOAT& r, FX_FLOAT& g, FX_FLOAT& b) {
73 FX_DWORD i;
74 FX_FLOAT color_value[8];
75 for (i = 0; i < m_nComps; i++) {
76 color_value[i] = m_ColorMin[i] +
77 m_BitStream.GetBits(m_nCompBits) *
78 (m_ColorMax[i] - m_ColorMin[i]) / m_CompMax;
79 }
80 if (m_nFuncs) {
81 static const int kMaxResults = 8;
82 FX_FLOAT result[kMaxResults];
83 int nResults;
84 FXSYS_memset(result, 0, sizeof(result));
85 for (FX_DWORD i = 0; i < m_nFuncs; i++) {
86 if (m_pFuncs[i] && m_pFuncs[i]->CountOutputs() <= kMaxResults) {
87 m_pFuncs[i]->Call(color_value, 1, result, nResults);
88 }
89 }
90 m_pCS->GetRGB(result, r, g, b);
91 } else {
92 m_pCS->GetRGB(color_value, r, g, b);
93 }
94 }
95
96 FX_DWORD CPDF_MeshStream::GetVertex(CPDF_MeshVertex& vertex,
97 CFX_Matrix* pObject2Bitmap) {
98 FX_DWORD flag = GetFlag();
99 GetCoords(vertex.x, vertex.y);
100 pObject2Bitmap->Transform(vertex.x, vertex.y);
101 GetColor(vertex.r, vertex.g, vertex.b);
102 m_BitStream.ByteAlign();
103 return flag;
104 }
105
106 FX_BOOL CPDF_MeshStream::GetVertexRow(CPDF_MeshVertex* vertex,
107 int count,
108 CFX_Matrix* pObject2Bitmap) {
109 for (int i = 0; i < count; i++) {
110 if (m_BitStream.IsEOF())
111 return FALSE;
112
113 GetCoords(vertex[i].x, vertex[i].y);
114 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y);
115 GetColor(vertex[i].r, vertex[i].g, vertex[i].b);
116 m_BitStream.ByteAlign();
117 }
118 return TRUE;
119 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_page/cpdf_meshstream.h ('k') | core/fpdfapi/fpdf_page/cpdf_page.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698