1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 # include "HelpersSkia.h"
11 # include "skia/src/core/SkBitmapScaler.h"
17 bool Scale(uint8_t* srcData
, int32_t srcWidth
, int32_t srcHeight
,
18 int32_t srcStride
, uint8_t* dstData
, int32_t dstWidth
,
19 int32_t dstHeight
, int32_t dstStride
, SurfaceFormat format
) {
21 SkPixmap
srcPixmap(MakeSkiaImageInfo(IntSize(srcWidth
, srcHeight
), format
),
24 // Rescaler is compatible with N32 only. Convert to N32 if needed.
26 if (srcPixmap
.colorType() != kN32_SkColorType
) {
27 if (!tmpBitmap
.tryAllocPixels(
28 SkImageInfo::MakeN32Premul(srcWidth
, srcHeight
)) ||
29 !tmpBitmap
.writePixels(srcPixmap
) ||
30 !tmpBitmap
.peekPixels(&srcPixmap
)) {
35 SkPixmap
dstPixmap(SkImageInfo::MakeN32Premul(dstWidth
, dstHeight
), dstData
,
37 return SkBitmapScaler::Resize(dstPixmap
, srcPixmap
,
38 SkBitmapScaler::RESIZE_LANCZOS3
);
45 } // namespace mozilla