Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1408)

Side by Side Diff: core/fxge/dib/fx_dib_main.cpp

Issue 2149903002: Use smart pointers for various Jbig2 decoding contexts (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/fxge/include/fx_dib.h" 7 #include "core/fxge/include/fx_dib.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
11 #include "core/fxcodec/include/fx_codec.h" 11 #include "core/fxcodec/include/fx_codec.h"
12 #include "core/fxge/dib/dib_int.h" 12 #include "core/fxge/dib/dib_int.h"
13 #include "core/fxge/include/fx_ge.h" 13 #include "core/fxge/include/fx_ge.h"
14 14
15 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { 15 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) {
16 c = FXSYS_GetCValue(cmyk); 16 c = FXSYS_GetCValue(cmyk);
17 m = FXSYS_GetMValue(cmyk); 17 m = FXSYS_GetMValue(cmyk);
18 y = FXSYS_GetYValue(cmyk); 18 y = FXSYS_GetYValue(cmyk);
19 k = FXSYS_GetKValue(cmyk); 19 k = FXSYS_GetKValue(cmyk);
20 } 20 }
21
21 void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) { 22 void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) {
22 a = FXARGB_A(argb); 23 a = FXARGB_A(argb);
23 r = FXARGB_R(argb); 24 r = FXARGB_R(argb);
24 g = FXARGB_G(argb); 25 g = FXARGB_G(argb);
25 b = FXARGB_B(argb); 26 b = FXARGB_B(argb);
26 } 27 }
28
27 void ArgbDecode(uint32_t argb, int& a, FX_COLORREF& rgb) { 29 void ArgbDecode(uint32_t argb, int& a, FX_COLORREF& rgb) {
28 a = FXARGB_A(argb); 30 a = FXARGB_A(argb);
29 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); 31 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb));
30 } 32 }
33
31 uint32_t ArgbEncode(int a, FX_COLORREF rgb) { 34 uint32_t ArgbEncode(int a, FX_COLORREF rgb) {
32 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb), 35 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb),
33 FXSYS_GetBValue(rgb)); 36 FXSYS_GetBValue(rgb));
34 } 37 }
35 38
36 CFX_DIBSource::CFX_DIBSource() { 39 CFX_DIBSource::CFX_DIBSource()
37 m_bpp = 0; 40 : m_pAlphaMask(nullptr),
38 m_AlphaFlag = 0; 41 m_Width(0),
39 m_Width = m_Height = 0; 42 m_Height(0),
40 m_Pitch = 0; 43 m_bpp(0),
41 m_pPalette = nullptr; 44 m_AlphaFlag(0),
42 m_pAlphaMask = nullptr; 45 m_Pitch(0) {}
43 }
44 46
45 CFX_DIBSource::~CFX_DIBSource() { 47 CFX_DIBSource::~CFX_DIBSource() {
46 FX_Free(m_pPalette);
47 delete m_pAlphaMask; 48 delete m_pAlphaMask;
48 } 49 }
49 50
50 uint8_t* CFX_DIBSource::GetBuffer() const { 51 uint8_t* CFX_DIBSource::GetBuffer() const {
51 return nullptr; 52 return nullptr;
52 } 53 }
53 54
54 FX_BOOL CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const { 55 FX_BOOL CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const {
55 return FALSE; 56 return FALSE;
56 } 57 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 144 }
144 145
145 const uint8_t* CFX_DIBitmap::GetScanline(int line) const { 146 const uint8_t* CFX_DIBitmap::GetScanline(int line) const {
146 return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr; 147 return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr;
147 } 148 }
148 149
149 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) { 150 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
150 if (!m_bExtBuf) 151 if (!m_bExtBuf)
151 FX_Free(m_pBuffer); 152 FX_Free(m_pBuffer);
152 153
153 FX_Free(m_pPalette);
154 delete m_pAlphaMask; 154 delete m_pAlphaMask;
155 m_pBuffer = pSrcBitmap->m_pBuffer; 155 m_pBuffer = pSrcBitmap->m_pBuffer;
156 m_pPalette = pSrcBitmap->m_pPalette; 156 m_pPalette = std::move(pSrcBitmap->m_pPalette);
157 m_pAlphaMask = pSrcBitmap->m_pAlphaMask; 157 m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
158 pSrcBitmap->m_pBuffer = nullptr; 158 pSrcBitmap->m_pBuffer = nullptr;
159 pSrcBitmap->m_pPalette = nullptr;
160 pSrcBitmap->m_pAlphaMask = nullptr; 159 pSrcBitmap->m_pAlphaMask = nullptr;
161 m_bpp = pSrcBitmap->m_bpp; 160 m_bpp = pSrcBitmap->m_bpp;
162 m_bExtBuf = pSrcBitmap->m_bExtBuf; 161 m_bExtBuf = pSrcBitmap->m_bExtBuf;
163 m_AlphaFlag = pSrcBitmap->m_AlphaFlag; 162 m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
164 m_Width = pSrcBitmap->m_Width; 163 m_Width = pSrcBitmap->m_Width;
165 m_Height = pSrcBitmap->m_Height; 164 m_Height = pSrcBitmap->m_Height;
166 m_Pitch = pSrcBitmap->m_Pitch; 165 m_Pitch = pSrcBitmap->m_Pitch;
167 } 166 }
168 167
169 CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const { 168 CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const {
170 FX_RECT rect(0, 0, m_Width, m_Height); 169 FX_RECT rect(0, 0, m_Width, m_Height);
171 if (pClip) { 170 if (pClip) {
172 rect.Intersect(*pClip); 171 rect.Intersect(*pClip);
173 if (rect.IsEmpty()) { 172 if (rect.IsEmpty()) {
174 return nullptr; 173 return nullptr;
175 } 174 }
176 } 175 }
177 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap; 176 std::unique_ptr<CFX_DIBitmap> pNewBitmap(new CFX_DIBitmap);
178 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) { 177 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
179 delete pNewBitmap;
180 return nullptr; 178 return nullptr;
181 } 179
182 pNewBitmap->CopyPalette(m_pPalette); 180 pNewBitmap->CopyPalette(m_pPalette.get());
183 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip); 181 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip);
184 if (GetBPP() == 1 && rect.left % 8 != 0) { 182 if (GetBPP() == 1 && rect.left % 8 != 0) {
185 int left_shift = rect.left % 32; 183 int left_shift = rect.left % 32;
186 int right_shift = 32 - left_shift; 184 int right_shift = 32 - left_shift;
187 int dword_count = pNewBitmap->m_Pitch / 4; 185 int dword_count = pNewBitmap->m_Pitch / 4;
188 for (int row = rect.top; row < rect.bottom; row++) { 186 for (int row = rect.top; row < rect.bottom; row++) {
189 uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32; 187 uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32;
190 uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top); 188 uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top);
191 for (int i = 0; i < dword_count; i++) { 189 for (int i = 0; i < dword_count; i++) {
192 dest_scan[i] = 190 dest_scan[i] =
193 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift); 191 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift);
194 } 192 }
195 } 193 }
196 } else { 194 } else {
197 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8; 195 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
198 if (m_Pitch < (uint32_t)copy_len) { 196 if (m_Pitch < (uint32_t)copy_len) {
199 copy_len = m_Pitch; 197 copy_len = m_Pitch;
200 } 198 }
201 for (int row = rect.top; row < rect.bottom; row++) { 199 for (int row = rect.top; row < rect.bottom; row++) {
202 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8; 200 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8;
203 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top); 201 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top);
204 FXSYS_memcpy(dest_scan, src_scan, copy_len); 202 FXSYS_memcpy(dest_scan, src_scan, copy_len);
205 } 203 }
206 } 204 }
207 return pNewBitmap; 205 return pNewBitmap.release();
208 } 206 }
207
209 void CFX_DIBSource::BuildPalette() { 208 void CFX_DIBSource::BuildPalette() {
210 if (m_pPalette) { 209 if (m_pPalette) {
211 return; 210 return;
212 } 211 }
213 if (GetBPP() == 1) { 212 if (GetBPP() == 1) {
214 m_pPalette = FX_Alloc(uint32_t, 2); 213 m_pPalette.reset(FX_Alloc(uint32_t, 2));
215 if (IsCmykImage()) { 214 if (IsCmykImage()) {
216 m_pPalette[0] = 0xff; 215 m_pPalette.get()[0] = 0xff;
217 m_pPalette[1] = 0; 216 m_pPalette.get()[1] = 0;
218 } else { 217 } else {
219 m_pPalette[0] = 0xff000000; 218 m_pPalette.get()[0] = 0xff000000;
220 m_pPalette[1] = 0xffffffff; 219 m_pPalette.get()[1] = 0xffffffff;
221 } 220 }
222 } else if (GetBPP() == 8) { 221 } else if (GetBPP() == 8) {
223 m_pPalette = FX_Alloc(uint32_t, 256); 222 m_pPalette.reset(FX_Alloc(uint32_t, 256));
224 if (IsCmykImage()) { 223 if (IsCmykImage()) {
225 for (int i = 0; i < 256; i++) { 224 for (int i = 0; i < 256; i++) {
226 m_pPalette[i] = 0xff - i; 225 m_pPalette.get()[i] = 0xff - i;
227 } 226 }
228 } else { 227 } else {
229 for (int i = 0; i < 256; i++) { 228 for (int i = 0; i < 256; i++) {
230 m_pPalette[i] = 0xff000000 | (i * 0x10101); 229 m_pPalette.get()[i] = 0xff000000 | (i * 0x10101);
231 } 230 }
232 } 231 }
233 } 232 }
234 } 233 }
234
235 FX_BOOL CFX_DIBSource::BuildAlphaMask() { 235 FX_BOOL CFX_DIBSource::BuildAlphaMask() {
236 if (m_pAlphaMask) { 236 if (m_pAlphaMask) {
237 return TRUE; 237 return TRUE;
238 } 238 }
239 m_pAlphaMask = new CFX_DIBitmap; 239 m_pAlphaMask = new CFX_DIBitmap;
240 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 240 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
241 delete m_pAlphaMask; 241 delete m_pAlphaMask;
242 m_pAlphaMask = nullptr; 242 m_pAlphaMask = nullptr;
243 return FALSE; 243 return FALSE;
244 } 244 }
245 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff, 245 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff,
246 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch()); 246 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
247 return TRUE; 247 return TRUE;
248 } 248 }
249
249 uint32_t CFX_DIBSource::GetPaletteEntry(int index) const { 250 uint32_t CFX_DIBSource::GetPaletteEntry(int index) const {
250 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 251 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
251 if (m_pPalette) { 252 if (m_pPalette) {
252 return m_pPalette[index]; 253 return m_pPalette.get()[index];
253 } 254 }
254 if (IsCmykImage()) { 255 if (IsCmykImage()) {
255 if (GetBPP() == 1) { 256 if (GetBPP() == 1) {
256 return index ? 0 : 0xff; 257 return index ? 0 : 0xff;
257 } 258 }
258 return 0xff - index; 259 return 0xff - index;
259 } 260 }
260 if (GetBPP() == 1) { 261 if (GetBPP() == 1) {
261 return index ? 0xffffffff : 0xff000000; 262 return index ? 0xffffffff : 0xff000000;
262 } 263 }
263 return index * 0x10101 | 0xff000000; 264 return index * 0x10101 | 0xff000000;
264 } 265 }
266
265 void CFX_DIBSource::SetPaletteEntry(int index, uint32_t color) { 267 void CFX_DIBSource::SetPaletteEntry(int index, uint32_t color) {
266 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 268 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
267 if (!m_pPalette) { 269 if (!m_pPalette) {
268 BuildPalette(); 270 BuildPalette();
269 } 271 }
270 m_pPalette[index] = color; 272 m_pPalette.get()[index] = color;
271 } 273 }
274
272 int CFX_DIBSource::FindPalette(uint32_t color) const { 275 int CFX_DIBSource::FindPalette(uint32_t color) const {
273 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 276 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
274 if (!m_pPalette) { 277 if (!m_pPalette) {
275 if (IsCmykImage()) { 278 if (IsCmykImage()) {
276 if (GetBPP() == 1) { 279 if (GetBPP() == 1) {
277 return ((uint8_t)color == 0xff) ? 0 : 1; 280 return ((uint8_t)color == 0xff) ? 0 : 1;
278 } 281 }
279 return 0xff - (uint8_t)color; 282 return 0xff - (uint8_t)color;
280 } 283 }
281 if (GetBPP() == 1) { 284 if (GetBPP() == 1) {
282 return ((uint8_t)color == 0xff) ? 1 : 0; 285 return ((uint8_t)color == 0xff) ? 1 : 0;
283 } 286 }
284 return (uint8_t)color; 287 return (uint8_t)color;
285 } 288 }
286 int palsize = (1 << GetBPP()); 289 int palsize = (1 << GetBPP());
287 for (int i = 0; i < palsize; i++) 290 for (int i = 0; i < palsize; i++)
288 if (m_pPalette[i] == color) { 291 if (m_pPalette.get()[i] == color) {
289 return i; 292 return i;
290 } 293 }
291 return -1; 294 return -1;
292 } 295 }
296
293 void CFX_DIBitmap::Clear(uint32_t color) { 297 void CFX_DIBitmap::Clear(uint32_t color) {
294 if (!m_pBuffer) { 298 if (!m_pBuffer) {
295 return; 299 return;
296 } 300 }
297 switch (GetFormat()) { 301 switch (GetFormat()) {
298 case FXDIB_1bppMask: 302 case FXDIB_1bppMask:
299 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0, 303 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0,
300 m_Pitch * m_Height); 304 m_Pitch * m_Height);
301 break; 305 break;
302 case FXDIB_1bppRgb: { 306 case FXDIB_1bppRgb: {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 348 }
345 for (int row = 1; row < m_Height; row++) { 349 for (int row = 1; row < m_Height; row++) {
346 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch); 350 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch);
347 } 351 }
348 break; 352 break;
349 } 353 }
350 default: 354 default:
351 break; 355 break;
352 } 356 }
353 } 357 }
358
354 void CFX_DIBSource::GetOverlapRect(int& dest_left, 359 void CFX_DIBSource::GetOverlapRect(int& dest_left,
355 int& dest_top, 360 int& dest_top,
356 int& width, 361 int& width,
357 int& height, 362 int& height,
358 int src_width, 363 int src_width,
359 int src_height, 364 int src_height,
360 int& src_left, 365 int& src_left,
361 int& src_top, 366 int& src_top,
362 const CFX_ClipRgn* pClipRgn) { 367 const CFX_ClipRgn* pClipRgn) {
363 if (width == 0 || height == 0) { 368 if (width == 0 || height == 0) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 439 }
435 } else { 440 } else {
436 if (m_pPalette) 441 if (m_pPalette)
437 return FALSE; 442 return FALSE;
438 443
439 if (m_bpp == 8) 444 if (m_bpp == 8)
440 dest_format = FXDIB_8bppMask; 445 dest_format = FXDIB_8bppMask;
441 446
442 uint8_t* dest_buf = 447 uint8_t* dest_buf =
443 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8; 448 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8;
444 uint32_t* d_plt = nullptr; 449 std::unique_ptr<uint32_t, FxFreeDeleter> d_plt;
445 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, 450 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height,
446 pSrcBitmap, src_left, src_top, d_plt)) { 451 pSrcBitmap, src_left, src_top, &d_plt)) {
447 return FALSE; 452 return FALSE;
448 } 453 }
449 } 454 }
450 return TRUE; 455 return TRUE;
451 } 456 }
452 457
453 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, 458 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left,
454 int dest_top, 459 int dest_top,
455 int width, 460 int width,
456 int height, 461 int height,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 for (int col = 0; col < width; col++) { 557 for (int col = 0; col < width; col++) {
553 FXSYS_memcpy(dest_color_pos, color_p, comps); 558 FXSYS_memcpy(dest_color_pos, color_p, comps);
554 dest_color_pos += comps; 559 dest_color_pos += comps;
555 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255); 560 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255);
556 } 561 }
557 } 562 }
558 } 563 }
559 } 564 }
560 return TRUE; 565 return TRUE;
561 } 566 }
562 void CFX_DIBSource::CopyPalette(const uint32_t* pSrc, uint32_t size) { 567
568 void CFX_DIBSource::CopyPalette(const uint32_t* pSrc) {
569 static const uint32_t kPaletteSize = 256;
570
563 if (!pSrc || GetBPP() > 8) { 571 if (!pSrc || GetBPP() > 8) {
564 FX_Free(m_pPalette); 572 m_pPalette.reset();
565 m_pPalette = nullptr;
566 } else { 573 } else {
567 uint32_t pal_size = 1 << GetBPP(); 574 uint32_t pal_size = 1 << GetBPP();
568 if (!m_pPalette) { 575 if (!m_pPalette)
569 m_pPalette = FX_Alloc(uint32_t, pal_size); 576 m_pPalette.reset(FX_Alloc(uint32_t, pal_size));
570 } 577 if (pal_size > kPaletteSize)
Lei Zhang 2016/07/18 23:55:10 pal_size = std::min(pal_size, kPalletSize);
Wei Li 2016/07/19 21:21:29 Done.
571 if (pal_size > size) { 578 pal_size = kPaletteSize;
572 pal_size = size; 579 FXSYS_memcpy(m_pPalette.get(), pSrc, pal_size * sizeof(uint32_t));
573 }
574 FXSYS_memcpy(m_pPalette, pSrc, pal_size * sizeof(uint32_t));
575 } 580 }
576 } 581 }
582
577 void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const { 583 void CFX_DIBSource::GetPalette(uint32_t* pal, int alpha) const {
578 ASSERT(GetBPP() <= 8 && !IsCmykImage()); 584 ASSERT(GetBPP() <= 8 && !IsCmykImage());
579 if (GetBPP() == 1) { 585 if (GetBPP() == 1) {
580 pal[0] = 586 pal[0] = ((m_pPalette ? m_pPalette.get()[0] : 0xff000000) & 0xffffff) |
581 ((m_pPalette ? m_pPalette[0] : 0xff000000) & 0xffffff) | (alpha << 24); 587 (alpha << 24);
582 pal[1] = 588 pal[1] = ((m_pPalette ? m_pPalette.get()[1] : 0xffffffff) & 0xffffff) |
583 ((m_pPalette ? m_pPalette[1] : 0xffffffff) & 0xffffff) | (alpha << 24); 589 (alpha << 24);
584 return; 590 return;
585 } 591 }
586 if (m_pPalette) { 592 if (m_pPalette) {
587 for (int i = 0; i < 256; i++) { 593 for (int i = 0; i < 256; i++) {
588 pal[i] = (m_pPalette[i] & 0x00ffffff) | (alpha << 24); 594 pal[i] = (m_pPalette.get()[i] & 0x00ffffff) | (alpha << 24);
589 } 595 }
590 } else { 596 } else {
591 for (int i = 0; i < 256; i++) { 597 for (int i = 0; i < 256; i++) {
592 pal[i] = (i * 0x10101) | (alpha << 24); 598 pal[i] = (i * 0x10101) | (alpha << 24);
593 } 599 }
594 } 600 }
595 } 601 }
596 CFX_DIBitmap* CFX_DIBSource::GetAlphaMask(const FX_RECT* pClip) const { 602 CFX_DIBitmap* CFX_DIBSource::GetAlphaMask(const FX_RECT* pClip) const {
597 ASSERT(GetFormat() == FXDIB_Argb); 603 ASSERT(GetFormat() == FXDIB_Argb);
598 FX_RECT rect(0, 0, m_Width, m_Height); 604 FX_RECT rect(0, 0, m_Width, m_Height);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } 643 }
638 for (int row = 0; row < m_Height; row++) 644 for (int row = 0; row < m_Height; row++)
639 FXSYS_memcpy((void*)m_pAlphaMask->GetScanline(row), 645 FXSYS_memcpy((void*)m_pAlphaMask->GetScanline(row),
640 pAlphaMask->GetScanline(row + rect.top) + rect.left, 646 pAlphaMask->GetScanline(row + rect.top) + rect.left,
641 m_pAlphaMask->m_Pitch); 647 m_pAlphaMask->m_Pitch);
642 } else { 648 } else {
643 m_pAlphaMask->Clear(0xff000000); 649 m_pAlphaMask->Clear(0xff000000);
644 } 650 }
645 return TRUE; 651 return TRUE;
646 } 652 }
653
647 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3}; 654 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
648 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, 655 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
649 const CFX_DIBSource* pSrcBitmap, 656 const CFX_DIBSource* pSrcBitmap,
650 FXDIB_Channel srcChannel) { 657 FXDIB_Channel srcChannel) {
651 if (!m_pBuffer) { 658 if (!m_pBuffer) {
652 return FALSE; 659 return FALSE;
653 } 660 }
654 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap; 661 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap;
655 CFX_DIBitmap* pDst = this; 662 CFX_DIBitmap* pDst = this;
656 int destOffset, srcOffset; 663 int destOffset, srcOffset;
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 if (!m_pBuffer) { 923 if (!m_pBuffer) {
917 return FALSE; 924 return FALSE;
918 } 925 }
919 switch (GetFormat()) { 926 switch (GetFormat()) {
920 case FXDIB_1bppRgb: { 927 case FXDIB_1bppRgb: {
921 if (!m_pPalette) { 928 if (!m_pPalette) {
922 return FALSE; 929 return FALSE;
923 } 930 }
924 uint8_t gray[2]; 931 uint8_t gray[2];
925 for (int i = 0; i < 2; i++) { 932 for (int i = 0; i < 2; i++) {
926 int r = (uint8_t)(m_pPalette[i] >> 16); 933 int r = (uint8_t)(m_pPalette.get()[i] >> 16);
Lei Zhang 2016/07/18 23:55:10 get rid of the C-style cast while we are here?
Wei Li 2016/07/19 21:21:29 Done.
927 int g = (uint8_t)(m_pPalette[i] >> 8); 934 int g = (uint8_t)(m_pPalette.get()[i] >> 8);
928 int b = (uint8_t)m_pPalette[i]; 935 int b = (uint8_t)m_pPalette.get()[i];
929 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); 936 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b);
930 } 937 }
931 CFX_DIBitmap* pMask = new CFX_DIBitmap; 938 CFX_DIBitmap* pMask = new CFX_DIBitmap;
932 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 939 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
933 delete pMask; 940 delete pMask;
934 return FALSE; 941 return FALSE;
935 } 942 }
936 FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height); 943 FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height);
937 for (int row = 0; row < m_Height; row++) { 944 for (int row = 0; row < m_Height; row++) {
938 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 945 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
939 uint8_t* dest_pos = (uint8_t*)pMask->GetScanline(row); 946 uint8_t* dest_pos = (uint8_t*)pMask->GetScanline(row);
940 for (int col = 0; col < m_Width; col++) { 947 for (int col = 0; col < m_Width; col++) {
941 if (src_pos[col / 8] & (1 << (7 - col % 8))) { 948 if (src_pos[col / 8] & (1 << (7 - col % 8))) {
942 *dest_pos = gray[1]; 949 *dest_pos = gray[1];
943 } 950 }
944 dest_pos++; 951 dest_pos++;
945 } 952 }
946 } 953 }
947 TakeOver(pMask); 954 TakeOver(pMask);
948 delete pMask; 955 delete pMask;
949 break; 956 break;
950 } 957 }
951 case FXDIB_8bppRgb: { 958 case FXDIB_8bppRgb: {
952 if (!m_pPalette) { 959 if (!m_pPalette) {
953 return FALSE; 960 return FALSE;
954 } 961 }
955 uint8_t gray[256]; 962 uint8_t gray[256];
956 for (int i = 0; i < 256; i++) { 963 for (int i = 0; i < 256; i++) {
957 int r = (uint8_t)(m_pPalette[i] >> 16); 964 int r = (uint8_t)(m_pPalette.get()[i] >> 16);
Lei Zhang 2016/07/18 23:55:10 Ditto
Wei Li 2016/07/19 21:21:29 Done.
958 int g = (uint8_t)(m_pPalette[i] >> 8); 965 int g = (uint8_t)(m_pPalette.get()[i] >> 8);
959 int b = (uint8_t)m_pPalette[i]; 966 int b = (uint8_t)m_pPalette.get()[i];
960 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); 967 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b);
961 } 968 }
962 CFX_DIBitmap* pMask = new CFX_DIBitmap; 969 CFX_DIBitmap* pMask = new CFX_DIBitmap;
963 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 970 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
964 delete pMask; 971 delete pMask;
965 return FALSE; 972 return FALSE;
966 } 973 }
967 for (int row = 0; row < m_Height; row++) { 974 for (int row = 0; row < m_Height; row++) {
968 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); 975 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
969 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 976 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 } else { 1064 } else {
1058 if (!ConvertFormat(FXDIB_Argb)) { 1065 if (!ConvertFormat(FXDIB_Argb)) {
1059 return FALSE; 1066 return FALSE;
1060 } 1067 }
1061 MultiplyAlpha(alpha); 1068 MultiplyAlpha(alpha);
1062 } 1069 }
1063 break; 1070 break;
1064 } 1071 }
1065 return TRUE; 1072 return TRUE;
1066 } 1073 }
1074
1067 uint32_t CFX_DIBitmap::GetPixel(int x, int y) const { 1075 uint32_t CFX_DIBitmap::GetPixel(int x, int y) const {
1068 if (!m_pBuffer) { 1076 if (!m_pBuffer) {
1069 return 0; 1077 return 0;
1070 } 1078 }
1071 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; 1079 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
1072 switch (GetFormat()) { 1080 switch (GetFormat()) {
1073 case FXDIB_1bppMask: { 1081 case FXDIB_1bppMask: {
1074 if ((*pos) & (1 << (7 - x % 8))) { 1082 if ((*pos) & (1 << (7 - x % 8))) {
1075 return 0xff000000; 1083 return 0xff000000;
1076 } 1084 }
1077 return 0; 1085 return 0;
1078 } 1086 }
1079 case FXDIB_1bppRgb: { 1087 case FXDIB_1bppRgb: {
1080 if ((*pos) & (1 << (7 - x % 8))) { 1088 if ((*pos) & (1 << (7 - x % 8))) {
1081 return m_pPalette ? m_pPalette[1] : 0xffffffff; 1089 return m_pPalette ? m_pPalette.get()[1] : 0xffffffff;
1082 } 1090 }
1083 return m_pPalette ? m_pPalette[0] : 0xff000000; 1091 return m_pPalette ? m_pPalette.get()[0] : 0xff000000;
1084 } 1092 }
1085 case FXDIB_8bppMask: 1093 case FXDIB_8bppMask:
1086 return (*pos) << 24; 1094 return (*pos) << 24;
1087 case FXDIB_8bppRgb: 1095 case FXDIB_8bppRgb:
1088 return m_pPalette ? m_pPalette[*pos] : (0xff000000 | ((*pos) * 0x10101)); 1096 return m_pPalette ? m_pPalette.get()[*pos]
1097 : (0xff000000 | ((*pos) * 0x10101));
1089 case FXDIB_Rgb: 1098 case FXDIB_Rgb:
1090 case FXDIB_Rgba: 1099 case FXDIB_Rgba:
1091 case FXDIB_Rgb32: 1100 case FXDIB_Rgb32:
1092 return FXARGB_GETDIB(pos) | 0xff000000; 1101 return FXARGB_GETDIB(pos) | 0xff000000;
1093 case FXDIB_Argb: 1102 case FXDIB_Argb:
1094 return FXARGB_GETDIB(pos); 1103 return FXARGB_GETDIB(pos);
1095 default: 1104 default:
1096 break; 1105 break;
1097 } 1106 }
1098 return 0; 1107 return 0;
1099 } 1108 }
1109
1100 void CFX_DIBitmap::SetPixel(int x, int y, uint32_t color) { 1110 void CFX_DIBitmap::SetPixel(int x, int y, uint32_t color) {
1101 if (!m_pBuffer) { 1111 if (!m_pBuffer) {
1102 return; 1112 return;
1103 } 1113 }
1104 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) { 1114 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) {
1105 return; 1115 return;
1106 } 1116 }
1107 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; 1117 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
1108 switch (GetFormat()) { 1118 switch (GetFormat()) {
1109 case FXDIB_1bppMask: 1119 case FXDIB_1bppMask:
1110 if (color >> 24) { 1120 if (color >> 24) {
1111 *pos |= 1 << (7 - x % 8); 1121 *pos |= 1 << (7 - x % 8);
1112 } else { 1122 } else {
1113 *pos &= ~(1 << (7 - x % 8)); 1123 *pos &= ~(1 << (7 - x % 8));
1114 } 1124 }
1115 break; 1125 break;
1116 case FXDIB_1bppRgb: 1126 case FXDIB_1bppRgb:
1117 if (m_pPalette) { 1127 if (m_pPalette) {
1118 if (color == m_pPalette[1]) { 1128 if (color == m_pPalette.get()[1]) {
1119 *pos |= 1 << (7 - x % 8); 1129 *pos |= 1 << (7 - x % 8);
1120 } else { 1130 } else {
1121 *pos &= ~(1 << (7 - x % 8)); 1131 *pos &= ~(1 << (7 - x % 8));
1122 } 1132 }
1123 } else { 1133 } else {
1124 if (color == 0xffffffff) { 1134 if (color == 0xffffffff) {
1125 *pos |= 1 << (7 - x % 8); 1135 *pos |= 1 << (7 - x % 8);
1126 } else { 1136 } else {
1127 *pos &= ~(1 << (7 - x % 8)); 1137 *pos &= ~(1 << (7 - x % 8));
1128 } 1138 }
1129 } 1139 }
1130 break; 1140 break;
1131 case FXDIB_8bppMask: 1141 case FXDIB_8bppMask:
1132 *pos = (uint8_t)(color >> 24); 1142 *pos = (uint8_t)(color >> 24);
1133 break; 1143 break;
1134 case FXDIB_8bppRgb: { 1144 case FXDIB_8bppRgb: {
1135 if (m_pPalette) { 1145 if (m_pPalette) {
1136 for (int i = 0; i < 256; i++) { 1146 for (int i = 0; i < 256; i++) {
1137 if (m_pPalette[i] == color) { 1147 if (m_pPalette.get()[i] == color) {
1138 *pos = (uint8_t)i; 1148 *pos = (uint8_t)i;
1139 return; 1149 return;
1140 } 1150 }
1141 } 1151 }
1142 *pos = 0; 1152 *pos = 0;
1143 } else { 1153 } else {
1144 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color)); 1154 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
1145 } 1155 }
1146 break; 1156 break;
1147 } 1157 }
(...skipping 11 matching lines...) Expand all
1159 pos[2] = FXARGB_R(color); 1169 pos[2] = FXARGB_R(color);
1160 break; 1170 break;
1161 } 1171 }
1162 case FXDIB_Argb: 1172 case FXDIB_Argb:
1163 FXARGB_SETDIB(pos, color); 1173 FXARGB_SETDIB(pos, color);
1164 break; 1174 break;
1165 default: 1175 default:
1166 break; 1176 break;
1167 } 1177 }
1168 } 1178 }
1179
1169 void CFX_DIBitmap::DownSampleScanline(int line, 1180 void CFX_DIBitmap::DownSampleScanline(int line,
1170 uint8_t* dest_scan, 1181 uint8_t* dest_scan,
1171 int dest_bpp, 1182 int dest_bpp,
1172 int dest_width, 1183 int dest_width,
1173 FX_BOOL bFlipX, 1184 FX_BOOL bFlipX,
1174 int clip_left, 1185 int clip_left,
1175 int clip_width) const { 1186 int clip_width) const {
1176 if (!m_pBuffer) { 1187 if (!m_pBuffer) {
1177 return; 1188 return;
1178 } 1189 }
(...skipping 14 matching lines...) Expand all
1193 uint32_t dest_x = clip_left + i; 1204 uint32_t dest_x = clip_left + i;
1194 uint32_t src_x = dest_x * m_Width / dest_width; 1205 uint32_t src_x = dest_x * m_Width / dest_width;
1195 if (bFlipX) { 1206 if (bFlipX) {
1196 src_x = m_Width - src_x - 1; 1207 src_x = m_Width - src_x - 1;
1197 } 1208 }
1198 src_x %= m_Width; 1209 src_x %= m_Width;
1199 int dest_pos = i; 1210 int dest_pos = i;
1200 if (m_pPalette) { 1211 if (m_pPalette) {
1201 if (!IsCmykImage()) { 1212 if (!IsCmykImage()) {
1202 dest_pos *= 3; 1213 dest_pos *= 3;
1203 FX_ARGB argb = m_pPalette[scanline[src_x]]; 1214 FX_ARGB argb = m_pPalette.get()[scanline[src_x]];
1204 dest_scan[dest_pos] = FXARGB_B(argb); 1215 dest_scan[dest_pos] = FXARGB_B(argb);
1205 dest_scan[dest_pos + 1] = FXARGB_G(argb); 1216 dest_scan[dest_pos + 1] = FXARGB_G(argb);
1206 dest_scan[dest_pos + 2] = FXARGB_R(argb); 1217 dest_scan[dest_pos + 2] = FXARGB_R(argb);
1207 } else { 1218 } else {
1208 dest_pos *= 4; 1219 dest_pos *= 4;
1209 FX_CMYK cmyk = m_pPalette[scanline[src_x]]; 1220 FX_CMYK cmyk = m_pPalette.get()[scanline[src_x]];
1210 dest_scan[dest_pos] = FXSYS_GetCValue(cmyk); 1221 dest_scan[dest_pos] = FXSYS_GetCValue(cmyk);
1211 dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk); 1222 dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk);
1212 dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk); 1223 dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk);
1213 dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk); 1224 dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk);
1214 } 1225 }
1215 } else { 1226 } else {
1216 dest_scan[dest_pos] = scanline[src_x]; 1227 dest_scan[dest_pos] = scanline[src_x];
1217 } 1228 }
1218 } 1229 }
1219 } else { 1230 } else {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) { 1292 } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) {
1282 return TRUE; 1293 return TRUE;
1283 } 1294 }
1284 if (!m_pPalette) { 1295 if (!m_pPalette) {
1285 BuildPalette(); 1296 BuildPalette();
1286 } 1297 }
1287 int size = 1 << m_bpp; 1298 int size = 1 << m_bpp;
1288 if (isCmykImage) { 1299 if (isCmykImage) {
1289 for (int i = 0; i < size; i++) { 1300 for (int i = 0; i < size; i++) {
1290 uint8_t b, g, r; 1301 uint8_t b, g, r;
1291 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), 1302 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]),
1292 FXSYS_GetMValue(m_pPalette[i]), 1303 FXSYS_GetMValue(m_pPalette.get()[i]),
1293 FXSYS_GetYValue(m_pPalette[i]), 1304 FXSYS_GetYValue(m_pPalette.get()[i]),
1294 FXSYS_GetKValue(m_pPalette[i]), r, g, b); 1305 FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b);
1295 int gray = 255 - FXRGB2GRAY(r, g, b); 1306 int gray = 255 - FXRGB2GRAY(r, g, b);
1296 m_pPalette[i] = CmykEncode( 1307 m_pPalette.get()[i] = CmykEncode(
1297 bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255, 1308 bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255,
1298 by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255); 1309 by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255);
1299 } 1310 }
1300 } else { 1311 } else {
1301 for (int i = 0; i < size; i++) { 1312 for (int i = 0; i < size; i++) {
1302 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette[i]), FXARGB_G(m_pPalette[i]), 1313 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]),
1303 FXARGB_B(m_pPalette[i])); 1314 FXARGB_G(m_pPalette.get()[i]),
1304 m_pPalette[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, 1315 FXARGB_B(m_pPalette.get()[i]));
1305 bg + (fg - bg) * gray / 255, 1316 m_pPalette.get()[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255,
1306 bb + (fb - bb) * gray / 255); 1317 bg + (fg - bg) * gray / 255,
1318 bb + (fb - bb) * gray / 255);
1307 } 1319 }
1308 } 1320 }
1309 return TRUE; 1321 return TRUE;
1310 } 1322 }
1311 if (isCmykImage) { 1323 if (isCmykImage) {
1312 if (forecolor == 0xff && backcolor == 0x00) { 1324 if (forecolor == 0xff && backcolor == 0x00) {
1313 for (int row = 0; row < m_Height; row++) { 1325 for (int row = 0; row < m_Height; row++) {
1314 uint8_t* scanline = m_pBuffer + row * m_Pitch; 1326 uint8_t* scanline = m_pBuffer + row * m_Pitch;
1315 for (int col = 0; col < m_Width; col++) { 1327 for (int col = 0; col < m_Width; col++) {
1316 uint8_t b, g, r; 1328 uint8_t b, g, r;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 } 1379 }
1368 return TRUE; 1380 return TRUE;
1369 } 1381 }
1370 1382
1371 CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const { 1383 CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const {
1372 CFX_DIBitmap* pFlipped = new CFX_DIBitmap; 1384 CFX_DIBitmap* pFlipped = new CFX_DIBitmap;
1373 if (!pFlipped->Create(m_Width, m_Height, GetFormat())) { 1385 if (!pFlipped->Create(m_Width, m_Height, GetFormat())) {
1374 delete pFlipped; 1386 delete pFlipped;
1375 return nullptr; 1387 return nullptr;
1376 } 1388 }
1377 pFlipped->CopyPalette(m_pPalette); 1389 pFlipped->CopyPalette(m_pPalette.get());
1378 uint8_t* pDestBuffer = pFlipped->GetBuffer(); 1390 uint8_t* pDestBuffer = pFlipped->GetBuffer();
1379 int Bpp = m_bpp / 8; 1391 int Bpp = m_bpp / 8;
1380 for (int row = 0; row < m_Height; row++) { 1392 for (int row = 0; row < m_Height; row++) {
1381 const uint8_t* src_scan = GetScanline(row); 1393 const uint8_t* src_scan = GetScanline(row);
1382 uint8_t* dest_scan = 1394 uint8_t* dest_scan =
1383 pDestBuffer + m_Pitch * (bYFlip ? (m_Height - row - 1) : row); 1395 pDestBuffer + m_Pitch * (bYFlip ? (m_Height - row - 1) : row);
1384 if (!bXFlip) { 1396 if (!bXFlip) {
1385 FXSYS_memcpy(dest_scan, src_scan, m_Pitch); 1397 FXSYS_memcpy(dest_scan, src_scan, m_Pitch);
1386 continue; 1398 continue;
1387 } 1399 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 } 1463 }
1452 m_pBitmap->CopyPalette(pSrc->GetPalette()); 1464 m_pBitmap->CopyPalette(pSrc->GetPalette());
1453 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); 1465 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
1454 } else { 1466 } else {
1455 m_pBitmap = pSrc->Clone(); 1467 m_pBitmap = pSrc->Clone();
1456 } 1468 }
1457 } 1469 }
1458 CFX_DIBExtractor::~CFX_DIBExtractor() { 1470 CFX_DIBExtractor::~CFX_DIBExtractor() {
1459 delete m_pBitmap; 1471 delete m_pBitmap;
1460 } 1472 }
1473
1461 CFX_FilteredDIB::CFX_FilteredDIB() { 1474 CFX_FilteredDIB::CFX_FilteredDIB() {
1462 m_pScanline = nullptr; 1475 m_pScanline = nullptr;
1463 m_pSrc = nullptr; 1476 m_pSrc = nullptr;
1464 } 1477 }
1478
1465 CFX_FilteredDIB::~CFX_FilteredDIB() { 1479 CFX_FilteredDIB::~CFX_FilteredDIB() {
1466 if (m_bAutoDropSrc) { 1480 if (m_bAutoDropSrc) {
1467 delete m_pSrc; 1481 delete m_pSrc;
1468 } 1482 }
1469 FX_Free(m_pScanline); 1483 FX_Free(m_pScanline);
1470 } 1484 }
1485
1471 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { 1486 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) {
1472 m_pSrc = pSrc; 1487 m_pSrc = pSrc;
1473 m_bAutoDropSrc = bAutoDropSrc; 1488 m_bAutoDropSrc = bAutoDropSrc;
1474 m_Width = pSrc->GetWidth(); 1489 m_Width = pSrc->GetWidth();
1475 m_Height = pSrc->GetHeight(); 1490 m_Height = pSrc->GetHeight();
1476 FXDIB_Format format = GetDestFormat(); 1491 FXDIB_Format format = GetDestFormat();
1477 m_bpp = (uint8_t)format; 1492 m_bpp = (uint8_t)format;
1478 m_AlphaFlag = (uint8_t)(format >> 8); 1493 m_AlphaFlag = (uint8_t)(format >> 8);
1479 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; 1494 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
1480 m_pPalette = GetDestPalette(); 1495 m_pPalette.reset(GetDestPalette());
1481 m_pScanline = FX_Alloc(uint8_t, m_Pitch); 1496 m_pScanline = FX_Alloc(uint8_t, m_Pitch);
1482 } 1497 }
1498
1483 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const { 1499 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const {
1484 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); 1500 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line));
1485 return m_pScanline; 1501 return m_pScanline;
1486 } 1502 }
1503
1487 void CFX_FilteredDIB::DownSampleScanline(int line, 1504 void CFX_FilteredDIB::DownSampleScanline(int line,
1488 uint8_t* dest_scan, 1505 uint8_t* dest_scan,
1489 int dest_bpp, 1506 int dest_bpp,
1490 int dest_width, 1507 int dest_width,
1491 FX_BOOL bFlipX, 1508 FX_BOOL bFlipX,
1492 int clip_left, 1509 int clip_left,
1493 int clip_width) const { 1510 int clip_width) const {
1494 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, 1511 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX,
1495 clip_left, clip_width); 1512 clip_left, clip_width);
1496 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp); 1513 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp);
1497 } 1514 }
1515
1498 CFX_ImageRenderer::CFX_ImageRenderer() { 1516 CFX_ImageRenderer::CFX_ImageRenderer() {
1499 m_Status = 0; 1517 m_Status = 0;
1500 m_pTransformer = nullptr; 1518 m_pTransformer = nullptr;
1501 m_bRgbByteOrder = FALSE; 1519 m_bRgbByteOrder = FALSE;
1502 m_BlendType = FXDIB_BLEND_NORMAL; 1520 m_BlendType = FXDIB_BLEND_NORMAL;
1503 } 1521 }
1504 CFX_ImageRenderer::~CFX_ImageRenderer() { 1522 CFX_ImageRenderer::~CFX_ImageRenderer() {
1505 delete m_pTransformer; 1523 delete m_pTransformer;
1506 } 1524 }
1507 1525
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 uint32_t* pSrcPalette) { 1682 uint32_t* pSrcPalette) {
1665 m_pBitmap.reset(new CFX_DIBitmap); 1683 m_pBitmap.reset(new CFX_DIBitmap);
1666 if (!m_pBitmap->Create(width, height, src_format)) { 1684 if (!m_pBitmap->Create(width, height, src_format)) {
1667 m_pBitmap.reset(); 1685 m_pBitmap.reset();
1668 return FALSE; 1686 return FALSE;
1669 } 1687 }
1670 if (pSrcPalette) 1688 if (pSrcPalette)
1671 m_pBitmap->CopyPalette(pSrcPalette); 1689 m_pBitmap->CopyPalette(pSrcPalette);
1672 return TRUE; 1690 return TRUE;
1673 } 1691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698