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

Unified Diff: chrome/browser/thumbnails/simple_thumbnail_crop.h

Issue 11985003: Refactored-out the code of thumbnaling algorithm from thumbnail_tab_helper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another round of updates from OWNER's review. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/thumbnails/simple_thumbnail_crop.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/thumbnails/simple_thumbnail_crop.h
diff --git a/chrome/browser/thumbnails/simple_thumbnail_crop.h b/chrome/browser/thumbnails/simple_thumbnail_crop.h
new file mode 100644
index 0000000000000000000000000000000000000000..472eda75b3b7e3ede4e66c0f16073764b4bf45d7
--- /dev/null
+++ b/chrome/browser/thumbnails/simple_thumbnail_crop.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2013 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 CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
+#define CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
+
+#include "chrome/browser/thumbnails/thumbnailing_algorithm.h"
+
+namespace thumbnails {
+
+// The implementation of the 'classic' thumbnail cropping algorithm. It is not
+// content-driven in any meaningful way (save for score calculation). Rather,
+// the choice of a cropping region is based on relation between source and
+// target sizes. The selected source region is then rescaled into the target
+// thumbnail image.
+class SimpleThumbnailCrop : public ThumbnailingAlgorithm {
+ public:
+ explicit SimpleThumbnailCrop(const gfx::Size& target_size);
+
+ virtual ClipResult GetCanvasCopyInfo(const gfx::Size& source_size,
+ ui::ScaleFactor scale_factor,
+ gfx::Rect* clipping_rect,
+ gfx::Size* target_size) const OVERRIDE;
+
+ virtual void ProcessBitmap(ThumbnailingContext* context,
+ const ConsumerCallback& callback,
+ const SkBitmap& bitmap) OVERRIDE;
+
+ // Calculates how "boring" a thumbnail is. The boring score is the
+ // 0,1 ranged percentage of pixels that are the most common
+ // luma. Higher boring scores indicate that a higher percentage of a
+ // bitmap are all the same brightness.
+ // Statically exposed for use by tests only.
+ static double CalculateBoringScore(const SkBitmap& bitmap);
+
+ // Gets the clipped bitmap from |bitmap| per the aspect ratio of the
+ // desired width and the desired height. For instance, if the input
+ // bitmap is vertically long (ex. 400x900) and the desired size is
+ // square (ex. 100x100), the clipped bitmap will be the top half of the
+ // input bitmap (400x400).
+ // Statically exposed for use by tests only.
+ static SkBitmap GetClippedBitmap(const SkBitmap& bitmap,
+ int desired_width,
+ int desired_height,
+ thumbnails::ClipResult* clip_result);
+ static gfx::Size GetCopySizeForThumbnail(ui::ScaleFactor scale_factor,
+ const gfx::Size& thumbnail_size);
+
+ protected:
+ virtual ~SimpleThumbnailCrop();
+
+ private:
+ gfx::Size GetThumbnailSizeInPixel() const;
+ static gfx::Rect GetClippingRect(const gfx::Size& source_size,
+ const gfx::Size& desired_size,
+ ClipResult* clip_result);
+ static SkBitmap CreateThumbnail(const SkBitmap& bitmap,
+ const gfx::Size& desired_size,
+ ClipResult* clip_result);
+
+ const gfx::Size target_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleThumbnailCrop);
+};
+
+}
+
+#endif // CHROME_BROWSER_THUMBNAILS_SIMPLE_THUMBNAIL_CROP_H_
« no previous file with comments | « no previous file | chrome/browser/thumbnails/simple_thumbnail_crop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698