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/. */
8 #include "HelpersSkia.h"
9 #include "skia/SkBitmap.h"
10 #include "image_operations.h"
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
,
21 SkAlphaType alphaType
;
22 if (format
== SurfaceFormat::B8G8R8A8
) {
23 alphaType
= kPremul_SkAlphaType
;
25 alphaType
= kOpaque_SkAlphaType
;
28 SkImageInfo info
= SkImageInfo::Make(srcWidth
,
30 GfxFormatToSkiaColorType(format
),
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
,
48 return !result
.isNull();