| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SKIA_EXT_IMAGE_OPERATIONS_H_ | |
| 6 #define SKIA_EXT_IMAGE_OPERATIONS_H_ | |
| 7 | |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | |
| 9 #include "third_party/skia/include/core/SkTypes.h" | |
| 10 | |
| 11 struct SkIRect; | |
| 12 | |
| 13 namespace skia { | |
| 14 | |
| 15 class SK_API ImageOperations { | |
| 16 public: | |
| 17 enum ResizeMethod { | |
| 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 | |
| 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 | |
| 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 | |
| 73 // 2-cycle Lanczos filter. This is tall in the middle, goes negative on | |
| 74 // each side, then returns to zero. Does not provide as good a frequency | |
| 75 // response as a 3-cycle Lanczos but is roughly 30% faster. | |
| 76 RESIZE_LANCZOS2, | |
| 77 | |
| 78 // 3-cycle Lanczos filter. This is tall in the middle, goes negative on | |
| 79 // each side, then oscillates 2 more times. It gives nice sharp edges. | |
| 80 RESIZE_LANCZOS3, | |
| 81 | |
| 82 // enum aliases for first and last methods by algorithm or by quality. | |
| 83 RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD, | |
| 84 RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST, | |
| 85 RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX, | |
| 86 RESIZE_LAST_ALGORITHM_METHOD = RESIZE_LANCZOS3, | |
| 87 }; | |
| 88 | |
| 89 // Resizes the given source bitmap using the specified resize method, so that | |
| 90 // the entire image is (dest_size) big. The dest_subset is the rectangle in | |
| 91 // this destination image that should actually be returned. | |
| 92 // | |
| 93 // The output image will be (dest_subset.width(), dest_subset.height()). This | |
| 94 // will save work if you do not need the entire bitmap. | |
| 95 // | |
| 96 // The destination subset must be smaller than the destination image. | |
| 97 static SkBitmap Resize(const SkBitmap& source, | |
| 98 ResizeMethod method, | |
| 99 int dest_width, int dest_height, | |
| 100 const SkIRect& dest_subset, | |
| 101 SkBitmap::Allocator* allocator = NULL); | |
| 102 | |
| 103 // Alternate version for resizing and returning the entire bitmap rather than | |
| 104 // a subset. | |
| 105 static SkBitmap Resize(const SkBitmap& source, | |
| 106 ResizeMethod method, | |
| 107 int dest_width, int dest_height, | |
| 108 SkBitmap::Allocator* allocator = NULL); | |
| 109 | |
| 110 private: | |
| 111 ImageOperations(); // Class for scoping only. | |
| 112 }; | |
| 113 | |
| 114 } // namespace skia | |
| 115 | |
| 116 #endif // SKIA_EXT_IMAGE_OPERATIONS_H_ | |
| OLD | NEW |