From db444d2063df6c574882d9263e885c4fe1134133 Mon Sep 17 00:00:00 2001 From: weili Date: Thu, 2 Jun 2016 15:48:15 -0700 Subject: Fix all the code which has duplicate variable declarations When there are duplicate variable declarations, the inner names shadow the outter ones. This is error prone and harder to read. Remove all the instances found by /analyze. BUG=chromium:613623, chromium:427616 Review-Url: https://codereview.chromium.org/2027273002 --- core/fxge/dib/fx_dib_composite.cpp | 107 +++++++++++++++---------------------- core/fxge/dib/fx_dib_convert.cpp | 7 ++- core/fxge/dib/fx_dib_transform.cpp | 2 +- 3 files changed, 47 insertions(+), 69 deletions(-) (limited to 'core/fxge/dib') diff --git a/core/fxge/dib/fx_dib_composite.cpp b/core/fxge/dib/fx_dib_composite.cpp index 282b93d6da..28f6e49044 100644 --- a/core/fxge/dib/fx_dib_composite.cpp +++ b/core/fxge/dib/fx_dib_composite.cpp @@ -2512,11 +2512,10 @@ void CompositeRow_ByteMask2Argb(uint8_t* dest_scan, int alpha_ratio = src_alpha * 255 / dest_alpha; if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + RGB_Blend(blend_type, scan, dest_scan, blended_colors); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio); dest_scan++; @@ -2583,11 +2582,10 @@ void CompositeRow_ByteMask2Rgba(uint8_t* dest_scan, int alpha_ratio = src_alpha * 255 / dest_alpha; if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + RGB_Blend(blend_type, scan, dest_scan, blended_colors); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio); dest_scan++; @@ -2644,11 +2642,10 @@ void CompositeRow_ByteMask2Rgb(uint8_t* dest_scan, } if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + RGB_Blend(blend_type, scan, dest_scan, blended_colors); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_alpha); dest_scan++; *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_alpha); @@ -2791,11 +2788,10 @@ void CompositeRow_BitMask2Argb(uint8_t* dest_scan, int alpha_ratio = src_alpha * 255 / dest_alpha; if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + RGB_Blend(blend_type, scan, dest_scan, blended_colors); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], alpha_ratio); dest_scan++; @@ -2866,11 +2862,10 @@ void CompositeRow_BitMask2Rgb(uint8_t* dest_scan, } if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - RGB_Blend(blend_type, src_scan, dest_scan, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + RGB_Blend(blend_type, scan, dest_scan, blended_colors); *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[0], src_alpha); dest_scan++; *dest_scan = FXDIB_ALPHA_MERGE(*dest_scan, blended_colors[1], src_alpha); @@ -3584,15 +3579,11 @@ void CompositeRow_ByteMask2Argb_RgbByteOrder(uint8_t* dest_scan, int alpha_ratio = src_alpha * 255 / dest_alpha; if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - uint8_t dest_scan_o[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - dest_scan_o[0] = dest_scan[2]; - dest_scan_o[1] = dest_scan[1]; - dest_scan_o[2] = dest_scan[0]; - RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + uint8_t dest_scan_o[3] = {dest_scan[2], dest_scan[1], dest_scan[0]}; + RGB_Blend(blend_type, scan, dest_scan_o, blended_colors); dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], alpha_ratio); dest_scan[1] = @@ -3641,15 +3632,11 @@ void CompositeRow_ByteMask2Rgb_RgbByteOrder(uint8_t* dest_scan, } if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - uint8_t dest_scan_o[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - dest_scan_o[0] = dest_scan[2]; - dest_scan_o[1] = dest_scan[1]; - dest_scan_o[2] = dest_scan[0]; - RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + uint8_t dest_scan_o[3] = {dest_scan[2], dest_scan[1], dest_scan[0]}; + RGB_Blend(blend_type, scan, dest_scan_o, blended_colors); dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], src_alpha); dest_scan[1] = @@ -3715,15 +3702,11 @@ void CompositeRow_BitMask2Argb_RgbByteOrder(uint8_t* dest_scan, int alpha_ratio = src_alpha * 255 / dest_alpha; if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - uint8_t dest_scan_o[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - dest_scan_o[0] = dest_scan[2]; - dest_scan_o[1] = dest_scan[1]; - dest_scan_o[2] = dest_scan[0]; - RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + uint8_t dest_scan_o[3] = {dest_scan[2], dest_scan[1], dest_scan[0]}; + RGB_Blend(blend_type, scan, dest_scan_o, blended_colors); dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], alpha_ratio); dest_scan[1] = @@ -3788,15 +3771,11 @@ void CompositeRow_BitMask2Rgb_RgbByteOrder(uint8_t* dest_scan, } if (blend_type >= FXDIB_BLEND_NONSEPARABLE) { int blended_colors[3]; - uint8_t src_scan[3]; - uint8_t dest_scan_o[3]; - src_scan[0] = src_b; - src_scan[1] = src_g; - src_scan[2] = src_r; - dest_scan_o[0] = dest_scan[2]; - dest_scan_o[1] = dest_scan[1]; - dest_scan_o[2] = dest_scan[0]; - RGB_Blend(blend_type, src_scan, dest_scan_o, blended_colors); + uint8_t scan[3] = {static_cast(src_b), + static_cast(src_g), + static_cast(src_r)}; + uint8_t dest_scan_o[3] = {dest_scan[2], dest_scan[1], dest_scan[0]}; + RGB_Blend(blend_type, scan, dest_scan_o, blended_colors); dest_scan[2] = FXDIB_ALPHA_MERGE(dest_scan[2], blended_colors[0], src_alpha); dest_scan[1] = @@ -4710,7 +4689,7 @@ FX_BOOL CFX_DIBitmap::CompositeRect(int left, ASSERT(!IsCmykImage() && (uint8_t)(alpha_flag >> 8) == 0); int left_shift = rect.left % 8; int right_shift = rect.right % 8; - int width = rect.right / 8 - rect.left / 8; + int new_width = rect.right / 8 - rect.left / 8; int index = 0; if (m_pPalette) { for (int i = 0; i < 2; i++) { @@ -4726,8 +4705,8 @@ FX_BOOL CFX_DIBitmap::CompositeRect(int left, uint8_t* dest_scan_top_r = (uint8_t*)GetScanline(row) + rect.right / 8; uint8_t left_flag = *dest_scan_top & (255 << (8 - left_shift)); uint8_t right_flag = *dest_scan_top_r & (255 >> right_shift); - if (width) { - FXSYS_memset(dest_scan_top + 1, index ? 255 : 0, width - 1); + if (new_width) { + FXSYS_memset(dest_scan_top + 1, index ? 255 : 0, new_width - 1); if (!index) { *dest_scan_top &= left_flag; *dest_scan_top_r &= right_flag; diff --git a/core/fxge/dib/fx_dib_convert.cpp b/core/fxge/dib/fx_dib_convert.cpp index da380ee567..8937816531 100644 --- a/core/fxge/dib/fx_dib_convert.cpp +++ b/core/fxge/dib/fx_dib_convert.cpp @@ -433,7 +433,6 @@ FX_BOOL ConvertBuffer_Rgb2PltRgb8_NoTransform(uint8_t* dest_buf, int src_top, uint32_t* dst_plt) { int bpp = pSrcBitmap->GetBPP() / 8; - int row, col; CFX_Palette palette; palette.BuildPalette(pSrcBitmap); uint32_t* cLut = palette.GetColorLut(); @@ -446,7 +445,7 @@ FX_BOOL ConvertBuffer_Rgb2PltRgb8_NoTransform(uint8_t* dest_buf, if (lut > 256) { int err, min_err; int lut_256 = lut - 256; - for (row = 0; row < lut_256; row++) { + for (int row = 0; row < lut_256; row++) { min_err = 1000000; uint8_t r, g, b; _ColorDecode(cLut[row], r, g, b); @@ -466,11 +465,11 @@ FX_BOOL ConvertBuffer_Rgb2PltRgb8_NoTransform(uint8_t* dest_buf, } } int32_t lut_1 = lut - 1; - for (row = 0; row < height; row++) { + for (int row = 0; row < height; row++) { uint8_t* src_scan = (uint8_t*)pSrcBitmap->GetScanline(src_top + row) + src_left; uint8_t* dest_scan = dest_buf + row * dest_pitch; - for (col = 0; col < width; col++) { + for (int col = 0; col < width; col++) { uint8_t* src_port = src_scan + col * bpp; int r = src_port[2] & 0xf0; int g = src_port[1] & 0xf0; diff --git a/core/fxge/dib/fx_dib_transform.cpp b/core/fxge/dib/fx_dib_transform.cpp index f9b4250deb..914ca58013 100644 --- a/core/fxge/dib/fx_dib_transform.cpp +++ b/core/fxge/dib/fx_dib_transform.cpp @@ -624,7 +624,6 @@ FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) { } } else { int Bpp = m_Storer.GetBitmap()->GetBPP() / 8; - int destBpp = pTransformed->GetBPP() / 8; if (Bpp == 1) { uint32_t argb[256]; FX_ARGB* pPal = m_Storer.GetBitmap()->GetPalette(); @@ -643,6 +642,7 @@ FX_BOOL CFX_ImageTransformer::Continue(IFX_Pause* pPause) { } } } + int destBpp = pTransformed->GetBPP() / 8; if (!(m_Flags & FXDIB_DOWNSAMPLE) && !(m_Flags & FXDIB_BICUBIC_INTERPOL)) { CFX_BilinearMatrix result2stretch_fix(result2stretch, 8); -- cgit v1.2.3