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/fpdfapi/fpdf_module.h" | 7 #include "../../../include/fpdfapi/fpdf_module.h" |
8 #include "../../../include/fpdfapi/fpdf_page.h" | 8 #include "../../../include/fpdfapi/fpdf_page.h" |
9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
10 #include "../../../include/fpdfapi/fpdf_render.h" | 10 #include "../../../include/fpdfapi/fpdf_render.h" |
11 #include "../fpdf_page/pageint.h" | 11 #include "../fpdf_page/pageint.h" |
12 #include "../fpdf_render/render_int.h" | 12 #include "../fpdf_render/render_int.h" |
13 CPDF_Dictionary* CPDF_Image::InitJPEG(FX_LPBYTE pData, FX_DWORD size) | 13 CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, FX_DWORD size) |
14 { | 14 { |
15 int32_t width, height, color_trans, num_comps, bits; | 15 int32_t width, height, color_trans, num_comps, bits; |
16 if (!CPDF_ModuleMgr::Get()->GetJpegModule()-> | 16 if (!CPDF_ModuleMgr::Get()->GetJpegModule()-> |
17 LoadInfo(pData, size, width, height, num_comps, bits, color_trans))
{ | 17 LoadInfo(pData, size, width, height, num_comps, bits, color_trans))
{ |
18 return NULL; | 18 return NULL; |
19 } | 19 } |
20 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 20 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
21 pDict->SetAtName("Type", "XObject"); | 21 pDict->SetAtName("Type", "XObject"); |
22 pDict->SetAtName("Subtype", "Image"); | 22 pDict->SetAtName("Subtype", "Image"); |
23 pDict->SetAtInteger("Width", width); | 23 pDict->SetAtInteger("Width", width); |
24 pDict->SetAtInteger("Height", height); | 24 pDict->SetAtInteger("Height", height); |
25 FX_LPCSTR csname = NULL; | 25 const FX_CHAR* csname = NULL; |
26 if (num_comps == 1) { | 26 if (num_comps == 1) { |
27 csname = "DeviceGray"; | 27 csname = "DeviceGray"; |
28 } else if (num_comps == 3) { | 28 } else if (num_comps == 3) { |
29 csname = "DeviceRGB"; | 29 csname = "DeviceRGB"; |
30 } else if (num_comps == 4) { | 30 } else if (num_comps == 4) { |
31 csname = "DeviceCMYK"; | 31 csname = "DeviceCMYK"; |
32 CPDF_Array* pDecode = CPDF_Array::Create(); | 32 CPDF_Array* pDecode = CPDF_Array::Create(); |
33 for (int n = 0; n < 4; n ++) { | 33 for (int n = 0; n < 4; n ++) { |
34 pDecode->AddInteger(1); | 34 pDecode->AddInteger(1); |
35 pDecode->AddInteger(0); | 35 pDecode->AddInteger(0); |
36 } | 36 } |
37 pDict->SetAt(FX_BSTRC("Decode"), pDecode); | 37 pDict->SetAt(FX_BSTRC("Decode"), pDecode); |
38 } | 38 } |
39 pDict->SetAtName("ColorSpace", csname); | 39 pDict->SetAtName("ColorSpace", csname); |
40 pDict->SetAtInteger("BitsPerComponent", bits); | 40 pDict->SetAtInteger("BitsPerComponent", bits); |
41 pDict->SetAtName("Filter", "DCTDecode"); | 41 pDict->SetAtName("Filter", "DCTDecode"); |
42 if (!color_trans) { | 42 if (!color_trans) { |
43 CPDF_Dictionary* pParms = new CPDF_Dictionary; | 43 CPDF_Dictionary* pParms = new CPDF_Dictionary; |
44 pDict->SetAt("DecodeParms", pParms); | 44 pDict->SetAt("DecodeParms", pParms); |
45 pParms->SetAtInteger("ColorTransform", 0); | 45 pParms->SetAtInteger("ColorTransform", 0); |
46 } | 46 } |
47 m_bIsMask = FALSE; | 47 m_bIsMask = FALSE; |
48 m_Width = width; | 48 m_Width = width; |
49 m_Height = height; | 49 m_Height = height; |
50 if (m_pStream == NULL) { | 50 if (m_pStream == NULL) { |
51 m_pStream = new CPDF_Stream(NULL, 0, NULL); | 51 m_pStream = new CPDF_Stream(NULL, 0, NULL); |
52 } | 52 } |
53 return pDict; | 53 return pDict; |
54 } | 54 } |
55 void CPDF_Image::SetJpegImage(FX_LPBYTE pData, FX_DWORD size) | 55 void CPDF_Image::SetJpegImage(uint8_t* pData, FX_DWORD size) |
56 { | 56 { |
57 CPDF_Dictionary *pDict = InitJPEG(pData, size); | 57 CPDF_Dictionary *pDict = InitJPEG(pData, size); |
58 if (!pDict) { | 58 if (!pDict) { |
59 return; | 59 return; |
60 } | 60 } |
61 m_pStream->InitStream(pData, size, pDict); | 61 m_pStream->InitStream(pData, size, pDict); |
62 } | 62 } |
63 void CPDF_Image::SetJpegImage(IFX_FileRead *pFile) | 63 void CPDF_Image::SetJpegImage(IFX_FileRead *pFile) |
64 { | 64 { |
65 FX_DWORD size = (FX_DWORD)pFile->GetSize(); | 65 FX_DWORD size = (FX_DWORD)pFile->GetSize(); |
66 if (!size) { | 66 if (!size) { |
67 return; | 67 return; |
68 } | 68 } |
69 FX_DWORD dwEstimateSize = size; | 69 FX_DWORD dwEstimateSize = size; |
70 if (dwEstimateSize > 8192) { | 70 if (dwEstimateSize > 8192) { |
71 dwEstimateSize = 8192; | 71 dwEstimateSize = 8192; |
72 } | 72 } |
73 FX_LPBYTE pData = FX_Alloc(uint8_t, dwEstimateSize); | 73 uint8_t* pData = FX_Alloc(uint8_t, dwEstimateSize); |
74 pFile->ReadBlock(pData, 0, dwEstimateSize); | 74 pFile->ReadBlock(pData, 0, dwEstimateSize); |
75 CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize); | 75 CPDF_Dictionary *pDict = InitJPEG(pData, dwEstimateSize); |
76 FX_Free(pData); | 76 FX_Free(pData); |
77 if (!pDict && size > dwEstimateSize) { | 77 if (!pDict && size > dwEstimateSize) { |
78 pData = FX_Alloc(uint8_t, size); | 78 pData = FX_Alloc(uint8_t, size); |
79 pFile->ReadBlock(pData, 0, size); | 79 pFile->ReadBlock(pData, 0, size); |
80 pDict = InitJPEG(pData, size); | 80 pDict = InitJPEG(pData, size); |
81 FX_Free(pData); | 81 FX_Free(pData); |
82 } | 82 } |
83 if (!pDict) { | 83 if (!pDict) { |
84 return; | 84 return; |
85 } | 85 } |
86 m_pStream->InitStream(pFile, pDict); | 86 m_pStream->InitStream(pFile, pDict); |
87 } | 87 } |
88 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap,
int quality, FX_LPBYTE &buf, FX_STRSIZE &size) | 88 void _DCTEncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap* pBitmap,
int quality, uint8_t* &buf, FX_STRSIZE &size) |
89 { | 89 { |
90 } | 90 } |
91 void _JBIG2EncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap *pBitma
p, CPDF_Document *pDoc, FX_LPBYTE &buf, FX_STRSIZE &size, FX_BOOL bLossLess) | 91 void _JBIG2EncodeBitmap(CPDF_Dictionary *pBitmapDict, const CFX_DIBitmap *pBitma
p, CPDF_Document *pDoc, uint8_t* &buf, FX_STRSIZE &size, FX_BOOL bLossLess) |
92 { | 92 { |
93 } | 93 } |
94 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress, IFX_Fi
leWrite *pFileWrite, IFX_FileRead *pFileRead, const CFX_DIBitmap* pMask, const C
PDF_ImageSetParam* pParam) | 94 void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress, IFX_Fi
leWrite *pFileWrite, IFX_FileRead *pFileRead, const CFX_DIBitmap* pMask, const C
PDF_ImageSetParam* pParam) |
95 { | 95 { |
96 int32_t BitmapWidth = pBitmap->GetWidth(); | 96 int32_t BitmapWidth = pBitmap->GetWidth(); |
97 int32_t BitmapHeight = pBitmap->GetHeight(); | 97 int32_t BitmapHeight = pBitmap->GetHeight(); |
98 if (BitmapWidth < 1 || BitmapHeight < 1) { | 98 if (BitmapWidth < 1 || BitmapHeight < 1) { |
99 return; | 99 return; |
100 } | 100 } |
101 FX_LPBYTE src_buf = pBitmap->GetBuffer(); | 101 uint8_t* src_buf = pBitmap->GetBuffer(); |
102 int32_t src_pitch = pBitmap->GetPitch(); | 102 int32_t src_pitch = pBitmap->GetPitch(); |
103 int32_t bpp = pBitmap->GetBPP(); | 103 int32_t bpp = pBitmap->GetBPP(); |
104 FX_BOOL bUseMatte = pParam && pParam->pMatteColor && (pBitmap->GetFormat() =
= FXDIB_Argb); | 104 FX_BOOL bUseMatte = pParam && pParam->pMatteColor && (pBitmap->GetFormat() =
= FXDIB_Argb); |
105 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 105 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
106 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); | 106 pDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); |
107 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); | 107 pDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); |
108 pDict->SetAtInteger(FX_BSTRC("Width"), BitmapWidth); | 108 pDict->SetAtInteger(FX_BSTRC("Width"), BitmapWidth); |
109 pDict->SetAtInteger(FX_BSTRC("Height"), BitmapHeight); | 109 pDict->SetAtInteger(FX_BSTRC("Height"), BitmapHeight); |
110 FX_LPBYTE dest_buf = NULL; | 110 uint8_t* dest_buf = NULL; |
111 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; | 111 FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1; |
112 if (bpp == 1) { | 112 if (bpp == 1) { |
113 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; | 113 int32_t reset_a = 0, reset_r = 0, reset_g = 0, reset_b = 0; |
114 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; | 114 int32_t set_a = 0, set_r = 0, set_g = 0, set_b = 0; |
115 if (!pBitmap->IsAlphaMask()) { | 115 if (!pBitmap->IsAlphaMask()) { |
116 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, re
set_b); | 116 ArgbDecode(pBitmap->GetPaletteArgb(0), reset_a, reset_r, reset_g, re
set_b); |
117 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); | 117 ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b); |
118 } | 118 } |
119 if (set_a == 0 || reset_a == 0) { | 119 if (set_a == 0 || reset_a == 0) { |
120 pDict->SetAt(FX_BSTRC("ImageMask"), new CPDF_Boolean(TRUE)); | 120 pDict->SetAt(FX_BSTRC("ImageMask"), new CPDF_Boolean(TRUE)); |
121 if (reset_a == 0) { | 121 if (reset_a == 0) { |
122 CPDF_Array* pArray = new CPDF_Array; | 122 CPDF_Array* pArray = new CPDF_Array; |
123 pArray->AddInteger(1); | 123 pArray->AddInteger(1); |
124 pArray->AddInteger(0); | 124 pArray->AddInteger(0); |
125 pDict->SetAt(FX_BSTRC("Decode"), pArray); | 125 pDict->SetAt(FX_BSTRC("Decode"), pArray); |
126 } | 126 } |
127 } else { | 127 } else { |
128 CPDF_Array* pCS = new CPDF_Array; | 128 CPDF_Array* pCS = new CPDF_Array; |
129 pCS->AddName(FX_BSTRC("Indexed")); | 129 pCS->AddName(FX_BSTRC("Indexed")); |
130 pCS->AddName(FX_BSTRC("DeviceRGB")); | 130 pCS->AddName(FX_BSTRC("DeviceRGB")); |
131 pCS->AddInteger(1); | 131 pCS->AddInteger(1); |
132 CFX_ByteString ct; | 132 CFX_ByteString ct; |
133 FX_LPSTR pBuf = ct.GetBuffer(6); | 133 FX_CHAR* pBuf = ct.GetBuffer(6); |
134 pBuf[0] = (FX_CHAR)reset_r; | 134 pBuf[0] = (FX_CHAR)reset_r; |
135 pBuf[1] = (FX_CHAR)reset_g; | 135 pBuf[1] = (FX_CHAR)reset_g; |
136 pBuf[2] = (FX_CHAR)reset_b; | 136 pBuf[2] = (FX_CHAR)reset_b; |
137 pBuf[3] = (FX_CHAR)set_r; | 137 pBuf[3] = (FX_CHAR)set_r; |
138 pBuf[4] = (FX_CHAR)set_g; | 138 pBuf[4] = (FX_CHAR)set_g; |
139 pBuf[5] = (FX_CHAR)set_b; | 139 pBuf[5] = (FX_CHAR)set_b; |
140 ct.ReleaseBuffer(6); | 140 ct.ReleaseBuffer(6); |
141 pCS->Add(CPDF_String::Create(ct, TRUE)); | 141 pCS->Add(CPDF_String::Create(ct, TRUE)); |
142 pDict->SetAt(FX_BSTRC("ColorSpace"), pCS); | 142 pDict->SetAt(FX_BSTRC("ColorSpace"), pCS); |
143 } | 143 } |
144 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 1); | 144 pDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 1); |
145 dest_pitch = (BitmapWidth + 7) / 8; | 145 dest_pitch = (BitmapWidth + 7) / 8; |
146 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { | 146 if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) { |
147 opType = 1; | 147 opType = 1; |
148 } else { | 148 } else { |
149 opType = 0; | 149 opType = 0; |
150 } | 150 } |
151 } else if (bpp == 8) { | 151 } else if (bpp == 8) { |
152 int32_t iPalette = pBitmap->GetPaletteSize(); | 152 int32_t iPalette = pBitmap->GetPaletteSize(); |
153 if (iPalette > 0) { | 153 if (iPalette > 0) { |
154 CPDF_Array* pCS = new CPDF_Array; | 154 CPDF_Array* pCS = new CPDF_Array; |
155 m_pDocument->AddIndirectObject(pCS); | 155 m_pDocument->AddIndirectObject(pCS); |
156 pCS->AddName(FX_BSTRC("Indexed")); | 156 pCS->AddName(FX_BSTRC("Indexed")); |
157 pCS->AddName(FX_BSTRC("DeviceRGB")); | 157 pCS->AddName(FX_BSTRC("DeviceRGB")); |
158 pCS->AddInteger(iPalette - 1); | 158 pCS->AddInteger(iPalette - 1); |
159 FX_LPBYTE pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); | 159 uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3); |
160 FX_LPBYTE ptr = pColorTable; | 160 uint8_t* ptr = pColorTable; |
161 for (int32_t i = 0; i < iPalette; i ++) { | 161 for (int32_t i = 0; i < iPalette; i ++) { |
162 FX_DWORD argb = pBitmap->GetPaletteArgb(i); | 162 FX_DWORD argb = pBitmap->GetPaletteArgb(i); |
163 ptr[0] = (uint8_t)(argb >> 16); | 163 ptr[0] = (uint8_t)(argb >> 16); |
164 ptr[1] = (uint8_t)(argb >> 8); | 164 ptr[1] = (uint8_t)(argb >> 8); |
165 ptr[2] = (uint8_t)argb; | 165 ptr[2] = (uint8_t)argb; |
166 ptr += 3; | 166 ptr += 3; |
167 } | 167 } |
168 CPDF_Stream *pCTS = CPDF_Stream::Create(pColorTable, iPalette * 3, C
PDF_Dictionary::Create()); | 168 CPDF_Stream *pCTS = CPDF_Stream::Create(pColorTable, iPalette * 3, C
PDF_Dictionary::Create()); |
169 m_pDocument->AddIndirectObject(pCTS); | 169 m_pDocument->AddIndirectObject(pCTS); |
170 pCS->AddReference(m_pDocument, pCTS); | 170 pCS->AddReference(m_pDocument, pCTS); |
(...skipping 26 matching lines...) Expand all Loading... |
197 } | 197 } |
198 if (!pMaskBitmap && pMask) { | 198 if (!pMaskBitmap && pMask) { |
199 FXDIB_Format maskFormat = pMask->GetFormat(); | 199 FXDIB_Format maskFormat = pMask->GetFormat(); |
200 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) { | 200 if (maskFormat == FXDIB_1bppMask || maskFormat == FXDIB_8bppMask) { |
201 pMaskBitmap = pMask; | 201 pMaskBitmap = pMask; |
202 } | 202 } |
203 } | 203 } |
204 if (pMaskBitmap) { | 204 if (pMaskBitmap) { |
205 int32_t maskWidth = pMaskBitmap->GetWidth(); | 205 int32_t maskWidth = pMaskBitmap->GetWidth(); |
206 int32_t maskHeight = pMaskBitmap->GetHeight(); | 206 int32_t maskHeight = pMaskBitmap->GetHeight(); |
207 FX_LPBYTE mask_buf = NULL; | 207 uint8_t* mask_buf = NULL; |
208 FX_STRSIZE mask_size; | 208 FX_STRSIZE mask_size; |
209 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; | 209 CPDF_Dictionary* pMaskDict = new CPDF_Dictionary; |
210 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); | 210 pMaskDict->SetAtName(FX_BSTRC("Type"), FX_BSTRC("XObject")); |
211 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); | 211 pMaskDict->SetAtName(FX_BSTRC("Subtype"), FX_BSTRC("Image")); |
212 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); | 212 pMaskDict->SetAtInteger(FX_BSTRC("Width"), maskWidth); |
213 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); | 213 pMaskDict->SetAtInteger(FX_BSTRC("Height"), maskHeight); |
214 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); | 214 pMaskDict->SetAtName(FX_BSTRC("ColorSpace"), FX_BSTRC("DeviceGray")); |
215 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); | 215 pMaskDict->SetAtInteger(FX_BSTRC("BitsPerComponent"), 8); |
216 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP
RESS) != 0) { | 216 if (pMaskBitmap->GetBPP() == 8 && (iCompress & PDF_IMAGE_MASK_LOSSY_COMP
RESS) != 0) { |
217 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality :
75, mask_buf, mask_size); | 217 _DCTEncodeBitmap(pMaskDict, pMaskBitmap, pParam ? pParam->nQuality :
75, mask_buf, mask_size); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 FX_Free(dest_buf); | 263 FX_Free(dest_buf); |
264 dest_buf = NULL; | 264 dest_buf = NULL; |
265 } | 265 } |
266 dest_size = 0; | 266 dest_size = 0; |
267 delete pNewBitmap; | 267 delete pNewBitmap; |
268 return; | 268 return; |
269 } else { | 269 } else { |
270 if (bUseMatte) { | 270 if (bUseMatte) { |
271 CFX_DIBitmap *pNewBitmap = new CFX_DIBitmap(); | 271 CFX_DIBitmap *pNewBitmap = new CFX_DIBitmap(); |
272 pNewBitmap->Create(BitmapWidth, BitmapHeight, FXDIB_Argb); | 272 pNewBitmap->Create(BitmapWidth, BitmapHeight, FXDIB_Argb); |
273 FX_LPBYTE dst_buf = pNewBitmap->GetBuffer(); | 273 uint8_t* dst_buf = pNewBitmap->GetBuffer(); |
274 int32_t src_offset = 0; | 274 int32_t src_offset = 0; |
275 for (int32_t row = 0; row < BitmapHeight; row ++) { | 275 for (int32_t row = 0; row < BitmapHeight; row ++) { |
276 src_offset = row * src_pitch; | 276 src_offset = row * src_pitch; |
277 for (int32_t column = 0; column < BitmapWidth; column ++
) { | 277 for (int32_t column = 0; column < BitmapWidth; column ++
) { |
278 FX_FLOAT alpha = src_buf[src_offset + 3] / 255.0f; | 278 FX_FLOAT alpha = src_buf[src_offset + 3] / 255.0f; |
279 dst_buf[src_offset] = (uint8_t)(src_buf[src_offset]
* alpha); | 279 dst_buf[src_offset] = (uint8_t)(src_buf[src_offset]
* alpha); |
280 dst_buf[src_offset + 1] = (uint8_t)(src_buf[src_offs
et + 1] * alpha); | 280 dst_buf[src_offset + 1] = (uint8_t)(src_buf[src_offs
et + 1] * alpha); |
281 dst_buf[src_offset + 2] = (uint8_t)(src_buf[src_offs
et + 2] * alpha); | 281 dst_buf[src_offset + 2] = (uint8_t)(src_buf[src_offs
et + 2] * alpha); |
282 dst_buf[src_offset + 3] = (uint8_t)(src_buf[src_offs
et + 3]); | 282 dst_buf[src_offset + 3] = (uint8_t)(src_buf[src_offs
et + 3]); |
283 src_offset += 4; | 283 src_offset += 4; |
284 } | 284 } |
285 } | 285 } |
286 _DCTEncodeBitmap(pDict, pNewBitmap, pParam ? pParam->nQualit
y : 75, dest_buf, dest_size); | 286 _DCTEncodeBitmap(pDict, pNewBitmap, pParam ? pParam->nQualit
y : 75, dest_buf, dest_size); |
287 delete pNewBitmap; | 287 delete pNewBitmap; |
288 } else { | 288 } else { |
289 _DCTEncodeBitmap(pDict, pBitmap, pParam ? pParam->nQuality :
75, dest_buf, dest_size); | 289 _DCTEncodeBitmap(pDict, pBitmap, pParam ? pParam->nQuality :
75, dest_buf, dest_size); |
290 } | 290 } |
291 } | 291 } |
292 } | 292 } |
293 if (bStream) { | 293 if (bStream) { |
294 pFileWrite->WriteBlock(dest_buf, dest_size); | 294 pFileWrite->WriteBlock(dest_buf, dest_size); |
295 FX_Free(dest_buf); | 295 FX_Free(dest_buf); |
296 dest_buf = NULL; | 296 dest_buf = NULL; |
297 } | 297 } |
298 } else if (opType == 1) { | 298 } else if (opType == 1) { |
299 if (!bStream) { | 299 if (!bStream) { |
300 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); | 300 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); |
301 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc
returned. | 301 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc
returned. |
302 } | 302 } |
303 FX_LPBYTE pDest = dest_buf; | 303 uint8_t* pDest = dest_buf; |
304 for (int32_t i = 0; i < BitmapHeight; i ++) { | 304 for (int32_t i = 0; i < BitmapHeight; i ++) { |
305 if (!bStream) { | 305 if (!bStream) { |
306 FXSYS_memcpy32(pDest, src_buf, dest_pitch); | 306 FXSYS_memcpy32(pDest, src_buf, dest_pitch); |
307 pDest += dest_pitch; | 307 pDest += dest_pitch; |
308 } else { | 308 } else { |
309 pFileWrite->WriteBlock(src_buf, dest_pitch); | 309 pFileWrite->WriteBlock(src_buf, dest_pitch); |
310 } | 310 } |
311 src_buf += src_pitch; | 311 src_buf += src_pitch; |
312 } | 312 } |
313 } else if (opType == 2) { | 313 } else if (opType == 2) { |
314 if (!bStream) { | 314 if (!bStream) { |
315 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); | 315 dest_buf = FX_Alloc2D(uint8_t, dest_pitch, BitmapHeight); |
316 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc
returned. | 316 dest_size = dest_pitch * BitmapHeight; // Safe since checked alloc
returned. |
317 } else { | 317 } else { |
318 dest_buf = FX_Alloc(uint8_t, dest_pitch); | 318 dest_buf = FX_Alloc(uint8_t, dest_pitch); |
319 } | 319 } |
320 FX_LPBYTE pDest = dest_buf; | 320 uint8_t* pDest = dest_buf; |
321 int32_t src_offset = 0; | 321 int32_t src_offset = 0; |
322 int32_t dest_offset = 0; | 322 int32_t dest_offset = 0; |
323 for (int32_t row = 0; row < BitmapHeight; row ++) { | 323 for (int32_t row = 0; row < BitmapHeight; row ++) { |
324 src_offset = row * src_pitch; | 324 src_offset = row * src_pitch; |
325 for (int32_t column = 0; column < BitmapWidth; column ++) { | 325 for (int32_t column = 0; column < BitmapWidth; column ++) { |
326 FX_FLOAT alpha = bUseMatte ? src_buf[src_offset + 3] / 255.0f :
1; | 326 FX_FLOAT alpha = bUseMatte ? src_buf[src_offset + 3] / 255.0f :
1; |
327 pDest[dest_offset] = (uint8_t)(src_buf[src_offset + 2] * alpha); | 327 pDest[dest_offset] = (uint8_t)(src_buf[src_offset + 2] * alpha); |
328 pDest[dest_offset + 1] = (uint8_t)(src_buf[src_offset + 1] * alp
ha); | 328 pDest[dest_offset + 1] = (uint8_t)(src_buf[src_offset + 1] * alp
ha); |
329 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); | 329 pDest[dest_offset + 2] = (uint8_t)(src_buf[src_offset] * alpha); |
330 dest_offset += 3; | 330 dest_offset += 3; |
(...skipping 25 matching lines...) Expand all Loading... |
356 m_Width = BitmapWidth; | 356 m_Width = BitmapWidth; |
357 m_Height = BitmapHeight; | 357 m_Height = BitmapHeight; |
358 if (dest_buf) { | 358 if (dest_buf) { |
359 FX_Free(dest_buf); | 359 FX_Free(dest_buf); |
360 } | 360 } |
361 } | 361 } |
362 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) | 362 void CPDF_Image::ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pBitmap) |
363 { | 363 { |
364 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); | 364 pPage->GetRenderCache()->ResetBitmap(m_pStream, pBitmap); |
365 } | 365 } |
OLD | NEW |