diff options
author | pkasting <pkasting@chromium.org> | 2014-10-17 11:29:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-17 18:30:01 +0000 |
commit | e232eca6b56b30a0e483cac8e4303d2e547db213 (patch) | |
tree | 899cfd90a1cd2fce278da99155dad286435df2f6 /components/favicon_base | |
parent | 69ccb323be58ff1d3cc9cb802b5e656832c8ccdb (diff) | |
download | chromium_src-e232eca6b56b30a0e483cac8e4303d2e547db213.zip chromium_src-e232eca6b56b30a0e483cac8e4303d2e547db213.tar.gz chromium_src-e232eca6b56b30a0e483cac8e4303d2e547db213.tar.bz2 |
Type conversion fixes, components/ edition.
This is mostly to fix MSVC warnings about possible value truncation.
BUG=81439
TEST=none
Review URL: https://codereview.chromium.org/656363002
Cr-Commit-Position: refs/heads/master@{#300134}
Diffstat (limited to 'components/favicon_base')
-rw-r--r-- | components/favicon_base/favicon_util.cc | 47 | ||||
-rw-r--r-- | components/favicon_base/select_favicon_frames.cc | 8 |
2 files changed, 30 insertions, 25 deletions
diff --git a/components/favicon_base/favicon_util.cc b/components/favicon_base/favicon_util.cc index 54efdf4..af547f3 100644 --- a/components/favicon_base/favicon_util.cc +++ b/components/favicon_base/favicon_util.cc @@ -55,7 +55,8 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( // create a bitmap with given pixel size. std::map<int, float> desired_pixel_sizes; for (size_t i = 0; i < favicon_scales.size(); ++i) { - int pixel_size = std::ceil(favicon_size * favicon_scales[i]); + int pixel_size = + static_cast<int>(std::ceil(favicon_size * favicon_scales[i])); desired_pixel_sizes[pixel_size] = favicon_scales[i]; } @@ -78,57 +79,58 @@ std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( return png_reps; } -// Returns a resampled bitmap of -// |desired_size_in_pixel| x |desired_size_in_pixel| by resampling the best -// bitmap out of |input_bitmaps|. ResizeBitmapByDownsamplingIfPossible() is -// similar to SelectFaviconFrames() but it operates on bitmaps which have -// already been resampled via SelectFaviconFrames(). +// Returns a resampled bitmap of |desired_size| x |desired_size| by resampling +// the best bitmap out of |input_bitmaps|. +// ResizeBitmapByDownsamplingIfPossible() is similar to SelectFaviconFrames() +// but it operates on bitmaps which have already been resampled via +// SelectFaviconFrames(). SkBitmap ResizeBitmapByDownsamplingIfPossible( const std::vector<SkBitmap>& input_bitmaps, - int desired_size_in_pixel) { + int desired_size) { DCHECK(!input_bitmaps.empty()); - DCHECK_NE(desired_size_in_pixel, 0); + DCHECK_NE(0, desired_size); SkBitmap best_bitmap; for (size_t i = 0; i < input_bitmaps.size(); ++i) { const SkBitmap& input_bitmap = input_bitmaps[i]; - if (input_bitmap.width() == desired_size_in_pixel && - input_bitmap.height() == desired_size_in_pixel) { + if (input_bitmap.width() == desired_size && + input_bitmap.height() == desired_size) { return input_bitmap; } else if (best_bitmap.isNull()) { best_bitmap = input_bitmap; } else if (input_bitmap.width() >= best_bitmap.width() && input_bitmap.height() >= best_bitmap.height()) { - if (best_bitmap.width() < desired_size_in_pixel || - best_bitmap.height() < desired_size_in_pixel) { + if (best_bitmap.width() < desired_size || + best_bitmap.height() < desired_size) { best_bitmap = input_bitmap; } } else { - if (input_bitmap.width() >= desired_size_in_pixel && - input_bitmap.height() >= desired_size_in_pixel) { + if (input_bitmap.width() >= desired_size && + input_bitmap.height() >= desired_size) { best_bitmap = input_bitmap; } } } - if (desired_size_in_pixel % best_bitmap.width() == 0 && - desired_size_in_pixel % best_bitmap.height() == 0) { + if (desired_size % best_bitmap.width() == 0 && + desired_size % best_bitmap.height() == 0) { // Use nearest neighbour resampling if upsampling by an integer. This // makes the result look similar to the result of SelectFaviconFrames(). SkBitmap bitmap; - bitmap.allocN32Pixels(desired_size_in_pixel, desired_size_in_pixel); + bitmap.allocN32Pixels(desired_size, desired_size); if (!best_bitmap.isOpaque()) bitmap.eraseARGB(0, 0, 0, 0); SkCanvas canvas(bitmap); - SkRect dest(SkRect::MakeWH(desired_size_in_pixel, desired_size_in_pixel)); - canvas.drawBitmapRect(best_bitmap, NULL, dest); + canvas.drawBitmapRect( + best_bitmap, NULL, + SkRect::MakeFromIRect(SkIRect::MakeWH(desired_size, desired_size))); return bitmap; } return skia::ImageOperations::Resize(best_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, - desired_size_in_pixel, - desired_size_in_pixel); + desired_size, + desired_size); } } // namespace @@ -214,7 +216,8 @@ gfx::Image SelectFaviconFramesFromPNGs( gfx::ImageSkia resized_image_skia; for (size_t i = 0; i < favicon_scales_to_generate.size(); ++i) { float scale = favicon_scales_to_generate[i]; - int desired_size_in_pixel = std::ceil(favicon_size * scale); + int desired_size_in_pixel = + static_cast<int>(std::ceil(favicon_size * scale)); SkBitmap bitmap = ResizeBitmapByDownsamplingIfPossible(bitmaps, desired_size_in_pixel); resized_image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); diff --git a/components/favicon_base/select_favicon_frames.cc b/components/favicon_base/select_favicon_frames.cc index 8df5f8c..d53225d 100644 --- a/components/favicon_base/select_favicon_frames.cc +++ b/components/favicon_base/select_favicon_frames.cc @@ -41,8 +41,9 @@ SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) { { SkCanvas canvas(bitmap); - SkRect dest(SkRect::MakeWH(desired_size, desired_size)); - canvas.drawBitmapRect(contents, NULL, dest); + canvas.drawBitmapRect( + contents, NULL, + SkRect::MakeFromIRect(SkIRect::MakeWH(desired_size, desired_size))); } return bitmap; @@ -224,7 +225,8 @@ gfx::ImageSkia CreateFaviconImageSkia( } else { for (std::vector<float>::const_iterator iter = favicon_scales.begin(); iter != favicon_scales.end(); ++iter) { - desired_sizes.push_back(ceil(desired_size_in_dip * (*iter))); + desired_sizes.push_back( + static_cast<int>(ceil(desired_size_in_dip * (*iter)))); } } |