OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 SKIA_EXT_IMAGE_OPERATIONS_H_ | 5 #ifndef SKIA_EXT_IMAGE_OPERATIONS_H_ |
6 #define SKIA_EXT_IMAGE_OPERATIONS_H_ | 6 #define SKIA_EXT_IMAGE_OPERATIONS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 class SkBitmap; | 9 class SkBitmap; |
10 struct SkIRect; | 10 struct SkIRect; |
11 | 11 |
12 namespace skia { | 12 namespace skia { |
13 | 13 |
14 class ImageOperations { | 14 class ImageOperations { |
15 public: | 15 public: |
16 enum ResizeMethod { | 16 enum ResizeMethod { |
| 17 // |
| 18 // Quality Methods |
| 19 // |
| 20 // Those enumeration values express a desired quality/speed tradeoff. |
| 21 // They are translated into an algorithm-specific method that depends |
| 22 // on the capabilities (CPU, GPU) of the underlying platform. |
| 23 // It is possible for all three methods to be mapped to the same |
| 24 // algorithm on a given platform. |
| 25 |
| 26 // Good quality resizing. Fastest resizing with acceptable visual quality. |
| 27 // This is typically intended for use during interactive layouts |
| 28 // where slower platforms may want to trade image quality for large |
| 29 // increase in resizing performance. |
| 30 // |
| 31 // For example the resizing implementation may devolve to linear |
| 32 // filtering if this enables GPU acceleration to be used. |
| 33 // |
| 34 // Note that the underlying resizing method may be determined |
| 35 // on the fly based on the parameters for a given resize call. |
| 36 // For example an implementation using a GPU-based linear filter |
| 37 // in the common case may still use a higher-quality software-based |
| 38 // filter in cases where using the GPU would actually be slower - due |
| 39 // to too much latency - or impossible - due to image format or size |
| 40 // constraints. |
| 41 RESIZE_GOOD, |
| 42 |
| 43 // Medium quality resizing. Close to high quality resizing (better |
| 44 // than linear interpolation) with potentially some quality being |
| 45 // traded-off for additional speed compared to RESIZE_BEST. |
| 46 // |
| 47 // This is intended, for example, for generation of large thumbnails |
| 48 // (hundreds of pixels in each dimension) from large sources, where |
| 49 // a linear filter would produce too many artifacts but where |
| 50 // a RESIZE_HIGH might be too costly time-wise. |
| 51 RESIZE_BETTER, |
| 52 |
| 53 // High quality resizing. The algorithm is picked to favor image quality. |
| 54 RESIZE_BEST, |
| 55 |
| 56 // |
| 57 // Algorithm-specific enumerations |
| 58 // |
| 59 |
17 // Box filter. This is a weighted average of all of the pixels touching | 60 // Box filter. This is a weighted average of all of the pixels touching |
18 // the destination pixel. For enlargement, this is nearest neighbor. | 61 // the destination pixel. For enlargement, this is nearest neighbor. |
19 // | 62 // |
20 // You probably don't want this, it is here for testing since it is easy to | 63 // You probably don't want this, it is here for testing since it is easy to |
21 // compute. Use RESIZE_LANCZOS3 instead. | 64 // compute. Use RESIZE_LANCZOS3 instead. |
22 RESIZE_BOX, | 65 RESIZE_BOX, |
23 | 66 |
| 67 // 1-cycle Hamming filter. This is tall is the middle and falls off towards |
| 68 // the window edges but without going to 0. This is about 40% faster than |
| 69 // a 2-cycle Lanczos. |
| 70 RESIZE_HAMMING1, |
| 71 |
| 72 // 2-cycle Lanczos filter. This is tall in the middle, goes negative on |
| 73 // each side, then returns to zero. Does not provide as good a frequency |
| 74 // response as a 3-cycle Lanczos but is roughly 30% faster. |
| 75 RESIZE_LANCZOS2, |
| 76 |
24 // 3-cycle Lanczos filter. This is tall in the middle, goes negative on | 77 // 3-cycle Lanczos filter. This is tall in the middle, goes negative on |
25 // each side, then oscillates 2 more times. It gives nice sharp edges. | 78 // each side, then oscillates 2 more times. It gives nice sharp edges. |
26 RESIZE_LANCZOS3, | 79 RESIZE_LANCZOS3, |
27 | 80 |
28 // Lanczos filter + subpixel interpolation. If subpixel rendering is not | 81 // Lanczos filter + subpixel interpolation. If subpixel rendering is not |
29 // appropriate we automatically fall back to Lanczos. | 82 // appropriate we automatically fall back to Lanczos. |
30 RESIZE_SUBPIXEL, | 83 RESIZE_SUBPIXEL, |
| 84 |
| 85 // enum aliases for first and last methods by algorithm or by quality. |
| 86 RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD, |
| 87 RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST, |
| 88 RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX, |
| 89 RESIZE_LAST_ALGORITHM_METHOD = RESIZE_SUBPIXEL, |
31 }; | 90 }; |
32 | 91 |
33 // Resizes the given source bitmap using the specified resize method, so that | 92 // Resizes the given source bitmap using the specified resize method, so that |
34 // the entire image is (dest_size) big. The dest_subset is the rectangle in | 93 // the entire image is (dest_size) big. The dest_subset is the rectangle in |
35 // this destination image that should actually be returned. | 94 // this destination image that should actually be returned. |
36 // | 95 // |
37 // The output image will be (dest_subset.width(), dest_subset.height()). This | 96 // The output image will be (dest_subset.width(), dest_subset.height()). This |
38 // will save work if you do not need the entire bitmap. | 97 // will save work if you do not need the entire bitmap. |
39 // | 98 // |
40 // The destination subset must be smaller than the destination image. | 99 // The destination subset must be smaller than the destination image. |
(...skipping 19 matching lines...) Expand all Loading... |
60 | 119 |
61 // Subpixel renderer. | 120 // Subpixel renderer. |
62 static SkBitmap ResizeSubpixel(const SkBitmap& source, | 121 static SkBitmap ResizeSubpixel(const SkBitmap& source, |
63 int dest_width, int dest_height, | 122 int dest_width, int dest_height, |
64 const SkIRect& dest_subset); | 123 const SkIRect& dest_subset); |
65 }; | 124 }; |
66 | 125 |
67 } // namespace skia | 126 } // namespace skia |
68 | 127 |
69 #endif // SKIA_EXT_IMAGE_OPERATIONS_H_ | 128 #endif // SKIA_EXT_IMAGE_OPERATIONS_H_ |
OLD | NEW |