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

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

Issue 15458003: Plugs in the new thumbnailing algorithm to ThumbnailTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests. Created 7 years, 7 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 | Annotate | Revision Log
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 virtual ClipResult GetCanvasCopyInfo(const gfx::Size& source_size, 21 virtual 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* target_size) const OVERRIDE;
25 25
26 virtual void ProcessBitmap(ThumbnailingContext* context, 26 virtual 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 // Calculates how "boring" a thumbnail is. The boring score is the 30 // Calculates how "boring" a thumbnail is. The boring score is the
31 // 0,1 ranged percentage of pixels that are the most common 31 // 0,1 ranged percentage of pixels that are the most common
32 // luma. Higher boring scores indicate that a higher percentage of a 32 // luma. Higher boring scores indicate that a higher percentage of a
33 // bitmap are all the same brightness. 33 // bitmap are all the same brightness.
34 // Statically exposed for use by tests only. 34 // Statically exposed for use by tests only.
35 static double CalculateBoringScore(const SkBitmap& bitmap); 35 static double CalculateBoringScore(const SkBitmap& bitmap);
36 36
37 // Gets the clipped bitmap from |bitmap| per the aspect ratio of the 37 // Gets the clipped bitmap from |bitmap| per the aspect ratio of the
38 // desired width and the desired height. For instance, if the input 38 // desired width and the desired height. For instance, if the input
39 // bitmap is vertically long (ex. 400x900) and the desired size is 39 // bitmap is vertically long (ex. 400x900) and the desired size is
40 // square (ex. 100x100), the clipped bitmap will be the top half of the 40 // square (ex. 100x100), the clipped bitmap will be the top half of the
41 // input bitmap (400x400). 41 // input bitmap (400x400).
42 // Statically exposed for use by tests only. 42 // Statically exposed for use by tests only.
43 static SkBitmap GetClippedBitmap(const SkBitmap& bitmap, 43 static SkBitmap GetClippedBitmap(const SkBitmap& bitmap,
44 int desired_width, 44 int desired_width,
45 int desired_height, 45 int desired_height,
46 thumbnails::ClipResult* clip_result); 46 thumbnails::ClipResult* clip_result);
47 static gfx::Size GetCopySizeForThumbnail(ui::ScaleFactor scale_factor, 47 static gfx::Size GetCopySizeForThumbnail(ui::ScaleFactor scale_factor,
48 const gfx::Size& thumbnail_size); 48 const gfx::Size& thumbnail_size);
49 static gfx::Rect GetClippingRect(const gfx::Size& source_size,
50 const gfx::Size& desired_size,
51 ClipResult* clip_result);
49 52
50 protected: 53 protected:
51 virtual ~SimpleThumbnailCrop(); 54 virtual ~SimpleThumbnailCrop();
52 55
53 private: 56 private:
54 gfx::Size GetThumbnailSizeInPixel() const; 57 gfx::Size GetThumbnailSizeInPixel() const;
55 static gfx::Rect GetClippingRect(const gfx::Size& source_size,
56 const gfx::Size& desired_size,
57 ClipResult* clip_result);
58 static SkBitmap CreateThumbnail(const SkBitmap& bitmap, 58 static SkBitmap CreateThumbnail(const SkBitmap& bitmap,
59 const gfx::Size& desired_size, 59 const gfx::Size& desired_size,
60 ClipResult* clip_result); 60 ClipResult* clip_result);
61 61
62 const gfx::Size target_size_; 62 const gfx::Size target_size_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(SimpleThumbnailCrop); 64 DISALLOW_COPY_AND_ASSIGN(SimpleThumbnailCrop);
65 }; 65 };
66 66
67 } 67 }
68 68
69 #endif // CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_ 69 #endif // CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698