[email protected] | 384853b | 2011-01-30 17:58:21 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 5 | #ifndef SKIA_EXT_IMAGE_OPERATIONS_H_ |
| 6 | #define SKIA_EXT_IMAGE_OPERATIONS_H_ |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 7 | |
[email protected] | 7f02ff9 | 2013-01-18 15:16:23 | [diff] [blame] | 8 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | cf69668 | 2011-03-17 03:05:55 | [diff] [blame] | 9 | #include "third_party/skia/include/core/SkTypes.h" |
| 10 | |
[email protected] | cab34d6a | 2009-09-24 01:14:52 | [diff] [blame] | 11 | struct SkIRect; |
[email protected] | c4b347b | 2008-12-10 16:16:35 | [diff] [blame] | 12 | |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 13 | namespace skia { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 14 | |
[email protected] | cf69668 | 2011-03-17 03:05:55 | [diff] [blame] | 15 | class SK_API ImageOperations { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 16 | public: |
| 17 | enum ResizeMethod { |
[email protected] | 384853b | 2011-01-30 17:58:21 | [diff] [blame] | 18 | // |
| 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.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 61 | // 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] | 384853b | 2011-01-30 17:58:21 | [diff] [blame] | 68 | // 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.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 73 | // 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] | 15e46d2 | 2010-03-01 20:16:56 | [diff] [blame] | 76 | |
[email protected] | 384853b | 2011-01-30 17:58:21 | [diff] [blame] | 77 | // 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, |
fmalita | a006a8c | 2014-11-25 05:35:01 | [diff] [blame] | 81 | RESIZE_LAST_ALGORITHM_METHOD = RESIZE_LANCZOS3, |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 82 | }; |
| 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] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 94 | int dest_width, int dest_height, |
[email protected] | 7f02ff9 | 2013-01-18 15:16:23 | [diff] [blame] | 95 | const SkIRect& dest_subset, |
| 96 | SkBitmap::Allocator* allocator = NULL); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 97 | |
| 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] | 7f02ff9 | 2013-01-18 15:16:23 | [diff] [blame] | 102 | int dest_width, int dest_height, |
| 103 | SkBitmap::Allocator* allocator = NULL); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 104 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 105 | private: |
| 106 | ImageOperations(); // Class for scoping only. |
| 107 | }; |
| 108 | |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 109 | } // namespace skia |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 110 | |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 111 | #endif // SKIA_EXT_IMAGE_OPERATIONS_H_ |