Bumping manifests a=b2g-bump
[gecko.git] / gfx / 2d / Scale.cpp
blobcc471043570ba52b86ae83c8d4c86a8ed27abe4d
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)
20 #ifdef USE_SKIA
21 SkAlphaType alphaType;
22 if (format == SurfaceFormat::B8G8R8A8) {
23 alphaType = kPremul_SkAlphaType;
24 } else {
25 alphaType = kOpaque_SkAlphaType;
28 SkImageInfo info = SkImageInfo::Make(srcWidth,
29 srcHeight,
30 GfxFormatToSkiaColorType(format),
31 alphaType);
33 SkBitmap imgSrc;
34 imgSrc.installPixels(info, srcData, srcStride);
36 // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed.
37 if (format != SurfaceFormat::B8G8R8A8) {
38 imgSrc.copyTo(&imgSrc, kBGRA_8888_SkColorType);
41 // This returns an SkBitmap backed by dstData; since it also wrote to dstData,
42 // we don't need to look at that SkBitmap.
43 SkBitmap result = skia::ImageOperations::Resize(imgSrc,
44 skia::ImageOperations::RESIZE_BEST,
45 dstWidth, dstHeight,
46 dstData);
48 return !result.isNull();
49 #else
50 return false;
51 #endif