Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / thumbnails / simple_thumbnail_crop.h
blobb206cc259b67e9968725cea473f3fa16359e4cac
1 // Copyright (c) 2013 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.
5 #ifndef CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
6 #define CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
8 #include "chrome/browser/thumbnails/thumbnailing_algorithm.h"
10 namespace thumbnails {
12 // The implementation of the 'classic' thumbnail cropping algorithm. It is not
13 // content-driven in any meaningful way (save for score calculation). Rather,
14 // the choice of a cropping region is based on relation between source and
15 // target sizes. The selected source region is then rescaled into the target
16 // thumbnail image.
17 class SimpleThumbnailCrop : public ThumbnailingAlgorithm {
18 public:
19 explicit SimpleThumbnailCrop(const gfx::Size& target_size);
21 ClipResult GetCanvasCopyInfo(const gfx::Size& source_size,
22 ui::ScaleFactor scale_factor,
23 gfx::Rect* clipping_rect,
24 gfx::Size* copy_size) const override;
26 void ProcessBitmap(scoped_refptr<ThumbnailingContext> context,
27 const ConsumerCallback& callback,
28 const SkBitmap& bitmap) override;
30 // Gets the clipped bitmap from |bitmap| per the aspect ratio of the
31 // desired width and the desired height. For instance, if the input
32 // bitmap is vertically long (ex. 400x900) and the desired size is
33 // square (ex. 100x100), the clipped bitmap will be the top half of the
34 // input bitmap (400x400).
35 // Statically exposed for use by tests only.
36 static SkBitmap GetClippedBitmap(const SkBitmap& bitmap,
37 int desired_width,
38 int desired_height,
39 thumbnails::ClipResult* clip_result);
40 // Returns the size copied from the backing store. |thumbnail_size| is in
41 // DIP, returned size in pixels.
42 static gfx::Size GetCopySizeForThumbnail(ui::ScaleFactor scale_factor,
43 const gfx::Size& thumbnail_size);
44 static gfx::Rect GetClippingRect(const gfx::Size& source_size,
45 const gfx::Size& desired_size,
46 ClipResult* clip_result);
48 // Computes the size of a thumbnail that should be stored in the database from
49 // |given_size| (expected to be the thumbnail size we would normally want to
50 // see). The returned size is expressed in pixels and is determined by
51 // bumping the resolution up to the maximum scale factor.
52 static gfx::Size ComputeTargetSizeAtMaximumScale(const gfx::Size& given_size);
54 protected:
55 ~SimpleThumbnailCrop() override;
57 private:
58 static SkBitmap CreateThumbnail(const SkBitmap& bitmap,
59 const gfx::Size& desired_size,
60 ClipResult* clip_result);
62 // The target size of the captured thumbnails, in DIPs.
63 const gfx::Size target_size_;
65 DISALLOW_COPY_AND_ASSIGN(SimpleThumbnailCrop);
68 } // namespace thumbnails
70 #endif // CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_