| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #include "chrome/browser/favicon/favicon_util.h" | 5 #include "chrome/browser/favicon/favicon_util.h" |
| 6 | 6 |
| 7 #include "chrome/browser/history/history_types.h" | 7 #include "chrome/browser/history/history_types.h" |
| 8 #include "chrome/browser/history/select_favicon_frames.h" | 8 #include "chrome/browser/history/select_favicon_frames.h" |
| 9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "skia/ext/image_operations.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/gfx/codec/png_codec.h" | 13 #include "ui/gfx/codec/png_codec.h" |
| 14 #include "ui/gfx/favicon_size.h" |
| 12 #include "ui/gfx/image/image_png_rep.h" | 15 #include "ui/gfx/image/image_png_rep.h" |
| 13 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 17 #include "webkit/glue/image_decoder.h" |
| 14 | 18 |
| 15 namespace { | 19 namespace { |
| 16 | 20 |
| 17 // Creates image reps of DIP size |favicon_size| for the subset of | 21 // Creates image reps of DIP size |favicon_size| for the subset of |
| 18 // |scale_factors| for which the image reps can be created without resizing | 22 // |scale_factors| for which the image reps can be created without resizing |
| 19 // or decoding the bitmap data. | 23 // or decoding the bitmap data. |
| 20 std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( | 24 std::vector<gfx::ImagePNGRep> SelectFaviconFramesFromPNGsWithoutResizing( |
| 21 const std::vector<history::FaviconBitmapResult>& png_data, | 25 const std::vector<history::FaviconBitmapResult>& png_data, |
| 22 const std::vector<ui::ScaleFactor>& scale_factors, | 26 const std::vector<ui::ScaleFactor>& scale_factors, |
| 23 int favicon_size) { | 27 int favicon_size) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 int desired_size) { | 181 int desired_size) { |
| 178 std::vector<gfx::Size> sizes; | 182 std::vector<gfx::Size> sizes; |
| 179 for (size_t i = 0; i < bitmaps.size(); ++i) | 183 for (size_t i = 0; i < bitmaps.size(); ++i) |
| 180 sizes.push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); | 184 sizes.push_back(gfx::Size(bitmaps[i].width(), bitmaps[i].height())); |
| 181 std::vector<size_t> selected_bitmap_indices; | 185 std::vector<size_t> selected_bitmap_indices; |
| 182 SelectFaviconFrameIndices(sizes, scale_factors, desired_size, | 186 SelectFaviconFrameIndices(sizes, scale_factors, desired_size, |
| 183 &selected_bitmap_indices, NULL); | 187 &selected_bitmap_indices, NULL); |
| 184 DCHECK_EQ(1u, selected_bitmap_indices.size()); | 188 DCHECK_EQ(1u, selected_bitmap_indices.size()); |
| 185 return selected_bitmap_indices[0]; | 189 return selected_bitmap_indices[0]; |
| 186 } | 190 } |
| 191 |
| 192 // static |
| 193 bool FaviconUtil::ReencodeFavicon(const unsigned char* src_data, |
| 194 size_t src_len, |
| 195 std::vector<unsigned char>* png_data) { |
| 196 // Decode the favicon using WebKit's image decoder. |
| 197 webkit_glue::ImageDecoder decoder( |
| 198 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); |
| 199 SkBitmap decoded = decoder.Decode(src_data, src_len); |
| 200 if (decoded.empty()) |
| 201 return false; // Unable to decode. |
| 202 |
| 203 if (decoded.width() != gfx::kFaviconSize || |
| 204 decoded.height() != gfx::kFaviconSize) { |
| 205 // The bitmap is not the correct size, re-sample. |
| 206 int new_width = decoded.width(); |
| 207 int new_height = decoded.height(); |
| 208 gfx::CalculateFaviconTargetSize(&new_width, &new_height); |
| 209 decoded = skia::ImageOperations::Resize( |
| 210 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); |
| 211 } |
| 212 |
| 213 // Encode our bitmap as a PNG. |
| 214 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); |
| 215 return true; |
| 216 } |
| OLD | NEW |