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

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

Issue 2204773003: Add bounds checks to CWeightTable::Calc() and friends. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: store size Created 4 years, 4 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/dib_int.h ('k') | no next file » | 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 <limits.h> 7 #include <limits.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 14 matching lines...) Expand all
25 return FXDIB_8bppMask; 25 return FXDIB_8bppMask;
26 if (format == FXDIB_1bppRgb) 26 if (format == FXDIB_1bppRgb)
27 return FXDIB_8bppRgb; 27 return FXDIB_8bppRgb;
28 if (format == FXDIB_8bppRgb && src.GetPalette()) 28 if (format == FXDIB_8bppRgb && src.GetPalette())
29 return FXDIB_Rgb; 29 return FXDIB_Rgb;
30 return format; 30 return format;
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 void CWeightTable::Calc(int dest_len, 35 CWeightTable::CWeightTable()
36 : m_DestMin(0),
37 m_ItemSize(0),
38 m_pWeightTables(nullptr),
39 m_dwWeightTablesSize(0) {}
40
41 CWeightTable::~CWeightTable() {
42 FX_Free(m_pWeightTables);
43 }
44
45 bool CWeightTable::Calc(int dest_len,
36 int dest_min, 46 int dest_min,
37 int dest_max, 47 int dest_max,
38 int src_len, 48 int src_len,
39 int src_min, 49 int src_min,
40 int src_max, 50 int src_max,
41 int flags) { 51 int flags) {
42 FX_Free(m_pWeightTables); 52 FX_Free(m_pWeightTables);
43 m_pWeightTables = nullptr; 53 m_pWeightTables = nullptr;
44 double scale, base; 54 m_dwWeightTablesSize = 0;
45 scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len; 55 const double scale = (FX_FLOAT)src_len / (FX_FLOAT)dest_len;
46 if (dest_len < 0) { 56 const double base = dest_len < 0 ? (FX_FLOAT)(src_len) : 0;
47 base = (FX_FLOAT)(src_len); 57 const int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1;
48 } else {
49 base = 0;
50 }
51 int ext_size = flags & FXDIB_BICUBIC_INTERPOL ? 3 : 1;
52 m_ItemSize = 58 m_ItemSize =
53 sizeof(int) * 2 + 59 sizeof(int) * 2 +
54 (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + ext_size)); 60 (int)(sizeof(int) * (FXSYS_ceil(FXSYS_fabs((FX_FLOAT)scale)) + ext_size));
55 m_DestMin = dest_min; 61 m_DestMin = dest_min;
56 if ((dest_max - dest_min) > (int)((1U << 30) - 4) / m_ItemSize) { 62 if ((dest_max - dest_min) > (int)((1U << 30) - 4) / m_ItemSize)
57 return; 63 return false;
58 } 64
59 m_pWeightTables = 65 m_dwWeightTablesSize = (dest_max - dest_min) * m_ItemSize + 4;
60 FX_TryAlloc(uint8_t, (dest_max - dest_min) * m_ItemSize + 4); 66 m_pWeightTables = FX_TryAlloc(uint8_t, m_dwWeightTablesSize);
61 if (!m_pWeightTables) { 67 if (!m_pWeightTables)
62 return; 68 return false;
63 } 69
64 if ((flags & FXDIB_NOSMOOTH) != 0 || FXSYS_fabs((FX_FLOAT)scale) < 1.0f) { 70 if ((flags & FXDIB_NOSMOOTH) != 0 || FXSYS_fabs((FX_FLOAT)scale) < 1.0f) {
65 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) { 71 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) {
66 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel); 72 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
67 double src_pos = dest_pixel * scale + scale / 2 + base; 73 double src_pos = dest_pixel * scale + scale / 2 + base;
68 if (flags & FXDIB_INTERPOL) { 74 if (flags & FXDIB_INTERPOL) {
69 pixel_weights.m_SrcStart = 75 pixel_weights.m_SrcStart =
70 (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2); 76 (int)FXSYS_floor((FX_FLOAT)src_pos - 1.0f / 2);
71 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2); 77 pixel_weights.m_SrcEnd = (int)FXSYS_floor((FX_FLOAT)src_pos + 1.0f / 2);
72 if (pixel_weights.m_SrcStart < src_min) { 78 if (pixel_weights.m_SrcStart < src_min) {
73 pixel_weights.m_SrcStart = src_min; 79 pixel_weights.m_SrcStart = src_min;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 (int)FXSYS_floor((FX_FLOAT)src_pos); 178 (int)FXSYS_floor((FX_FLOAT)src_pos);
173 if (pixel_weights.m_SrcStart < src_min) { 179 if (pixel_weights.m_SrcStart < src_min) {
174 pixel_weights.m_SrcStart = src_min; 180 pixel_weights.m_SrcStart = src_min;
175 } 181 }
176 if (pixel_weights.m_SrcEnd >= src_max) { 182 if (pixel_weights.m_SrcEnd >= src_max) {
177 pixel_weights.m_SrcEnd = src_max - 1; 183 pixel_weights.m_SrcEnd = src_max - 1;
178 } 184 }
179 pixel_weights.m_Weights[0] = 65536; 185 pixel_weights.m_Weights[0] = 65536;
180 } 186 }
181 } 187 }
182 return; 188 return true;
183 } 189 }
190
184 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) { 191 for (int dest_pixel = dest_min; dest_pixel < dest_max; dest_pixel++) {
185 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel); 192 PixelWeight& pixel_weights = *GetPixelWeight(dest_pixel);
186 double src_start = dest_pixel * scale + base; 193 double src_start = dest_pixel * scale + base;
187 double src_end = src_start + scale; 194 double src_end = src_start + scale;
188 int start_i, end_i; 195 int start_i, end_i;
189 if (src_start < src_end) { 196 if (src_start < src_end) {
190 start_i = (int)FXSYS_floor((FX_FLOAT)src_start); 197 start_i = (int)FXSYS_floor((FX_FLOAT)src_start);
191 end_i = (int)FXSYS_ceil((FX_FLOAT)src_end); 198 end_i = (int)FXSYS_ceil((FX_FLOAT)src_end);
192 } else { 199 } else {
193 start_i = (int)FXSYS_floor((FX_FLOAT)src_end); 200 start_i = (int)FXSYS_floor((FX_FLOAT)src_end);
(...skipping 27 matching lines...) Expand all
221 ? dest_start 228 ? dest_start
222 : (FX_FLOAT)(dest_pixel); 229 : (FX_FLOAT)(dest_pixel);
223 double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1) 230 double area_end = dest_end > (FX_FLOAT)(dest_pixel + 1)
224 ? (FX_FLOAT)(dest_pixel + 1) 231 ? (FX_FLOAT)(dest_pixel + 1)
225 : dest_end; 232 : dest_end;
226 double weight = area_start >= area_end ? 0.0f : area_end - area_start; 233 double weight = area_start >= area_end ? 0.0f : area_end - area_start;
227 if (weight == 0 && j == end_i) { 234 if (weight == 0 && j == end_i) {
228 pixel_weights.m_SrcEnd--; 235 pixel_weights.m_SrcEnd--;
229 break; 236 break;
230 } 237 }
231 pixel_weights.m_Weights[j - start_i] = 238 size_t idx = j - start_i;
232 FXSYS_round((FX_FLOAT)(weight * 65536)); 239 if (idx >= m_dwWeightTablesSize)
240 return false;
241 pixel_weights.m_Weights[idx] = FXSYS_round((FX_FLOAT)(weight * 65536));
233 } 242 }
234 } 243 }
244 return true;
245 }
246
247 PixelWeight* CWeightTable::GetPixelWeight(int pixel) const {
248 ASSERT(pixel >= m_DestMin);
249 return reinterpret_cast<PixelWeight*>(m_pWeightTables +
250 (pixel - m_DestMin) * m_ItemSize);
251 }
252
253 int* CWeightTable::GetValueFromPixelWeight(PixelWeight* pWeight,
254 int index) const {
255 if (index < pWeight->m_SrcStart)
256 return nullptr;
257
258 size_t idx = index - pWeight->m_SrcStart;
Tom Sepez 2016/08/04 17:21:58 Technically, this subtraction hits the same issue,
Tom Sepez 2016/08/04 17:28:08 NM, I thought you were subtracting pWeight, I shou
259 return idx < m_dwWeightTablesSize ? &pWeight->m_Weights[idx] : nullptr;
235 } 260 }
236 261
237 CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap, 262 CStretchEngine::CStretchEngine(IFX_ScanlineComposer* pDestBitmap,
238 FXDIB_Format dest_format, 263 FXDIB_Format dest_format,
239 int dest_width, 264 int dest_width,
240 int dest_height, 265 int dest_height,
241 const FX_RECT& clip_rect, 266 const FX_RECT& clip_rect,
242 const CFX_DIBSource* pSrcBitmap, 267 const CFX_DIBSource* pSrcBitmap,
243 int flags) { 268 int flags) {
244 m_State = 0; 269 m_State = 0;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 return FALSE; 403 return FALSE;
379 404
380 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) { 405 if (m_pSource && m_bHasAlpha && m_pSource->m_pAlphaMask) {
381 m_pExtraAlphaBuf = 406 m_pExtraAlphaBuf =
382 FX_Alloc2D(unsigned char, m_SrcClip.Height(), m_ExtraMaskPitch); 407 FX_Alloc2D(unsigned char, m_SrcClip.Height(), m_ExtraMaskPitch);
383 uint32_t size = (m_DestClip.Width() * 8 + 31) / 32 * 4; 408 uint32_t size = (m_DestClip.Width() * 8 + 31) / 32 * 4;
384 m_pDestMaskScanline = FX_TryAlloc(unsigned char, size); 409 m_pDestMaskScanline = FX_TryAlloc(unsigned char, size);
385 if (!m_pDestMaskScanline) 410 if (!m_pDestMaskScanline)
386 return FALSE; 411 return FALSE;
387 } 412 }
388 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right, m_SrcWidth, 413 bool ret =
389 m_SrcClip.left, m_SrcClip.right, m_Flags); 414 m_WeightTable.Calc(m_DestWidth, m_DestClip.left, m_DestClip.right,
390 if (!m_WeightTable.m_pWeightTables) 415 m_SrcWidth, m_SrcClip.left, m_SrcClip.right, m_Flags);
416 if (!ret)
391 return FALSE; 417 return FALSE;
392 418
393 m_CurRow = m_SrcClip.top; 419 m_CurRow = m_SrcClip.top;
394 m_State = 1; 420 m_State = 1;
395 return TRUE; 421 return TRUE;
396 } 422 }
397 423
398 FX_BOOL CStretchEngine::ContinueStretchHorz(IFX_Pause* pPause) { 424 FX_BOOL CStretchEngine::ContinueStretchHorz(IFX_Pause* pPause) {
399 if (!m_DestWidth) 425 if (!m_DestWidth)
400 return FALSE; 426 return FALSE;
(...skipping 23 matching lines...) Expand all
424 m_pExtraAlphaBuf + (m_CurRow - m_SrcClip.top) * m_ExtraMaskPitch; 450 m_pExtraAlphaBuf + (m_CurRow - m_SrcClip.top) * m_ExtraMaskPitch;
425 } 451 }
426 switch (m_TransMethod) { 452 switch (m_TransMethod) {
427 case 1: 453 case 1:
428 case 2: { 454 case 2: {
429 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 455 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
430 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); 456 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
431 int dest_a = 0; 457 int dest_a = 0;
432 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 458 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
433 j++) { 459 j++) {
434 int pixel_weight = 460 int* pWeight =
435 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 461 m_WeightTable.GetValueFromPixelWeight(pPixelWeights, j);
462 if (!pWeight)
463 return FALSE;
464
465 int pixel_weight = *pWeight;
436 if (src_scan[j / 8] & (1 << (7 - j % 8))) { 466 if (src_scan[j / 8] & (1 << (7 - j % 8))) {
437 dest_a += pixel_weight * 255; 467 dest_a += pixel_weight * 255;
438 } 468 }
439 } 469 }
440 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 470 if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
441 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a; 471 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
442 } 472 }
443 *dest_scan++ = (uint8_t)(dest_a >> 16); 473 *dest_scan++ = (uint8_t)(dest_a >> 16);
444 } 474 }
445 break; 475 break;
446 } 476 }
447 case 3: { 477 case 3: {
448 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 478 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
449 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); 479 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
450 int dest_a = 0; 480 int dest_a = 0;
451 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 481 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
452 j++) { 482 j++) {
453 int pixel_weight = 483 int* pWeight =
454 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 484 m_WeightTable.GetValueFromPixelWeight(pPixelWeights, j);
485 if (!pWeight)
486 return FALSE;
487
488 int pixel_weight = *pWeight;
455 dest_a += pixel_weight * src_scan[j]; 489 dest_a += pixel_weight * src_scan[j];
456 } 490 }
457 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 491 if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
458 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a; 492 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
459 } 493 }
460 *dest_scan++ = (uint8_t)(dest_a >> 16); 494 *dest_scan++ = (uint8_t)(dest_a >> 16);
461 } 495 }
462 break; 496 break;
463 } 497 }
464 case 4: { 498 case 4: {
465 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 499 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
466 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); 500 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
467 int dest_a = 0, dest_r = 0; 501 int dest_a = 0, dest_r = 0;
468 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 502 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
469 j++) { 503 j++) {
470 int pixel_weight = 504 int* pWeight =
471 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 505 m_WeightTable.GetValueFromPixelWeight(pPixelWeights, j);
506 if (!pWeight)
507 return FALSE;
508
509 int pixel_weight = *pWeight;
472 pixel_weight = pixel_weight * src_scan_mask[j] / 255; 510 pixel_weight = pixel_weight * src_scan_mask[j] / 255;
473 dest_r += pixel_weight * src_scan[j]; 511 dest_r += pixel_weight * src_scan[j];
474 dest_a += pixel_weight; 512 dest_a += pixel_weight;
475 } 513 }
476 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 514 if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
477 dest_r = dest_r < 0 ? 0 : dest_r > 16711680 ? 16711680 : dest_r; 515 dest_r = dest_r < 0 ? 0 : dest_r > 16711680 ? 16711680 : dest_r;
478 dest_a = dest_a < 0 ? 0 : dest_a > 65536 ? 65536 : dest_a; 516 dest_a = dest_a < 0 ? 0 : dest_a > 65536 ? 65536 : dest_a;
479 } 517 }
480 *dest_scan++ = (uint8_t)(dest_r >> 16); 518 *dest_scan++ = (uint8_t)(dest_r >> 16);
481 *dest_scan_mask++ = (uint8_t)((dest_a * 255) >> 16); 519 *dest_scan_mask++ = (uint8_t)((dest_a * 255) >> 16);
482 } 520 }
483 break; 521 break;
484 } 522 }
485 case 5: { 523 case 5: {
486 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 524 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
487 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); 525 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
488 int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; 526 int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0;
489 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 527 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
490 j++) { 528 j++) {
491 int pixel_weight = 529 int* pWeight =
492 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 530 m_WeightTable.GetValueFromPixelWeight(pPixelWeights, j);
531 if (!pWeight)
532 return FALSE;
533
534 int pixel_weight = *pWeight;
493 unsigned long argb_cmyk = m_pSrcPalette[src_scan[j]]; 535 unsigned long argb_cmyk = m_pSrcPalette[src_scan[j]];
494 if (m_DestFormat == FXDIB_Rgb) { 536 if (m_DestFormat == FXDIB_Rgb) {
495 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 16); 537 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 16);
496 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 8); 538 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 8);
497 dest_b_c += pixel_weight * (uint8_t)argb_cmyk; 539 dest_b_c += pixel_weight * (uint8_t)argb_cmyk;
498 } else { 540 } else {
499 dest_b_c += pixel_weight * (uint8_t)(argb_cmyk >> 24); 541 dest_b_c += pixel_weight * (uint8_t)(argb_cmyk >> 24);
500 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 16); 542 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 16);
501 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 8); 543 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 8);
502 } 544 }
(...skipping 11 matching lines...) Expand all
514 *dest_scan++ = (uint8_t)(dest_r_y >> 16); 556 *dest_scan++ = (uint8_t)(dest_r_y >> 16);
515 } 557 }
516 break; 558 break;
517 } 559 }
518 case 6: { 560 case 6: {
519 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 561 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
520 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); 562 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
521 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; 563 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0;
522 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 564 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
523 j++) { 565 j++) {
524 int pixel_weight = 566 int* pWeight =
525 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 567 m_WeightTable.GetValueFromPixelWeight(pPixelWeights, j);
568 if (!pWeight)
569 return FALSE;
570
571 int pixel_weight = *pWeight;
526 pixel_weight = pixel_weight * src_scan_mask[j] / 255; 572 pixel_weight = pixel_weight * src_scan_mask[j] / 255;
527 unsigned long argb_cmyk = m_pSrcPalette[src_scan[j]]; 573 unsigned long argb_cmyk = m_pSrcPalette[src_scan[j]];
528 if (m_DestFormat == FXDIB_Rgba) { 574 if (m_DestFormat == FXDIB_Rgba) {
529 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 16); 575 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 16);
530 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 8); 576 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 8);
531 dest_b_c += pixel_weight * (uint8_t)argb_cmyk; 577 dest_b_c += pixel_weight * (uint8_t)argb_cmyk;
532 } else { 578 } else {
533 dest_b_c += pixel_weight * (uint8_t)(argb_cmyk >> 24); 579 dest_b_c += pixel_weight * (uint8_t)(argb_cmyk >> 24);
534 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 16); 580 dest_g_m += pixel_weight * (uint8_t)(argb_cmyk >> 16);
535 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 8); 581 dest_r_y += pixel_weight * (uint8_t)(argb_cmyk >> 8);
(...skipping 15 matching lines...) Expand all
551 *dest_scan_mask++ = (uint8_t)((dest_a * 255) >> 16); 597 *dest_scan_mask++ = (uint8_t)((dest_a * 255) >> 16);
552 } 598 }
553 break; 599 break;
554 } 600 }
555 case 7: { 601 case 7: {
556 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 602 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
557 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); 603 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
558 int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; 604 int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0;
559 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 605 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
560 j++) { 606 j++) {
561 int pixel_weight = 607 int* pWeight =
562 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 608 m_WeightTable.GetValueFromPixelWeight(pPixelWeights, j);
609 if (!pWeight)
610 return FALSE;
611
612 int pixel_weight = *pWeight;
563 const uint8_t* src_pixel = src_scan + j * Bpp; 613 const uint8_t* src_pixel = src_scan + j * Bpp;
564 dest_b_c += pixel_weight * (*src_pixel++); 614 dest_b_c += pixel_weight * (*src_pixel++);
565 dest_g_m += pixel_weight * (*src_pixel++); 615 dest_g_m += pixel_weight * (*src_pixel++);
566 dest_r_y += pixel_weight * (*src_pixel); 616 dest_r_y += pixel_weight * (*src_pixel);
567 } 617 }
568 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 618 if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
569 dest_b_c = 619 dest_b_c =
570 dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c; 620 dest_b_c < 0 ? 0 : dest_b_c > 16711680 ? 16711680 : dest_b_c;
571 dest_g_m = 621 dest_g_m =
572 dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m; 622 dest_g_m < 0 ? 0 : dest_g_m > 16711680 ? 16711680 : dest_g_m;
573 dest_r_y = 623 dest_r_y =
574 dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y; 624 dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
575 } 625 }
576 *dest_scan++ = (uint8_t)((dest_b_c) >> 16); 626 *dest_scan++ = (uint8_t)((dest_b_c) >> 16);
577 *dest_scan++ = (uint8_t)((dest_g_m) >> 16); 627 *dest_scan++ = (uint8_t)((dest_g_m) >> 16);
578 *dest_scan++ = (uint8_t)((dest_r_y) >> 16); 628 *dest_scan++ = (uint8_t)((dest_r_y) >> 16);
579 dest_scan += Bpp - 3; 629 dest_scan += Bpp - 3;
580 } 630 }
581 break; 631 break;
582 } 632 }
583 case 8: { 633 case 8: {
584 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 634 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
585 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col); 635 PixelWeight* pPixelWeights = m_WeightTable.GetPixelWeight(col);
586 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; 636 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0;
587 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 637 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
588 j++) { 638 j++) {
589 int pixel_weight = 639 int* pWeight =
590 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 640 m_WeightTable.GetValueFromPixelWeight(pPixelWeights, j);
641 if (!pWeight)
642 return FALSE;
643
644 int pixel_weight = *pWeight;
591 const uint8_t* src_pixel = src_scan + j * Bpp; 645 const uint8_t* src_pixel = src_scan + j * Bpp;
592 if (m_DestFormat == FXDIB_Argb) { 646 if (m_DestFormat == FXDIB_Argb) {
593 pixel_weight = pixel_weight * src_pixel[3] / 255; 647 pixel_weight = pixel_weight * src_pixel[3] / 255;
594 } else { 648 } else {
595 pixel_weight = pixel_weight * src_scan_mask[j] / 255; 649 pixel_weight = pixel_weight * src_scan_mask[j] / 255;
596 } 650 }
597 dest_b_c += pixel_weight * (*src_pixel++); 651 dest_b_c += pixel_weight * (*src_pixel++);
598 dest_g_m += pixel_weight * (*src_pixel++); 652 dest_g_m += pixel_weight * (*src_pixel++);
599 dest_r_y += pixel_weight * (*src_pixel); 653 dest_r_y += pixel_weight * (*src_pixel);
600 dest_a += pixel_weight; 654 dest_a += pixel_weight;
(...skipping 24 matching lines...) Expand all
625 rows_to_go--; 679 rows_to_go--;
626 } 680 }
627 return FALSE; 681 return FALSE;
628 } 682 }
629 683
630 void CStretchEngine::StretchVert() { 684 void CStretchEngine::StretchVert() {
631 if (m_DestHeight == 0) 685 if (m_DestHeight == 0)
632 return; 686 return;
633 687
634 CWeightTable table; 688 CWeightTable table;
635 table.Calc(m_DestHeight, m_DestClip.top, m_DestClip.bottom, m_SrcHeight, 689 bool ret = table.Calc(m_DestHeight, m_DestClip.top, m_DestClip.bottom,
636 m_SrcClip.top, m_SrcClip.bottom, m_Flags); 690 m_SrcHeight, m_SrcClip.top, m_SrcClip.bottom, m_Flags);
637 if (!table.m_pWeightTables) 691 if (!ret)
638 return; 692 return;
639 693
640 int DestBpp = m_DestBpp / 8; 694 const int DestBpp = m_DestBpp / 8;
641 for (int row = m_DestClip.top; row < m_DestClip.bottom; row++) { 695 for (int row = m_DestClip.top; row < m_DestClip.bottom; row++) {
642 unsigned char* dest_scan = m_pDestScanline; 696 unsigned char* dest_scan = m_pDestScanline;
643 unsigned char* dest_sacn_mask = m_pDestMaskScanline; 697 unsigned char* dest_scan_mask = m_pDestMaskScanline;
644 PixelWeight* pPixelWeights = table.GetPixelWeight(row); 698 PixelWeight* pPixelWeights = table.GetPixelWeight(row);
645 switch (m_TransMethod) { 699 switch (m_TransMethod) {
646 case 1: 700 case 1:
647 case 2: 701 case 2:
648 case 3: { 702 case 3: {
649 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 703 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
650 unsigned char* src_scan = 704 unsigned char* src_scan =
651 m_pInterBuf + (col - m_DestClip.left) * DestBpp; 705 m_pInterBuf + (col - m_DestClip.left) * DestBpp;
652 int dest_a = 0; 706 int dest_a = 0;
653 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 707 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
654 j++) { 708 j++) {
655 int pixel_weight = 709 int* pWeight = table.GetValueFromPixelWeight(pPixelWeights, j);
656 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 710 if (!pWeight)
711 return;
712
713 int pixel_weight = *pWeight;
657 dest_a += 714 dest_a +=
658 pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch]; 715 pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
659 } 716 }
660 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 717 if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
661 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a; 718 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
662 } 719 }
663 *dest_scan = (uint8_t)(dest_a >> 16); 720 *dest_scan = (uint8_t)(dest_a >> 16);
664 dest_scan += DestBpp; 721 dest_scan += DestBpp;
665 } 722 }
666 break; 723 break;
667 } 724 }
668 case 4: { 725 case 4: {
669 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 726 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
670 unsigned char* src_scan = 727 unsigned char* src_scan =
671 m_pInterBuf + (col - m_DestClip.left) * DestBpp; 728 m_pInterBuf + (col - m_DestClip.left) * DestBpp;
672 unsigned char* src_scan_mask = 729 unsigned char* src_scan_mask =
673 m_pExtraAlphaBuf + (col - m_DestClip.left); 730 m_pExtraAlphaBuf + (col - m_DestClip.left);
674 int dest_a = 0, dest_k = 0; 731 int dest_a = 0, dest_k = 0;
675 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 732 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
676 j++) { 733 j++) {
677 int pixel_weight = 734 int* pWeight = table.GetValueFromPixelWeight(pPixelWeights, j);
678 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 735 if (!pWeight)
736 return;
737
738 int pixel_weight = *pWeight;
679 dest_k += 739 dest_k +=
680 pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch]; 740 pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
681 dest_a += pixel_weight * 741 dest_a += pixel_weight *
682 src_scan_mask[(j - m_SrcClip.top) * m_ExtraMaskPitch]; 742 src_scan_mask[(j - m_SrcClip.top) * m_ExtraMaskPitch];
683 } 743 }
684 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 744 if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
685 dest_k = dest_k < 0 ? 0 : dest_k > 16711680 ? 16711680 : dest_k; 745 dest_k = dest_k < 0 ? 0 : dest_k > 16711680 ? 16711680 : dest_k;
686 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a; 746 dest_a = dest_a < 0 ? 0 : dest_a > 16711680 ? 16711680 : dest_a;
687 } 747 }
688 *dest_scan = (uint8_t)(dest_k >> 16); 748 *dest_scan = (uint8_t)(dest_k >> 16);
689 dest_scan += DestBpp; 749 dest_scan += DestBpp;
690 *dest_sacn_mask++ = (uint8_t)(dest_a >> 16); 750 *dest_scan_mask++ = (uint8_t)(dest_a >> 16);
691 } 751 }
692 break; 752 break;
693 } 753 }
694 case 5: 754 case 5:
695 case 7: { 755 case 7: {
696 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 756 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
697 unsigned char* src_scan = 757 unsigned char* src_scan =
698 m_pInterBuf + (col - m_DestClip.left) * DestBpp; 758 m_pInterBuf + (col - m_DestClip.left) * DestBpp;
699 int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; 759 int dest_r_y = 0, dest_g_m = 0, dest_b_c = 0;
700 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 760 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
701 j++) { 761 j++) {
702 int pixel_weight = 762 int* pWeight = table.GetValueFromPixelWeight(pPixelWeights, j);
703 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 763 if (!pWeight)
764 return;
765
766 int pixel_weight = *pWeight;
704 const uint8_t* src_pixel = 767 const uint8_t* src_pixel =
705 src_scan + (j - m_SrcClip.top) * m_InterPitch; 768 src_scan + (j - m_SrcClip.top) * m_InterPitch;
706 dest_b_c += pixel_weight * (*src_pixel++); 769 dest_b_c += pixel_weight * (*src_pixel++);
707 dest_g_m += pixel_weight * (*src_pixel++); 770 dest_g_m += pixel_weight * (*src_pixel++);
708 dest_r_y += pixel_weight * (*src_pixel); 771 dest_r_y += pixel_weight * (*src_pixel);
709 } 772 }
710 if (m_Flags & FXDIB_BICUBIC_INTERPOL) { 773 if (m_Flags & FXDIB_BICUBIC_INTERPOL) {
711 dest_r_y = 774 dest_r_y =
712 dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y; 775 dest_r_y < 0 ? 0 : dest_r_y > 16711680 ? 16711680 : dest_r_y;
713 dest_g_m = 776 dest_g_m =
(...skipping 13 matching lines...) Expand all
727 for (int col = m_DestClip.left; col < m_DestClip.right; col++) { 790 for (int col = m_DestClip.left; col < m_DestClip.right; col++) {
728 unsigned char* src_scan = 791 unsigned char* src_scan =
729 m_pInterBuf + (col - m_DestClip.left) * DestBpp; 792 m_pInterBuf + (col - m_DestClip.left) * DestBpp;
730 unsigned char* src_scan_mask = nullptr; 793 unsigned char* src_scan_mask = nullptr;
731 if (m_DestFormat != FXDIB_Argb) { 794 if (m_DestFormat != FXDIB_Argb) {
732 src_scan_mask = m_pExtraAlphaBuf + (col - m_DestClip.left); 795 src_scan_mask = m_pExtraAlphaBuf + (col - m_DestClip.left);
733 } 796 }
734 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0; 797 int dest_a = 0, dest_r_y = 0, dest_g_m = 0, dest_b_c = 0;
735 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd; 798 for (int j = pPixelWeights->m_SrcStart; j <= pPixelWeights->m_SrcEnd;
736 j++) { 799 j++) {
737 int pixel_weight = 800 int* pWeight = table.GetValueFromPixelWeight(pPixelWeights, j);
738 pPixelWeights->m_Weights[j - pPixelWeights->m_SrcStart]; 801 if (!pWeight)
802 return;
803
804 int pixel_weight = *pWeight;
739 const uint8_t* src_pixel = 805 const uint8_t* src_pixel =
740 src_scan + (j - m_SrcClip.top) * m_InterPitch; 806 src_scan + (j - m_SrcClip.top) * m_InterPitch;
741 int mask_v = 255; 807 int mask_v = 255;
742 if (src_scan_mask) { 808 if (src_scan_mask) {
743 mask_v = src_scan_mask[(j - m_SrcClip.top) * m_ExtraMaskPitch]; 809 mask_v = src_scan_mask[(j - m_SrcClip.top) * m_ExtraMaskPitch];
744 } 810 }
745 dest_b_c += pixel_weight * (*src_pixel++); 811 dest_b_c += pixel_weight * (*src_pixel++);
746 dest_g_m += pixel_weight * (*src_pixel++); 812 dest_g_m += pixel_weight * (*src_pixel++);
747 dest_r_y += pixel_weight * (*src_pixel); 813 dest_r_y += pixel_weight * (*src_pixel);
748 if (m_DestFormat == FXDIB_Argb) { 814 if (m_DestFormat == FXDIB_Argb) {
(...skipping 15 matching lines...) Expand all
764 int r = ((uint32_t)dest_r_y) * 255 / dest_a; 830 int r = ((uint32_t)dest_r_y) * 255 / dest_a;
765 int g = ((uint32_t)dest_g_m) * 255 / dest_a; 831 int g = ((uint32_t)dest_g_m) * 255 / dest_a;
766 int b = ((uint32_t)dest_b_c) * 255 / dest_a; 832 int b = ((uint32_t)dest_b_c) * 255 / dest_a;
767 dest_scan[0] = b > 255 ? 255 : b < 0 ? 0 : b; 833 dest_scan[0] = b > 255 ? 255 : b < 0 ? 0 : b;
768 dest_scan[1] = g > 255 ? 255 : g < 0 ? 0 : g; 834 dest_scan[1] = g > 255 ? 255 : g < 0 ? 0 : g;
769 dest_scan[2] = r > 255 ? 255 : r < 0 ? 0 : r; 835 dest_scan[2] = r > 255 ? 255 : r < 0 ? 0 : r;
770 } 836 }
771 if (m_DestFormat == FXDIB_Argb) { 837 if (m_DestFormat == FXDIB_Argb) {
772 dest_scan[3] = (uint8_t)((dest_a) >> 16); 838 dest_scan[3] = (uint8_t)((dest_a) >> 16);
773 } else { 839 } else {
774 *dest_sacn_mask = (uint8_t)((dest_a) >> 16); 840 *dest_scan_mask = (uint8_t)((dest_a) >> 16);
775 } 841 }
776 dest_scan += DestBpp; 842 dest_scan += DestBpp;
777 if (dest_sacn_mask) { 843 if (dest_scan_mask) {
778 dest_sacn_mask++; 844 dest_scan_mask++;
779 } 845 }
780 } 846 }
781 break; 847 break;
782 } 848 }
783 } 849 }
784 m_pDestBitmap->ComposeScanline(row - m_DestClip.top, m_pDestScanline, 850 m_pDestBitmap->ComposeScanline(row - m_DestClip.top, m_pDestScanline,
785 m_pDestMaskScanline); 851 m_pDestMaskScanline);
786 } 852 }
787 } 853 }
788 854
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 result_width); 995 result_width);
930 if (m_pMaskScanline) { 996 if (m_pMaskScanline) {
931 m_pSource->m_pAlphaMask->DownSampleScanline( 997 m_pSource->m_pAlphaMask->DownSampleScanline(
932 src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX, 998 src_y, m_pMaskScanline.get(), 1, m_DestWidth, m_bFlipX,
933 m_ClipRect.left, result_width); 999 m_ClipRect.left, result_width);
934 } 1000 }
935 m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get()); 1001 m_pDest->ComposeScanline(dest_y, m_pScanline.get(), m_pMaskScanline.get());
936 } 1002 }
937 return FALSE; 1003 return FALSE;
938 } 1004 }
OLDNEW
« no previous file with comments | « core/fxge/dib/dib_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698