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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_HISTORY_SELECT_FAVICON_FRAMES_H_ 6 #define CHROME_BROWSER_HISTORY_SELECT_FAVICON_FRAMES_H_ 7 8 #include <vector> 9 10 #include "ui/base/layout.h" 11 12 class SkBitmap; 13 14 namespace gfx { 15 class ImageSkia; 16 class Size; 17 } 18 19 // Score which is smaller than the minimum score returned by 20 // SelectFaviconFrames() or SelectFaviconBitmapIDs(). 21 extern const float kSelectFaviconFramesInvalidScore; 22 23 // Takes a list of all bitmaps found in a .ico file, and creates an 24 // ImageSkia that's |desired_size| x |desired_size| DIP big. This 25 // function adds a representation at every desired scale factor. 26 // If |desired_size| is 0, the largest bitmap is returned unmodified. 27 // |original_sizes| are the original sizes of the bitmaps. (For instance, 28 // WebContents::DownloadImage() does resampling if it is passed a max size.) 29 // If score is non-NULL, it receives a score between 0 (bad) and 1 (good) 30 // that describes how well |bitmaps| were able to produce an image at 31 // |desired_size| for |scale_factors|. 32 // The score is arbitrary, but it's best for exact size matches, 33 // and gets worse the more resampling needs to happen. 34 // If the resampling algorithm is modified, the resampling done in 35 // FaviconUtil::SelectFaviconFramesFromPNGs() should probably be modified too as 36 // it inspired by this method. 37 gfx::ImageSkia SelectFaviconFrames( 38 const std::vector<SkBitmap>& bitmaps, 39 const std::vector<gfx::Size>& original_sizes, 40 const std::vector<ui::ScaleFactor>& scale_factors, 41 int desired_size, 42 float* score); 43 44 // Takes a list of the pixel sizes of a favicon's favicon bitmaps and returns 45 // the indices of the best sizes to use to create an ImageSkia that's 46 // |desired_size| x |desired_size| DIP big. If |desired_size| is 0, the index 47 // of the largest size is returned. If score is non-NULL, it receives a score 48 // between 0 (bad) and 1 (good) that describes how well the bitmap data with 49 // the sizes at |best_indices| will produce an image of |desired_size| DIP for 50 // |scale_factors|. The score is arbitrary, but it's best for exact size 51 // matches, and gets worse the more resampling needs to happen. 52 // TODO(pkotwicz): Remove need to pass in |scale_factors|. 53 // TODO(pkotwicz): Remove callers of this method for which |frame_pixel_sizes| 54 // are the sizes of the favicon bitmaps after they were resized. 55 void SelectFaviconFrameIndices( 56 const std::vector<gfx::Size>& frame_pixel_sizes, 57 const std::vector<ui::ScaleFactor>& scale_factors, 58 int desired_size, 59 std::vector<size_t>* best_indices, 60 float* score); 61 62 #endif // CHROME_BROWSER_HISTORY_SELECT_FAVICON_FRAMES_H_ 63