select_favicon_frames.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2014 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. #ifndef COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_
  5. #define COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_
  6. #include <stddef.h>
  7. #include <vector>
  8. class SkBitmap;
  9. namespace gfx {
  10. class ImageSkia;
  11. class Size;
  12. }
  13. // Score which is smaller than the minimum score returned by
  14. // SelectFaviconFrames() or SelectFaviconFrameIndices().
  15. extern const float kSelectFaviconFramesInvalidScore;
  16. // Takes a list of all bitmaps found in a .ico file, and creates an
  17. // ImageSkia that's |desired_size_in_dip| x |desired_size_in_dip| big.
  18. // Bitmaps are selected by using |SelectFaviconFrameIndices| and the
  19. // platform's supported favicon scales (favicon_base::GetFaviconScales()).
  20. // If |desired_size_in_dip| is 0, the largest bitmap is returned unmodified.
  21. // |original_sizes| are the original sizes of the bitmaps. (For instance,
  22. // WebContents::DownloadImage() does resampling if it is passed a max size.)
  23. // If score is non-NULL, it receives a score between 0 (bad) and 1 (good)
  24. // that describes how well |bitmaps| were able to produce an image at
  25. // |desired_size_in_dip| for |favicon_scales|.
  26. // The score is arbitrary, but it's best for exact size matches,
  27. // and gets worse the more resampling needs to happen.
  28. // If the resampling algorithm is modified, the resampling done in
  29. // FaviconUtil::SelectFaviconFramesFromPNGs() should probably be modified too as
  30. // it inspired by this method.
  31. // If an unsupported scale (not in the favicon_base::GetFaviconScales())
  32. // is requested, the ImageSkia will automatically scales using lancoz3.
  33. // |original_sizes| represents the pixel sizes of the favicon bitmaps in
  34. // |bitmaps|, which also means both vectors must have the same size.
  35. gfx::ImageSkia CreateFaviconImageSkia(
  36. const std::vector<SkBitmap>& bitmaps,
  37. const std::vector<gfx::Size>& original_sizes,
  38. int desired_size_in_dip,
  39. float* score);
  40. // Takes a list of the pixel sizes of a favicon's favicon bitmaps and returns
  41. // the indices of the best sizes to use to create an ImageSkia with
  42. // ImageSkiaReps with edge sizes |desired_sizes|. If '0' is one of
  43. // |desired_sizes|, the index of the largest size is returned. If |score| is
  44. // non-NULL, |score| is set to a value between 0 (bad) and 1 (good) that
  45. // describes how well the bitmap data with the sizes at |best_indices| will
  46. // produce the ImageSkia. The score is arbitrary, but it's best for exact
  47. // matches, and gets worse the more resampling needs to happen.
  48. // TODO(pkotwicz): Change API so that |desired_sizes| being empty indicates
  49. // that the index of the largest size is requested.
  50. // TODO(pkotwicz): Remove callers of this method for which |frame_pixel_sizes|
  51. // are the sizes of the favicon bitmaps after they were resized.
  52. void SelectFaviconFrameIndices(const std::vector<gfx::Size>& frame_pixel_sizes,
  53. const std::vector<int>& desired_sizes,
  54. std::vector<size_t>* best_indices,
  55. float* score);
  56. #endif // COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_