summaryrefslogtreecommitdiffstats
path: root/components/favicon_base/select_favicon_frames.h
blob: cc57a802f8e13a3cabcd271aee53409c53117bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_
#define COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_

#include <vector>

#include "ui/base/layout.h"

class SkBitmap;

namespace gfx {
class ImageSkia;
class Size;
}

// Score which is smaller than the minimum score returned by
// SelectFaviconFrames() or SelectFaviconBitmapIDs().
extern const float kSelectFaviconFramesInvalidScore;

// Takes a list of all bitmaps found in a .ico file, and creates an
// ImageSkia that's |desired_size| x |desired_size| DIP big. This
// function adds a representation at every desired scale factor.
// If |desired_size| is 0, the largest bitmap is returned unmodified.
// |original_sizes| are the original sizes of the bitmaps. (For instance,
// WebContents::DownloadImage() does resampling if it is passed a max size.)
// If score is non-NULL, it receives a score between 0 (bad) and 1 (good)
// that describes how well |bitmaps| were able to produce an image at
// |desired_size| for |scale_factors|.
// The score is arbitrary, but it's best for exact size matches,
// and gets worse the more resampling needs to happen.
// If the resampling algorithm is modified, the resampling done in
// FaviconUtil::SelectFaviconFramesFromPNGs() should probably be modified too as
// it inspired by this method.
gfx::ImageSkia SelectFaviconFrames(
    const std::vector<SkBitmap>& bitmaps,
    const std::vector<gfx::Size>& original_sizes,
    const std::vector<ui::ScaleFactor>& scale_factors,
    int desired_size,
    float* score);

// Takes a list of the pixel sizes of a favicon's favicon bitmaps and returns
// the indices of the best sizes to use to create an ImageSkia that's
// |desired_size| x |desired_size| DIP big. If |desired_size| is 0, the index
// of the largest size is returned. If score is non-NULL, it receives a score
// between 0 (bad) and 1 (good) that describes how well the bitmap data with
// the sizes at |best_indices| will produce an image of |desired_size| DIP for
// |scale_factors|. The score is arbitrary, but it's best for exact size
// matches, and gets worse the more resampling needs to happen.
// TODO(pkotwicz): Remove need to pass in |scale_factors|.
// TODO(pkotwicz): Remove callers of this method for which |frame_pixel_sizes|
// are the sizes of the favicon bitmaps after they were resized.
void SelectFaviconFrameIndices(
    const std::vector<gfx::Size>& frame_pixel_sizes,
    const std::vector<ui::ScaleFactor>& scale_factors,
    int desired_size,
    std::vector<size_t>* best_indices,
    float* score);

#endif  // COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_