gfx/2d/image_operations.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/2d/image_operations.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,157 @@
     1.4 +// Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
     1.5 +//
     1.6 +// Redistribution and use in source and binary forms, with or without
     1.7 +// modification, are permitted provided that the following conditions
     1.8 +// are met:
     1.9 +//  * Redistributions of source code must retain the above copyright
    1.10 +//    notice, this list of conditions and the following disclaimer.
    1.11 +//  * Redistributions in binary form must reproduce the above copyright
    1.12 +//    notice, this list of conditions and the following disclaimer in
    1.13 +//    the documentation and/or other materials provided with the
    1.14 +//    distribution.
    1.15 +//  * Neither the name of Google, Inc. nor the names of its contributors
    1.16 +//    may be used to endorse or promote products derived from this
    1.17 +//    software without specific prior written permission.
    1.18 +//
    1.19 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.20 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.21 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    1.22 +// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    1.23 +// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    1.24 +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    1.25 +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
    1.26 +// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    1.27 +// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.28 +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    1.29 +// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    1.30 +// SUCH DAMAGE.
    1.31 +
    1.32 +#ifndef SKIA_EXT_IMAGE_OPERATIONS_H_
    1.33 +#define SKIA_EXT_IMAGE_OPERATIONS_H_
    1.34 +
    1.35 +#include "skia/SkTypes.h"
    1.36 +#include "Types.h"
    1.37 +
    1.38 +class SkBitmap;
    1.39 +struct SkIRect;
    1.40 +
    1.41 +namespace skia {
    1.42 +
    1.43 +class ImageOperations {
    1.44 + public:
    1.45 +  enum ResizeMethod {
    1.46 +    //
    1.47 +    // Quality Methods
    1.48 +    //
    1.49 +    // Those enumeration values express a desired quality/speed tradeoff.
    1.50 +    // They are translated into an algorithm-specific method that depends
    1.51 +    // on the capabilities (CPU, GPU) of the underlying platform.
    1.52 +    // It is possible for all three methods to be mapped to the same
    1.53 +    // algorithm on a given platform.
    1.54 +
    1.55 +    // Good quality resizing. Fastest resizing with acceptable visual quality.
    1.56 +    // This is typically intended for use during interactive layouts
    1.57 +    // where slower platforms may want to trade image quality for large
    1.58 +    // increase in resizing performance.
    1.59 +    //
    1.60 +    // For example the resizing implementation may devolve to linear
    1.61 +    // filtering if this enables GPU acceleration to be used.
    1.62 +    //
    1.63 +    // Note that the underlying resizing method may be determined
    1.64 +    // on the fly based on the parameters for a given resize call.
    1.65 +    // For example an implementation using a GPU-based linear filter
    1.66 +    // in the common case may still use a higher-quality software-based
    1.67 +    // filter in cases where using the GPU would actually be slower - due
    1.68 +    // to too much latency - or impossible - due to image format or size
    1.69 +    // constraints.
    1.70 +    RESIZE_GOOD,
    1.71 +
    1.72 +    // Medium quality resizing. Close to high quality resizing (better
    1.73 +    // than linear interpolation) with potentially some quality being
    1.74 +    // traded-off for additional speed compared to RESIZE_BEST.
    1.75 +    //
    1.76 +    // This is intended, for example, for generation of large thumbnails
    1.77 +    // (hundreds of pixels in each dimension) from large sources, where
    1.78 +    // a linear filter would produce too many artifacts but where
    1.79 +    // a RESIZE_HIGH might be too costly time-wise.
    1.80 +    RESIZE_BETTER,
    1.81 +
    1.82 +    // High quality resizing. The algorithm is picked to favor image quality.
    1.83 +    RESIZE_BEST,
    1.84 +
    1.85 +    //
    1.86 +    // Algorithm-specific enumerations
    1.87 +    //
    1.88 +
    1.89 +    // Box filter. This is a weighted average of all of the pixels touching
    1.90 +    // the destination pixel. For enlargement, this is nearest neighbor.
    1.91 +    //
    1.92 +    // You probably don't want this, it is here for testing since it is easy to
    1.93 +    // compute. Use RESIZE_LANCZOS3 instead.
    1.94 +    RESIZE_BOX,
    1.95 +
    1.96 +    // 1-cycle Hamming filter. This is tall is the middle and falls off towards
    1.97 +    // the window edges but without going to 0. This is about 40% faster than
    1.98 +    // a 2-cycle Lanczos.
    1.99 +    RESIZE_HAMMING1,
   1.100 +
   1.101 +    // 2-cycle Lanczos filter. This is tall in the middle, goes negative on
   1.102 +    // each side, then returns to zero. Does not provide as good a frequency
   1.103 +    // response as a 3-cycle Lanczos but is roughly 30% faster.
   1.104 +    RESIZE_LANCZOS2,
   1.105 +
   1.106 +    // 3-cycle Lanczos filter. This is tall in the middle, goes negative on
   1.107 +    // each side, then oscillates 2 more times. It gives nice sharp edges.
   1.108 +    RESIZE_LANCZOS3,
   1.109 +
   1.110 +    // Lanczos filter + subpixel interpolation. If subpixel rendering is not
   1.111 +    // appropriate we automatically fall back to Lanczos.
   1.112 +    RESIZE_SUBPIXEL,
   1.113 +
   1.114 +    // enum aliases for first and last methods by algorithm or by quality.
   1.115 +    RESIZE_FIRST_QUALITY_METHOD = RESIZE_GOOD,
   1.116 +    RESIZE_LAST_QUALITY_METHOD = RESIZE_BEST,
   1.117 +    RESIZE_FIRST_ALGORITHM_METHOD = RESIZE_BOX,
   1.118 +    RESIZE_LAST_ALGORITHM_METHOD = RESIZE_SUBPIXEL,
   1.119 +  };
   1.120 +
   1.121 +  // Resizes the given source bitmap using the specified resize method, so that
   1.122 +  // the entire image is (dest_size) big. The dest_subset is the rectangle in
   1.123 +  // this destination image that should actually be returned.
   1.124 +  //
   1.125 +  // The output image will be (dest_subset.width(), dest_subset.height()). This
   1.126 +  // will save work if you do not need the entire bitmap.
   1.127 +  //
   1.128 +  // The destination subset must be smaller than the destination image.
   1.129 +  static SkBitmap Resize(const SkBitmap& source,
   1.130 +                         ResizeMethod method,
   1.131 +                         int dest_width, int dest_height,
   1.132 +                         const SkIRect& dest_subset,
   1.133 +                         void* dest_pixels = nullptr);
   1.134 +
   1.135 +  // Alternate version for resizing and returning the entire bitmap rather than
   1.136 +  // a subset.
   1.137 +  static SkBitmap Resize(const SkBitmap& source,
   1.138 +                         ResizeMethod method,
   1.139 +                         int dest_width, int dest_height,
   1.140 +                         void* dest_pixels = nullptr);
   1.141 +
   1.142 + private:
   1.143 +  ImageOperations();  // Class for scoping only.
   1.144 +
   1.145 +  // Supports all methods except RESIZE_SUBPIXEL.
   1.146 +  static SkBitmap ResizeBasic(const SkBitmap& source,
   1.147 +                              ResizeMethod method,
   1.148 +                              int dest_width, int dest_height,
   1.149 +                              const SkIRect& dest_subset,
   1.150 +                              void* dest_pixels = nullptr);
   1.151 +
   1.152 +  // Subpixel renderer.
   1.153 +  static SkBitmap ResizeSubpixel(const SkBitmap& source,
   1.154 +                                 int dest_width, int dest_height,
   1.155 +                                 const SkIRect& dest_subset);
   1.156 +};
   1.157 +
   1.158 +}  // namespace skia
   1.159 +
   1.160 +#endif  // SKIA_EXT_IMAGE_OPERATIONS_H_

mercurial