michael@0: // Copyright (c) 2006-2011 The Chromium Authors. All rights reserved. michael@0: // michael@0: // Redistribution and use in source and binary forms, with or without michael@0: // modification, are permitted provided that the following conditions michael@0: // are met: michael@0: // * Redistributions of source code must retain the above copyright michael@0: // notice, this list of conditions and the following disclaimer. michael@0: // * Redistributions in binary form must reproduce the above copyright michael@0: // notice, this list of conditions and the following disclaimer in michael@0: // the documentation and/or other materials provided with the michael@0: // distribution. michael@0: // * Neither the name of Google, Inc. nor the names of its contributors michael@0: // may be used to endorse or promote products derived from this michael@0: // software without specific prior written permission. michael@0: // michael@0: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS michael@0: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE michael@0: // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, michael@0: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, michael@0: // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS michael@0: // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED michael@0: // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, michael@0: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT michael@0: // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@0: // SUCH DAMAGE. michael@0: michael@0: #ifndef SKIA_EXT_IMAGE_OPERATIONS_H_ michael@0: #define SKIA_EXT_IMAGE_OPERATIONS_H_ michael@0: michael@0: #include "skia/SkTypes.h" michael@0: #include "Types.h" michael@0: michael@0: class SkBitmap; michael@0: struct SkIRect; michael@0: michael@0: namespace skia { michael@0: michael@0: class ImageOperations { michael@0: public: michael@0: enum ResizeMethod { michael@0: // michael@0: // Quality Methods michael@0: // michael@0: // Those enumeration values express a desired quality/speed tradeoff. michael@0: // They are translated into an algorithm-specific method that depends michael@0: // on the capabilities (CPU, GPU) of the underlying platform. michael@0: // It is possible for all three methods to be mapped to the same michael@0: // algorithm on a given platform. michael@0: michael@0: // Good quality resizing. Fastest resizing with acceptable visual quality. michael@0: // This is typically intended for use during interactive layouts michael@0: // where slower platforms may want to trade image quality for large michael@0: // increase in resizing performance. michael@0: // michael@0: // For example the resizing implementation may devolve to linear michael@0: // filtering if this enables GPU acceleration to be used. michael@0: // michael@0: // Note that the underlying resizing method may be determined michael@0: // on the fly based on the parameters for a given resize call. michael@0: // For example an implementation using a GPU-based linear filter michael@0: // in the common case may still use a higher-quality software-based michael@0: // filter in cases where using the GPU would actually be slower - due michael@0: // to too much latency - or impossible - due to image format or size michael@0: // constraints. michael@0: RESIZE_GOOD, michael@0: michael@0: // Medium quality resizing. Close to high quality resizing (better michael@0: // than linear interpolation) with potentially some quality being michael@0: // traded-off for additional speed compared to RESIZE_BEST. michael@0: // michael@0: // This is intended, for example, for generation of large thumbnails michael@0: // (hundreds of pixels in each dimension) from large sources, where michael@0: // a linear filter would produce too many artifacts but where michael@0: // a RESIZE_HIGH might be too costly time-wise. michael@0: RESIZE_BETTER, michael@0: michael@0: // High quality resizing. The algorithm is picked to favor image quality. michael@0: RESIZE_BEST, michael@0: michael@0: // michael@0: // Algorithm-specific enumerations michael@0: // michael@0: michael@0: // Box filter. This is a weighted average of all of the pixels touching michael@0: // the destination pixel. For enlargement, this is nearest neighbor. michael@0: // michael@0: // You probably don't want this, it is here for testing since it is easy to michael@0: // compute. Use RESIZE_LANCZOS3 instead. michael@0: RESIZE_BOX, michael@0: michael@0: // 1-cycle Hamming filter. This is tall is the middle and falls off towards michael@0: // the window edges but without going to 0. This is about 40% faster than michael@0: // a 2-cycle Lanczos. michael@0: RESIZE_HAMMING1, michael@0: michael@0: // 2-cycle Lanczos filter. This is tall in the middle, goes negative on michael@0: // each side, then returns to zero. Does not provide as good a frequency michael@0: // response as a 3-cycle Lanczos but is roughly 30% faster. michael@0: RESIZE_LANCZOS2, michael@0: michael@0: // 3-cycle Lanczos filter. This is tall in the middle, goes negative on michael@0: // each side, then oscillates 2 more times. It gives nice sharp edges. michael@0: RESIZE_LANCZOS3, michael@0: michael@0: // Lanczos filter + subpixel interpolation. If subpixel rendering is not michael@0: // appropriate we automatically fall back to Lanczos. michael@0: RESIZE_SUBPIXEL, michael@0: michael@0: // enum aliases for first and last methods by algorithm or by quality. michael@0: RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD, michael@0: RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST, michael@0: RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX, michael@0: RESIZE_LAST_ALGORITHM_METHOD = RESIZE_SUBPIXEL, michael@0: }; michael@0: michael@0: // Resizes the given source bitmap using the specified resize method, so that michael@0: // the entire image is (dest_size) big. The dest_subset is the rectangle in michael@0: // this destination image that should actually be returned. michael@0: // michael@0: // The output image will be (dest_subset.width(), dest_subset.height()). This michael@0: // will save work if you do not need the entire bitmap. michael@0: // michael@0: // The destination subset must be smaller than the destination image. michael@0: static SkBitmap Resize(const SkBitmap& source, michael@0: ResizeMethod method, michael@0: int dest_width, int dest_height, michael@0: const SkIRect& dest_subset, michael@0: void* dest_pixels = nullptr); michael@0: michael@0: // Alternate version for resizing and returning the entire bitmap rather than michael@0: // a subset. michael@0: static SkBitmap Resize(const SkBitmap& source, michael@0: ResizeMethod method, michael@0: int dest_width, int dest_height, michael@0: void* dest_pixels = nullptr); michael@0: michael@0: private: michael@0: ImageOperations(); // Class for scoping only. michael@0: michael@0: // Supports all methods except RESIZE_SUBPIXEL. michael@0: static SkBitmap ResizeBasic(const SkBitmap& source, michael@0: ResizeMethod method, michael@0: int dest_width, int dest_height, michael@0: const SkIRect& dest_subset, michael@0: void* dest_pixels = nullptr); michael@0: michael@0: // Subpixel renderer. michael@0: static SkBitmap ResizeSubpixel(const SkBitmap& source, michael@0: int dest_width, int dest_height, michael@0: const SkIRect& dest_subset); michael@0: }; michael@0: michael@0: } // namespace skia michael@0: michael@0: #endif // SKIA_EXT_IMAGE_OPERATIONS_H_