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 "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
10 #include "core/fpdfapi/fpdf_page/pageint.h" | 10 #include "core/fpdfapi/fpdf_page/pageint.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 if (m_bInline) | 51 if (m_bInline) |
52 pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE))); | 52 pImage->SetInlineDict(ToDictionary(m_pInlineDict->Clone(TRUE))); |
53 | 53 |
54 return pImage; | 54 return pImage; |
55 } | 55 } |
56 | 56 |
57 FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) { | 57 FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) { |
58 m_pStream = pStream; | 58 m_pStream = pStream; |
59 if (m_bInline && m_pInlineDict) { | 59 if (m_bInline && m_pInlineDict) { |
60 m_pInlineDict->Release(); | 60 m_pInlineDict->Release(); |
61 m_pInlineDict = NULL; | 61 m_pInlineDict = nullptr; |
62 } | 62 } |
63 m_bInline = bInline; | 63 m_bInline = bInline; |
64 CPDF_Dictionary* pDict = pStream->GetDict(); | 64 CPDF_Dictionary* pDict = pStream->GetDict(); |
65 if (m_bInline) { | 65 if (m_bInline) { |
66 m_pInlineDict = ToDictionary(pDict->Clone()); | 66 m_pInlineDict = ToDictionary(pDict->Clone()); |
67 } | 67 } |
68 m_pOC = pDict->GetDictBy("OC"); | 68 m_pOC = pDict->GetDictBy("OC"); |
69 m_bIsMask = | 69 m_bIsMask = |
70 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); | 70 !pDict->KeyExist("ColorSpace") || pDict->GetIntegerBy("ImageMask"); |
71 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); | 71 m_bInterpolate = pDict->GetIntegerBy("Interpolate"); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 161 } |
162 uint8_t* src_buf = pBitmap->GetBuffer(); | 162 uint8_t* src_buf = pBitmap->GetBuffer(); |
163 int32_t src_pitch = pBitmap->GetPitch(); | 163 int32_t src_pitch = pBitmap->GetPitch(); |
164 int32_t bpp = pBitmap->GetBPP(); | 164 int32_t bpp = pBitmap->GetBPP(); |
165 | 165 |
166 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 166 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
167 pDict->SetAtName("Type", "XObject"); | 167 pDict->SetAtName("Type", "XObject"); |
168 pDict->SetAtName("Subtype", "Image"); | 168 pDict->SetAtName("Subtype", "Image"); |
169 pDict->SetAtInteger("Width", BitmapWidth); | 169 pDict->SetAtInteger("Width", BitmapWidth); |
170 pDict->SetAtInteger("Height", BitmapHeight); | 170 pDict->SetAtInteger("Height", BitmapHeight); |
171 uint8_t* dest_buf = NULL; | 171 uint8_t* dest_buf = nullptr; |
172 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; | 172 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; |
173 if (bpp == 1) { | 173 if (bpp == 1) { |
174 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; | 174 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; |
175 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; | 175 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; |
176 if (!pBitmap->IsAlphaMask()) { | 176 if (!pBitmap->IsAlphaMask()) { |
177 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, | 177 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, |
178 reset_b); | 178 reset_b); |
179 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); | 179 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); |
180 } | 180 } |
181 if (set_a == 0 || reset_a == 0) { | 181 if (set_a == 0 || reset_a == 0) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } else { | 245 } else { |
246 pDict->SetAtName("ColorSpace", "DeviceRGB"); | 246 pDict->SetAtName("ColorSpace", "DeviceRGB"); |
247 pDict->SetAtInteger("BitsPerComponent", 8); | 247 pDict->SetAtInteger("BitsPerComponent", 8); |
248 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 248 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
249 dest_pitch = BitmapWidth * 3; | 249 dest_pitch = BitmapWidth * 3; |
250 opType = 2; | 250 opType = 2; |
251 } else { | 251 } else { |
252 opType = 0; | 252 opType = 0; |
253 } | 253 } |
254 } | 254 } |
255 const CFX_DIBitmap* pMaskBitmap = NULL; | 255 const CFX_DIBitmap* pMaskBitmap = nullptr; |
256 FX_BOOL bDeleteMask = FALSE; | 256 FX_BOOL bDeleteMask = FALSE; |
257 if (pBitmap->HasAlpha()) { | 257 if (pBitmap->HasAlpha()) { |
258 pMaskBitmap = pBitmap->GetAlphaMask(); | 258 pMaskBitmap = pBitmap->GetAlphaMask(); |
259 bDeleteMask = TRUE; | 259 bDeleteMask = TRUE; |
260 } | 260 } |
261 if (pMaskBitmap) { | 261 if (pMaskBitmap) { |
262 int32_t maskWidth = pMaskBitmap->GetWidth(); | 262 int32_t maskWidth = pMaskBitmap->GetWidth(); |
263 int32_t maskHeight = pMaskBitmap->GetHeight(); | 263 int32_t maskHeight = pMaskBitmap->GetHeight(); |
264 uint8_t* mask_buf = NULL; | 264 uint8_t* mask_buf = nullptr; |
265 FX_STRSIZE mask_size = 0; | 265 FX_STRSIZE mask_size = 0; |
266 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; | 266 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; |
267 pMaskDict->SetAtName("Type", "XObject"); | 267 pMaskDict->SetAtName("Type", "XObject"); |
268 pMaskDict->SetAtName("Subtype", "Image"); | 268 pMaskDict->SetAtName("Subtype", "Image"); |
269 pMaskDict->SetAtInteger("Width", maskWidth); | 269 pMaskDict->SetAtInteger("Width", maskWidth); |
270 pMaskDict->SetAtInteger("Height", maskHeight); | 270 pMaskDict->SetAtInteger("Height", maskHeight); |
271 pMaskDict->SetAtName("ColorSpace", "DeviceGray"); | 271 pMaskDict->SetAtName("ColorSpace", "DeviceGray"); |
272 pMaskDict->SetAtInteger("BitsPerComponent", 8); | 272 pMaskDict->SetAtInteger("BitsPerComponent", 8); |
273 if (pMaskBitmap->GetBPP() == 8 && | 273 if (pMaskBitmap->GetBPP() == 8 && |
274 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { | 274 (iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) { |
(...skipping 19 matching lines...) Expand all Loading... |
294 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { | 294 if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) { |
295 } else { | 295 } else { |
296 if (pBitmap->GetBPP() == 1) { | 296 if (pBitmap->GetBPP() == 1) { |
297 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { | 297 } else if (pBitmap->GetBPP() >= 8 && pBitmap->GetPalette()) { |
298 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); | 298 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap(); |
299 pNewBitmap->Copy(pBitmap); | 299 pNewBitmap->Copy(pBitmap); |
300 pNewBitmap->ConvertFormat(FXDIB_Rgb); | 300 pNewBitmap->ConvertFormat(FXDIB_Rgb); |
301 SetImage(pNewBitmap, iCompress); | 301 SetImage(pNewBitmap, iCompress); |
302 if (pDict) { | 302 if (pDict) { |
303 pDict->Release(); | 303 pDict->Release(); |
304 pDict = NULL; | 304 pDict = nullptr; |
305 } | 305 } |
306 FX_Free(dest_buf); | 306 FX_Free(dest_buf); |
307 dest_buf = NULL; | 307 dest_buf = nullptr; |
308 dest_size = 0; | 308 dest_size = 0; |
309 delete pNewBitmap; | 309 delete pNewBitmap; |
310 return; | 310 return; |
311 } | 311 } |
312 } | 312 } |
313 } else if (opType == 1) { | 313 } else if (opType == 1) { |
314 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); | 314 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); |
315 dest_size = dest_pitch * BitmapHeight; // Safe as checked alloc returned. | 315 dest_size = dest_pitch * BitmapHeight; // Safe as checked alloc returned. |
316 | 316 |
317 uint8_t* pDest = dest_buf; | 317 uint8_t* pDest = dest_buf; |
(...skipping 18 matching lines...) Expand all Loading... |
336 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); | 336 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); |
337 dest_offset += 3; | 337 dest_offset += 3; |
338 src_offset += bpp == 24 ? 3 : 4; | 338 src_offset += bpp == 24 ? 3 : 4; |
339 } | 339 } |
340 | 340 |
341 pDest += dest_pitch; | 341 pDest += dest_pitch; |
342 dest_offset = 0; | 342 dest_offset = 0; |
343 } | 343 } |
344 } | 344 } |
345 if (!m_pStream) { | 345 if (!m_pStream) { |
346 m_pStream = new CPDF_Stream(NULL, 0, NULL); | 346 m_pStream = new CPDF_Stream(nullptr, 0, nullptr); |
347 } | 347 } |
348 m_pStream->InitStream(dest_buf, dest_size, pDict); | 348 m_pStream->InitStream(dest_buf, dest_size, pDict); |
349 m_bIsMask = pBitmap->IsAlphaMask(); | 349 m_bIsMask = pBitmap->IsAlphaMask(); |
350 m_Width = BitmapWidth; | 350 m_Width = BitmapWidth; |
351 m_Height = BitmapHeight; | 351 m_Height = BitmapHeight; |
352 FX_Free(dest_buf); | 352 FX_Free(dest_buf); |
353 } | 353 } |
354 | 354 |
355 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { | 355 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) { |
356 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); | 356 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 413 } |
414 if (!ret) { | 414 if (!ret) { |
415 delete m_pDIBSource; | 415 delete m_pDIBSource; |
416 m_pDIBSource = nullptr; | 416 m_pDIBSource = nullptr; |
417 return FALSE; | 417 return FALSE; |
418 } | 418 } |
419 m_pMask = pSource->DetachMask(); | 419 m_pMask = pSource->DetachMask(); |
420 m_MatteColor = pSource->GetMatteColor(); | 420 m_MatteColor = pSource->GetMatteColor(); |
421 return FALSE; | 421 return FALSE; |
422 } | 422 } |
OLD | NEW |