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

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

Issue 2477443002: Remove FX_BOOL from core (Closed)
Patch Set: Created 4 years, 1 month 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_composite.cpp ('k') | core/fxge/dib/fx_dib_engine.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/fxcodec/fx_codec.h" 7 #include "core/fxcodec/fx_codec.h"
8 #include "core/fxge/fx_dib.h" 8 #include "core/fxge/fx_dib.h"
9 9
10 class CFX_Palette { 10 class CFX_Palette {
11 public: 11 public:
12 CFX_Palette(); 12 CFX_Palette();
13 ~CFX_Palette(); 13 ~CFX_Palette();
14 14
15 FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap); 15 bool BuildPalette(const CFX_DIBSource* pBitmap);
16 uint32_t* GetPalette() const { return m_pPalette; } 16 uint32_t* GetPalette() const { return m_pPalette; }
17 uint32_t* GetColorLut() const { return m_cLut; } 17 uint32_t* GetColorLut() const { return m_cLut; }
18 uint32_t* GetAmountLut() const { return m_aLut; } 18 uint32_t* GetAmountLut() const { return m_aLut; }
19 int32_t Getlut() const { return m_lut; } 19 int32_t Getlut() const { return m_lut; }
20 20
21 protected: 21 protected:
22 uint32_t* m_pPalette; 22 uint32_t* m_pPalette;
23 uint32_t* m_cLut; 23 uint32_t* m_cLut;
24 uint32_t* m_aLut; 24 uint32_t* m_aLut;
25 int m_lut; 25 int m_lut;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 m_lut = 0; 89 m_lut = 0;
90 } 90 }
91 91
92 CFX_Palette::~CFX_Palette() { 92 CFX_Palette::~CFX_Palette() {
93 FX_Free(m_pPalette); 93 FX_Free(m_pPalette);
94 FX_Free(m_cLut); 94 FX_Free(m_cLut);
95 FX_Free(m_aLut); 95 FX_Free(m_aLut);
96 m_lut = 0; 96 m_lut = 0;
97 } 97 }
98 98
99 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) { 99 bool CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap) {
100 if (!pBitmap) { 100 if (!pBitmap) {
101 return FALSE; 101 return false;
102 } 102 }
103 FX_Free(m_pPalette); 103 FX_Free(m_pPalette);
104 m_pPalette = FX_Alloc(uint32_t, 256); 104 m_pPalette = FX_Alloc(uint32_t, 256);
105 int bpp = pBitmap->GetBPP() / 8; 105 int bpp = pBitmap->GetBPP() / 8;
106 int width = pBitmap->GetWidth(); 106 int width = pBitmap->GetWidth();
107 int height = pBitmap->GetHeight(); 107 int height = pBitmap->GetHeight();
108 FX_Free(m_cLut); 108 FX_Free(m_cLut);
109 m_cLut = nullptr; 109 m_cLut = nullptr;
110 FX_Free(m_aLut); 110 FX_Free(m_aLut);
111 m_aLut = nullptr; 111 m_aLut = nullptr;
(...skipping 14 matching lines...) Expand all
126 } 126 }
127 for (row = 0; row < 4096; row++) { 127 for (row = 0; row < 4096; row++) {
128 if (m_aLut[row] != 0) { 128 if (m_aLut[row] != 0) {
129 m_aLut[m_lut] = m_aLut[row]; 129 m_aLut[m_lut] = m_aLut[row];
130 m_cLut[m_lut] = row; 130 m_cLut[m_lut] = row;
131 m_lut++; 131 m_lut++;
132 } 132 }
133 } 133 }
134 _Qsort(m_aLut, m_cLut, 0, m_lut - 1); 134 _Qsort(m_aLut, m_cLut, 0, m_lut - 1);
135 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, m_lut); 135 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, m_lut);
136 return TRUE; 136 return true;
137 } 137 }
138 138
139 FX_BOOL ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf, 139 bool ConvertBuffer_1bppMask2Gray(uint8_t* dest_buf,
140 int dest_pitch, 140 int dest_pitch,
141 int width, 141 int width,
142 int height, 142 int height,
143 const CFX_DIBSource* pSrcBitmap, 143 const CFX_DIBSource* pSrcBitmap,
144 int src_left, 144 int src_left,
145 int src_top) { 145 int src_top) {
146 uint8_t set_gray, reset_gray; 146 uint8_t set_gray, reset_gray;
147 set_gray = 0xff; 147 set_gray = 0xff;
148 reset_gray = 0x00; 148 reset_gray = 0x00;
149 for (int row = 0; row < height; row++) { 149 for (int row = 0; row < height; row++) {
150 uint8_t* dest_scan = dest_buf + row * dest_pitch; 150 uint8_t* dest_scan = dest_buf + row * dest_pitch;
151 FXSYS_memset(dest_scan, reset_gray, width); 151 FXSYS_memset(dest_scan, reset_gray, width);
152 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 152 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
153 for (int col = src_left; col < src_left + width; col++) { 153 for (int col = src_left; col < src_left + width; col++) {
154 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 154 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
155 *dest_scan = set_gray; 155 *dest_scan = set_gray;
156 } 156 }
157 dest_scan++; 157 dest_scan++;
158 } 158 }
159 } 159 }
160 return TRUE; 160 return true;
161 } 161 }
162 162
163 FX_BOOL ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf, 163 bool ConvertBuffer_8bppMask2Gray(uint8_t* dest_buf,
164 int dest_pitch, 164 int dest_pitch,
165 int width, 165 int width,
166 int height, 166 int height,
167 const CFX_DIBSource* pSrcBitmap, 167 const CFX_DIBSource* pSrcBitmap,
168 int src_left, 168 int src_left,
169 int src_top) { 169 int src_top) {
170 for (int row = 0; row < height; row++) { 170 for (int row = 0; row < height; row++) {
171 uint8_t* dest_scan = dest_buf + row * dest_pitch; 171 uint8_t* dest_scan = dest_buf + row * dest_pitch;
172 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; 172 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
173 FXSYS_memcpy(dest_scan, src_scan, width); 173 FXSYS_memcpy(dest_scan, src_scan, width);
174 } 174 }
175 return TRUE; 175 return true;
176 } 176 }
177 177
178 FX_BOOL ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf, 178 bool ConvertBuffer_1bppPlt2Gray(uint8_t* dest_buf,
179 int dest_pitch, 179 int dest_pitch,
180 int width, 180 int width,
181 int height, 181 int height,
182 const CFX_DIBSource* pSrcBitmap, 182 const CFX_DIBSource* pSrcBitmap,
183 int src_left, 183 int src_left,
184 int src_top) { 184 int src_top) {
185 uint32_t* src_plt = pSrcBitmap->GetPalette(); 185 uint32_t* src_plt = pSrcBitmap->GetPalette();
186 uint8_t gray[2]; 186 uint8_t gray[2];
187 uint8_t reset_r; 187 uint8_t reset_r;
188 uint8_t reset_g; 188 uint8_t reset_g;
189 uint8_t reset_b; 189 uint8_t reset_b;
190 uint8_t set_r; 190 uint8_t set_r;
191 uint8_t set_g; 191 uint8_t set_g;
192 uint8_t set_b; 192 uint8_t set_b;
193 if (pSrcBitmap->IsCmykImage()) { 193 if (pSrcBitmap->IsCmykImage()) {
194 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]), 194 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_plt[0]),
(...skipping 17 matching lines...) Expand all
212 uint8_t* dest_scan = dest_buf + row * dest_pitch; 212 uint8_t* dest_scan = dest_buf + row * dest_pitch;
213 FXSYS_memset(dest_scan, gray[0], width); 213 FXSYS_memset(dest_scan, gray[0], width);
214 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 214 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
215 for (int col = src_left; col < src_left + width; col++) { 215 for (int col = src_left; col < src_left + width; col++) {
216 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 216 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
217 *dest_scan = gray[1]; 217 *dest_scan = gray[1];
218 } 218 }
219 dest_scan++; 219 dest_scan++;
220 } 220 }
221 } 221 }
222 return TRUE; 222 return true;
223 } 223 }
224 224
225 FX_BOOL ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf, 225 bool ConvertBuffer_8bppPlt2Gray(uint8_t* dest_buf,
226 int dest_pitch, 226 int dest_pitch,
227 int width, 227 int width,
228 int height, 228 int height,
229 const CFX_DIBSource* pSrcBitmap, 229 const CFX_DIBSource* pSrcBitmap,
230 int src_left, 230 int src_left,
231 int src_top) { 231 int src_top) {
232 uint32_t* src_plt = pSrcBitmap->GetPalette(); 232 uint32_t* src_plt = pSrcBitmap->GetPalette();
233 uint8_t gray[256]; 233 uint8_t gray[256];
234 if (pSrcBitmap->IsCmykImage()) { 234 if (pSrcBitmap->IsCmykImage()) {
235 uint8_t r; 235 uint8_t r;
236 uint8_t g; 236 uint8_t g;
237 uint8_t b; 237 uint8_t b;
238 for (size_t i = 0; i < FX_ArraySize(gray); i++) { 238 for (size_t i = 0; i < FX_ArraySize(gray); i++) {
239 AdobeCMYK_to_sRGB1( 239 AdobeCMYK_to_sRGB1(
240 FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), 240 FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
241 FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b); 241 FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
242 gray[i] = FXRGB2GRAY(r, g, b); 242 gray[i] = FXRGB2GRAY(r, g, b);
243 } 243 }
244 } else { 244 } else {
245 for (size_t i = 0; i < FX_ArraySize(gray); i++) { 245 for (size_t i = 0; i < FX_ArraySize(gray); i++) {
246 gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]), 246 gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]),
247 FXARGB_B(src_plt[i])); 247 FXARGB_B(src_plt[i]));
248 } 248 }
249 } 249 }
250 250
251 for (int row = 0; row < height; row++) { 251 for (int row = 0; row < height; row++) {
252 uint8_t* dest_scan = dest_buf + row * dest_pitch; 252 uint8_t* dest_scan = dest_buf + row * dest_pitch;
253 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; 253 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
254 for (int col = 0; col < width; col++) { 254 for (int col = 0; col < width; col++) {
255 *dest_scan++ = gray[*src_scan++]; 255 *dest_scan++ = gray[*src_scan++];
256 } 256 }
257 } 257 }
258 return TRUE; 258 return true;
259 } 259 }
260 260
261 FX_BOOL ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf, 261 bool ConvertBuffer_RgbOrCmyk2Gray(uint8_t* dest_buf,
262 int dest_pitch, 262 int dest_pitch,
263 int width, 263 int width,
264 int height, 264 int height,
265 const CFX_DIBSource* pSrcBitmap, 265 const CFX_DIBSource* pSrcBitmap,
266 int src_left, 266 int src_left,
267 int src_top) { 267 int src_top) {
268 int Bpp = pSrcBitmap->GetBPP() / 8; 268 int Bpp = pSrcBitmap->GetBPP() / 8;
269 if (pSrcBitmap->IsCmykImage()) { 269 if (pSrcBitmap->IsCmykImage()) {
270 for (int row = 0; row < height; row++) { 270 for (int row = 0; row < height; row++) {
271 uint8_t* dest_scan = dest_buf + row * dest_pitch; 271 uint8_t* dest_scan = dest_buf + row * dest_pitch;
272 const uint8_t* src_scan = 272 const uint8_t* src_scan =
273 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; 273 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
274 for (int col = 0; col < width; col++) { 274 for (int col = 0; col < width; col++) {
275 uint8_t r, g, b; 275 uint8_t r, g, b;
276 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((uint32_t)src_scan[0]), 276 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((uint32_t)src_scan[0]),
277 FXSYS_GetMValue((uint32_t)src_scan[1]), 277 FXSYS_GetMValue((uint32_t)src_scan[1]),
278 FXSYS_GetYValue((uint32_t)src_scan[2]), 278 FXSYS_GetYValue((uint32_t)src_scan[2]),
279 FXSYS_GetKValue((uint32_t)src_scan[3]), r, g, b); 279 FXSYS_GetKValue((uint32_t)src_scan[3]), r, g, b);
280 *dest_scan++ = FXRGB2GRAY(r, g, b); 280 *dest_scan++ = FXRGB2GRAY(r, g, b);
281 src_scan += 4; 281 src_scan += 4;
282 } 282 }
283 } 283 }
284 } else { 284 } else {
285 for (int row = 0; row < height; row++) { 285 for (int row = 0; row < height; row++) {
286 uint8_t* dest_scan = dest_buf + row * dest_pitch; 286 uint8_t* dest_scan = dest_buf + row * dest_pitch;
287 const uint8_t* src_scan = 287 const uint8_t* src_scan =
288 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; 288 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp;
289 for (int col = 0; col < width; col++) { 289 for (int col = 0; col < width; col++) {
290 *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]); 290 *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]);
291 src_scan += Bpp; 291 src_scan += Bpp;
292 } 292 }
293 } 293 }
294 } 294 }
295 return TRUE; 295 return true;
296 } 296 }
297 297
298 void ConvertBuffer_IndexCopy(uint8_t* dest_buf, 298 void ConvertBuffer_IndexCopy(uint8_t* dest_buf,
299 int dest_pitch, 299 int dest_pitch,
300 int width, 300 int width,
301 int height, 301 int height,
302 const CFX_DIBSource* pSrcBitmap, 302 const CFX_DIBSource* pSrcBitmap,
303 int src_left, 303 int src_left,
304 int src_top) { 304 int src_top) {
305 if (pSrcBitmap->GetBPP() == 1) { 305 if (pSrcBitmap->GetBPP() == 1) {
(...skipping 11 matching lines...) Expand all
317 } else { 317 } else {
318 for (int row = 0; row < height; row++) { 318 for (int row = 0; row < height; row++) {
319 uint8_t* dest_scan = dest_buf + row * dest_pitch; 319 uint8_t* dest_scan = dest_buf + row * dest_pitch;
320 const uint8_t* src_scan = 320 const uint8_t* src_scan =
321 pSrcBitmap->GetScanline(src_top + row) + src_left; 321 pSrcBitmap->GetScanline(src_top + row) + src_left;
322 FXSYS_memcpy(dest_scan, src_scan, width); 322 FXSYS_memcpy(dest_scan, src_scan, width);
323 } 323 }
324 } 324 }
325 } 325 }
326 326
327 FX_BOOL ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf, 327 bool ConvertBuffer_Plt2PltRgb8(uint8_t* dest_buf,
328 int dest_pitch, 328 int dest_pitch,
329 int width, 329 int width,
330 int height, 330 int height,
331 const CFX_DIBSource* pSrcBitmap, 331 const CFX_DIBSource* pSrcBitmap,
332 int src_left, 332 int src_left,
333 int src_top, 333 int src_top,
334 uint32_t* dst_plt) { 334 uint32_t* dst_plt) {
335 ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap, 335 ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap,
336 src_left, src_top); 336 src_left, src_top);
337 uint32_t* src_plt = pSrcBitmap->GetPalette(); 337 uint32_t* src_plt = pSrcBitmap->GetPalette();
338 int plt_size = pSrcBitmap->GetPaletteSize(); 338 int plt_size = pSrcBitmap->GetPaletteSize();
339 if (pSrcBitmap->IsCmykImage()) { 339 if (pSrcBitmap->IsCmykImage()) {
340 for (int i = 0; i < plt_size; i++) { 340 for (int i = 0; i < plt_size; i++) {
341 uint8_t r; 341 uint8_t r;
342 uint8_t g; 342 uint8_t g;
343 uint8_t b; 343 uint8_t b;
344 AdobeCMYK_to_sRGB1( 344 AdobeCMYK_to_sRGB1(
345 FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]), 345 FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(src_plt[i]),
346 FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b); 346 FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), r, g, b);
347 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b); 347 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b);
348 } 348 }
349 } else { 349 } else {
350 FXSYS_memcpy(dst_plt, src_plt, plt_size * 4); 350 FXSYS_memcpy(dst_plt, src_plt, plt_size * 4);
351 } 351 }
352 return TRUE; 352 return true;
353 } 353 }
354 354
355 FX_BOOL ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf, 355 bool ConvertBuffer_Rgb2PltRgb8(uint8_t* dest_buf,
356 int dest_pitch, 356 int dest_pitch,
357 int width, 357 int width,
358 int height, 358 int height,
359 const CFX_DIBSource* pSrcBitmap, 359 const CFX_DIBSource* pSrcBitmap,
360 int src_left, 360 int src_left,
361 int src_top, 361 int src_top,
362 uint32_t* dst_plt) { 362 uint32_t* dst_plt) {
363 int bpp = pSrcBitmap->GetBPP() / 8; 363 int bpp = pSrcBitmap->GetBPP() / 8;
364 CFX_Palette palette; 364 CFX_Palette palette;
365 palette.BuildPalette(pSrcBitmap); 365 palette.BuildPalette(pSrcBitmap);
366 uint32_t* cLut = palette.GetColorLut(); 366 uint32_t* cLut = palette.GetColorLut();
367 uint32_t* aLut = palette.GetAmountLut(); 367 uint32_t* aLut = palette.GetAmountLut();
368 if (!cLut || !aLut) { 368 if (!cLut || !aLut) {
369 return FALSE; 369 return false;
370 } 370 }
371 int lut = palette.Getlut(); 371 int lut = palette.Getlut();
372 uint32_t* pPalette = palette.GetPalette(); 372 uint32_t* pPalette = palette.GetPalette();
373 if (lut > 256) { 373 if (lut > 256) {
374 int err, min_err; 374 int err, min_err;
375 int lut_256 = lut - 256; 375 int lut_256 = lut - 256;
376 for (int row = 0; row < lut_256; row++) { 376 for (int row = 0; row < lut_256; row++) {
377 min_err = 1000000; 377 min_err = 1000000;
378 uint8_t r, g, b; 378 uint8_t r, g, b;
379 _ColorDecode(cLut[row], r, g, b); 379 _ColorDecode(cLut[row], r, g, b);
(...skipping 24 matching lines...) Expand all
404 int b = src_port[0] & 0xf0; 404 int b = src_port[0] & 0xf0;
405 uint32_t clrindex = (r << 4) + g + (b >> 4); 405 uint32_t clrindex = (r << 4) + g + (b >> 4);
406 for (int i = lut_1; i >= 0; i--) 406 for (int i = lut_1; i >= 0; i--)
407 if (clrindex == cLut[i]) { 407 if (clrindex == cLut[i]) {
408 *(dest_scan + col) = (uint8_t)(aLut[i]); 408 *(dest_scan + col) = (uint8_t)(aLut[i]);
409 break; 409 break;
410 } 410 }
411 } 411 }
412 } 412 }
413 FXSYS_memcpy(dst_plt, pPalette, sizeof(uint32_t) * 256); 413 FXSYS_memcpy(dst_plt, pPalette, sizeof(uint32_t) * 256);
414 return TRUE; 414 return true;
415 } 415 }
416 416
417 FX_BOOL ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, 417 bool ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format,
418 uint8_t* dest_buf, 418 uint8_t* dest_buf,
419 int dest_pitch, 419 int dest_pitch,
420 int width, 420 int width,
421 int height, 421 int height,
422 const CFX_DIBSource* pSrcBitmap, 422 const CFX_DIBSource* pSrcBitmap,
423 int src_left, 423 int src_left,
424 int src_top) { 424 int src_top) {
425 int comps = (dst_format & 0xff) / 8; 425 int comps = (dst_format & 0xff) / 8;
426 uint8_t set_gray, reset_gray; 426 uint8_t set_gray, reset_gray;
427 set_gray = 0xff; 427 set_gray = 0xff;
428 reset_gray = 0x00; 428 reset_gray = 0x00;
429 for (int row = 0; row < height; row++) { 429 for (int row = 0; row < height; row++) {
430 uint8_t* dest_scan = dest_buf + row * dest_pitch; 430 uint8_t* dest_scan = dest_buf + row * dest_pitch;
431 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row); 431 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row);
432 for (int col = src_left; col < src_left + width; col++) { 432 for (int col = src_left; col < src_left + width; col++) {
433 if (src_scan[col / 8] & (1 << (7 - col % 8))) { 433 if (src_scan[col / 8] & (1 << (7 - col % 8))) {
434 dest_scan[0] = set_gray; 434 dest_scan[0] = set_gray;
435 dest_scan[1] = set_gray; 435 dest_scan[1] = set_gray;
436 dest_scan[2] = set_gray; 436 dest_scan[2] = set_gray;
437 } else { 437 } else {
438 dest_scan[0] = reset_gray; 438 dest_scan[0] = reset_gray;
439 dest_scan[1] = reset_gray; 439 dest_scan[1] = reset_gray;
440 dest_scan[2] = reset_gray; 440 dest_scan[2] = reset_gray;
441 } 441 }
442 dest_scan += comps; 442 dest_scan += comps;
443 } 443 }
444 } 444 }
445 return TRUE; 445 return true;
446 } 446 }
447 447
448 FX_BOOL ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, 448 bool ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format,
449 uint8_t* dest_buf, 449 uint8_t* dest_buf,
450 int dest_pitch, 450 int dest_pitch,
451 int width, 451 int width,
452 int height, 452 int height,
453 const CFX_DIBSource* pSrcBitmap, 453 const CFX_DIBSource* pSrcBitmap,
454 int src_left, 454 int src_left,
455 int src_top) { 455 int src_top) {
456 int comps = (dst_format & 0xff) / 8; 456 int comps = (dst_format & 0xff) / 8;
457 for (int row = 0; row < height; row++) { 457 for (int row = 0; row < height; row++) {
458 uint8_t* dest_scan = dest_buf + row * dest_pitch; 458 uint8_t* dest_scan = dest_buf + row * dest_pitch;
459 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; 459 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
460 uint8_t src_pixel; 460 uint8_t src_pixel;
461 for (int col = 0; col < width; col++) { 461 for (int col = 0; col < width; col++) {
462 src_pixel = *src_scan++; 462 src_pixel = *src_scan++;
463 *dest_scan++ = src_pixel; 463 *dest_scan++ = src_pixel;
464 *dest_scan++ = src_pixel; 464 *dest_scan++ = src_pixel;
465 *dest_scan = src_pixel; 465 *dest_scan = src_pixel;
466 dest_scan += comps - 2; 466 dest_scan += comps - 2;
467 } 467 }
468 } 468 }
469 return TRUE; 469 return true;
470 } 470 }
471 471
472 FX_BOOL ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, 472 bool ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format,
473 uint8_t* dest_buf, 473 uint8_t* dest_buf,
474 int dest_pitch, 474 int dest_pitch,
475 int width, 475 int width,
476 int height, 476 int height,
477 const CFX_DIBSource* pSrcBitmap, 477 const CFX_DIBSource* pSrcBitmap,
478 int src_left, 478 int src_left,
479 int src_top) { 479 int src_top) {
480 int comps = (dst_format & 0xff) / 8; 480 int comps = (dst_format & 0xff) / 8;
481 uint32_t* src_plt = pSrcBitmap->GetPalette(); 481 uint32_t* src_plt = pSrcBitmap->GetPalette();
482 uint32_t plt[2]; 482 uint32_t plt[2];
483 uint8_t* bgr_ptr = (uint8_t*)plt; 483 uint8_t* bgr_ptr = (uint8_t*)plt;
484 if (pSrcBitmap->IsCmykImage()) { 484 if (pSrcBitmap->IsCmykImage()) {
485 plt[0] = FXCMYK_TODIB(src_plt[0]); 485 plt[0] = FXCMYK_TODIB(src_plt[0]);
486 plt[1] = FXCMYK_TODIB(src_plt[1]); 486 plt[1] = FXCMYK_TODIB(src_plt[1]);
487 } else { 487 } else {
488 bgr_ptr[0] = FXARGB_B(src_plt[0]); 488 bgr_ptr[0] = FXARGB_B(src_plt[0]);
489 bgr_ptr[1] = FXARGB_G(src_plt[0]); 489 bgr_ptr[1] = FXARGB_G(src_plt[0]);
(...skipping 21 matching lines...) Expand all
511 *dest_scan++ = bgr_ptr[4]; 511 *dest_scan++ = bgr_ptr[4];
512 *dest_scan = bgr_ptr[5]; 512 *dest_scan = bgr_ptr[5];
513 } else { 513 } else {
514 *dest_scan++ = bgr_ptr[0]; 514 *dest_scan++ = bgr_ptr[0];
515 *dest_scan++ = bgr_ptr[1]; 515 *dest_scan++ = bgr_ptr[1];
516 *dest_scan = bgr_ptr[2]; 516 *dest_scan = bgr_ptr[2];
517 } 517 }
518 dest_scan += comps - 2; 518 dest_scan += comps - 2;
519 } 519 }
520 } 520 }
521 return TRUE; 521 return true;
522 } 522 }
523 523
524 FX_BOOL ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, 524 bool ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format,
525 uint8_t* dest_buf, 525 uint8_t* dest_buf,
526 int dest_pitch, 526 int dest_pitch,
527 int width, 527 int width,
528 int height, 528 int height,
529 const CFX_DIBSource* pSrcBitmap, 529 const CFX_DIBSource* pSrcBitmap,
530 int src_left, 530 int src_left,
531 int src_top) { 531 int src_top) {
532 int comps = (dst_format & 0xff) / 8; 532 int comps = (dst_format & 0xff) / 8;
533 uint32_t* src_plt = pSrcBitmap->GetPalette(); 533 uint32_t* src_plt = pSrcBitmap->GetPalette();
534 uint32_t plt[256]; 534 uint32_t plt[256];
535 uint8_t* bgr_ptr = (uint8_t*)plt; 535 uint8_t* bgr_ptr = (uint8_t*)plt;
536 if (!pSrcBitmap->IsCmykImage()) { 536 if (!pSrcBitmap->IsCmykImage()) {
537 for (int i = 0; i < 256; i++) { 537 for (int i = 0; i < 256; i++) {
538 *bgr_ptr++ = FXARGB_B(src_plt[i]); 538 *bgr_ptr++ = FXARGB_B(src_plt[i]);
539 *bgr_ptr++ = FXARGB_G(src_plt[i]); 539 *bgr_ptr++ = FXARGB_G(src_plt[i]);
540 *bgr_ptr++ = FXARGB_R(src_plt[i]); 540 *bgr_ptr++ = FXARGB_R(src_plt[i]);
541 } 541 }
(...skipping 15 matching lines...) Expand all
557 uint8_t* dest_scan = dest_buf + row * dest_pitch; 557 uint8_t* dest_scan = dest_buf + row * dest_pitch;
558 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; 558 const uint8_t* src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left;
559 for (int col = 0; col < width; col++) { 559 for (int col = 0; col < width; col++) {
560 uint8_t* src_pixel = bgr_ptr + 3 * (*src_scan++); 560 uint8_t* src_pixel = bgr_ptr + 3 * (*src_scan++);
561 *dest_scan++ = *src_pixel++; 561 *dest_scan++ = *src_pixel++;
562 *dest_scan++ = *src_pixel++; 562 *dest_scan++ = *src_pixel++;
563 *dest_scan = *src_pixel++; 563 *dest_scan = *src_pixel++;
564 dest_scan += comps - 2; 564 dest_scan += comps - 2;
565 } 565 }
566 } 566 }
567 return TRUE; 567 return true;
568 } 568 }
569 569
570 FX_BOOL ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf, 570 bool ConvertBuffer_24bppRgb2Rgb24(uint8_t* dest_buf,
571 int dest_pitch, 571 int dest_pitch,
572 int width, 572 int width,
573 int height, 573 int height,
574 const CFX_DIBSource* pSrcBitmap, 574 const CFX_DIBSource* pSrcBitmap,
575 int src_left, 575 int src_left,
576 int src_top) { 576 int src_top) {
577 for (int row = 0; row < height; row++) { 577 for (int row = 0; row < height; row++) {
578 uint8_t* dest_scan = dest_buf + row * dest_pitch; 578 uint8_t* dest_scan = dest_buf + row * dest_pitch;
579 const uint8_t* src_scan = 579 const uint8_t* src_scan =
580 pSrcBitmap->GetScanline(src_top + row) + src_left * 3; 580 pSrcBitmap->GetScanline(src_top + row) + src_left * 3;
581 FXSYS_memcpy(dest_scan, src_scan, width * 3); 581 FXSYS_memcpy(dest_scan, src_scan, width * 3);
582 } 582 }
583 return TRUE; 583 return true;
584 } 584 }
585 585
586 FX_BOOL ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf, 586 bool ConvertBuffer_32bppRgb2Rgb24(uint8_t* dest_buf,
587 int dest_pitch, 587 int dest_pitch,
588 int width, 588 int width,
589 int height, 589 int height,
590 const CFX_DIBSource* pSrcBitmap, 590 const CFX_DIBSource* pSrcBitmap,
591 int src_left, 591 int src_left,
592 int src_top) { 592 int src_top) {
593 for (int row = 0; row < height; row++) { 593 for (int row = 0; row < height; row++) {
594 uint8_t* dest_scan = dest_buf + row * dest_pitch; 594 uint8_t* dest_scan = dest_buf + row * dest_pitch;
595 const uint8_t* src_scan = 595 const uint8_t* src_scan =
596 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; 596 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
597 for (int col = 0; col < width; col++) { 597 for (int col = 0; col < width; col++) {
598 *dest_scan++ = *src_scan++; 598 *dest_scan++ = *src_scan++;
599 *dest_scan++ = *src_scan++; 599 *dest_scan++ = *src_scan++;
600 *dest_scan++ = *src_scan++; 600 *dest_scan++ = *src_scan++;
601 src_scan++; 601 src_scan++;
602 } 602 }
603 } 603 }
604 return TRUE; 604 return true;
605 } 605 }
606 606
607 FX_BOOL ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf, 607 bool ConvertBuffer_Rgb2Rgb32(uint8_t* dest_buf,
608 int dest_pitch, 608 int dest_pitch,
609 int width, 609 int width,
610 int height, 610 int height,
611 const CFX_DIBSource* pSrcBitmap, 611 const CFX_DIBSource* pSrcBitmap,
612 int src_left, 612 int src_left,
613 int src_top) { 613 int src_top) {
614 int comps = pSrcBitmap->GetBPP() / 8; 614 int comps = pSrcBitmap->GetBPP() / 8;
615 for (int row = 0; row < height; row++) { 615 for (int row = 0; row < height; row++) {
616 uint8_t* dest_scan = dest_buf + row * dest_pitch; 616 uint8_t* dest_scan = dest_buf + row * dest_pitch;
617 const uint8_t* src_scan = 617 const uint8_t* src_scan =
618 pSrcBitmap->GetScanline(src_top + row) + src_left * comps; 618 pSrcBitmap->GetScanline(src_top + row) + src_left * comps;
619 for (int col = 0; col < width; col++) { 619 for (int col = 0; col < width; col++) {
620 *dest_scan++ = *src_scan++; 620 *dest_scan++ = *src_scan++;
621 *dest_scan++ = *src_scan++; 621 *dest_scan++ = *src_scan++;
622 *dest_scan++ = *src_scan++; 622 *dest_scan++ = *src_scan++;
623 dest_scan++; 623 dest_scan++;
624 src_scan += comps - 3; 624 src_scan += comps - 3;
625 } 625 }
626 } 626 }
627 return TRUE; 627 return true;
628 } 628 }
629 629
630 FX_BOOL ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf, 630 bool ConvertBuffer_32bppCmyk2Rgb32(uint8_t* dest_buf,
631 int dest_pitch, 631 int dest_pitch,
632 int width, 632 int width,
633 int height, 633 int height,
634 const CFX_DIBSource* pSrcBitmap, 634 const CFX_DIBSource* pSrcBitmap,
635 int src_left, 635 int src_left,
636 int src_top) { 636 int src_top) {
637 for (int row = 0; row < height; row++) { 637 for (int row = 0; row < height; row++) {
638 uint8_t* dest_scan = dest_buf + row * dest_pitch; 638 uint8_t* dest_scan = dest_buf + row * dest_pitch;
639 const uint8_t* src_scan = 639 const uint8_t* src_scan =
640 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; 640 pSrcBitmap->GetScanline(src_top + row) + src_left * 4;
641 for (int col = 0; col < width; col++) { 641 for (int col = 0; col < width; col++) {
642 AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_scan[3], 642 AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_scan[3],
643 dest_scan[2], dest_scan[1], dest_scan[0]); 643 dest_scan[2], dest_scan[1], dest_scan[0]);
644 dest_scan += 4; 644 dest_scan += 4;
645 src_scan += 4; 645 src_scan += 4;
646 } 646 }
647 } 647 }
648 return TRUE; 648 return true;
649 } 649 }
650 650
651 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, 651 bool ConvertBuffer(FXDIB_Format dest_format,
652 uint8_t* dest_buf, 652 uint8_t* dest_buf,
653 int dest_pitch, 653 int dest_pitch,
654 int width, 654 int width,
655 int height, 655 int height,
656 const CFX_DIBSource* pSrcBitmap, 656 const CFX_DIBSource* pSrcBitmap,
657 int src_left, 657 int src_left,
658 int src_top, 658 int src_top,
659 std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) { 659 std::unique_ptr<uint32_t, FxFreeDeleter>* p_pal) {
660 FXDIB_Format src_format = pSrcBitmap->GetFormat(); 660 FXDIB_Format src_format = pSrcBitmap->GetFormat();
661 switch (dest_format) { 661 switch (dest_format) {
662 case FXDIB_Invalid: 662 case FXDIB_Invalid:
663 case FXDIB_1bppCmyk: 663 case FXDIB_1bppCmyk:
664 case FXDIB_1bppMask: 664 case FXDIB_1bppMask:
665 case FXDIB_1bppRgb: 665 case FXDIB_1bppRgb:
666 ASSERT(FALSE); 666 ASSERT(false);
667 return FALSE; 667 return false;
668 case FXDIB_8bppMask: { 668 case FXDIB_8bppMask: {
669 if ((src_format & 0xff) == 1) { 669 if ((src_format & 0xff) == 1) {
670 if (pSrcBitmap->GetPalette()) { 670 if (pSrcBitmap->GetPalette()) {
671 return ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height, 671 return ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch, width, height,
672 pSrcBitmap, src_left, src_top); 672 pSrcBitmap, src_left, src_top);
673 } 673 }
674 return ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height, 674 return ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, width, height,
675 pSrcBitmap, src_left, src_top); 675 pSrcBitmap, src_left, src_top);
676 } 676 }
677 if ((src_format & 0xff) == 8) { 677 if ((src_format & 0xff) == 8) {
678 if (pSrcBitmap->GetPalette()) { 678 if (pSrcBitmap->GetPalette()) {
679 return ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height, 679 return ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch, width, height,
680 pSrcBitmap, src_left, src_top); 680 pSrcBitmap, src_left, src_top);
681 } 681 }
682 return ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height, 682 return ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, width, height,
683 pSrcBitmap, src_left, src_top); 683 pSrcBitmap, src_left, src_top);
684 } 684 }
685 if ((src_format & 0xff) >= 24) { 685 if ((src_format & 0xff) >= 24) {
686 return ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height, 686 return ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, width, height,
687 pSrcBitmap, src_left, src_top); 687 pSrcBitmap, src_left, src_top);
688 } 688 }
689 return FALSE; 689 return false;
690 } 690 }
691 case FXDIB_8bppRgb: 691 case FXDIB_8bppRgb:
692 case FXDIB_8bppRgba: { 692 case FXDIB_8bppRgba: {
693 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) { 693 if ((src_format & 0xff) == 8 && !pSrcBitmap->GetPalette()) {
694 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width, 694 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, width,
695 height, pSrcBitmap, src_left, src_top, p_pal); 695 height, pSrcBitmap, src_left, src_top, p_pal);
696 } 696 }
697 p_pal->reset(FX_Alloc(uint32_t, 256)); 697 p_pal->reset(FX_Alloc(uint32_t, 256));
698 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && 698 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) &&
699 pSrcBitmap->GetPalette()) { 699 pSrcBitmap->GetPalette()) {
700 return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height, 700 return ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, width, height,
701 pSrcBitmap, src_left, src_top, 701 pSrcBitmap, src_left, src_top,
702 p_pal->get()); 702 p_pal->get());
703 } 703 }
704 if ((src_format & 0xff) >= 24) { 704 if ((src_format & 0xff) >= 24) {
705 return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height, 705 return ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, width, height,
706 pSrcBitmap, src_left, src_top, 706 pSrcBitmap, src_left, src_top,
707 p_pal->get()); 707 p_pal->get());
708 } 708 }
709 return FALSE; 709 return false;
710 } 710 }
711 case FXDIB_Rgb: 711 case FXDIB_Rgb:
712 case FXDIB_Rgba: { 712 case FXDIB_Rgba: {
713 if ((src_format & 0xff) == 1) { 713 if ((src_format & 0xff) == 1) {
714 if (pSrcBitmap->GetPalette()) { 714 if (pSrcBitmap->GetPalette()) {
715 return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, 715 return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
716 width, height, pSrcBitmap, src_left, 716 width, height, pSrcBitmap, src_left,
717 src_top); 717 src_top);
718 } 718 }
719 return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, 719 return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
(...skipping 11 matching lines...) Expand all
731 src_top); 731 src_top);
732 } 732 }
733 if ((src_format & 0xff) == 24) { 733 if ((src_format & 0xff) == 24) {
734 return ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width, height, 734 return ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
735 pSrcBitmap, src_left, src_top); 735 pSrcBitmap, src_left, src_top);
736 } 736 }
737 if ((src_format & 0xff) == 32) { 737 if ((src_format & 0xff) == 32) {
738 return ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width, height, 738 return ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, width, height,
739 pSrcBitmap, src_left, src_top); 739 pSrcBitmap, src_left, src_top);
740 } 740 }
741 return FALSE; 741 return false;
742 } 742 }
743 case FXDIB_Argb: 743 case FXDIB_Argb:
744 case FXDIB_Rgb32: { 744 case FXDIB_Rgb32: {
745 if ((src_format & 0xff) == 1) { 745 if ((src_format & 0xff) == 1) {
746 if (pSrcBitmap->GetPalette()) { 746 if (pSrcBitmap->GetPalette()) {
747 return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch, 747 return ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf, dest_pitch,
748 width, height, pSrcBitmap, src_left, 748 width, height, pSrcBitmap, src_left,
749 src_top); 749 src_top);
750 } 750 }
751 return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch, 751 return ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, dest_pitch,
(...skipping 12 matching lines...) Expand all
764 } 764 }
765 if ((src_format & 0xff) >= 24) { 765 if ((src_format & 0xff) >= 24) {
766 if (src_format & 0x0400) { 766 if (src_format & 0x0400) {
767 return ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width, 767 return ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pitch, width,
768 height, pSrcBitmap, src_left, 768 height, pSrcBitmap, src_left,
769 src_top); 769 src_top);
770 } 770 }
771 return ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height, 771 return ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width, height,
772 pSrcBitmap, src_left, src_top); 772 pSrcBitmap, src_left, src_top);
773 } 773 }
774 return FALSE; 774 return false;
775 } 775 }
776 default: 776 default:
777 return FALSE; 777 return false;
778 } 778 }
779 } 779 }
780 780
781 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format) const { 781 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format) const {
782 if (dest_format == GetFormat()) 782 if (dest_format == GetFormat())
783 return Clone(nullptr); 783 return Clone(nullptr);
784 784
785 std::unique_ptr<CFX_DIBitmap> pClone(new CFX_DIBitmap); 785 std::unique_ptr<CFX_DIBitmap> pClone(new CFX_DIBitmap);
786 if (!pClone->Create(m_Width, m_Height, dest_format)) 786 if (!pClone->Create(m_Width, m_Height, dest_format))
787 return nullptr; 787 return nullptr;
788 788
789 CFX_DIBitmap* pSrcAlpha = nullptr; 789 CFX_DIBitmap* pSrcAlpha = nullptr;
790 if (HasAlpha()) { 790 if (HasAlpha()) {
791 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; 791 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask;
792 if (!pSrcAlpha) 792 if (!pSrcAlpha)
793 return nullptr; 793 return nullptr;
794 } 794 }
795 795
796 FX_BOOL ret = TRUE; 796 bool ret = true;
797 if (dest_format & 0x0200) { 797 if (dest_format & 0x0200) {
798 if (dest_format == FXDIB_Argb) { 798 if (dest_format == FXDIB_Argb) {
799 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) 799 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha)
800 : pClone->LoadChannel(FXDIB_Alpha, 0xff); 800 : pClone->LoadChannel(FXDIB_Alpha, 0xff);
801 } else { 801 } else {
802 ret = pClone->CopyAlphaMask(pSrcAlpha); 802 ret = pClone->CopyAlphaMask(pSrcAlpha);
803 } 803 }
804 } 804 }
805 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { 805 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) {
806 delete pSrcAlpha; 806 delete pSrcAlpha;
807 pSrcAlpha = nullptr; 807 pSrcAlpha = nullptr;
808 } 808 }
809 if (!ret) 809 if (!ret)
810 return nullptr; 810 return nullptr;
811 811
812 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; 812 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
813 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), 813 if (!ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(),
814 m_Width, m_Height, this, 0, 0, &pal_8bpp)) { 814 m_Width, m_Height, this, 0, 0, &pal_8bpp)) {
815 return nullptr; 815 return nullptr;
816 } 816 }
817 if (pal_8bpp) 817 if (pal_8bpp)
818 pClone->CopyPalette(pal_8bpp.get()); 818 pClone->CopyPalette(pal_8bpp.get());
819 return pClone.release(); 819 return pClone.release();
820 } 820 }
821 821
822 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) { 822 bool CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format) {
823 FXDIB_Format src_format = GetFormat(); 823 FXDIB_Format src_format = GetFormat();
824 if (dest_format == src_format) 824 if (dest_format == src_format)
825 return TRUE; 825 return true;
826 826
827 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && 827 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb &&
828 !m_pPalette) { 828 !m_pPalette) {
829 m_AlphaFlag = 1; 829 m_AlphaFlag = 1;
830 return TRUE; 830 return true;
831 } 831 }
832 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32) { 832 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32) {
833 m_AlphaFlag = 2; 833 m_AlphaFlag = 2;
834 for (int row = 0; row < m_Height; row++) { 834 for (int row = 0; row < m_Height; row++) {
835 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3; 835 uint8_t* scanline = m_pBuffer + row * m_Pitch + 3;
836 for (int col = 0; col < m_Width; col++) { 836 for (int col = 0; col < m_Width; col++) {
837 *scanline = 0xff; 837 *scanline = 0xff;
838 scanline += 4; 838 scanline += 4;
839 } 839 }
840 } 840 }
841 return TRUE; 841 return true;
842 } 842 }
843 int dest_bpp = dest_format & 0xff; 843 int dest_bpp = dest_format & 0xff;
844 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; 844 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4;
845 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4); 845 uint8_t* dest_buf = FX_TryAlloc(uint8_t, dest_pitch * m_Height + 4);
846 if (!dest_buf) { 846 if (!dest_buf) {
847 return FALSE; 847 return false;
848 } 848 }
849 CFX_DIBitmap* pAlphaMask = nullptr; 849 CFX_DIBitmap* pAlphaMask = nullptr;
850 if (dest_format == FXDIB_Argb) { 850 if (dest_format == FXDIB_Argb) {
851 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4); 851 FXSYS_memset(dest_buf, 0xff, dest_pitch * m_Height + 4);
852 if (m_pAlphaMask) { 852 if (m_pAlphaMask) {
853 for (int row = 0; row < m_Height; row++) { 853 for (int row = 0; row < m_Height; row++) {
854 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3; 854 uint8_t* pDstScanline = dest_buf + row * dest_pitch + 3;
855 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row); 855 const uint8_t* pSrcScanline = m_pAlphaMask->GetScanline(row);
856 for (int col = 0; col < m_Width; col++) { 856 for (int col = 0; col < m_Width; col++) {
857 *pDstScanline = *pSrcScanline++; 857 *pDstScanline = *pSrcScanline++;
858 pDstScanline += 4; 858 pDstScanline += 4;
859 } 859 }
860 } 860 }
861 } 861 }
862 } else if (dest_format & 0x0200) { 862 } else if (dest_format & 0x0200) {
863 if (src_format == FXDIB_Argb) { 863 if (src_format == FXDIB_Argb) {
864 pAlphaMask = GetAlphaMask(); 864 pAlphaMask = GetAlphaMask();
865 if (!pAlphaMask) { 865 if (!pAlphaMask) {
866 FX_Free(dest_buf); 866 FX_Free(dest_buf);
867 return FALSE; 867 return false;
868 } 868 }
869 } else { 869 } else {
870 if (!m_pAlphaMask) { 870 if (!m_pAlphaMask) {
871 if (!BuildAlphaMask()) { 871 if (!BuildAlphaMask()) {
872 FX_Free(dest_buf); 872 FX_Free(dest_buf);
873 return FALSE; 873 return false;
874 } 874 }
875 pAlphaMask = m_pAlphaMask; 875 pAlphaMask = m_pAlphaMask;
876 m_pAlphaMask = nullptr; 876 m_pAlphaMask = nullptr;
877 } else { 877 } else {
878 pAlphaMask = m_pAlphaMask; 878 pAlphaMask = m_pAlphaMask;
879 } 879 }
880 } 880 }
881 } 881 }
882 FX_BOOL ret = FALSE; 882 bool ret = false;
883 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp; 883 std::unique_ptr<uint32_t, FxFreeDeleter> pal_8bpp;
884 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, 884 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height,
885 this, 0, 0, &pal_8bpp); 885 this, 0, 0, &pal_8bpp);
886 if (!ret) { 886 if (!ret) {
887 if (pAlphaMask != m_pAlphaMask) 887 if (pAlphaMask != m_pAlphaMask)
888 delete pAlphaMask; 888 delete pAlphaMask;
889 FX_Free(dest_buf); 889 FX_Free(dest_buf);
890 return FALSE; 890 return false;
891 } 891 }
892 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) 892 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask)
893 delete m_pAlphaMask; 893 delete m_pAlphaMask;
894 m_pAlphaMask = pAlphaMask; 894 m_pAlphaMask = pAlphaMask;
895 m_pPalette = std::move(pal_8bpp); 895 m_pPalette = std::move(pal_8bpp);
896 if (!m_bExtBuf) 896 if (!m_bExtBuf)
897 FX_Free(m_pBuffer); 897 FX_Free(m_pBuffer);
898 m_bExtBuf = FALSE; 898 m_bExtBuf = false;
899 m_pBuffer = dest_buf; 899 m_pBuffer = dest_buf;
900 m_bpp = (uint8_t)dest_format; 900 m_bpp = (uint8_t)dest_format;
901 m_AlphaFlag = (uint8_t)(dest_format >> 8); 901 m_AlphaFlag = (uint8_t)(dest_format >> 8);
902 m_Pitch = dest_pitch; 902 m_Pitch = dest_pitch;
903 return TRUE; 903 return true;
904 } 904 }
OLDNEW
« no previous file with comments | « core/fxge/dib/fx_dib_composite.cpp ('k') | core/fxge/dib/fx_dib_engine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698