| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 m_Height = pDict->GetIntegerBy("Height"); | 72 m_Height = pDict->GetIntegerBy("Height"); |
| 73 m_Width = pDict->GetIntegerBy("Width"); | 73 m_Width = pDict->GetIntegerBy("Width"); |
| 74 return TRUE; | 74 return TRUE; |
| 75 } | 75 } |
| 76 | 76 |
| 77 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { | 77 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) { |
| 78 int32_t width; | 78 int32_t width; |
| 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 FX_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 NULL; | 85 return nullptr; |
| 86 } | 86 } |
| 87 |
| 87 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 88 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
| 88 pDict->SetAtName("Type", "XObject"); | 89 pDict->SetAtName("Type", "XObject"); |
| 89 pDict->SetAtName("Subtype", "Image"); | 90 pDict->SetAtName("Subtype", "Image"); |
| 90 pDict->SetAtInteger("Width", width); | 91 pDict->SetAtInteger("Width", width); |
| 91 pDict->SetAtInteger("Height", height); | 92 pDict->SetAtInteger("Height", height); |
| 92 const FX_CHAR* csname = NULL; | 93 const FX_CHAR* csname = nullptr; |
| 93 if (num_comps == 1) { | 94 if (num_comps == 1) { |
| 94 csname = "DeviceGray"; | 95 csname = "DeviceGray"; |
| 95 } else if (num_comps == 3) { | 96 } else if (num_comps == 3) { |
| 96 csname = "DeviceRGB"; | 97 csname = "DeviceRGB"; |
| 97 } else if (num_comps == 4) { | 98 } else if (num_comps == 4) { |
| 98 csname = "DeviceCMYK"; | 99 csname = "DeviceCMYK"; |
| 99 CPDF_Array* pDecode = new CPDF_Array; | 100 CPDF_Array* pDecode = new CPDF_Array; |
| 100 for (int n = 0; n < 4; n++) { | 101 for (int n = 0; n < 4; n++) { |
| 101 pDecode->AddInteger(1); | 102 pDecode->AddInteger(1); |
| 102 pDecode->AddInteger(0); | 103 pDecode->AddInteger(0); |
| 103 } | 104 } |
| 104 pDict->SetAt("Decode", pDecode); | 105 pDict->SetAt("Decode", pDecode); |
| 105 } | 106 } |
| 106 pDict->SetAtName("ColorSpace", csname); | 107 pDict->SetAtName("ColorSpace", csname); |
| 107 pDict->SetAtInteger("BitsPerComponent", bits); | 108 pDict->SetAtInteger("BitsPerComponent", bits); |
| 108 pDict->SetAtName("Filter", "DCTDecode"); | 109 pDict->SetAtName("Filter", "DCTDecode"); |
| 109 if (!color_trans) { | 110 if (!color_trans) { |
| 110 CPDF_Dictionary* pParms = new CPDF_Dictionary; | 111 CPDF_Dictionary* pParms = new CPDF_Dictionary; |
| 111 pDict->SetAt("DecodeParms", pParms); | 112 pDict->SetAt("DecodeParms", pParms); |
| 112 pParms->SetAtInteger("ColorTransform", 0); | 113 pParms->SetAtInteger("ColorTransform", 0); |
| 113 } | 114 } |
| 114 m_bIsMask = FALSE; | 115 m_bIsMask = FALSE; |
| 115 m_Width = width; | 116 m_Width = width; |
| 116 m_Height = height; | 117 m_Height = height; |
| 117 if (!m_pStream) { | 118 if (!m_pStream) |
| 118 m_pStream = new CPDF_Stream(NULL, 0, NULL); | 119 m_pStream = new CPDF_Stream(nullptr, 0, nullptr); |
| 119 } | |
| 120 return pDict; | 120 return pDict; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void CPDF_Image::SetJpegImage(uint8_t* pData, uint32_t size) { | 123 void CPDF_Image::SetJpegImage(uint8_t* pData, uint32_t size) { |
| 124 CPDF_Dictionary* pDict = InitJPEG(pData, size); | 124 CPDF_Dictionary* pDict = InitJPEG(pData, size); |
| 125 if (!pDict) { | 125 if (!pDict) { |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 m_pStream->InitStream(pData, size, pDict); | 128 m_pStream->InitStream(pData, size, pDict); |
| 129 } | 129 } |
| (...skipping 283 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 |