OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
8 #include "../../../include/fxcodec/fx_codec.h" | 8 #include "../../../include/fxcodec/fx_codec.h" |
9 #include "../../../include/fpdfapi/fpdf_module.h" | 9 #include "../../../include/fpdfapi/fpdf_module.h" |
10 #include "../../../include/fpdfapi/fpdf_render.h" | 10 #include "../../../include/fpdfapi/fpdf_render.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 158 } |
159 } | 159 } |
160 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, const CPDF_Stream* pStream, CP
DF_DIBSource** ppMask, | 160 FX_BOOL CPDF_DIBSource::Load(CPDF_Document* pDoc, const CPDF_Stream* pStream, CP
DF_DIBSource** ppMask, |
161 FX_DWORD* pMatteColor, CPDF_Dictionary* pFormResour
ces, CPDF_Dictionary* pPageResources, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_B
OOL bLoadMask) | 161 FX_DWORD* pMatteColor, CPDF_Dictionary* pFormResour
ces, CPDF_Dictionary* pPageResources, FX_BOOL bStdCS, FX_DWORD GroupFamily, FX_B
OOL bLoadMask) |
162 { | 162 { |
163 if (pStream == NULL) { | 163 if (pStream == NULL) { |
164 return FALSE; | 164 return FALSE; |
165 } | 165 } |
166 m_pDocument = pDoc; | 166 m_pDocument = pDoc; |
167 m_pDict = pStream->GetDict(); | 167 m_pDict = pStream->GetDict(); |
| 168 if (m_pDict == NULL) { |
| 169 return FALSE; |
| 170 } |
168 m_pStream = pStream; | 171 m_pStream = pStream; |
169 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); | 172 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); |
170 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); | 173 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); |
171 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { | 174 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { |
172 return FALSE; | 175 return FALSE; |
173 } | 176 } |
174 m_GroupFamily = GroupFamily; | 177 m_GroupFamily = GroupFamily; |
175 m_bLoadMask = bLoadMask; | 178 m_bLoadMask = bLoadMask; |
176 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { | 179 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { |
177 return FALSE; | 180 return FALSE; |
178 } | 181 } |
179 | |
180 if (m_bpc == 0 || m_nComponents == 0) { | 182 if (m_bpc == 0 || m_nComponents == 0) { |
181 return FALSE; | 183 return FALSE; |
182 } | 184 } |
183 | |
184 FX_SAFE_DWORD src_pitch = m_bpc; | 185 FX_SAFE_DWORD src_pitch = m_bpc; |
185 src_pitch *= m_nComponents; | 186 src_pitch *= m_nComponents; |
186 src_pitch *= m_Width; | 187 src_pitch *= m_Width; |
187 src_pitch += 7; | 188 src_pitch += 7; |
188 src_pitch /= 8; | 189 src_pitch /= 8; |
189 src_pitch *= m_Height; | 190 src_pitch *= m_Height; |
190 if (!src_pitch.IsValid()) { | 191 if (!src_pitch.IsValid()) { |
191 return FALSE; | 192 return FALSE; |
192 } | 193 } |
193 | |
194 m_pStreamAcc = FX_NEW CPDF_StreamAcc; | 194 m_pStreamAcc = FX_NEW CPDF_StreamAcc; |
195 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); | 195 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); |
196 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { | 196 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { |
197 return FALSE; | 197 return FALSE; |
198 } | 198 } |
199 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 199 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
200 if (!decoder.IsEmpty() && decoder == FX_BSTRC("CCITTFaxDecode")) { | 200 if (!decoder.IsEmpty() && decoder == FX_BSTRC("CCITTFaxDecode")) { |
201 m_bpc = 1; | 201 m_bpc = 1; |
202 } | 202 } |
203 if (!CreateDecoder()) { | 203 if (!CreateDecoder()) { |
204 return FALSE; | 204 return FALSE; |
205 } | 205 } |
206 if (m_bImageMask) { | 206 if (m_bImageMask) { |
207 m_bpp = 1; | 207 m_bpp = 1; |
208 m_bpc = 1; | 208 m_bpc = 1; |
209 m_nComponents = 1; | 209 m_nComponents = 1; |
210 m_AlphaFlag = 1; | 210 m_AlphaFlag = 1; |
211 } else if (m_bpc * m_nComponents == 1) { | 211 } else if (m_bpc * m_nComponents == 1) { |
212 m_bpp = 1; | 212 m_bpp = 1; |
213 } else if (m_bpc * m_nComponents <= 8) { | 213 } else if (m_bpc * m_nComponents <= 8) { |
214 m_bpp = 8; | 214 m_bpp = 8; |
215 } else { | 215 } else { |
216 m_bpp = 24; | 216 m_bpp = 24; |
217 } | 217 } |
218 | |
219 FX_SAFE_DWORD pitch = m_Width; | 218 FX_SAFE_DWORD pitch = m_Width; |
220 pitch *= m_bpp; | 219 pitch *= m_bpp; |
221 pitch += 31; | 220 pitch += 31; |
222 pitch /= 8; | 221 pitch /= 8; |
223 if (!pitch.IsValid()) { | 222 if (!pitch.IsValid()) { |
224 return FALSE; | 223 return FALSE; |
225 } | 224 } |
226 | |
227 m_pLineBuf = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); | 225 m_pLineBuf = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); |
228 if (m_pColorSpace && bStdCS) { | 226 if (m_pColorSpace && bStdCS) { |
229 m_pColorSpace->EnableStdConversion(TRUE); | 227 m_pColorSpace->EnableStdConversion(TRUE); |
230 } | 228 } |
231 LoadPalette(); | 229 LoadPalette(); |
232 if (m_bColorKey) { | 230 if (m_bColorKey) { |
233 m_bpp = 32; | 231 m_bpp = 32; |
234 m_AlphaFlag = 2; | 232 m_AlphaFlag = 2; |
235 pitch = m_Width; | 233 pitch = m_Width; |
236 pitch *= m_bpp; | 234 pitch *= m_bpp; |
237 pitch += 31; | 235 pitch += 31; |
238 pitch /= 8; | 236 pitch /= 8; |
239 if (!pitch.IsValid()) { | 237 if (!pitch.IsValid()) { |
240 return FALSE; | 238 return FALSE; |
241 } | 239 } |
242 | |
243 m_pMaskedLine = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); | 240 m_pMaskedLine = FX_Alloc(FX_BYTE, pitch.ValueOrDie()); |
244 } | 241 } |
245 m_Pitch = pitch.ValueOrDie(); | 242 m_Pitch = pitch.ValueOrDie(); |
246 if (ppMask) { | 243 if (ppMask) { |
247 *ppMask = LoadMask(*pMatteColor); | 244 *ppMask = LoadMask(*pMatteColor); |
248 } | 245 } |
249 if (m_pColorSpace && bStdCS) { | 246 if (m_pColorSpace && bStdCS) { |
250 m_pColorSpace->EnableStdConversion(FALSE); | 247 m_pColorSpace->EnableStdConversion(FALSE); |
251 } | 248 } |
252 return TRUE; | 249 return TRUE; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); | 307 m_Width = m_pDict->GetInteger(FX_BSTRC("Width")); |
311 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); | 308 m_Height = m_pDict->GetInteger(FX_BSTRC("Height")); |
312 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { | 309 if (m_Width <= 0 || m_Height <= 0 || m_Width > 0x01ffff || m_Height > 0x01ff
ff) { |
313 return 0; | 310 return 0; |
314 } | 311 } |
315 m_GroupFamily = GroupFamily; | 312 m_GroupFamily = GroupFamily; |
316 m_bLoadMask = bLoadMask; | 313 m_bLoadMask = bLoadMask; |
317 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { | 314 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, pPag
eResources)) { |
318 return 0; | 315 return 0; |
319 } | 316 } |
320 | |
321 if (m_bpc == 0 || m_nComponents == 0) { | 317 if (m_bpc == 0 || m_nComponents == 0) { |
322 return 0; | 318 return 0; |
323 } | 319 } |
324 | |
325 FX_SAFE_DWORD src_pitch = m_bpc; | 320 FX_SAFE_DWORD src_pitch = m_bpc; |
326 src_pitch *= m_nComponents; | 321 src_pitch *= m_nComponents; |
327 src_pitch *= m_Width; | 322 src_pitch *= m_Width; |
328 src_pitch += 7; | 323 src_pitch += 7; |
329 src_pitch /= 8; | 324 src_pitch /= 8; |
330 src_pitch *= m_Height; | 325 src_pitch *= m_Height; |
331 if (!src_pitch.IsValid()) { | 326 if (!src_pitch.IsValid()) { |
332 return 0; | 327 return 0; |
333 } | 328 } |
334 | |
335 m_pStreamAcc = FX_NEW CPDF_StreamAcc; | 329 m_pStreamAcc = FX_NEW CPDF_StreamAcc; |
336 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); | 330 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); |
337 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { | 331 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { |
338 return 0; | 332 return 0; |
339 } | 333 } |
340 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); | 334 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); |
341 if (!decoder.IsEmpty() && decoder == FX_BSTRC("CCITTFaxDecode")) { | |
342 m_bpc = 1; | |
343 } | |
344 int ret = CreateDecoder(); | 335 int ret = CreateDecoder(); |
345 if (ret != 1) { | 336 if (ret != 1) { |
346 if (!ret) { | 337 if (!ret) { |
347 return ret; | 338 return ret; |
348 } | 339 } |
349 if (!ContinueToLoadMask()) { | 340 if (!ContinueToLoadMask()) { |
350 return 0; | 341 return 0; |
351 } | 342 } |
352 if (m_bHasMask) { | 343 if (m_bHasMask) { |
353 StratLoadMask(); | 344 StratLoadMask(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 } | 435 } |
445 return ret1; | 436 return ret1; |
446 } else if (m_Status == 2) { | 437 } else if (m_Status == 2) { |
447 return ContinueLoadMaskDIB(pPause); | 438 return ContinueLoadMaskDIB(pPause); |
448 } | 439 } |
449 return 0; | 440 return 0; |
450 } | 441 } |
451 FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, CPDF_Dict
ionary* pPageResources) | 442 FX_BOOL CPDF_DIBSource::LoadColorInfo(CPDF_Dictionary* pFormResources, CPDF_Dict
ionary* pPageResources) |
452 { | 443 { |
453 m_bpc_orig = m_pDict->GetInteger(FX_BSTRC("BitsPerComponent")); | 444 m_bpc_orig = m_pDict->GetInteger(FX_BSTRC("BitsPerComponent")); |
454 ValidateBpc(); | |
455 if (m_pDict->GetInteger("ImageMask")) { | 445 if (m_pDict->GetInteger("ImageMask")) { |
456 m_bImageMask = TRUE; | 446 m_bImageMask = TRUE; |
457 } | 447 } |
458 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { | 448 if (m_bImageMask || !m_pDict->KeyExist(FX_BSTRC("ColorSpace"))) { |
459 if (!m_bImageMask) { | 449 if (!m_bImageMask) { |
460 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); | 450 CPDF_Object* pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); |
461 if (pFilter) { | 451 if (pFilter) { |
462 CFX_ByteString filter; | 452 CFX_ByteString filter; |
463 if (pFilter->GetType() == PDFOBJ_NAME) { | 453 if (pFilter->GetType() == PDFOBJ_NAME) { |
464 filter = pFilter->GetString(); | 454 filter = pFilter->GetString(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 if (m_Family == PDFCS_ICCBASED && pCSObj->GetType() == PDFOBJ_NAME) { | 488 if (m_Family == PDFCS_ICCBASED && pCSObj->GetType() == PDFOBJ_NAME) { |
499 CFX_ByteString cs = pCSObj->GetString(); | 489 CFX_ByteString cs = pCSObj->GetString(); |
500 if (cs == FX_BSTRC("DeviceGray")) { | 490 if (cs == FX_BSTRC("DeviceGray")) { |
501 m_nComponents = 1; | 491 m_nComponents = 1; |
502 } else if (cs == FX_BSTRC("DeviceRGB")) { | 492 } else if (cs == FX_BSTRC("DeviceRGB")) { |
503 m_nComponents = 3; | 493 m_nComponents = 3; |
504 } else if (cs == FX_BSTRC("DeviceCMYK")) { | 494 } else if (cs == FX_BSTRC("DeviceCMYK")) { |
505 m_nComponents = 4; | 495 m_nComponents = 4; |
506 } | 496 } |
507 } | 497 } |
| 498 ValidateDictParam(); |
508 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); | 499 m_pCompData = FX_Alloc(DIB_COMP_DATA, m_nComponents); |
509 if (m_bpc == 0) { | 500 if (m_bpc == 0) { |
510 return TRUE; | 501 return TRUE; |
511 } | 502 } |
512 int max_data = (1 << m_bpc) - 1; | 503 int max_data = (1 << m_bpc) - 1; |
513 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); | 504 CPDF_Array* pDecode = m_pDict->GetArray(FX_BSTRC("Decode")); |
514 if (pDecode) { | 505 if (pDecode) { |
515 for (FX_DWORD i = 0; i < m_nComponents; i ++) { | 506 for (FX_DWORD i = 0; i < m_nComponents; i ++) { |
516 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); | 507 m_pCompData[i].m_DecodeMin = pDecode->GetNumber(i * 2); |
517 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); | 508 FX_FLOAT max = pDecode->GetNumber(i * 2 + 1); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 } | 899 } |
909 m_pColorSpace->GetRGB(temp_buf, R, G, B); | 900 m_pColorSpace->GetRGB(temp_buf, R, G, B); |
910 FX_Free(temp_buf); | 901 FX_Free(temp_buf); |
911 } else { | 902 } else { |
912 m_pColorSpace->GetRGB(color_value, R, G, B); | 903 m_pColorSpace->GetRGB(color_value, R, G, B); |
913 } | 904 } |
914 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round(
G * 255), FXSYS_round(B * 255))); | 905 SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round(
G * 255), FXSYS_round(B * 255))); |
915 } | 906 } |
916 } | 907 } |
917 } | 908 } |
918 void CPDF_DIBSource::ValidateBpc() | 909 void CPDF_DIBSource::ValidateDictParam() |
919 { | 910 { |
920 m_bpc = m_bpc_orig; | 911 m_bpc = m_bpc_orig; |
921 » CPDF_Object * pFilter = m_pDict ? m_pDict->GetElementValue(FX_BSTRC("Fil
ter")) : NULL; | 912 » CPDF_Object * pFilter = m_pDict->GetElementValue(FX_BSTRC("Filter")); |
922 if (pFilter) { | 913 if (pFilter) { |
923 if (pFilter->GetType() == PDFOBJ_NAME) { | 914 if (pFilter->GetType() == PDFOBJ_NAME) { |
924 CFX_ByteString filter = pFilter->GetString(); | 915 CFX_ByteString filter = pFilter->GetString(); |
925 if (filter == FX_BSTRC("CCITTFaxDecode") || filter == FX_BSTRC("JBIG
2Decode")) { | 916 if (filter == FX_BSTRC("CCITTFaxDecode") || filter == FX_BSTRC("JBIG
2Decode")) { |
926 m_bpc = 1; | 917 m_bpc = 1; |
| 918 m_nComponents = 1; |
927 } | 919 } |
928 if (filter == FX_BSTRC("RunLengthDecode") || filter == FX_BSTRC("DCT
Decode")) { | 920 if (filter == FX_BSTRC("RunLengthDecode") || filter == FX_BSTRC("DCT
Decode")) { |
929 m_bpc = 8; | 921 m_bpc = 8; |
930 } | 922 } |
931 } else if (pFilter->GetType() == PDFOBJ_ARRAY) { | 923 } else if (pFilter->GetType() == PDFOBJ_ARRAY) { |
932 CPDF_Array *pArray = (CPDF_Array *)pFilter; | 924 CPDF_Array *pArray = (CPDF_Array *)pFilter; |
933 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("CCITTFacD
ecode") || | 925 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("CCITTFacD
ecode") || |
934 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("JBIG2
Decode")) { | 926 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("JBIG2
Decode")) { |
935 m_bpc = 1; | 927 m_bpc = 1; |
| 928 m_nComponents = 1; |
936 } | 929 } |
937 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("RunLength
Decode") || | 930 if (pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("RunLength
Decode") || |
938 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("DCTDe
code")) { | 931 pArray->GetString(pArray->GetCount() - 1) == FX_BSTRC("DCTDe
code")) { |
939 m_bpc = 8; | 932 m_bpc = 8; |
940 } | 933 } |
941 } | 934 } |
942 } | 935 } |
943 if (m_bpc != 1 && m_bpc != 2 && m_bpc != 4 && m_bpc != 8 && m_bpc != 16) { | 936 if (m_bpc != 1 && m_bpc != 2 && m_bpc != 4 && m_bpc != 8 && m_bpc != 16) { |
944 m_bpc = 0; | 937 m_bpc = 0; |
945 } | 938 } |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1552 if (!m_bCached) { | 1545 if (!m_bCached) { |
1553 if (m_pBitmap) { | 1546 if (m_pBitmap) { |
1554 delete m_pBitmap; | 1547 delete m_pBitmap; |
1555 m_pBitmap = NULL; | 1548 m_pBitmap = NULL; |
1556 } | 1549 } |
1557 if (m_pMask) { | 1550 if (m_pMask) { |
1558 delete m_pMask; | 1551 delete m_pMask; |
1559 } | 1552 } |
1560 } | 1553 } |
1561 } | 1554 } |
OLD | NEW |