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
17 class SimpleThumbnailCrop
: public ThumbnailingAlgorithm
{
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
* target_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
,
39 thumbnails::ClipResult
* clip_result
);
40 static gfx::Size
GetCopySizeForThumbnail(ui::ScaleFactor scale_factor
,
41 const gfx::Size
& thumbnail_size
);
42 static gfx::Rect
GetClippingRect(const gfx::Size
& source_size
,
43 const gfx::Size
& desired_size
,
44 ClipResult
* clip_result
);
46 // Computes the size of a thumbnail that should be stored in the database from
47 // |given_size| (expected to be the thumbnail size we would normally want to
48 // see). The returned size is expressed in pixels and is determined by
49 // bumping the resolution up to the maximum scale factor.
50 static gfx::Size
ComputeTargetSizeAtMaximumScale(const gfx::Size
& given_size
);
53 ~SimpleThumbnailCrop() override
;
56 static SkBitmap
CreateThumbnail(const SkBitmap
& bitmap
,
57 const gfx::Size
& desired_size
,
58 ClipResult
* clip_result
);
60 const gfx::Size target_size_
;
62 DISALLOW_COPY_AND_ASSIGN(SimpleThumbnailCrop
);
65 } // namespace thumbnails
67 #endif // CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_