[email protected] | b01048d | 2013-04-18 11:06:43 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_THUMBNAILS_CONTENT_ANALYSIS_H_ |
| 6 | #define CHROME_BROWSER_THUMBNAILS_CONTENT_ANALYSIS_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | #include "base/basictypes.h" |
| 11 | #include "third_party/skia/include/core/SkColor.h" |
| 12 | #include "ui/base/ui_export.h" |
| 13 | #include "ui/gfx/rect.h" |
| 14 | #include "ui/gfx/size.h" |
| 15 | |
| 16 | class SkBitmap; |
| 17 | |
| 18 | namespace thumbnailing_utils { |
| 19 | |
| 20 | // Compute in-place gaussian gradient magnitude of |input_bitmap| with sigma |
| 21 | // |kernel_sigma|. |input_bitmap| is requried to be of SkBitmap::kA8_Config |
| 22 | // type. The routine computes first-order gaussian derivative on a |
| 23 | // gaussian-smoothed image. Beware, this is fairly slow since kernel size is |
| 24 | // 4 * kernel_sigma + 1. |
| 25 | void ApplyGaussianGradientMagnitudeFilter(SkBitmap* input_bitmap, |
| 26 | float kernel_sigma); |
| 27 | |
| 28 | // Accumulates vertical and horizontal sum of pixel values from a subsection of |
| 29 | // |input_bitmap| defined by |image_area|. The image is required to be of |
| 30 | // SkBitmap::kA8_Config type. |
| 31 | // If non-empty |target_size| is given, the routine will use it to process the |
| 32 | // profiles with closing operator sized to eliminate gaps which would be smaller |
| 33 | // than 1 pixel after rescaling to |target_size|. |
| 34 | // If |apply_log| is true, logarithm of counts are used for morhology (and |
| 35 | // returned). |
| 36 | void ExtractImageProfileInformation(const SkBitmap& input_bitmap, |
| 37 | const gfx::Rect& image_area, |
| 38 | const gfx::Size& target_size, |
| 39 | bool apply_log, |
| 40 | std::vector<float>* rows, |
| 41 | std::vector<float>* columns); |
| 42 | |
| 43 | // Compute a threshold value separating background (low) from signal (high) |
| 44 | // areas in the |input| profile. |
| 45 | float AutoSegmentPeaks(const std::vector<float>& input); |
| 46 | |
| 47 | // Shrinks the source |bitmap| by removing rows and columns where |rows| and |
| 48 | // |columns| are false, respectively. The function returns a new bitmap if the |
| 49 | // shrinking can be performed and an empty instance otherwise. |
| 50 | SkBitmap ComputeDecimatedImage(const SkBitmap& bitmap, |
| 51 | const std::vector<bool>& rows, |
| 52 | const std::vector<bool>& columns); |
| 53 | |
| 54 | // Creates a new bitmap which contains only 'interesting' areas of |
| 55 | // |source_bitmap|. The |target_size| is used to estimate some computation |
| 56 | // parameters, but the resulting bitmap will not necessarily be of that size. |
| 57 | // |kernel_sigma| defines the degree of image smoothing in gradient computation. |
| 58 | // For a natural-sized (not shrunk) screenshot at 96 DPI and regular font size |
| 59 | // 5.0 was determined to be a good value. |
[email protected] | 821e62c | 2013-06-04 06:04:09 | [diff] [blame^] | 60 | SkBitmap CreateRetargetedThumbnailImage(const SkBitmap& source_bitmap, |
| 61 | const gfx::Size& target_size, |
| 62 | float kernel_sigma); |
[email protected] | b01048d | 2013-04-18 11:06:43 | [diff] [blame] | 63 | |
| 64 | } // namespace thumbnailing_utils |
| 65 | |
| 66 | #endif // CHROME_BROWSER_THUMBNAILS_CONTENT_ANALYSIS_H_ |