Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: chrome/browser/thumbnails/simple_thumbnail_crop.h

Issue 1028393003: [Thumbnails] Specify copy size in Pixels, not DIPs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: correct rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_ 5 #ifndef CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
6 #define CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_ 6 #define CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
7 7
8 #include "chrome/browser/thumbnails/thumbnailing_algorithm.h" 8 #include "chrome/browser/thumbnails/thumbnailing_algorithm.h"
9 9
10 namespace thumbnails { 10 namespace thumbnails {
11 11
12 // The implementation of the 'classic' thumbnail cropping algorithm. It is not 12 // The implementation of the 'classic' thumbnail cropping algorithm. It is not
13 // content-driven in any meaningful way (save for score calculation). Rather, 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 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 15 // target sizes. The selected source region is then rescaled into the target
16 // thumbnail image. 16 // thumbnail image.
17 class SimpleThumbnailCrop : public ThumbnailingAlgorithm { 17 class SimpleThumbnailCrop : public ThumbnailingAlgorithm {
18 public: 18 public:
19 explicit SimpleThumbnailCrop(const gfx::Size& target_size); 19 explicit SimpleThumbnailCrop(const gfx::Size& target_size);
20 20
21 ClipResult GetCanvasCopyInfo(const gfx::Size& source_size, 21 ClipResult GetCanvasCopyInfo(const gfx::Size& source_size,
22 ui::ScaleFactor scale_factor, 22 ui::ScaleFactor scale_factor,
23 gfx::Rect* clipping_rect, 23 gfx::Rect* clipping_rect,
24 gfx::Size* target_size) const override; 24 gfx::Size* copy_size) const override;
25 25
26 void ProcessBitmap(scoped_refptr<ThumbnailingContext> context, 26 void ProcessBitmap(scoped_refptr<ThumbnailingContext> context,
27 const ConsumerCallback& callback, 27 const ConsumerCallback& callback,
28 const SkBitmap& bitmap) override; 28 const SkBitmap& bitmap) override;
29 29
30 // Gets the clipped bitmap from |bitmap| per the aspect ratio of the 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 31 // desired width and the desired height. For instance, if the input
32 // bitmap is vertically long (ex. 400x900) and the desired size is 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 33 // square (ex. 100x100), the clipped bitmap will be the top half of the
34 // input bitmap (400x400). 34 // input bitmap (400x400).
35 // Statically exposed for use by tests only. 35 // Statically exposed for use by tests only.
36 static SkBitmap GetClippedBitmap(const SkBitmap& bitmap, 36 static SkBitmap GetClippedBitmap(const SkBitmap& bitmap,
37 int desired_width, 37 int desired_width,
38 int desired_height, 38 int desired_height,
39 thumbnails::ClipResult* clip_result); 39 thumbnails::ClipResult* clip_result);
40 // Returns the size copied from the backing store. |thumbnail_size| is in
41 // DIP, returned size in pixels.
40 static gfx::Size GetCopySizeForThumbnail(ui::ScaleFactor scale_factor, 42 static gfx::Size GetCopySizeForThumbnail(ui::ScaleFactor scale_factor,
41 const gfx::Size& thumbnail_size); 43 const gfx::Size& thumbnail_size);
42 static gfx::Rect GetClippingRect(const gfx::Size& source_size, 44 static gfx::Rect GetClippingRect(const gfx::Size& source_size,
43 const gfx::Size& desired_size, 45 const gfx::Size& desired_size,
44 ClipResult* clip_result); 46 ClipResult* clip_result);
45 47
46 // Computes the size of a thumbnail that should be stored in the database from 48 // 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 49 // |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 50 // see). The returned size is expressed in pixels and is determined by
49 // bumping the resolution up to the maximum scale factor. 51 // bumping the resolution up to the maximum scale factor.
50 static gfx::Size ComputeTargetSizeAtMaximumScale(const gfx::Size& given_size); 52 static gfx::Size ComputeTargetSizeAtMaximumScale(const gfx::Size& given_size);
51 53
52 protected: 54 protected:
53 ~SimpleThumbnailCrop() override; 55 ~SimpleThumbnailCrop() override;
54 56
55 private: 57 private:
56 static SkBitmap CreateThumbnail(const SkBitmap& bitmap, 58 static SkBitmap CreateThumbnail(const SkBitmap& bitmap,
57 const gfx::Size& desired_size, 59 const gfx::Size& desired_size,
58 ClipResult* clip_result); 60 ClipResult* clip_result);
59 61
62 // The target size of the captured thumbnails, in DIPs.
60 const gfx::Size target_size_; 63 const gfx::Size target_size_;
61 64
62 DISALLOW_COPY_AND_ASSIGN(SimpleThumbnailCrop); 65 DISALLOW_COPY_AND_ASSIGN(SimpleThumbnailCrop);
63 }; 66 };
64 67
65 } // namespace thumbnails 68 } // namespace thumbnails
66 69
67 #endif // CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_ 70 #endif // CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
OLDNEW
« no previous file with comments | « chrome/browser/thumbnails/content_based_thumbnailing_algorithm.cc ('k') | chrome/browser/thumbnails/simple_thumbnail_crop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698