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

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 more 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
« no previous file with comments | « core/fxge/dib/fx_dib_convert.cpp ('k') | core/fxge/dib/fx_dib_transform.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm>
Lei Zhang 2016/07/19 22:57:26 C++ headers after C headers.
Wei Li 2016/07/19 23:39:41 Will fix this style in next CL, thanks
9 #include <limits.h> 10 #include <limits.h>
10 11
11 #include "core/fxcodec/include/fx_codec.h" 12 #include "core/fxcodec/include/fx_codec.h"
12 #include "core/fxge/dib/dib_int.h" 13 #include "core/fxge/dib/dib_int.h"
13 #include "core/fxge/include/fx_ge.h" 14 #include "core/fxge/include/fx_ge.h"
14 15
15 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { 16 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) {
16 c = FXSYS_GetCValue(cmyk); 17 c = FXSYS_GetCValue(cmyk);
17 m = FXSYS_GetMValue(cmyk); 18 m = FXSYS_GetMValue(cmyk);
18 y = FXSYS_GetYValue(cmyk); 19 y = FXSYS_GetYValue(cmyk);
19 k = FXSYS_GetKValue(cmyk); 20 k = FXSYS_GetKValue(cmyk);
20 } 21 }
22
21 void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) { 23 void ArgbDecode(uint32_t argb, int& a, int& r, int& g, int& b) {
22 a = FXARGB_A(argb); 24 a = FXARGB_A(argb);
23 r = FXARGB_R(argb); 25 r = FXARGB_R(argb);
24 g = FXARGB_G(argb); 26 g = FXARGB_G(argb);
25 b = FXARGB_B(argb); 27 b = FXARGB_B(argb);
26 } 28 }
29
27 void ArgbDecode(uint32_t argb, int& a, FX_COLORREF& rgb) { 30 void ArgbDecode(uint32_t argb, int& a, FX_COLORREF& rgb) {
28 a = FXARGB_A(argb); 31 a = FXARGB_A(argb);
29 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb)); 32 rgb = FXSYS_RGB(FXARGB_R(argb), FXARGB_G(argb), FXARGB_B(argb));
30 } 33 }
34
31 uint32_t ArgbEncode(int a, FX_COLORREF rgb) { 35 uint32_t ArgbEncode(int a, FX_COLORREF rgb) {
32 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb), 36 return FXARGB_MAKE(a, FXSYS_GetRValue(rgb), FXSYS_GetGValue(rgb),
33 FXSYS_GetBValue(rgb)); 37 FXSYS_GetBValue(rgb));
34 } 38 }
35 39
36 CFX_DIBSource::CFX_DIBSource() { 40 CFX_DIBSource::CFX_DIBSource()
37 m_bpp = 0; 41 : m_pAlphaMask(nullptr),
38 m_AlphaFlag = 0; 42 m_Width(0),
39 m_Width = m_Height = 0; 43 m_Height(0),
40 m_Pitch = 0; 44 m_bpp(0),
41 m_pPalette = nullptr; 45 m_AlphaFlag(0),
42 m_pAlphaMask = nullptr; 46 m_Pitch(0) {}
43 }
44 47
45 CFX_DIBSource::~CFX_DIBSource() { 48 CFX_DIBSource::~CFX_DIBSource() {
46 FX_Free(m_pPalette);
47 delete m_pAlphaMask; 49 delete m_pAlphaMask;
48 } 50 }
49 51
50 uint8_t* CFX_DIBSource::GetBuffer() const { 52 uint8_t* CFX_DIBSource::GetBuffer() const {
51 return nullptr; 53 return nullptr;
52 } 54 }
53 55
54 FX_BOOL CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const { 56 FX_BOOL CFX_DIBSource::SkipToScanline(int line, IFX_Pause* pPause) const {
55 return FALSE; 57 return FALSE;
56 } 58 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 145 }
144 146
145 const uint8_t* CFX_DIBitmap::GetScanline(int line) const { 147 const uint8_t* CFX_DIBitmap::GetScanline(int line) const {
146 return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr; 148 return m_pBuffer ? m_pBuffer + line * m_Pitch : nullptr;
147 } 149 }
148 150
149 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) { 151 void CFX_DIBitmap::TakeOver(CFX_DIBitmap* pSrcBitmap) {
150 if (!m_bExtBuf) 152 if (!m_bExtBuf)
151 FX_Free(m_pBuffer); 153 FX_Free(m_pBuffer);
152 154
153 FX_Free(m_pPalette);
154 delete m_pAlphaMask; 155 delete m_pAlphaMask;
155 m_pBuffer = pSrcBitmap->m_pBuffer; 156 m_pBuffer = pSrcBitmap->m_pBuffer;
156 m_pPalette = pSrcBitmap->m_pPalette; 157 m_pPalette = std::move(pSrcBitmap->m_pPalette);
157 m_pAlphaMask = pSrcBitmap->m_pAlphaMask; 158 m_pAlphaMask = pSrcBitmap->m_pAlphaMask;
158 pSrcBitmap->m_pBuffer = nullptr; 159 pSrcBitmap->m_pBuffer = nullptr;
159 pSrcBitmap->m_pPalette = nullptr;
160 pSrcBitmap->m_pAlphaMask = nullptr; 160 pSrcBitmap->m_pAlphaMask = nullptr;
161 m_bpp = pSrcBitmap->m_bpp; 161 m_bpp = pSrcBitmap->m_bpp;
162 m_bExtBuf = pSrcBitmap->m_bExtBuf; 162 m_bExtBuf = pSrcBitmap->m_bExtBuf;
163 m_AlphaFlag = pSrcBitmap->m_AlphaFlag; 163 m_AlphaFlag = pSrcBitmap->m_AlphaFlag;
164 m_Width = pSrcBitmap->m_Width; 164 m_Width = pSrcBitmap->m_Width;
165 m_Height = pSrcBitmap->m_Height; 165 m_Height = pSrcBitmap->m_Height;
166 m_Pitch = pSrcBitmap->m_Pitch; 166 m_Pitch = pSrcBitmap->m_Pitch;
167 } 167 }
168 168
169 CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const { 169 CFX_DIBitmap* CFX_DIBSource::Clone(const FX_RECT* pClip) const {
170 FX_RECT rect(0, 0, m_Width, m_Height); 170 FX_RECT rect(0, 0, m_Width, m_Height);
171 if (pClip) { 171 if (pClip) {
172 rect.Intersect(*pClip); 172 rect.Intersect(*pClip);
173 if (rect.IsEmpty()) { 173 if (rect.IsEmpty()) {
174 return nullptr; 174 return nullptr;
175 } 175 }
176 } 176 }
177 CFX_DIBitmap* pNewBitmap = new CFX_DIBitmap; 177 std::unique_ptr<CFX_DIBitmap> pNewBitmap(new CFX_DIBitmap);
178 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat())) { 178 if (!pNewBitmap->Create(rect.Width(), rect.Height(), GetFormat()))
179 delete pNewBitmap;
180 return nullptr; 179 return nullptr;
181 } 180
182 pNewBitmap->CopyPalette(m_pPalette); 181 pNewBitmap->CopyPalette(m_pPalette.get());
183 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip); 182 pNewBitmap->CopyAlphaMask(m_pAlphaMask, pClip);
184 if (GetBPP() == 1 && rect.left % 8 != 0) { 183 if (GetBPP() == 1 && rect.left % 8 != 0) {
185 int left_shift = rect.left % 32; 184 int left_shift = rect.left % 32;
186 int right_shift = 32 - left_shift; 185 int right_shift = 32 - left_shift;
187 int dword_count = pNewBitmap->m_Pitch / 4; 186 int dword_count = pNewBitmap->m_Pitch / 4;
188 for (int row = rect.top; row < rect.bottom; row++) { 187 for (int row = rect.top; row < rect.bottom; row++) {
189 uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32; 188 uint32_t* src_scan = (uint32_t*)GetScanline(row) + rect.left / 32;
190 uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top); 189 uint32_t* dest_scan = (uint32_t*)pNewBitmap->GetScanline(row - rect.top);
191 for (int i = 0; i < dword_count; i++) { 190 for (int i = 0; i < dword_count; i++) {
192 dest_scan[i] = 191 dest_scan[i] =
193 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift); 192 (src_scan[i] << left_shift) | (src_scan[i + 1] >> right_shift);
194 } 193 }
195 } 194 }
196 } else { 195 } else {
197 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8; 196 int copy_len = (pNewBitmap->GetWidth() * pNewBitmap->GetBPP() + 7) / 8;
198 if (m_Pitch < (uint32_t)copy_len) { 197 if (m_Pitch < (uint32_t)copy_len) {
199 copy_len = m_Pitch; 198 copy_len = m_Pitch;
200 } 199 }
201 for (int row = rect.top; row < rect.bottom; row++) { 200 for (int row = rect.top; row < rect.bottom; row++) {
202 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8; 201 const uint8_t* src_scan = GetScanline(row) + rect.left * m_bpp / 8;
203 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top); 202 uint8_t* dest_scan = (uint8_t*)pNewBitmap->GetScanline(row - rect.top);
204 FXSYS_memcpy(dest_scan, src_scan, copy_len); 203 FXSYS_memcpy(dest_scan, src_scan, copy_len);
205 } 204 }
206 } 205 }
207 return pNewBitmap; 206 return pNewBitmap.release();
208 } 207 }
208
209 void CFX_DIBSource::BuildPalette() { 209 void CFX_DIBSource::BuildPalette() {
210 if (m_pPalette) { 210 if (m_pPalette) {
211 return; 211 return;
212 } 212 }
213 if (GetBPP() == 1) { 213 if (GetBPP() == 1) {
214 m_pPalette = FX_Alloc(uint32_t, 2); 214 m_pPalette.reset(FX_Alloc(uint32_t, 2));
215 if (IsCmykImage()) { 215 if (IsCmykImage()) {
216 m_pPalette[0] = 0xff; 216 m_pPalette.get()[0] = 0xff;
217 m_pPalette[1] = 0; 217 m_pPalette.get()[1] = 0;
218 } else { 218 } else {
219 m_pPalette[0] = 0xff000000; 219 m_pPalette.get()[0] = 0xff000000;
220 m_pPalette[1] = 0xffffffff; 220 m_pPalette.get()[1] = 0xffffffff;
221 } 221 }
222 } else if (GetBPP() == 8) { 222 } else if (GetBPP() == 8) {
223 m_pPalette = FX_Alloc(uint32_t, 256); 223 m_pPalette.reset(FX_Alloc(uint32_t, 256));
224 if (IsCmykImage()) { 224 if (IsCmykImage()) {
225 for (int i = 0; i < 256; i++) { 225 for (int i = 0; i < 256; i++) {
226 m_pPalette[i] = 0xff - i; 226 m_pPalette.get()[i] = 0xff - i;
227 } 227 }
228 } else { 228 } else {
229 for (int i = 0; i < 256; i++) { 229 for (int i = 0; i < 256; i++) {
230 m_pPalette[i] = 0xff000000 | (i * 0x10101); 230 m_pPalette.get()[i] = 0xff000000 | (i * 0x10101);
231 } 231 }
232 } 232 }
233 } 233 }
234 } 234 }
235
235 FX_BOOL CFX_DIBSource::BuildAlphaMask() { 236 FX_BOOL CFX_DIBSource::BuildAlphaMask() {
236 if (m_pAlphaMask) { 237 if (m_pAlphaMask) {
237 return TRUE; 238 return TRUE;
238 } 239 }
239 m_pAlphaMask = new CFX_DIBitmap; 240 m_pAlphaMask = new CFX_DIBitmap;
240 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 241 if (!m_pAlphaMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
241 delete m_pAlphaMask; 242 delete m_pAlphaMask;
242 m_pAlphaMask = nullptr; 243 m_pAlphaMask = nullptr;
243 return FALSE; 244 return FALSE;
244 } 245 }
245 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff, 246 FXSYS_memset(m_pAlphaMask->GetBuffer(), 0xff,
246 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch()); 247 m_pAlphaMask->GetHeight() * m_pAlphaMask->GetPitch());
247 return TRUE; 248 return TRUE;
248 } 249 }
250
249 uint32_t CFX_DIBSource::GetPaletteEntry(int index) const { 251 uint32_t CFX_DIBSource::GetPaletteEntry(int index) const {
250 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 252 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
251 if (m_pPalette) { 253 if (m_pPalette) {
252 return m_pPalette[index]; 254 return m_pPalette.get()[index];
253 } 255 }
254 if (IsCmykImage()) { 256 if (IsCmykImage()) {
255 if (GetBPP() == 1) { 257 if (GetBPP() == 1) {
256 return index ? 0 : 0xff; 258 return index ? 0 : 0xff;
257 } 259 }
258 return 0xff - index; 260 return 0xff - index;
259 } 261 }
260 if (GetBPP() == 1) { 262 if (GetBPP() == 1) {
261 return index ? 0xffffffff : 0xff000000; 263 return index ? 0xffffffff : 0xff000000;
262 } 264 }
263 return index * 0x10101 | 0xff000000; 265 return index * 0x10101 | 0xff000000;
264 } 266 }
267
265 void CFX_DIBSource::SetPaletteEntry(int index, uint32_t color) { 268 void CFX_DIBSource::SetPaletteEntry(int index, uint32_t color) {
266 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 269 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
267 if (!m_pPalette) { 270 if (!m_pPalette) {
268 BuildPalette(); 271 BuildPalette();
269 } 272 }
270 m_pPalette[index] = color; 273 m_pPalette.get()[index] = color;
271 } 274 }
275
272 int CFX_DIBSource::FindPalette(uint32_t color) const { 276 int CFX_DIBSource::FindPalette(uint32_t color) const {
273 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask()); 277 ASSERT((GetBPP() == 1 || GetBPP() == 8) && !IsAlphaMask());
274 if (!m_pPalette) { 278 if (!m_pPalette) {
275 if (IsCmykImage()) { 279 if (IsCmykImage()) {
276 if (GetBPP() == 1) { 280 if (GetBPP() == 1) {
277 return ((uint8_t)color == 0xff) ? 0 : 1; 281 return ((uint8_t)color == 0xff) ? 0 : 1;
278 } 282 }
279 return 0xff - (uint8_t)color; 283 return 0xff - (uint8_t)color;
280 } 284 }
281 if (GetBPP() == 1) { 285 if (GetBPP() == 1) {
282 return ((uint8_t)color == 0xff) ? 1 : 0; 286 return ((uint8_t)color == 0xff) ? 1 : 0;
283 } 287 }
284 return (uint8_t)color; 288 return (uint8_t)color;
285 } 289 }
286 int palsize = (1 << GetBPP()); 290 int palsize = (1 << GetBPP());
287 for (int i = 0; i < palsize; i++) 291 for (int i = 0; i < palsize; i++)
288 if (m_pPalette[i] == color) { 292 if (m_pPalette.get()[i] == color) {
289 return i; 293 return i;
290 } 294 }
291 return -1; 295 return -1;
292 } 296 }
297
293 void CFX_DIBitmap::Clear(uint32_t color) { 298 void CFX_DIBitmap::Clear(uint32_t color) {
294 if (!m_pBuffer) { 299 if (!m_pBuffer) {
295 return; 300 return;
296 } 301 }
297 switch (GetFormat()) { 302 switch (GetFormat()) {
298 case FXDIB_1bppMask: 303 case FXDIB_1bppMask:
299 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0, 304 FXSYS_memset(m_pBuffer, (color & 0xff000000) ? 0xff : 0,
300 m_Pitch * m_Height); 305 m_Pitch * m_Height);
301 break; 306 break;
302 case FXDIB_1bppRgb: { 307 case FXDIB_1bppRgb: {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 349 }
345 for (int row = 1; row < m_Height; row++) { 350 for (int row = 1; row < m_Height; row++) {
346 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch); 351 FXSYS_memcpy(m_pBuffer + row * m_Pitch, m_pBuffer, m_Pitch);
347 } 352 }
348 break; 353 break;
349 } 354 }
350 default: 355 default:
351 break; 356 break;
352 } 357 }
353 } 358 }
359
354 void CFX_DIBSource::GetOverlapRect(int& dest_left, 360 void CFX_DIBSource::GetOverlapRect(int& dest_left,
355 int& dest_top, 361 int& dest_top,
356 int& width, 362 int& width,
357 int& height, 363 int& height,
358 int src_width, 364 int src_width,
359 int src_height, 365 int src_height,
360 int& src_left, 366 int& src_left,
361 int& src_top, 367 int& src_top,
362 const CFX_ClipRgn* pClipRgn) { 368 const CFX_ClipRgn* pClipRgn) {
363 if (width == 0 || height == 0) { 369 if (width == 0 || height == 0) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 440 }
435 } else { 441 } else {
436 if (m_pPalette) 442 if (m_pPalette)
437 return FALSE; 443 return FALSE;
438 444
439 if (m_bpp == 8) 445 if (m_bpp == 8)
440 dest_format = FXDIB_8bppMask; 446 dest_format = FXDIB_8bppMask;
441 447
442 uint8_t* dest_buf = 448 uint8_t* dest_buf =
443 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8; 449 m_pBuffer + dest_top * m_Pitch + dest_left * GetBPP() / 8;
444 uint32_t* d_plt = nullptr; 450 std::unique_ptr<uint32_t, FxFreeDeleter> d_plt;
445 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height, 451 if (!ConvertBuffer(dest_format, dest_buf, m_Pitch, width, height,
446 pSrcBitmap, src_left, src_top, d_plt)) { 452 pSrcBitmap, src_left, src_top, &d_plt)) {
447 return FALSE; 453 return FALSE;
448 } 454 }
449 } 455 }
450 return TRUE; 456 return TRUE;
451 } 457 }
452 458
453 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left, 459 FX_BOOL CFX_DIBitmap::TransferMask(int dest_left,
454 int dest_top, 460 int dest_top,
455 int width, 461 int width,
456 int height, 462 int height,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 for (int col = 0; col < width; col++) { 558 for (int col = 0; col < width; col++) {
553 FXSYS_memcpy(dest_color_pos, color_p, comps); 559 FXSYS_memcpy(dest_color_pos, color_p, comps);
554 dest_color_pos += comps; 560 dest_color_pos += comps;
555 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255); 561 *dest_alpha_pos++ = (alpha * (*src_scan++) / 255);
556 } 562 }
557 } 563 }
558 } 564 }
559 } 565 }
560 return TRUE; 566 return TRUE;
561 } 567 }
562 void CFX_DIBSource::CopyPalette(const uint32_t* pSrc, uint32_t size) { 568
569 void CFX_DIBSource::CopyPalette(const uint32_t* pSrc) {
570 static const uint32_t kPaletteSize = 256;
571
563 if (!pSrc || GetBPP() > 8) { 572 if (!pSrc || GetBPP() > 8) {
564 FX_Free(m_pPalette); 573 m_pPalette.reset();
565 m_pPalette = nullptr;
566 } else { 574 } else {
567 uint32_t pal_size = 1 << GetBPP(); 575 uint32_t pal_size = 1 << GetBPP();
568 if (!m_pPalette) { 576 if (!m_pPalette)
569 m_pPalette = FX_Alloc(uint32_t, pal_size); 577 m_pPalette.reset(FX_Alloc(uint32_t, pal_size));
570 } 578 pal_size = std::min(pal_size, kPaletteSize);
571 if (pal_size > size) { 579 FXSYS_memcpy(m_pPalette.get(), pSrc, pal_size * sizeof(uint32_t));
572 pal_size = size;
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 }
602
596 CFX_DIBitmap* CFX_DIBSource::GetAlphaMask(const FX_RECT* pClip) const { 603 CFX_DIBitmap* CFX_DIBSource::GetAlphaMask(const FX_RECT* pClip) const {
597 ASSERT(GetFormat() == FXDIB_Argb); 604 ASSERT(GetFormat() == FXDIB_Argb);
598 FX_RECT rect(0, 0, m_Width, m_Height); 605 FX_RECT rect(0, 0, m_Width, m_Height);
599 if (pClip) { 606 if (pClip) {
600 rect.Intersect(*pClip); 607 rect.Intersect(*pClip);
601 if (rect.IsEmpty()) { 608 if (rect.IsEmpty()) {
602 return nullptr; 609 return nullptr;
603 } 610 }
604 } 611 }
605 CFX_DIBitmap* pMask = new CFX_DIBitmap; 612 CFX_DIBitmap* pMask = new CFX_DIBitmap;
606 if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask)) { 613 if (!pMask->Create(rect.Width(), rect.Height(), FXDIB_8bppMask)) {
607 delete pMask; 614 delete pMask;
608 return nullptr; 615 return nullptr;
609 } 616 }
610 for (int row = rect.top; row < rect.bottom; row++) { 617 for (int row = rect.top; row < rect.bottom; row++) {
611 const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3; 618 const uint8_t* src_scan = GetScanline(row) + rect.left * 4 + 3;
612 uint8_t* dest_scan = (uint8_t*)pMask->GetScanline(row - rect.top); 619 uint8_t* dest_scan = (uint8_t*)pMask->GetScanline(row - rect.top);
613 for (int col = rect.left; col < rect.right; col++) { 620 for (int col = rect.left; col < rect.right; col++) {
614 *dest_scan++ = *src_scan; 621 *dest_scan++ = *src_scan;
615 src_scan += 4; 622 src_scan += 4;
616 } 623 }
617 } 624 }
618 return pMask; 625 return pMask;
619 } 626 }
627
620 FX_BOOL CFX_DIBSource::CopyAlphaMask(const CFX_DIBSource* pAlphaMask, 628 FX_BOOL CFX_DIBSource::CopyAlphaMask(const CFX_DIBSource* pAlphaMask,
621 const FX_RECT* pClip) { 629 const FX_RECT* pClip) {
622 if (!HasAlpha() || GetFormat() == FXDIB_Argb) { 630 if (!HasAlpha() || GetFormat() == FXDIB_Argb) {
623 return FALSE; 631 return FALSE;
624 } 632 }
625 if (pAlphaMask) { 633 if (pAlphaMask) {
626 FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height); 634 FX_RECT rect(0, 0, pAlphaMask->m_Width, pAlphaMask->m_Height);
627 if (pClip) { 635 if (pClip) {
628 rect.Intersect(*pClip); 636 rect.Intersect(*pClip);
629 if (rect.IsEmpty() || rect.Width() != m_Width || 637 if (rect.IsEmpty() || rect.Width() != m_Width ||
630 rect.Height() != m_Height) { 638 rect.Height() != m_Height) {
631 return FALSE; 639 return FALSE;
632 } 640 }
633 } else { 641 } else {
634 if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height) { 642 if (pAlphaMask->m_Width != m_Width || pAlphaMask->m_Height != m_Height) {
635 return FALSE; 643 return FALSE;
636 } 644 }
637 } 645 }
638 for (int row = 0; row < m_Height; row++) 646 for (int row = 0; row < m_Height; row++)
639 FXSYS_memcpy((void*)m_pAlphaMask->GetScanline(row), 647 FXSYS_memcpy((void*)m_pAlphaMask->GetScanline(row),
640 pAlphaMask->GetScanline(row + rect.top) + rect.left, 648 pAlphaMask->GetScanline(row + rect.top) + rect.left,
641 m_pAlphaMask->m_Pitch); 649 m_pAlphaMask->m_Pitch);
642 } else { 650 } else {
643 m_pAlphaMask->Clear(0xff000000); 651 m_pAlphaMask->Clear(0xff000000);
644 } 652 }
645 return TRUE; 653 return TRUE;
646 } 654 }
655
647 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3}; 656 const int g_ChannelOffset[] = {0, 2, 1, 0, 0, 1, 2, 3, 3};
648 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, 657 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel,
649 const CFX_DIBSource* pSrcBitmap, 658 const CFX_DIBSource* pSrcBitmap,
650 FXDIB_Channel srcChannel) { 659 FXDIB_Channel srcChannel) {
651 if (!m_pBuffer) { 660 if (!m_pBuffer) {
652 return FALSE; 661 return FALSE;
653 } 662 }
654 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap; 663 CFX_DIBSource* pSrcClone = (CFX_DIBSource*)pSrcBitmap;
655 CFX_DIBitmap* pDst = this; 664 CFX_DIBitmap* pDst = this;
656 int destOffset, srcOffset; 665 int destOffset, srcOffset;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 *dest_pos = *src_pos; 789 *dest_pos = *src_pos;
781 dest_pos += destBytes; 790 dest_pos += destBytes;
782 src_pos += srcBytes; 791 src_pos += srcBytes;
783 } 792 }
784 } 793 }
785 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) { 794 if (pSrcClone != pSrcBitmap && pSrcClone != pSrcBitmap->m_pAlphaMask) {
786 delete pSrcClone; 795 delete pSrcClone;
787 } 796 }
788 return TRUE; 797 return TRUE;
789 } 798 }
799
790 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) { 800 FX_BOOL CFX_DIBitmap::LoadChannel(FXDIB_Channel destChannel, int value) {
791 if (!m_pBuffer) { 801 if (!m_pBuffer) {
792 return FALSE; 802 return FALSE;
793 } 803 }
794 int destOffset; 804 int destOffset;
795 if (destChannel == FXDIB_Alpha) { 805 if (destChannel == FXDIB_Alpha) {
796 if (IsAlphaMask()) { 806 if (IsAlphaMask()) {
797 if (!ConvertFormat(FXDIB_8bppMask)) { 807 if (!ConvertFormat(FXDIB_8bppMask)) {
798 return FALSE; 808 return FALSE;
799 } 809 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 } 848 }
839 for (int row = 0; row < m_Height; row++) { 849 for (int row = 0; row < m_Height; row++) {
840 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset; 850 uint8_t* scan_line = m_pBuffer + row * m_Pitch + destOffset;
841 for (int col = 0; col < m_Width; col++) { 851 for (int col = 0; col < m_Width; col++) {
842 *scan_line = value; 852 *scan_line = value;
843 scan_line += Bpp; 853 scan_line += Bpp;
844 } 854 }
845 } 855 }
846 return TRUE; 856 return TRUE;
847 } 857 }
858
848 FX_BOOL CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) { 859 FX_BOOL CFX_DIBitmap::MultiplyAlpha(const CFX_DIBSource* pSrcBitmap) {
849 if (!m_pBuffer) { 860 if (!m_pBuffer) {
850 return FALSE; 861 return FALSE;
851 } 862 }
852 ASSERT(pSrcBitmap->IsAlphaMask()); 863 ASSERT(pSrcBitmap->IsAlphaMask());
853 if (!pSrcBitmap->IsAlphaMask()) { 864 if (!pSrcBitmap->IsAlphaMask()) {
854 return FALSE; 865 return FALSE;
855 } 866 }
856 if (!IsAlphaMask() && !HasAlpha()) { 867 if (!IsAlphaMask() && !HasAlpha()) {
857 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha); 868 return LoadChannel(FXDIB_Alpha, pSrcBitmap, FXDIB_Alpha);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 } 916 }
906 } else { 917 } else {
907 m_pAlphaMask->MultiplyAlpha(pSrcClone); 918 m_pAlphaMask->MultiplyAlpha(pSrcClone);
908 } 919 }
909 } 920 }
910 if (pSrcClone != pSrcBitmap) { 921 if (pSrcClone != pSrcBitmap) {
911 delete pSrcClone; 922 delete pSrcClone;
912 } 923 }
913 return TRUE; 924 return TRUE;
914 } 925 }
926
915 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) { 927 FX_BOOL CFX_DIBitmap::GetGrayData(void* pIccTransform) {
916 if (!m_pBuffer) { 928 if (!m_pBuffer) {
917 return FALSE; 929 return FALSE;
918 } 930 }
919 switch (GetFormat()) { 931 switch (GetFormat()) {
920 case FXDIB_1bppRgb: { 932 case FXDIB_1bppRgb: {
921 if (!m_pPalette) { 933 if (!m_pPalette) {
922 return FALSE; 934 return FALSE;
923 } 935 }
924 uint8_t gray[2]; 936 uint8_t gray[2];
925 for (int i = 0; i < 2; i++) { 937 for (int i = 0; i < 2; i++) {
926 int r = (uint8_t)(m_pPalette[i] >> 16); 938 int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
927 int g = (uint8_t)(m_pPalette[i] >> 8); 939 int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8);
928 int b = (uint8_t)m_pPalette[i]; 940 int b = static_cast<uint8_t>(m_pPalette.get()[i]);
929 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); 941 gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
930 } 942 }
931 CFX_DIBitmap* pMask = new CFX_DIBitmap; 943 CFX_DIBitmap* pMask = new CFX_DIBitmap;
932 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 944 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
933 delete pMask; 945 delete pMask;
934 return FALSE; 946 return FALSE;
935 } 947 }
936 FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height); 948 FXSYS_memset(pMask->GetBuffer(), gray[0], pMask->GetPitch() * m_Height);
937 for (int row = 0; row < m_Height; row++) { 949 for (int row = 0; row < m_Height; row++) {
938 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 950 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
939 uint8_t* dest_pos = (uint8_t*)pMask->GetScanline(row); 951 uint8_t* dest_pos = (uint8_t*)pMask->GetScanline(row);
940 for (int col = 0; col < m_Width; col++) { 952 for (int col = 0; col < m_Width; col++) {
941 if (src_pos[col / 8] & (1 << (7 - col % 8))) { 953 if (src_pos[col / 8] & (1 << (7 - col % 8))) {
942 *dest_pos = gray[1]; 954 *dest_pos = gray[1];
943 } 955 }
944 dest_pos++; 956 dest_pos++;
945 } 957 }
946 } 958 }
947 TakeOver(pMask); 959 TakeOver(pMask);
948 delete pMask; 960 delete pMask;
949 break; 961 break;
950 } 962 }
951 case FXDIB_8bppRgb: { 963 case FXDIB_8bppRgb: {
952 if (!m_pPalette) { 964 if (!m_pPalette) {
953 return FALSE; 965 return FALSE;
954 } 966 }
955 uint8_t gray[256]; 967 uint8_t gray[256];
956 for (int i = 0; i < 256; i++) { 968 for (int i = 0; i < 256; i++) {
957 int r = (uint8_t)(m_pPalette[i] >> 16); 969 int r = static_cast<uint8_t>(m_pPalette.get()[i] >> 16);
958 int g = (uint8_t)(m_pPalette[i] >> 8); 970 int g = static_cast<uint8_t>(m_pPalette.get()[i] >> 8);
959 int b = (uint8_t)m_pPalette[i]; 971 int b = static_cast<uint8_t>(m_pPalette.get()[i]);
960 gray[i] = (uint8_t)FXRGB2GRAY(r, g, b); 972 gray[i] = static_cast<uint8_t>(FXRGB2GRAY(r, g, b));
961 } 973 }
962 CFX_DIBitmap* pMask = new CFX_DIBitmap; 974 CFX_DIBitmap* pMask = new CFX_DIBitmap;
963 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) { 975 if (!pMask->Create(m_Width, m_Height, FXDIB_8bppMask)) {
964 delete pMask; 976 delete pMask;
965 return FALSE; 977 return FALSE;
966 } 978 }
967 for (int row = 0; row < m_Height; row++) { 979 for (int row = 0; row < m_Height; row++) {
968 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch(); 980 uint8_t* dest_pos = pMask->GetBuffer() + row * pMask->GetPitch();
969 uint8_t* src_pos = m_pBuffer + row * m_Pitch; 981 uint8_t* src_pos = m_pBuffer + row * m_Pitch;
970 for (int col = 0; col < m_Width; col++) { 982 for (int col = 0; col < m_Width; col++) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 } 1021 }
1010 TakeOver(pMask); 1022 TakeOver(pMask);
1011 delete pMask; 1023 delete pMask;
1012 break; 1024 break;
1013 } 1025 }
1014 default: 1026 default:
1015 return FALSE; 1027 return FALSE;
1016 } 1028 }
1017 return TRUE; 1029 return TRUE;
1018 } 1030 }
1031
1019 FX_BOOL CFX_DIBitmap::MultiplyAlpha(int alpha) { 1032 FX_BOOL CFX_DIBitmap::MultiplyAlpha(int alpha) {
1020 if (!m_pBuffer) { 1033 if (!m_pBuffer) {
1021 return FALSE; 1034 return FALSE;
1022 } 1035 }
1023 switch (GetFormat()) { 1036 switch (GetFormat()) {
1024 case FXDIB_1bppMask: 1037 case FXDIB_1bppMask:
1025 if (!ConvertFormat(FXDIB_8bppMask)) { 1038 if (!ConvertFormat(FXDIB_8bppMask)) {
1026 return FALSE; 1039 return FALSE;
1027 } 1040 }
1028 MultiplyAlpha(alpha); 1041 MultiplyAlpha(alpha);
(...skipping 28 matching lines...) Expand all
1057 } else { 1070 } else {
1058 if (!ConvertFormat(FXDIB_Argb)) { 1071 if (!ConvertFormat(FXDIB_Argb)) {
1059 return FALSE; 1072 return FALSE;
1060 } 1073 }
1061 MultiplyAlpha(alpha); 1074 MultiplyAlpha(alpha);
1062 } 1075 }
1063 break; 1076 break;
1064 } 1077 }
1065 return TRUE; 1078 return TRUE;
1066 } 1079 }
1080
1067 uint32_t CFX_DIBitmap::GetPixel(int x, int y) const { 1081 uint32_t CFX_DIBitmap::GetPixel(int x, int y) const {
1068 if (!m_pBuffer) { 1082 if (!m_pBuffer) {
1069 return 0; 1083 return 0;
1070 } 1084 }
1071 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; 1085 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
1072 switch (GetFormat()) { 1086 switch (GetFormat()) {
1073 case FXDIB_1bppMask: { 1087 case FXDIB_1bppMask: {
1074 if ((*pos) & (1 << (7 - x % 8))) { 1088 if ((*pos) & (1 << (7 - x % 8))) {
1075 return 0xff000000; 1089 return 0xff000000;
1076 } 1090 }
1077 return 0; 1091 return 0;
1078 } 1092 }
1079 case FXDIB_1bppRgb: { 1093 case FXDIB_1bppRgb: {
1080 if ((*pos) & (1 << (7 - x % 8))) { 1094 if ((*pos) & (1 << (7 - x % 8))) {
1081 return m_pPalette ? m_pPalette[1] : 0xffffffff; 1095 return m_pPalette ? m_pPalette.get()[1] : 0xffffffff;
1082 } 1096 }
1083 return m_pPalette ? m_pPalette[0] : 0xff000000; 1097 return m_pPalette ? m_pPalette.get()[0] : 0xff000000;
1084 } 1098 }
1085 case FXDIB_8bppMask: 1099 case FXDIB_8bppMask:
1086 return (*pos) << 24; 1100 return (*pos) << 24;
1087 case FXDIB_8bppRgb: 1101 case FXDIB_8bppRgb:
1088 return m_pPalette ? m_pPalette[*pos] : (0xff000000 | ((*pos) * 0x10101)); 1102 return m_pPalette ? m_pPalette.get()[*pos]
1103 : (0xff000000 | ((*pos) * 0x10101));
1089 case FXDIB_Rgb: 1104 case FXDIB_Rgb:
1090 case FXDIB_Rgba: 1105 case FXDIB_Rgba:
1091 case FXDIB_Rgb32: 1106 case FXDIB_Rgb32:
1092 return FXARGB_GETDIB(pos) | 0xff000000; 1107 return FXARGB_GETDIB(pos) | 0xff000000;
1093 case FXDIB_Argb: 1108 case FXDIB_Argb:
1094 return FXARGB_GETDIB(pos); 1109 return FXARGB_GETDIB(pos);
1095 default: 1110 default:
1096 break; 1111 break;
1097 } 1112 }
1098 return 0; 1113 return 0;
1099 } 1114 }
1115
1100 void CFX_DIBitmap::SetPixel(int x, int y, uint32_t color) { 1116 void CFX_DIBitmap::SetPixel(int x, int y, uint32_t color) {
1101 if (!m_pBuffer) { 1117 if (!m_pBuffer) {
1102 return; 1118 return;
1103 } 1119 }
1104 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) { 1120 if (x < 0 || x >= m_Width || y < 0 || y >= m_Height) {
1105 return; 1121 return;
1106 } 1122 }
1107 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8; 1123 uint8_t* pos = m_pBuffer + y * m_Pitch + x * GetBPP() / 8;
1108 switch (GetFormat()) { 1124 switch (GetFormat()) {
1109 case FXDIB_1bppMask: 1125 case FXDIB_1bppMask:
1110 if (color >> 24) { 1126 if (color >> 24) {
1111 *pos |= 1 << (7 - x % 8); 1127 *pos |= 1 << (7 - x % 8);
1112 } else { 1128 } else {
1113 *pos &= ~(1 << (7 - x % 8)); 1129 *pos &= ~(1 << (7 - x % 8));
1114 } 1130 }
1115 break; 1131 break;
1116 case FXDIB_1bppRgb: 1132 case FXDIB_1bppRgb:
1117 if (m_pPalette) { 1133 if (m_pPalette) {
1118 if (color == m_pPalette[1]) { 1134 if (color == m_pPalette.get()[1]) {
1119 *pos |= 1 << (7 - x % 8); 1135 *pos |= 1 << (7 - x % 8);
1120 } else { 1136 } else {
1121 *pos &= ~(1 << (7 - x % 8)); 1137 *pos &= ~(1 << (7 - x % 8));
1122 } 1138 }
1123 } else { 1139 } else {
1124 if (color == 0xffffffff) { 1140 if (color == 0xffffffff) {
1125 *pos |= 1 << (7 - x % 8); 1141 *pos |= 1 << (7 - x % 8);
1126 } else { 1142 } else {
1127 *pos &= ~(1 << (7 - x % 8)); 1143 *pos &= ~(1 << (7 - x % 8));
1128 } 1144 }
1129 } 1145 }
1130 break; 1146 break;
1131 case FXDIB_8bppMask: 1147 case FXDIB_8bppMask:
1132 *pos = (uint8_t)(color >> 24); 1148 *pos = (uint8_t)(color >> 24);
1133 break; 1149 break;
1134 case FXDIB_8bppRgb: { 1150 case FXDIB_8bppRgb: {
1135 if (m_pPalette) { 1151 if (m_pPalette) {
1136 for (int i = 0; i < 256; i++) { 1152 for (int i = 0; i < 256; i++) {
1137 if (m_pPalette[i] == color) { 1153 if (m_pPalette.get()[i] == color) {
1138 *pos = (uint8_t)i; 1154 *pos = (uint8_t)i;
1139 return; 1155 return;
1140 } 1156 }
1141 } 1157 }
1142 *pos = 0; 1158 *pos = 0;
1143 } else { 1159 } else {
1144 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color)); 1160 *pos = FXRGB2GRAY(FXARGB_R(color), FXARGB_G(color), FXARGB_B(color));
1145 } 1161 }
1146 break; 1162 break;
1147 } 1163 }
(...skipping 11 matching lines...) Expand all
1159 pos[2] = FXARGB_R(color); 1175 pos[2] = FXARGB_R(color);
1160 break; 1176 break;
1161 } 1177 }
1162 case FXDIB_Argb: 1178 case FXDIB_Argb:
1163 FXARGB_SETDIB(pos, color); 1179 FXARGB_SETDIB(pos, color);
1164 break; 1180 break;
1165 default: 1181 default:
1166 break; 1182 break;
1167 } 1183 }
1168 } 1184 }
1185
1169 void CFX_DIBitmap::DownSampleScanline(int line, 1186 void CFX_DIBitmap::DownSampleScanline(int line,
1170 uint8_t* dest_scan, 1187 uint8_t* dest_scan,
1171 int dest_bpp, 1188 int dest_bpp,
1172 int dest_width, 1189 int dest_width,
1173 FX_BOOL bFlipX, 1190 FX_BOOL bFlipX,
1174 int clip_left, 1191 int clip_left,
1175 int clip_width) const { 1192 int clip_width) const {
1176 if (!m_pBuffer) { 1193 if (!m_pBuffer) {
1177 return; 1194 return;
1178 } 1195 }
(...skipping 14 matching lines...) Expand all
1193 uint32_t dest_x = clip_left + i; 1210 uint32_t dest_x = clip_left + i;
1194 uint32_t src_x = dest_x * m_Width / dest_width; 1211 uint32_t src_x = dest_x * m_Width / dest_width;
1195 if (bFlipX) { 1212 if (bFlipX) {
1196 src_x = m_Width - src_x - 1; 1213 src_x = m_Width - src_x - 1;
1197 } 1214 }
1198 src_x %= m_Width; 1215 src_x %= m_Width;
1199 int dest_pos = i; 1216 int dest_pos = i;
1200 if (m_pPalette) { 1217 if (m_pPalette) {
1201 if (!IsCmykImage()) { 1218 if (!IsCmykImage()) {
1202 dest_pos *= 3; 1219 dest_pos *= 3;
1203 FX_ARGB argb = m_pPalette[scanline[src_x]]; 1220 FX_ARGB argb = m_pPalette.get()[scanline[src_x]];
1204 dest_scan[dest_pos] = FXARGB_B(argb); 1221 dest_scan[dest_pos] = FXARGB_B(argb);
1205 dest_scan[dest_pos + 1] = FXARGB_G(argb); 1222 dest_scan[dest_pos + 1] = FXARGB_G(argb);
1206 dest_scan[dest_pos + 2] = FXARGB_R(argb); 1223 dest_scan[dest_pos + 2] = FXARGB_R(argb);
1207 } else { 1224 } else {
1208 dest_pos *= 4; 1225 dest_pos *= 4;
1209 FX_CMYK cmyk = m_pPalette[scanline[src_x]]; 1226 FX_CMYK cmyk = m_pPalette.get()[scanline[src_x]];
1210 dest_scan[dest_pos] = FXSYS_GetCValue(cmyk); 1227 dest_scan[dest_pos] = FXSYS_GetCValue(cmyk);
1211 dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk); 1228 dest_scan[dest_pos + 1] = FXSYS_GetMValue(cmyk);
1212 dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk); 1229 dest_scan[dest_pos + 2] = FXSYS_GetYValue(cmyk);
1213 dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk); 1230 dest_scan[dest_pos + 3] = FXSYS_GetKValue(cmyk);
1214 } 1231 }
1215 } else { 1232 } else {
1216 dest_scan[dest_pos] = scanline[src_x]; 1233 dest_scan[dest_pos] = scanline[src_x];
1217 } 1234 }
1218 } 1235 }
1219 } else { 1236 } else {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) { 1298 } else if (forecolor == 0 && backcolor == 0xffffff && !m_pPalette) {
1282 return TRUE; 1299 return TRUE;
1283 } 1300 }
1284 if (!m_pPalette) { 1301 if (!m_pPalette) {
1285 BuildPalette(); 1302 BuildPalette();
1286 } 1303 }
1287 int size = 1 << m_bpp; 1304 int size = 1 << m_bpp;
1288 if (isCmykImage) { 1305 if (isCmykImage) {
1289 for (int i = 0; i < size; i++) { 1306 for (int i = 0; i < size; i++) {
1290 uint8_t b, g, r; 1307 uint8_t b, g, r;
1291 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette[i]), 1308 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(m_pPalette.get()[i]),
1292 FXSYS_GetMValue(m_pPalette[i]), 1309 FXSYS_GetMValue(m_pPalette.get()[i]),
1293 FXSYS_GetYValue(m_pPalette[i]), 1310 FXSYS_GetYValue(m_pPalette.get()[i]),
1294 FXSYS_GetKValue(m_pPalette[i]), r, g, b); 1311 FXSYS_GetKValue(m_pPalette.get()[i]), r, g, b);
1295 int gray = 255 - FXRGB2GRAY(r, g, b); 1312 int gray = 255 - FXRGB2GRAY(r, g, b);
1296 m_pPalette[i] = CmykEncode( 1313 m_pPalette.get()[i] = CmykEncode(
1297 bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255, 1314 bc + (fc - bc) * gray / 255, bm + (fm - bm) * gray / 255,
1298 by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255); 1315 by + (fy - by) * gray / 255, bk + (fk - bk) * gray / 255);
1299 } 1316 }
1300 } else { 1317 } else {
1301 for (int i = 0; i < size; i++) { 1318 for (int i = 0; i < size; i++) {
1302 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette[i]), FXARGB_G(m_pPalette[i]), 1319 int gray = FXRGB2GRAY(FXARGB_R(m_pPalette.get()[i]),
1303 FXARGB_B(m_pPalette[i])); 1320 FXARGB_G(m_pPalette.get()[i]),
1304 m_pPalette[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255, 1321 FXARGB_B(m_pPalette.get()[i]));
1305 bg + (fg - bg) * gray / 255, 1322 m_pPalette.get()[i] = FXARGB_MAKE(0xff, br + (fr - br) * gray / 255,
1306 bb + (fb - bb) * gray / 255); 1323 bg + (fg - bg) * gray / 255,
1324 bb + (fb - bb) * gray / 255);
1307 } 1325 }
1308 } 1326 }
1309 return TRUE; 1327 return TRUE;
1310 } 1328 }
1311 if (isCmykImage) { 1329 if (isCmykImage) {
1312 if (forecolor == 0xff && backcolor == 0x00) { 1330 if (forecolor == 0xff && backcolor == 0x00) {
1313 for (int row = 0; row < m_Height; row++) { 1331 for (int row = 0; row < m_Height; row++) {
1314 uint8_t* scanline = m_pBuffer + row * m_Pitch; 1332 uint8_t* scanline = m_pBuffer + row * m_Pitch;
1315 for (int col = 0; col < m_Width; col++) { 1333 for (int col = 0; col < m_Width; col++) {
1316 uint8_t b, g, r; 1334 uint8_t b, g, r;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 } 1385 }
1368 return TRUE; 1386 return TRUE;
1369 } 1387 }
1370 1388
1371 CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const { 1389 CFX_DIBitmap* CFX_DIBSource::FlipImage(FX_BOOL bXFlip, FX_BOOL bYFlip) const {
1372 CFX_DIBitmap* pFlipped = new CFX_DIBitmap; 1390 CFX_DIBitmap* pFlipped = new CFX_DIBitmap;
1373 if (!pFlipped->Create(m_Width, m_Height, GetFormat())) { 1391 if (!pFlipped->Create(m_Width, m_Height, GetFormat())) {
1374 delete pFlipped; 1392 delete pFlipped;
1375 return nullptr; 1393 return nullptr;
1376 } 1394 }
1377 pFlipped->CopyPalette(m_pPalette); 1395 pFlipped->CopyPalette(m_pPalette.get());
1378 uint8_t* pDestBuffer = pFlipped->GetBuffer(); 1396 uint8_t* pDestBuffer = pFlipped->GetBuffer();
1379 int Bpp = m_bpp / 8; 1397 int Bpp = m_bpp / 8;
1380 for (int row = 0; row < m_Height; row++) { 1398 for (int row = 0; row < m_Height; row++) {
1381 const uint8_t* src_scan = GetScanline(row); 1399 const uint8_t* src_scan = GetScanline(row);
1382 uint8_t* dest_scan = 1400 uint8_t* dest_scan =
1383 pDestBuffer + m_Pitch * (bYFlip ? (m_Height - row - 1) : row); 1401 pDestBuffer + m_Pitch * (bYFlip ? (m_Height - row - 1) : row);
1384 if (!bXFlip) { 1402 if (!bXFlip) {
1385 FXSYS_memcpy(dest_scan, src_scan, m_Pitch); 1403 FXSYS_memcpy(dest_scan, src_scan, m_Pitch);
1386 continue; 1404 continue;
1387 } 1405 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 dest_scan += (m_Width - 1); 1450 dest_scan += (m_Width - 1);
1433 for (int col = 0; col < m_Width; col++) { 1451 for (int col = 0; col < m_Width; col++) {
1434 *dest_scan = *src_scan; 1452 *dest_scan = *src_scan;
1435 dest_scan--; 1453 dest_scan--;
1436 src_scan++; 1454 src_scan++;
1437 } 1455 }
1438 } 1456 }
1439 } 1457 }
1440 return pFlipped; 1458 return pFlipped;
1441 } 1459 }
1460
1442 CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { 1461 CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) {
1443 m_pBitmap = nullptr; 1462 m_pBitmap = nullptr;
1444 if (pSrc->GetBuffer()) { 1463 if (pSrc->GetBuffer()) {
1445 m_pBitmap = new CFX_DIBitmap; 1464 m_pBitmap = new CFX_DIBitmap;
1446 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), 1465 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(),
1447 pSrc->GetFormat(), pSrc->GetBuffer())) { 1466 pSrc->GetFormat(), pSrc->GetBuffer())) {
1448 delete m_pBitmap; 1467 delete m_pBitmap;
1449 m_pBitmap = nullptr; 1468 m_pBitmap = nullptr;
1450 return; 1469 return;
1451 } 1470 }
1452 m_pBitmap->CopyPalette(pSrc->GetPalette()); 1471 m_pBitmap->CopyPalette(pSrc->GetPalette());
1453 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); 1472 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask);
1454 } else { 1473 } else {
1455 m_pBitmap = pSrc->Clone(); 1474 m_pBitmap = pSrc->Clone();
1456 } 1475 }
1457 } 1476 }
1477
1458 CFX_DIBExtractor::~CFX_DIBExtractor() { 1478 CFX_DIBExtractor::~CFX_DIBExtractor() {
1459 delete m_pBitmap; 1479 delete m_pBitmap;
1460 } 1480 }
1481
1461 CFX_FilteredDIB::CFX_FilteredDIB() { 1482 CFX_FilteredDIB::CFX_FilteredDIB() {
1462 m_pScanline = nullptr; 1483 m_pScanline = nullptr;
1463 m_pSrc = nullptr; 1484 m_pSrc = nullptr;
1464 } 1485 }
1486
1465 CFX_FilteredDIB::~CFX_FilteredDIB() { 1487 CFX_FilteredDIB::~CFX_FilteredDIB() {
1466 if (m_bAutoDropSrc) { 1488 if (m_bAutoDropSrc) {
1467 delete m_pSrc; 1489 delete m_pSrc;
1468 } 1490 }
1469 FX_Free(m_pScanline); 1491 FX_Free(m_pScanline);
1470 } 1492 }
1493
1471 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { 1494 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) {
1472 m_pSrc = pSrc; 1495 m_pSrc = pSrc;
1473 m_bAutoDropSrc = bAutoDropSrc; 1496 m_bAutoDropSrc = bAutoDropSrc;
1474 m_Width = pSrc->GetWidth(); 1497 m_Width = pSrc->GetWidth();
1475 m_Height = pSrc->GetHeight(); 1498 m_Height = pSrc->GetHeight();
1476 FXDIB_Format format = GetDestFormat(); 1499 FXDIB_Format format = GetDestFormat();
1477 m_bpp = (uint8_t)format; 1500 m_bpp = (uint8_t)format;
1478 m_AlphaFlag = (uint8_t)(format >> 8); 1501 m_AlphaFlag = (uint8_t)(format >> 8);
1479 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; 1502 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4;
1480 m_pPalette = GetDestPalette(); 1503 m_pPalette.reset(GetDestPalette());
1481 m_pScanline = FX_Alloc(uint8_t, m_Pitch); 1504 m_pScanline = FX_Alloc(uint8_t, m_Pitch);
1482 } 1505 }
1506
1483 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const { 1507 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const {
1484 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); 1508 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line));
1485 return m_pScanline; 1509 return m_pScanline;
1486 } 1510 }
1511
1487 void CFX_FilteredDIB::DownSampleScanline(int line, 1512 void CFX_FilteredDIB::DownSampleScanline(int line,
1488 uint8_t* dest_scan, 1513 uint8_t* dest_scan,
1489 int dest_bpp, 1514 int dest_bpp,
1490 int dest_width, 1515 int dest_width,
1491 FX_BOOL bFlipX, 1516 FX_BOOL bFlipX,
1492 int clip_left, 1517 int clip_left,
1493 int clip_width) const { 1518 int clip_width) const {
1494 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, 1519 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX,
1495 clip_left, clip_width); 1520 clip_left, clip_width);
1496 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp); 1521 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp);
1497 } 1522 }
1523
1498 CFX_ImageRenderer::CFX_ImageRenderer() { 1524 CFX_ImageRenderer::CFX_ImageRenderer() {
1499 m_Status = 0; 1525 m_Status = 0;
1500 m_pTransformer = nullptr; 1526 m_pTransformer = nullptr;
1501 m_bRgbByteOrder = FALSE; 1527 m_bRgbByteOrder = FALSE;
1502 m_BlendType = FXDIB_BLEND_NORMAL; 1528 m_BlendType = FXDIB_BLEND_NORMAL;
1503 } 1529 }
1530
1504 CFX_ImageRenderer::~CFX_ImageRenderer() { 1531 CFX_ImageRenderer::~CFX_ImageRenderer() {
1505 delete m_pTransformer; 1532 delete m_pTransformer;
1506 } 1533 }
1507 1534
1508 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, 1535 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice,
1509 const CFX_ClipRgn* pClipRgn, 1536 const CFX_ClipRgn* pClipRgn,
1510 const CFX_DIBSource* pSource, 1537 const CFX_DIBSource* pSource,
1511 int bitmap_alpha, 1538 int bitmap_alpha,
1512 uint32_t mask_color, 1539 uint32_t mask_color,
1513 const CFX_Matrix* pMatrix, 1540 const CFX_Matrix* pMatrix,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 ? const_cast<uint8_t*>(m_pBitmap->m_pAlphaMask->GetScanline(line)) 1678 ? const_cast<uint8_t*>(m_pBitmap->m_pAlphaMask->GetScanline(line))
1652 : nullptr; 1679 : nullptr;
1653 if (dest_buf) 1680 if (dest_buf)
1654 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch()); 1681 FXSYS_memcpy(dest_buf, scanline, m_pBitmap->GetPitch());
1655 1682
1656 if (dest_alpha_buf) { 1683 if (dest_alpha_buf) {
1657 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha, 1684 FXSYS_memcpy(dest_alpha_buf, scan_extra_alpha,
1658 m_pBitmap->m_pAlphaMask->GetPitch()); 1685 m_pBitmap->m_pAlphaMask->GetPitch());
1659 } 1686 }
1660 } 1687 }
1688
1661 FX_BOOL CFX_BitmapStorer::SetInfo(int width, 1689 FX_BOOL CFX_BitmapStorer::SetInfo(int width,
1662 int height, 1690 int height,
1663 FXDIB_Format src_format, 1691 FXDIB_Format src_format,
1664 uint32_t* pSrcPalette) { 1692 uint32_t* pSrcPalette) {
1665 m_pBitmap.reset(new CFX_DIBitmap); 1693 m_pBitmap.reset(new CFX_DIBitmap);
1666 if (!m_pBitmap->Create(width, height, src_format)) { 1694 if (!m_pBitmap->Create(width, height, src_format)) {
1667 m_pBitmap.reset(); 1695 m_pBitmap.reset();
1668 return FALSE; 1696 return FALSE;
1669 } 1697 }
1670 if (pSrcPalette) 1698 if (pSrcPalette)
1671 m_pBitmap->CopyPalette(pSrcPalette); 1699 m_pBitmap->CopyPalette(pSrcPalette);
1672 return TRUE; 1700 return TRUE;
1673 } 1701 }
OLDNEW
« no previous file with comments | « core/fxge/dib/fx_dib_convert.cpp ('k') | core/fxge/dib/fx_dib_transform.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698