gfx/2d/Scale.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "Scale.h"
     7 #ifdef USE_SKIA
     8 #include "HelpersSkia.h"
     9 #include "skia/SkBitmap.h"
    10 #include "image_operations.h"
    11 #endif
    13 namespace mozilla {
    14 namespace gfx {
    16 bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride,
    17            uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride,
    18            SurfaceFormat format)
    19 {
    20 #ifdef USE_SKIA
    21   SkAlphaType alphaType;
    22   if (format == SurfaceFormat::B8G8R8A8) {
    23     alphaType = kPremul_SkAlphaType;
    24   } else {
    25     alphaType = kOpaque_SkAlphaType;
    26   }
    28   SkBitmap::Config config = GfxFormatToSkiaConfig(format);
    30   SkBitmap imgSrc;
    31   imgSrc.setConfig(config, srcWidth, srcHeight, srcStride, alphaType);
    32   imgSrc.setPixels(srcData);
    34   // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed.
    35   if (config != SkBitmap::kARGB_8888_Config) {
    36     imgSrc.copyTo(&imgSrc, kRGBA_8888_SkColorType);
    37   }
    39   // This returns an SkBitmap backed by dstData; since it also wrote to dstData,
    40   // we don't need to look at that SkBitmap.
    41   SkBitmap result = skia::ImageOperations::Resize(imgSrc,
    42                                                   skia::ImageOperations::RESIZE_BEST,
    43                                                   dstWidth, dstHeight,
    44                                                   dstData);
    46   return !result.isNull();
    47 #else
    48   return false;
    49 #endif
    50 }
    52 }
    53 }

mercurial