1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkBitmapScaler.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkBitmapScaler_DEFINED 1.12 +#define SkBitmapScaler_DEFINED 1.13 + 1.14 +#include "SkBitmap.h" 1.15 +#include "SkConvolver.h" 1.16 + 1.17 +/** \class SkBitmapScaler 1.18 + 1.19 + Provides the interface for high quality image resampling. 1.20 + */ 1.21 + 1.22 +class SK_API SkBitmapScaler { 1.23 +public: 1.24 + enum ResizeMethod { 1.25 + // Quality Methods 1.26 + // 1.27 + // Those enumeration values express a desired quality/speed tradeoff. 1.28 + // They are translated into an algorithm-specific method that depends 1.29 + // on the capabilities (CPU, GPU) of the underlying platform. 1.30 + // It is possible for all three methods to be mapped to the same 1.31 + // algorithm on a given platform. 1.32 + 1.33 + // Good quality resizing. Fastest resizing with acceptable visual quality. 1.34 + // This is typically intended for use during interactive layouts 1.35 + // where slower platforms may want to trade image quality for large 1.36 + // increase in resizing performance. 1.37 + // 1.38 + // For example the resizing implementation may devolve to linear 1.39 + // filtering if this enables GPU acceleration to be used. 1.40 + // 1.41 + // Note that the underlying resizing method may be determined 1.42 + // on the fly based on the parameters for a given resize call. 1.43 + // For example an implementation using a GPU-based linear filter 1.44 + // in the common case may still use a higher-quality software-based 1.45 + // filter in cases where using the GPU would actually be slower - due 1.46 + // to too much latency - or impossible - due to image format or size 1.47 + // constraints. 1.48 + RESIZE_GOOD, 1.49 + 1.50 + // Medium quality resizing. Close to high quality resizing (better 1.51 + // than linear interpolation) with potentially some quality being 1.52 + // traded-off for additional speed compared to RESIZE_BEST. 1.53 + // 1.54 + // This is intended, for example, for generation of large thumbnails 1.55 + // (hundreds of pixels in each dimension) from large sources, where 1.56 + // a linear filter would produce too many artifacts but where 1.57 + // a RESIZE_HIGH might be too costly time-wise. 1.58 + RESIZE_BETTER, 1.59 + 1.60 + // High quality resizing. The algorithm is picked to favor image quality. 1.61 + RESIZE_BEST, 1.62 + 1.63 + // 1.64 + // Algorithm-specific enumerations 1.65 + // 1.66 + 1.67 + // Box filter. This is a weighted average of all of the pixels touching 1.68 + // the destination pixel. For enlargement, this is nearest neighbor. 1.69 + // 1.70 + // You probably don't want this, it is here for testing since it is easy to 1.71 + // compute. Use RESIZE_LANCZOS3 instead. 1.72 + RESIZE_BOX, 1.73 + RESIZE_TRIANGLE, 1.74 + RESIZE_LANCZOS3, 1.75 + RESIZE_HAMMING, 1.76 + RESIZE_MITCHELL, 1.77 + 1.78 + // enum aliases for first and last methods by algorithm or by quality. 1.79 + RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD, 1.80 + RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST, 1.81 + RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX, 1.82 + RESIZE_LAST_ALGORITHM_METHOD = RESIZE_MITCHELL, 1.83 + }; 1.84 + 1.85 + // Resizes the given source bitmap using the specified resize method, so that 1.86 + // the entire image is (dest_size) big. The dest_subset is the rectangle in 1.87 + // this destination image that should actually be returned. 1.88 + // 1.89 + // The output image will be (dest_subset.width(), dest_subset.height()). This 1.90 + // will save work if you do not need the entire bitmap. 1.91 + // 1.92 + // The destination subset must be smaller than the destination image. 1.93 + static bool Resize(SkBitmap* result, 1.94 + const SkBitmap& source, 1.95 + ResizeMethod method, 1.96 + int dest_width, int dest_height, 1.97 + const SkIRect& dest_subset, 1.98 + const SkConvolutionProcs&, 1.99 + SkBitmap::Allocator* allocator = NULL); 1.100 + 1.101 + // Alternate version for resizing and returning the entire bitmap rather than 1.102 + // a subset. 1.103 + static bool Resize(SkBitmap* result, 1.104 + const SkBitmap& source, 1.105 + ResizeMethod method, 1.106 + int dest_width, int dest_height, 1.107 + const SkConvolutionProcs&, 1.108 + SkBitmap::Allocator* allocator = NULL); 1.109 +}; 1.110 + 1.111 +#endif