| 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/favicon/favicon_types.h" | 7 #include "chrome/browser/favicon/favicon_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 "content/public/child/image_decoder_utils.h" |
| 10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 11 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/gfx/codec/png_codec.h" | 14 #include "ui/gfx/codec/png_codec.h" |
| 14 #include "ui/gfx/favicon_size.h" | 15 #include "ui/gfx/favicon_size.h" |
| 15 #include "ui/gfx/image/image_png_rep.h" | 16 #include "ui/gfx/image/image_png_rep.h" |
| 16 #include "ui/gfx/image/image_skia.h" | 17 #include "ui/gfx/image/image_skia.h" |
| 17 #include "webkit/glue/image_decoder.h" | 18 #include "ui/gfx/size.h" |
| 18 | 19 |
| 19 #if defined(OS_MACOSX) && !defined(OS_IOS) | 20 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 20 #include "base/mac/mac_util.h" | 21 #include "base/mac/mac_util.h" |
| 21 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 22 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Creates image reps of DIP size |favicon_size| for the subset of | 26 // Creates image reps of DIP size |favicon_size| for the subset of |
| 26 // |scale_factors| for which the image reps can be created without resizing | 27 // |scale_factors| for which the image reps can be created without resizing |
| 27 // or decoding the bitmap data. | 28 // or decoding the bitmap data. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 &selected_bitmap_indices, NULL); | 199 &selected_bitmap_indices, NULL); |
| 199 DCHECK_EQ(1u, selected_bitmap_indices.size()); | 200 DCHECK_EQ(1u, selected_bitmap_indices.size()); |
| 200 return selected_bitmap_indices[0]; | 201 return selected_bitmap_indices[0]; |
| 201 } | 202 } |
| 202 | 203 |
| 203 // static | 204 // static |
| 204 bool FaviconUtil::ReencodeFavicon(const unsigned char* src_data, | 205 bool FaviconUtil::ReencodeFavicon(const unsigned char* src_data, |
| 205 size_t src_len, | 206 size_t src_len, |
| 206 std::vector<unsigned char>* png_data) { | 207 std::vector<unsigned char>* png_data) { |
| 207 // Decode the favicon using WebKit's image decoder. | 208 // Decode the favicon using WebKit's image decoder. |
| 208 webkit_glue::ImageDecoder decoder( | 209 SkBitmap decoded = content::DecodeImage( |
| 209 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); | 210 src_data, |
| 210 SkBitmap decoded = decoder.Decode(src_data, src_len); | 211 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
| 212 src_len); |
| 211 if (decoded.empty()) | 213 if (decoded.empty()) |
| 212 return false; // Unable to decode. | 214 return false; // Unable to decode. |
| 213 | 215 |
| 214 if (decoded.width() != gfx::kFaviconSize || | 216 if (decoded.width() != gfx::kFaviconSize || |
| 215 decoded.height() != gfx::kFaviconSize) { | 217 decoded.height() != gfx::kFaviconSize) { |
| 216 // The bitmap is not the correct size, re-sample. | 218 // The bitmap is not the correct size, re-sample. |
| 217 int new_width = decoded.width(); | 219 int new_width = decoded.width(); |
| 218 int new_height = decoded.height(); | 220 int new_height = decoded.height(); |
| 219 gfx::CalculateFaviconTargetSize(&new_width, &new_height); | 221 gfx::CalculateFaviconTargetSize(&new_width, &new_height); |
| 220 decoded = skia::ImageOperations::Resize( | 222 decoded = skia::ImageOperations::Resize( |
| 221 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); | 223 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); |
| 222 } | 224 } |
| 223 | 225 |
| 224 // Encode our bitmap as a PNG. | 226 // Encode our bitmap as a PNG. |
| 225 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); | 227 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); |
| 226 return true; | 228 return true; |
| 227 } | 229 } |
| OLD | NEW |