OLD | NEW |
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/page/cpdf_image.h" | 7 #include "core/fpdfapi/page/cpdf_image.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
14 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 14 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
15 #include "core/fpdfapi/page/cpdf_page.h" | 15 #include "core/fpdfapi/page/cpdf_page.h" |
16 #include "core/fpdfapi/parser/cpdf_array.h" | 16 #include "core/fpdfapi/parser/cpdf_array.h" |
17 #include "core/fpdfapi/parser/cpdf_boolean.h" | 17 #include "core/fpdfapi/parser/cpdf_boolean.h" |
18 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 18 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
19 #include "core/fpdfapi/parser/cpdf_document.h" | 19 #include "core/fpdfapi/parser/cpdf_document.h" |
| 20 #include "core/fpdfapi/parser/cpdf_name.h" |
| 21 #include "core/fpdfapi/parser/cpdf_number.h" |
| 22 #include "core/fpdfapi/parser/cpdf_reference.h" |
20 #include "core/fpdfapi/parser/cpdf_string.h" | 23 #include "core/fpdfapi/parser/cpdf_string.h" |
21 #include "core/fpdfapi/render/cpdf_pagerendercache.h" | 24 #include "core/fpdfapi/render/cpdf_pagerendercache.h" |
22 #include "core/fpdfapi/render/render_int.h" | 25 #include "core/fpdfapi/render/render_int.h" |
23 #include "core/fxcodec/fx_codec.h" | 26 #include "core/fxcodec/fx_codec.h" |
24 #include "core/fxge/fx_dib.h" | 27 #include "core/fxge/fx_dib.h" |
25 | 28 |
26 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} | 29 CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} |
27 | 30 |
28 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, | 31 CPDF_Image::CPDF_Image(CPDF_Document* pDoc, |
29 std::unique_ptr<CPDF_Stream> pStream) | 32 std::unique_ptr<CPDF_Stream> pStream) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 pDict->SetIntegerFor("Height", height); | 103 pDict->SetIntegerFor("Height", height); |
101 const FX_CHAR* csname = nullptr; | 104 const FX_CHAR* csname = nullptr; |
102 if (num_comps == 1) { | 105 if (num_comps == 1) { |
103 csname = "DeviceGray"; | 106 csname = "DeviceGray"; |
104 } else if (num_comps == 3) { | 107 } else if (num_comps == 3) { |
105 csname = "DeviceRGB"; | 108 csname = "DeviceRGB"; |
106 } else if (num_comps == 4) { | 109 } else if (num_comps == 4) { |
107 csname = "DeviceCMYK"; | 110 csname = "DeviceCMYK"; |
108 CPDF_Array* pDecode = new CPDF_Array; | 111 CPDF_Array* pDecode = new CPDF_Array; |
109 for (int n = 0; n < 4; n++) { | 112 for (int n = 0; n < 4; n++) { |
110 pDecode->AddInteger(1); | 113 pDecode->AddNew<CPDF_Number>(1); |
111 pDecode->AddInteger(0); | 114 pDecode->AddNew<CPDF_Number>(0); |
112 } | 115 } |
113 pDict->SetFor("Decode", pDecode); | 116 pDict->SetFor("Decode", pDecode); |
114 } | 117 } |
115 pDict->SetNameFor("ColorSpace", csname); | 118 pDict->SetNameFor("ColorSpace", csname); |
116 pDict->SetIntegerFor("BitsPerComponent", bits); | 119 pDict->SetIntegerFor("BitsPerComponent", bits); |
117 pDict->SetNameFor("Filter", "DCTDecode"); | 120 pDict->SetNameFor("Filter", "DCTDecode"); |
118 if (!color_trans) { | 121 if (!color_trans) { |
119 CPDF_Dictionary* pParms = | 122 CPDF_Dictionary* pParms = |
120 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 123 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); |
121 pDict->SetFor("DecodeParms", pParms); | 124 pDict->SetFor("DecodeParms", pParms); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; | 177 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; |
175 if (!pBitmap->IsAlphaMask()) { | 178 if (!pBitmap->IsAlphaMask()) { |
176 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, | 179 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, |
177 reset_b); | 180 reset_b); |
178 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); | 181 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); |
179 } | 182 } |
180 if (set_a == 0 || reset_a == 0) { | 183 if (set_a == 0 || reset_a == 0) { |
181 pDict->SetFor("ImageMask", new CPDF_Boolean(true)); | 184 pDict->SetFor("ImageMask", new CPDF_Boolean(true)); |
182 if (reset_a == 0) { | 185 if (reset_a == 0) { |
183 CPDF_Array* pArray = new CPDF_Array; | 186 CPDF_Array* pArray = new CPDF_Array; |
184 pArray->AddInteger(1); | 187 pArray->AddNew<CPDF_Number>(1); |
185 pArray->AddInteger(0); | 188 pArray->AddNew<CPDF_Number>(0); |
186 pDict->SetFor("Decode", pArray); | 189 pDict->SetFor("Decode", pArray); |
187 } | 190 } |
188 } else { | 191 } else { |
189 CPDF_Array* pCS = new CPDF_Array; | 192 CPDF_Array* pCS = new CPDF_Array; |
190 pCS->AddName("Indexed"); | 193 pCS->AddNew<CPDF_Name>("Indexed"); |
191 pCS->AddName("DeviceRGB"); | 194 pCS->AddNew<CPDF_Name>("DeviceRGB"); |
192 pCS->AddInteger(1); | 195 pCS->AddNew<CPDF_Number>(1); |
193 CFX_ByteString ct; | 196 CFX_ByteString ct; |
194 FX_CHAR* pBuf = ct.GetBuffer(6); | 197 FX_CHAR* pBuf = ct.GetBuffer(6); |
195 pBuf[0] = (FX_CHAR)reset_r; | 198 pBuf[0] = (FX_CHAR)reset_r; |
196 pBuf[1] = (FX_CHAR)reset_g; | 199 pBuf[1] = (FX_CHAR)reset_g; |
197 pBuf[2] = (FX_CHAR)reset_b; | 200 pBuf[2] = (FX_CHAR)reset_b; |
198 pBuf[3] = (FX_CHAR)set_r; | 201 pBuf[3] = (FX_CHAR)set_r; |
199 pBuf[4] = (FX_CHAR)set_g; | 202 pBuf[4] = (FX_CHAR)set_g; |
200 pBuf[5] = (FX_CHAR)set_b; | 203 pBuf[5] = (FX_CHAR)set_b; |
201 ct.ReleaseBuffer(6); | 204 ct.ReleaseBuffer(6); |
202 pCS->Add(new CPDF_String(ct, true)); | 205 pCS->AddNew<CPDF_String>(ct, true); |
203 pDict->SetFor("ColorSpace", pCS); | 206 pDict->SetFor("ColorSpace", pCS); |
204 } | 207 } |
205 pDict->SetIntegerFor("BitsPerComponent", 1); | 208 pDict->SetIntegerFor("BitsPerComponent", 1); |
206 dest_pitch = (BitmapWidth + 7) / 8; | 209 dest_pitch = (BitmapWidth + 7) / 8; |
207 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 210 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
208 opType = 1; | 211 opType = 1; |
209 } else { | 212 } else { |
210 opType = 0; | 213 opType = 0; |
211 } | 214 } |
212 } else if (bpp == 8) { | 215 } else if (bpp == 8) { |
213 int32_t iPalette = pBitmap->GetPaletteSize(); | 216 int32_t iPalette = pBitmap->GetPaletteSize(); |
214 if (iPalette > 0) { | 217 if (iPalette > 0) { |
215 CPDF_Array* pCS = m_pDocument->NewIndirect<CPDF_Array>(); | 218 CPDF_Array* pCS = m_pDocument->NewIndirect<CPDF_Array>(); |
216 pCS->AddName("Indexed"); | 219 pCS->AddNew<CPDF_Name>("Indexed"); |
217 pCS->AddName("DeviceRGB"); | 220 pCS->AddNew<CPDF_Name>("DeviceRGB"); |
218 pCS->AddInteger(iPalette - 1); | 221 pCS->AddNew<CPDF_Number>(iPalette - 1); |
219 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); | 222 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); |
220 uint8_t* ptr = pColorTable; | 223 uint8_t* ptr = pColorTable; |
221 for (int32_t i = 0; i < iPalette; i++) { | 224 for (int32_t i = 0; i < iPalette; i++) { |
222 uint32_t argb = pBitmap->GetPaletteArgb(i); | 225 uint32_t argb = pBitmap->GetPaletteArgb(i); |
223 ptr[0] = (uint8_t)(argb >> 16); | 226 ptr[0] = (uint8_t)(argb >> 16); |
224 ptr[1] = (uint8_t)(argb >> 8); | 227 ptr[1] = (uint8_t)(argb >> 8); |
225 ptr[2] = (uint8_t)argb; | 228 ptr[2] = (uint8_t)argb; |
226 ptr += 3; | 229 ptr += 3; |
227 } | 230 } |
228 CPDF_Stream* pCTS = m_pDocument->NewIndirect<CPDF_Stream>( | 231 CPDF_Stream* pCTS = m_pDocument->NewIndirect<CPDF_Stream>( |
229 pColorTable, iPalette * 3, | 232 pColorTable, iPalette * 3, |
230 new CPDF_Dictionary(m_pDocument->GetByteStringPool())); | 233 new CPDF_Dictionary(m_pDocument->GetByteStringPool())); |
231 pCS->AddReference(m_pDocument, pCTS); | 234 pCS->AddNew<CPDF_Reference>(m_pDocument, pCTS->GetObjNum()); |
232 pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS); | 235 pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS); |
233 } else { | 236 } else { |
234 pDict->SetNameFor("ColorSpace", "DeviceGray"); | 237 pDict->SetNameFor("ColorSpace", "DeviceGray"); |
235 } | 238 } |
236 pDict->SetIntegerFor("BitsPerComponent", 8); | 239 pDict->SetIntegerFor("BitsPerComponent", 8); |
237 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 240 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
238 dest_pitch = BitmapWidth; | 241 dest_pitch = BitmapWidth; |
239 opType = 1; | 242 opType = 1; |
240 } else { | 243 } else { |
241 opType = 0; | 244 opType = 0; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } | 412 } |
410 if (!ret) { | 413 if (!ret) { |
411 delete m_pDIBSource; | 414 delete m_pDIBSource; |
412 m_pDIBSource = nullptr; | 415 m_pDIBSource = nullptr; |
413 return false; | 416 return false; |
414 } | 417 } |
415 m_pMask = pSource->DetachMask(); | 418 m_pMask = pSource->DetachMask(); |
416 m_MatteColor = pSource->GetMatteColor(); | 419 m_MatteColor = pSource->GetMatteColor(); |
417 return false; | 420 return false; |
418 } | 421 } |
OLD | NEW |