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/fpdf_page/include/cpdf_image.h" | 7 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 27 matching lines...) Expand all Loading... |
38 m_bInterpolate(false), | 38 m_bInterpolate(false), |
39 m_pDocument(pDoc), | 39 m_pDocument(pDoc), |
40 m_pOC(nullptr) { | 40 m_pOC(nullptr) { |
41 if (!pStream) | 41 if (!pStream) |
42 return; | 42 return; |
43 | 43 |
44 CPDF_Dictionary* pDict = pStream->GetDict(); | 44 CPDF_Dictionary* pDict = pStream->GetDict(); |
45 if (m_bInline) | 45 if (m_bInline) |
46 m_pInlineDict = ToDictionary(pDict->Clone()); | 46 m_pInlineDict = ToDictionary(pDict->Clone()); |
47 | 47 |
48 m_pOC = pDict->GetDictBy("OC"); | 48 m_pOC = pDict->GetDictFor("OC"); |
49 m_bIsMask = | 49 m_bIsMask = |
50 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); | 50 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerFor("ImageMask"); |
51 m_bInterpolate = !!pDict->GetIntegerBy("Interpolate"); | 51 m_bInterpolate = !!pDict->GetIntegerFor("Interpolate"); |
52 m_Height = pDict->GetIntegerBy("Height"); | 52 m_Height = pDict->GetIntegerFor("Height"); |
53 m_Width = pDict->GetIntegerBy("Width"); | 53 m_Width = pDict->GetIntegerFor("Width"); |
54 } | 54 } |
55 | 55 |
56 CPDF_Image::~CPDF_Image() { | 56 CPDF_Image::~CPDF_Image() { |
57 if (m_bInline) { | 57 if (m_bInline) { |
58 if (m_pStream) | 58 if (m_pStream) |
59 m_pStream->Release(); | 59 m_pStream->Release(); |
60 if (m_pInlineDict) | 60 if (m_pInlineDict) |
61 m_pInlineDict->Release(); | 61 m_pInlineDict->Release(); |
62 } | 62 } |
63 } | 63 } |
(...skipping 15 matching lines...) Expand all Loading... |
79 int32_t height; | 79 int32_t height; |
80 int32_t num_comps; | 80 int32_t num_comps; |
81 int32_t bits; | 81 int32_t bits; |
82 bool color_trans; | 82 bool color_trans; |
83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( | 83 if (!CPDF_ModuleMgr::Get()->GetJpegModule()->LoadInfo( |
84 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { | 84 pData, size, &width, &height, &num_comps, &bits, &color_trans)) { |
85 return nullptr; | 85 return nullptr; |
86 } | 86 } |
87 | 87 |
88 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 88 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
89 pDict->SetAtName("Type", "XObject"); | 89 pDict->SetNameFor("Type", "XObject"); |
90 pDict->SetAtName("Subtype", "Image"); | 90 pDict->SetNameFor("Subtype", "Image"); |
91 pDict->SetAtInteger("Width", width); | 91 pDict->SetIntegerFor("Width", width); |
92 pDict->SetAtInteger("Height", height); | 92 pDict->SetIntegerFor("Height", height); |
93 const FX_CHAR* csname = nullptr; | 93 const FX_CHAR* csname = nullptr; |
94 if (num_comps == 1) { | 94 if (num_comps == 1) { |
95 csname = "DeviceGray"; | 95 csname = "DeviceGray"; |
96 } else if (num_comps == 3) { | 96 } else if (num_comps == 3) { |
97 csname = "DeviceRGB"; | 97 csname = "DeviceRGB"; |
98 } else if (num_comps == 4) { | 98 } else if (num_comps == 4) { |
99 csname = "DeviceCMYK"; | 99 csname = "DeviceCMYK"; |
100 CPDF_Array* pDecode = new CPDF_Array; | 100 CPDF_Array* pDecode = new CPDF_Array; |
101 for (int n = 0; n < 4; n++) { | 101 for (int n = 0; n < 4; n++) { |
102 pDecode->AddInteger(1); | 102 pDecode->AddInteger(1); |
103 pDecode->AddInteger(0); | 103 pDecode->AddInteger(0); |
104 } | 104 } |
105 pDict->SetAt("Decode", pDecode); | 105 pDict->SetFor("Decode", pDecode); |
106 } | 106 } |
107 pDict->SetAtName("ColorSpace", csname); | 107 pDict->SetNameFor("ColorSpace", csname); |
108 pDict->SetAtInteger("BitsPerComponent", bits); | 108 pDict->SetIntegerFor("BitsPerComponent", bits); |
109 pDict->SetAtName("Filter", "DCTDecode"); | 109 pDict->SetNameFor("Filter", "DCTDecode"); |
110 if (!color_trans) { | 110 if (!color_trans) { |
111 CPDF_Dictionary* pParms = new CPDF_Dictionary; | 111 CPDF_Dictionary* pParms = new CPDF_Dictionary; |
112 pDict->SetAt("DecodeParms", pParms); | 112 pDict->SetFor("DecodeParms", pParms); |
113 pParms->SetAtInteger("ColorTransform", 0); | 113 pParms->SetIntegerFor("ColorTransform", 0); |
114 } | 114 } |
115 m_bIsMask = FALSE; | 115 m_bIsMask = FALSE; |
116 m_Width = width; | 116 m_Width = width; |
117 m_Height = height; | 117 m_Height = height; |
118 if (!m_pStream) | 118 if (!m_pStream) |
119 m_pStream = new CPDF_Stream(nullptr, 0, nullptr); | 119 m_pStream = new CPDF_Stream(nullptr, 0, nullptr); |
120 return pDict; | 120 return pDict; |
121 } | 121 } |
122 | 122 |
123 void CPDF_Image::SetJpegImage(IFX_FileRead* pFile) { | 123 void CPDF_Image::SetJpegImage(IFX_FileRead* pFile) { |
(...skipping 20 matching lines...) Expand all Loading... |
144 int32_t BitmapWidth = pBitmap->GetWidth(); | 144 int32_t BitmapWidth = pBitmap->GetWidth(); |
145 int32_t BitmapHeight = pBitmap->GetHeight(); | 145 int32_t BitmapHeight = pBitmap->GetHeight(); |
146 if (BitmapWidth < 1 || BitmapHeight < 1) { | 146 if (BitmapWidth < 1 || BitmapHeight < 1) { |
147 return; | 147 return; |
148 } | 148 } |
149 uint8_t* src_buf = pBitmap->GetBuffer(); | 149 uint8_t* src_buf = pBitmap->GetBuffer(); |
150 int32_t src_pitch = pBitmap->GetPitch(); | 150 int32_t src_pitch = pBitmap->GetPitch(); |
151 int32_t bpp = pBitmap->GetBPP(); | 151 int32_t bpp = pBitmap->GetBPP(); |
152 | 152 |
153 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 153 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
154 pDict->SetAtName("Type", "XObject"); | 154 pDict->SetNameFor("Type", "XObject"); |
155 pDict->SetAtName("Subtype", "Image"); | 155 pDict->SetNameFor("Subtype", "Image"); |
156 pDict->SetAtInteger("Width", BitmapWidth); | 156 pDict->SetIntegerFor("Width", BitmapWidth); |
157 pDict->SetAtInteger("Height", BitmapHeight); | 157 pDict->SetIntegerFor("Height", BitmapHeight); |
158 uint8_t* dest_buf = nullptr; | 158 uint8_t* dest_buf = nullptr; |
159 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; | 159 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; |
160 if (bpp == 1) { | 160 if (bpp == 1) { |
161 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; | 161 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; |
162 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; | 162 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; |
163 if (!pBitmap->IsAlphaMask()) { | 163 if (!pBitmap->IsAlphaMask()) { |
164 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, | 164 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, |
165 reset_b); | 165 reset_b); |
166 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); | 166 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); |
167 } | 167 } |
168 if (set_a == 0 || reset_a == 0) { | 168 if (set_a == 0 || reset_a == 0) { |
169 pDict->SetAt("ImageMask", new CPDF_Boolean(TRUE)); | 169 pDict->SetFor("ImageMask", new CPDF_Boolean(TRUE)); |
170 if (reset_a == 0) { | 170 if (reset_a == 0) { |
171 CPDF_Array* pArray = new CPDF_Array; | 171 CPDF_Array* pArray = new CPDF_Array; |
172 pArray->AddInteger(1); | 172 pArray->AddInteger(1); |
173 pArray->AddInteger(0); | 173 pArray->AddInteger(0); |
174 pDict->SetAt("Decode", pArray); | 174 pDict->SetFor("Decode", pArray); |
175 } | 175 } |
176 } else { | 176 } else { |
177 CPDF_Array* pCS = new CPDF_Array; | 177 CPDF_Array* pCS = new CPDF_Array; |
178 pCS->AddName("Indexed"); | 178 pCS->AddName("Indexed"); |
179 pCS->AddName("DeviceRGB"); | 179 pCS->AddName("DeviceRGB"); |
180 pCS->AddInteger(1); | 180 pCS->AddInteger(1); |
181 CFX_ByteString ct; | 181 CFX_ByteString ct; |
182 FX_CHAR* pBuf = ct.GetBuffer(6); | 182 FX_CHAR* pBuf = ct.GetBuffer(6); |
183 pBuf[0] = (FX_CHAR)reset_r; | 183 pBuf[0] = (FX_CHAR)reset_r; |
184 pBuf[1] = (FX_CHAR)reset_g; | 184 pBuf[1] = (FX_CHAR)reset_g; |
185 pBuf[2] = (FX_CHAR)reset_b; | 185 pBuf[2] = (FX_CHAR)reset_b; |
186 pBuf[3] = (FX_CHAR)set_r; | 186 pBuf[3] = (FX_CHAR)set_r; |
187 pBuf[4] = (FX_CHAR)set_g; | 187 pBuf[4] = (FX_CHAR)set_g; |
188 pBuf[5] = (FX_CHAR)set_b; | 188 pBuf[5] = (FX_CHAR)set_b; |
189 ct.ReleaseBuffer(6); | 189 ct.ReleaseBuffer(6); |
190 pCS->Add(new CPDF_String(ct, TRUE)); | 190 pCS->Add(new CPDF_String(ct, TRUE)); |
191 pDict->SetAt("ColorSpace", pCS); | 191 pDict->SetFor("ColorSpace", pCS); |
192 } | 192 } |
193 pDict->SetAtInteger("BitsPerComponent", 1); | 193 pDict->SetIntegerFor("BitsPerComponent", 1); |
194 dest_pitch = (BitmapWidth + 7) / 8; | 194 dest_pitch = (BitmapWidth + 7) / 8; |
195 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 195 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
196 opType = 1; | 196 opType = 1; |
197 } else { | 197 } else { |
198 opType = 0; | 198 opType = 0; |
199 } | 199 } |
200 } else if (bpp == 8) { | 200 } else if (bpp == 8) { |
201 int32_t iPalette = pBitmap->GetPaletteSize(); | 201 int32_t iPalette = pBitmap->GetPaletteSize(); |
202 if (iPalette > 0) { | 202 if (iPalette > 0) { |
203 CPDF_Array* pCS = new CPDF_Array; | 203 CPDF_Array* pCS = new CPDF_Array; |
204 m_pDocument->AddIndirectObject(pCS); | 204 m_pDocument->AddIndirectObject(pCS); |
205 pCS->AddName("Indexed"); | 205 pCS->AddName("Indexed"); |
206 pCS->AddName("DeviceRGB"); | 206 pCS->AddName("DeviceRGB"); |
207 pCS->AddInteger(iPalette - 1); | 207 pCS->AddInteger(iPalette - 1); |
208 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); | 208 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); |
209 uint8_t* ptr = pColorTable; | 209 uint8_t* ptr = pColorTable; |
210 for (int32_t i = 0; i < iPalette; i++) { | 210 for (int32_t i = 0; i < iPalette; i++) { |
211 uint32_t argb = pBitmap->GetPaletteArgb(i); | 211 uint32_t argb = pBitmap->GetPaletteArgb(i); |
212 ptr[0] = (uint8_t)(argb >> 16); | 212 ptr[0] = (uint8_t)(argb >> 16); |
213 ptr[1] = (uint8_t)(argb >> 8); | 213 ptr[1] = (uint8_t)(argb >> 8); |
214 ptr[2] = (uint8_t)argb; | 214 ptr[2] = (uint8_t)argb; |
215 ptr += 3; | 215 ptr += 3; |
216 } | 216 } |
217 CPDF_Stream* pCTS = | 217 CPDF_Stream* pCTS = |
218 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); | 218 new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary); |
219 m_pDocument->AddIndirectObject(pCTS); | 219 m_pDocument->AddIndirectObject(pCTS); |
220 pCS->AddReference(m_pDocument, pCTS); | 220 pCS->AddReference(m_pDocument, pCTS); |
221 pDict->SetAtReference("ColorSpace", m_pDocument, pCS); | 221 pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS); |
222 } else { | 222 } else { |
223 pDict->SetAtName("ColorSpace", "DeviceGray"); | 223 pDict->SetNameFor("ColorSpace", "DeviceGray"); |
224 } | 224 } |
225 pDict->SetAtInteger("BitsPerComponent", 8); | 225 pDict->SetIntegerFor("BitsPerComponent", 8); |
226 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 226 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
227 dest_pitch = BitmapWidth; | 227 dest_pitch = BitmapWidth; |
228 opType = 1; | 228 opType = 1; |
229 } else { | 229 } else { |
230 opType = 0; | 230 opType = 0; |
231 } | 231 } |
232 } else { | 232 } else { |
233 pDict->SetAtName("ColorSpace", "DeviceRGB"); | 233 pDict->SetNameFor("ColorSpace", "DeviceRGB"); |
234 pDict->SetAtInteger("BitsPerComponent", 8); | 234 pDict->SetIntegerFor("BitsPerComponent", 8); |
235 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 235 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
236 dest_pitch = BitmapWidth * 3; | 236 dest_pitch = BitmapWidth * 3; |
237 opType = 2; | 237 opType = 2; |
238 } else { | 238 } else { |
239 opType = 0; | 239 opType = 0; |
240 } | 240 } |
241 } | 241 } |
242 const CFX_DIBitmap* pMaskBitmap = nullptr; | 242 const CFX_DIBitmap* pMaskBitmap = nullptr; |
243 FX_BOOL bDeleteMask = FALSE; | 243 FX_BOOL bDeleteMask = FALSE; |
244 if (pBitmap->HasAlpha()) { | 244 if (pBitmap->HasAlpha()) { |
245 pMaskBitmap = pBitmap->GetAlphaMask(); | 245 pMaskBitmap = pBitmap->GetAlphaMask(); |
246 bDeleteMask = TRUE; | 246 bDeleteMask = TRUE; |
247 } | 247 } |
248 if (pMaskBitmap) { | 248 if (pMaskBitmap) { |
249 int32_t maskWidth = pMaskBitmap->GetWidth(); | 249 int32_t maskWidth = pMaskBitmap->GetWidth(); |
250 int32_t maskHeight = pMaskBitmap->GetHeight(); | 250 int32_t maskHeight = pMaskBitmap->GetHeight(); |
251 uint8_t* mask_buf = nullptr; | 251 uint8_t* mask_buf = nullptr; |
252 FX_STRSIZE mask_size = 0; | 252 FX_STRSIZE mask_size = 0; |
253 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; | 253 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; |
254 pMaskDict->SetAtName("Type", "XObject"); | 254 pMaskDict->SetNameFor("Type", "XObject"); |
255 pMaskDict->SetAtName("Subtype", "Image"); | 255 pMaskDict->SetNameFor("Subtype", "Image"); |
256 pMaskDict->SetAtInteger("Width", maskWidth); | 256 pMaskDict->SetIntegerFor("Width", maskWidth); |
257 pMaskDict->SetAtInteger("Height", maskHeight); | 257 pMaskDict->SetIntegerFor("Height", maskHeight); |
258 pMaskDict->SetAtName("ColorSpace", "DeviceGray"); | 258 pMaskDict->SetNameFor("ColorSpace", "DeviceGray"); |
259 pMaskDict->SetAtInteger("BitsPerComponent", 8); | 259 pMaskDict->SetIntegerFor("BitsPerComponent", 8); |
260 if (pMaskBitmap->GetBPP() == 8 && | 260 if (pMaskBitmap->GetBPP() == 8 && |
261 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { | 261 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { |
262 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { | 262 } else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) { |
263 } else { | 263 } else { |
264 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); | 264 mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth); |
265 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. | 265 mask_size = maskHeight * maskWidth; // Safe since checked alloc returned. |
266 for (int32_t a = 0; a < maskHeight; a++) { | 266 for (int32_t a = 0; a < maskHeight; a++) { |
267 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), | 267 FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a), |
268 maskWidth); | 268 maskWidth); |
269 } | 269 } |
270 } | 270 } |
271 pMaskDict->SetAtInteger("Length", mask_size); | 271 pMaskDict->SetIntegerFor("Length", mask_size); |
272 | 272 |
273 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict); | 273 CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict); |
274 m_pDocument->AddIndirectObject(pMaskStream); | 274 m_pDocument->AddIndirectObject(pMaskStream); |
275 pDict->SetAtReference("SMask", m_pDocument, pMaskStream); | 275 pDict->SetReferenceFor("SMask", m_pDocument, pMaskStream); |
276 if (bDeleteMask) { | 276 if (bDeleteMask) { |
277 delete pMaskBitmap; | 277 delete pMaskBitmap; |
278 } | 278 } |
279 } | 279 } |
280 if (opType == 0) { | 280 if (opType == 0) { |
281 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { | 281 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { |
282 } else { | 282 } else { |
283 if (pBitmap->GetBPP() == 1) { | 283 if (pBitmap->GetBPP() == 1) { |
284 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { | 284 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { |
285 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); | 285 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 400 } |
401 if (!ret) { | 401 if (!ret) { |
402 delete m_pDIBSource; | 402 delete m_pDIBSource; |
403 m_pDIBSource = nullptr; | 403 m_pDIBSource = nullptr; |
404 return FALSE; | 404 return FALSE; |
405 } | 405 } |
406 m_pMask = pSource->DetachMask(); | 406 m_pMask = pSource->DetachMask(); |
407 m_MatteColor = pSource->GetMatteColor(); | 407 m_MatteColor = pSource->GetMatteColor(); |
408 return FALSE; | 408 return FALSE; |
409 } | 409 } |
OLD | NEW |