blob: 01d364b99e426a0833ae05aab07d1e8d89b9b8bb [file] [log] [blame]
[email protected]384853b2011-01-30 17:58:211// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
[email protected]83c9e6552008-12-03 16:22:105#ifndef SKIA_EXT_IMAGE_OPERATIONS_H_
6#define SKIA_EXT_IMAGE_OPERATIONS_H_
initial.commitd7cae122008-07-26 21:49:387
[email protected]7f02ff92013-01-18 15:16:238#include "third_party/skia/include/core/SkBitmap.h"
[email protected]cf696682011-03-17 03:05:559#include "third_party/skia/include/core/SkTypes.h"
10
[email protected]cab34d6a2009-09-24 01:14:5211struct SkIRect;
[email protected]c4b347b2008-12-10 16:16:3512
[email protected]465b34b72008-12-12 20:19:1413namespace skia {
initial.commitd7cae122008-07-26 21:49:3814
[email protected]cf696682011-03-17 03:05:5515class SK_API ImageOperations {
initial.commitd7cae122008-07-26 21:49:3816 public:
17 enum ResizeMethod {
[email protected]384853b2011-01-30 17:58:2118 //
19 // Quality Methods
20 //
21 // Those enumeration values express a desired quality/speed tradeoff.
22 // They are translated into an algorithm-specific method that depends
23 // on the capabilities (CPU, GPU) of the underlying platform.
24 // It is possible for all three methods to be mapped to the same
25 // algorithm on a given platform.
26
27 // Good quality resizing. Fastest resizing with acceptable visual quality.
28 // This is typically intended for use during interactive layouts
29 // where slower platforms may want to trade image quality for large
30 // increase in resizing performance.
31 //
32 // For example the resizing implementation may devolve to linear
33 // filtering if this enables GPU acceleration to be used.
34 //
35 // Note that the underlying resizing method may be determined
36 // on the fly based on the parameters for a given resize call.
37 // For example an implementation using a GPU-based linear filter
38 // in the common case may still use a higher-quality software-based
39 // filter in cases where using the GPU would actually be slower - due
40 // to too much latency - or impossible - due to image format or size
41 // constraints.
42 RESIZE_GOOD,
43
44 // Medium quality resizing. Close to high quality resizing (better
45 // than linear interpolation) with potentially some quality being
46 // traded-off for additional speed compared to RESIZE_BEST.
47 //
48 // This is intended, for example, for generation of large thumbnails
49 // (hundreds of pixels in each dimension) from large sources, where
50 // a linear filter would produce too many artifacts but where
51 // a RESIZE_HIGH might be too costly time-wise.
52 RESIZE_BETTER,
53
54 // High quality resizing. The algorithm is picked to favor image quality.
55 RESIZE_BEST,
56
57 //
58 // Algorithm-specific enumerations
59 //
60
initial.commitd7cae122008-07-26 21:49:3861 // Box filter. This is a weighted average of all of the pixels touching
62 // the destination pixel. For enlargement, this is nearest neighbor.
63 //
64 // You probably don't want this, it is here for testing since it is easy to
65 // compute. Use RESIZE_LANCZOS3 instead.
66 RESIZE_BOX,
67
[email protected]384853b2011-01-30 17:58:2168 // 1-cycle Hamming filter. This is tall is the middle and falls off towards
69 // the window edges but without going to 0. This is about 40% faster than
70 // a 2-cycle Lanczos.
71 RESIZE_HAMMING1,
72
initial.commitd7cae122008-07-26 21:49:3873 // 3-cycle Lanczos filter. This is tall in the middle, goes negative on
74 // each side, then oscillates 2 more times. It gives nice sharp edges.
75 RESIZE_LANCZOS3,
[email protected]15e46d22010-03-01 20:16:5676
[email protected]384853b2011-01-30 17:58:2177 // enum aliases for first and last methods by algorithm or by quality.
78 RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD,
79 RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST,
80 RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX,
fmalitaa006a8c2014-11-25 05:35:0181 RESIZE_LAST_ALGORITHM_METHOD = RESIZE_LANCZOS3,
initial.commitd7cae122008-07-26 21:49:3882 };
83
84 // Resizes the given source bitmap using the specified resize method, so that
85 // the entire image is (dest_size) big. The dest_subset is the rectangle in
86 // this destination image that should actually be returned.
87 //
88 // The output image will be (dest_subset.width(), dest_subset.height()). This
89 // will save work if you do not need the entire bitmap.
90 //
91 // The destination subset must be smaller than the destination image.
92 static SkBitmap Resize(const SkBitmap& source,
93 ResizeMethod method,
[email protected]465b34b72008-12-12 20:19:1494 int dest_width, int dest_height,
[email protected]7f02ff92013-01-18 15:16:2395 const SkIRect& dest_subset,
96 SkBitmap::Allocator* allocator = NULL);
initial.commitd7cae122008-07-26 21:49:3897
98 // Alternate version for resizing and returning the entire bitmap rather than
99 // a subset.
100 static SkBitmap Resize(const SkBitmap& source,
101 ResizeMethod method,
[email protected]7f02ff92013-01-18 15:16:23102 int dest_width, int dest_height,
103 SkBitmap::Allocator* allocator = NULL);
initial.commitd7cae122008-07-26 21:49:38104
initial.commitd7cae122008-07-26 21:49:38105 private:
106 ImageOperations(); // Class for scoping only.
107};
108
[email protected]465b34b72008-12-12 20:19:14109} // namespace skia
initial.commitd7cae122008-07-26 21:49:38110
[email protected]465b34b72008-12-12 20:19:14111#endif // SKIA_EXT_IMAGE_OPERATIONS_H_