1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/Scale.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,53 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "Scale.h" 1.9 + 1.10 +#ifdef USE_SKIA 1.11 +#include "HelpersSkia.h" 1.12 +#include "skia/SkBitmap.h" 1.13 +#include "image_operations.h" 1.14 +#endif 1.15 + 1.16 +namespace mozilla { 1.17 +namespace gfx { 1.18 + 1.19 +bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride, 1.20 + uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride, 1.21 + SurfaceFormat format) 1.22 +{ 1.23 +#ifdef USE_SKIA 1.24 + SkAlphaType alphaType; 1.25 + if (format == SurfaceFormat::B8G8R8A8) { 1.26 + alphaType = kPremul_SkAlphaType; 1.27 + } else { 1.28 + alphaType = kOpaque_SkAlphaType; 1.29 + } 1.30 + 1.31 + SkBitmap::Config config = GfxFormatToSkiaConfig(format); 1.32 + 1.33 + SkBitmap imgSrc; 1.34 + imgSrc.setConfig(config, srcWidth, srcHeight, srcStride, alphaType); 1.35 + imgSrc.setPixels(srcData); 1.36 + 1.37 + // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed. 1.38 + if (config != SkBitmap::kARGB_8888_Config) { 1.39 + imgSrc.copyTo(&imgSrc, kRGBA_8888_SkColorType); 1.40 + } 1.41 + 1.42 + // This returns an SkBitmap backed by dstData; since it also wrote to dstData, 1.43 + // we don't need to look at that SkBitmap. 1.44 + SkBitmap result = skia::ImageOperations::Resize(imgSrc, 1.45 + skia::ImageOperations::RESIZE_BEST, 1.46 + dstWidth, dstHeight, 1.47 + dstData); 1.48 + 1.49 + return !result.isNull(); 1.50 +#else 1.51 + return false; 1.52 +#endif 1.53 +} 1.54 + 1.55 +} 1.56 +}