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/. */
9 #include "HelpersSkia.h"
10 #include "skia/src/core/SkBitmapScaler.h"
15 bool Scale(uint8_t* srcData
, int32_t srcWidth
, int32_t srcHeight
,
16 int32_t srcStride
, uint8_t* dstData
, int32_t dstWidth
,
17 int32_t dstHeight
, int32_t dstStride
, SurfaceFormat format
) {
18 SkPixmap
srcPixmap(MakeSkiaImageInfo(IntSize(srcWidth
, srcHeight
), format
),
21 // Rescaler is compatible with N32 only. Convert to N32 if needed.
23 if (srcPixmap
.colorType() != kN32_SkColorType
) {
24 if (!tmpBitmap
.tryAllocPixels(
25 SkImageInfo::MakeN32Premul(srcWidth
, srcHeight
)) ||
26 !tmpBitmap
.writePixels(srcPixmap
) ||
27 !tmpBitmap
.peekPixels(&srcPixmap
)) {
32 SkPixmap
dstPixmap(SkImageInfo::MakeN32Premul(dstWidth
, dstHeight
), dstData
,
34 return SkBitmapScaler::Resize(dstPixmap
, srcPixmap
,
35 SkBitmapScaler::RESIZE_LANCZOS3
);
39 } // namespace mozilla