- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / thumbnails / content_analysis.h
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 // Compute and return a workable (not too distorted, not bigger than the image)
48 // target size for retargeting in ConstrainedProfileSegmentation. |target_size|
49 // is the desired image size (defines aspect ratio and minimal image size) while
50 // |computed_size| is the size of a result of unconstrained segmentation.
51 // This routine makes very little sense outside ConstrainedProfileSegmentation
52 // and is exposed only for unit tests (it is somehow complicated).
53 gfx::Size AdjustClippingSizeToAspectRatio(const gfx::Size& target_size,
54                                           const gfx::Size& image_size,
55                                           const gfx::Size& computed_size);
56
57 // Compute thresholding guides |included_rows| and |included_columns| by
58 // segmenting 1-d profiles |row_profile| and |column_profile|. The routine will
59 // attempt to keep the image which would result from using these guides as close
60 // to the desired aspect ratio (given by |target_size|) as reasonable.
61 void ConstrainedProfileSegmentation(const std::vector<float>& row_profile,
62                                     const std::vector<float>& column_profile,
63                                     const gfx::Size& target_size,
64                                     std::vector<bool>* included_rows,
65                                     std::vector<bool>* included_columns);
66
67 // Shrinks the source |bitmap| by removing rows and columns where |rows| and
68 // |columns| are false, respectively. The function returns a new bitmap if the
69 // shrinking can be performed and an empty instance otherwise.
70 SkBitmap ComputeDecimatedImage(const SkBitmap& bitmap,
71                                const std::vector<bool>& rows,
72                                const std::vector<bool>& columns);
73
74 // Creates a new bitmap which contains only 'interesting' areas of
75 // |source_bitmap|. The |target_size| is used to estimate some computation
76 // parameters, but the resulting bitmap will not necessarily be of that size.
77 // |kernel_sigma| defines the degree of image smoothing in gradient computation.
78 // For a natural-sized (not shrunk) screenshot at 96 DPI and regular font size
79 // 5.0 was determined to be a good value.
80 SkBitmap CreateRetargetedThumbnailImage(const SkBitmap& source_bitmap,
81                                         const gfx::Size& target_size,
82                                         float kernel_sigma);
83
84 }  // namespace thumbnailing_utils
85
86 #endif  // CHROME_BROWSER_THUMBNAILS_CONTENT_ANALYSIS_H_