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 // Resizes the given source bitmap using the specified resize method, so that 83 // the entire image is (dest_size) big. The dest_subset is the rectangle in 84 // this destination image that should actually be returned. 85 // 86 // The output image will be (dest_subset.width(), dest_subset.height()). This 87 // will save work if you do not need the entire bitmap. 88 // 89 // The destination subset must be smaller than the destination image. 90 static bool Resize(SkBitmap* result, 91 const SkBitmap& source, 92 ResizeMethod method, 93 int dest_width, int dest_height, 94 const SkIRect& dest_subset, 95 const SkConvolutionProcs&, 96 SkBitmap::Allocator* allocator = NULL); 97 98 // Alternate version for resizing and returning the entire bitmap rather than 99 // a subset. 100 static bool Resize(SkBitmap* result, 101 const SkBitmap& source, 102 ResizeMethod method, 103 int dest_width, int dest_height, 104 const SkConvolutionProcs&, 105 SkBitmap::Allocator* allocator = NULL); 106 }; 107 108 #endif 109