Bug 1758688 [wpt PR 33067] - [FedCM] Make revoke a non-static method, a=testonly
[gecko.git] / gfx / 2d / Scale.cpp
blob5e624b25acf7fe3554f00d303d815046fa867a63
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/. */
7 #include "Scale.h"
9 #include "HelpersSkia.h"
10 #include "skia/src/core/SkBitmapScaler.h"
12 namespace mozilla {
13 namespace gfx {
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),
19 srcData, srcStride);
21 // Rescaler is compatible with N32 only. Convert to N32 if needed.
22 SkBitmap tmpBitmap;
23 if (srcPixmap.colorType() != kN32_SkColorType) {
24 if (!tmpBitmap.tryAllocPixels(
25 SkImageInfo::MakeN32Premul(srcWidth, srcHeight)) ||
26 !tmpBitmap.writePixels(srcPixmap) ||
27 !tmpBitmap.peekPixels(&srcPixmap)) {
28 return false;
32 SkPixmap dstPixmap(SkImageInfo::MakeN32Premul(dstWidth, dstHeight), dstData,
33 dstStride);
34 return SkBitmapScaler::Resize(dstPixmap, srcPixmap,
35 SkBitmapScaler::RESIZE_LANCZOS3);
38 } // namespace gfx
39 } // namespace mozilla