michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "Scale.h" michael@0: michael@0: #ifdef USE_SKIA michael@0: #include "HelpersSkia.h" michael@0: #include "skia/SkBitmap.h" michael@0: #include "image_operations.h" michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride, michael@0: uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride, michael@0: SurfaceFormat format) michael@0: { michael@0: #ifdef USE_SKIA michael@0: SkAlphaType alphaType; michael@0: if (format == SurfaceFormat::B8G8R8A8) { michael@0: alphaType = kPremul_SkAlphaType; michael@0: } else { michael@0: alphaType = kOpaque_SkAlphaType; michael@0: } michael@0: michael@0: SkBitmap::Config config = GfxFormatToSkiaConfig(format); michael@0: michael@0: SkBitmap imgSrc; michael@0: imgSrc.setConfig(config, srcWidth, srcHeight, srcStride, alphaType); michael@0: imgSrc.setPixels(srcData); michael@0: michael@0: // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed. michael@0: if (config != SkBitmap::kARGB_8888_Config) { michael@0: imgSrc.copyTo(&imgSrc, kRGBA_8888_SkColorType); michael@0: } michael@0: michael@0: // This returns an SkBitmap backed by dstData; since it also wrote to dstData, michael@0: // we don't need to look at that SkBitmap. michael@0: SkBitmap result = skia::ImageOperations::Resize(imgSrc, michael@0: skia::ImageOperations::RESIZE_BEST, michael@0: dstWidth, dstHeight, michael@0: dstData); michael@0: michael@0: return !result.isNull(); michael@0: #else michael@0: return false; michael@0: #endif michael@0: } michael@0: michael@0: } michael@0: }