1138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com/*
2138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com * Copyright 2013 Google Inc.
3138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com *
4138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com * Use of this source code is governed by a BSD-style license that can be
5138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com * found in the LICENSE file.
6138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com */
71f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
8138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com#ifndef SkBitmapScaler_DEFINED
9138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com#define SkBitmapScaler_DEFINED
10138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com
11138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com#include "SkBitmap.h"
12138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com#include "SkConvolver.h"
131f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
14138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com/** \class SkBitmapScaler
15138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com
16138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com    Provides the interface for high quality image resampling.
17138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com */
181f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
19138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.comclass SK_API SkBitmapScaler {
201f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.compublic:
21138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com    enum ResizeMethod {
22138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // Quality Methods
23138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        //
24138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // Those enumeration values express a desired quality/speed tradeoff.
25138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // They are translated into an algorithm-specific method that depends
26138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // on the capabilities (CPU, GPU) of the underlying platform.
27138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // It is possible for all three methods to be mapped to the same
28138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // algorithm on a given platform.
291f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
30138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // Good quality resizing. Fastest resizing with acceptable visual quality.
31138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // This is typically intended for use during interactive layouts
32138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // where slower platforms may want to trade image quality for large
33138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // increase in resizing performance.
34138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        //
35138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // For example the resizing implementation may devolve to linear
36138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // filtering if this enables GPU acceleration to be used.
37138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        //
38138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // Note that the underlying resizing method may be determined
39138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // on the fly based on the parameters for a given resize call.
40138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // For example an implementation using a GPU-based linear filter
41138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // in the common case may still use a higher-quality software-based
42138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // filter in cases where using the GPU would actually be slower - due
43138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // to too much latency - or impossible - due to image format or size
44138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // constraints.
45138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_GOOD,
46138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com
47138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // Medium quality resizing. Close to high quality resizing (better
48138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // than linear interpolation) with potentially some quality being
49138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // traded-off for additional speed compared to RESIZE_BEST.
50138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        //
51138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // This is intended, for example, for generation of large thumbnails
52138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // (hundreds of pixels in each dimension) from large sources, where
53138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // a linear filter would produce too many artifacts but where
54138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // a RESIZE_HIGH might be too costly time-wise.
55138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_BETTER,
56138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com
57138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // High quality resizing. The algorithm is picked to favor image quality.
58138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_BEST,
591f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
60138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        //
61138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // Algorithm-specific enumerations
62138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        //
631f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
64138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // Box filter. This is a weighted average of all of the pixels touching
65138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // the destination pixel. For enlargement, this is nearest neighbor.
66138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        //
67138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // You probably don't want this, it is here for testing since it is easy to
68138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // compute. Use RESIZE_LANCZOS3 instead.
69138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_BOX,
70138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_TRIANGLE,
71138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_LANCZOS3,
72138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_HAMMING,
73138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_MITCHELL,
741f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
75138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        // enum aliases for first and last methods by algorithm or by quality.
76138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD,
77138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST,
78138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX,
79138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com        RESIZE_LAST_ALGORITHM_METHOD = RESIZE_MITCHELL,
80138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com    };
811f3c73825b8a1752abc6b74fbce978a430de6473skia.committer@gmail.com
821e182253f8358ad1bc46209e84d2b4058f1f16a6reed@google.com    static bool Resize(SkBitmap* result,
831e182253f8358ad1bc46209e84d2b4058f1f16a6reed@google.com                       const SkBitmap& source,
841e182253f8358ad1bc46209e84d2b4058f1f16a6reed@google.com                       ResizeMethod method,
85f449156bd00815eae1f1daea436f08068ef0f01ccommit-bot@chromium.org                       float dest_width, float dest_height,
86fed04b34315ed72dbb20e630908638d1c829c760reed@google.com                       const SkConvolutionProcs&,
871e182253f8358ad1bc46209e84d2b4058f1f16a6reed@google.com                       SkBitmap::Allocator* allocator = NULL);
88138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com};
89138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com
90138ebc3e4061cf533ea2f7f3717239670fdc6e43humper@google.com#endif
91