michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkBitmapScaler_DEFINED michael@0: #define SkBitmapScaler_DEFINED michael@0: michael@0: #include "SkBitmap.h" michael@0: #include "SkConvolver.h" michael@0: michael@0: /** \class SkBitmapScaler michael@0: michael@0: Provides the interface for high quality image resampling. michael@0: */ michael@0: michael@0: class SK_API SkBitmapScaler { michael@0: public: michael@0: enum ResizeMethod { 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: RESIZE_TRIANGLE, michael@0: RESIZE_LANCZOS3, michael@0: RESIZE_HAMMING, michael@0: RESIZE_MITCHELL, 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_MITCHELL, 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 bool Resize(SkBitmap* result, michael@0: const SkBitmap& source, michael@0: ResizeMethod method, michael@0: int dest_width, int dest_height, michael@0: const SkIRect& dest_subset, michael@0: const SkConvolutionProcs&, michael@0: SkBitmap::Allocator* allocator = NULL); michael@0: michael@0: // Alternate version for resizing and returning the entire bitmap rather than michael@0: // a subset. michael@0: static bool Resize(SkBitmap* result, michael@0: const SkBitmap& source, michael@0: ResizeMethod method, michael@0: int dest_width, int dest_height, michael@0: const SkConvolutionProcs&, michael@0: SkBitmap::Allocator* allocator = NULL); michael@0: }; michael@0: michael@0: #endif