1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkBitmapScaler_DEFINED 9 #define SkBitmapScaler_DEFINED 10 11 #include "SkBitmap.h" 12 #include "SkConvolver.h" 13 14 /** \class SkBitmapScaler 15 16 Provides the interface for high quality image resampling. 17 */ 18 19 class SK_API SkBitmapScaler { 20 public: 21 enum ResizeMethod { 22 // Quality Methods 23 // 24 // Those enumeration values express a desired quality/speed tradeoff. 25 // They are translated into an algorithm-specific method that depends 26 // on the capabilities (CPU, GPU) of the underlying platform. 27 // It is possible for all three methods to be mapped to the same 28 // algorithm on a given platform. 29 30 // Good quality resizing. Fastest resizing with acceptable visual quality. 31 // This is typically intended for use during interactive layouts 32 // where slower platforms may want to trade image quality for large 33 // increase in resizing performance. 34 // 35 // For example the resizing implementation may devolve to linear 36 // filtering if this enables GPU acceleration to be used. 37 // 38 // Note that the underlying resizing method may be determined 39 // on the fly based on the parameters for a given resize call. 40 // For example an implementation using a GPU-based linear filter 41 // in the common case may still use a higher-quality software-based 42 // filter in cases where using the GPU would actually be slower - due 43 // to too much latency - or impossible - due to image format or size 44 // constraints. 45 RESIZE_GOOD, 46 47 // Medium quality resizing. Close to high quality resizing (better 48 // than linear interpolation) with potentially some quality being 49 // traded-off for additional speed compared to RESIZE_BEST. 50 // 51 // This is intended, for example, for generation of large thumbnails 52 // (hundreds of pixels in each dimension) from large sources, where 53 // a linear filter would produce too many artifacts but where 54 // a RESIZE_HIGH might be too costly time-wise. 55 RESIZE_BETTER, 56 57 // High quality resizing. The algorithm is picked to favor image quality. 58 RESIZE_BEST, 59 60 // 61 // Algorithm-specific enumerations 62 // 63 64 // Box filter. This is a weighted average of all of the pixels touching 65 // the destination pixel. For enlargement, this is nearest neighbor. 66 // 67 // You probably don't want this, it is here for testing since it is easy to 68 // compute. Use RESIZE_LANCZOS3 instead. 69 RESIZE_BOX, 70 RESIZE_TRIANGLE, 71 RESIZE_LANCZOS3, 72 RESIZE_HAMMING, 73 RESIZE_MITCHELL, 74 75 // enum aliases for first and last methods by algorithm or by quality. 76 RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD, 77 RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST, 78 RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX, 79 RESIZE_LAST_ALGORITHM_METHOD = RESIZE_MITCHELL, 80 }; 81 82 static bool Resize(SkBitmap* result, 83 const SkBitmap& source, 84 ResizeMethod method, 85 float dest_width, float dest_height, 86 SkBitmap::Allocator* allocator = NULL); 87 88 static SkBitmap Resize(const SkBitmap& source, 89 ResizeMethod method, 90 float dest_width, float dest_height, 91 SkBitmap::Allocator* allocator = NULL); 92 93 /** Platforms can also optionally overwrite the convolution functions 94 if we have SIMD versions of them. 95 */ 96 97 static void PlatformConvolutionProcs(SkConvolutionProcs*); 98 }; 99 100 #endif 101