Bug 1686855 [wpt PR 27197] - PlzDedicatedWorker: WPT for clients.matchAll() with...
[gecko.git] / gfx / 2d / Scale.cpp
blobaf26cd37760ef5cf386aa73bb3e440b07688b5ad
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 #ifdef USE_SKIA
10 # include "HelpersSkia.h"
11 # include "skia/src/core/SkBitmapScaler.h"
12 #endif
14 namespace mozilla {
15 namespace gfx {
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) {
20 #ifdef USE_SKIA
21 SkPixmap srcPixmap(MakeSkiaImageInfo(IntSize(srcWidth, srcHeight), format),
22 srcData, srcStride);
24 // Rescaler is compatible with N32 only. Convert to N32 if needed.
25 SkBitmap tmpBitmap;
26 if (srcPixmap.colorType() != kN32_SkColorType) {
27 if (!tmpBitmap.tryAllocPixels(
28 SkImageInfo::MakeN32Premul(srcWidth, srcHeight)) ||
29 !tmpBitmap.writePixels(srcPixmap) ||
30 !tmpBitmap.peekPixels(&srcPixmap)) {
31 return false;
35 SkPixmap dstPixmap(SkImageInfo::MakeN32Premul(dstWidth, dstHeight), dstData,
36 dstStride);
37 return SkBitmapScaler::Resize(dstPixmap, srcPixmap,
38 SkBitmapScaler::RESIZE_LANCZOS3);
39 #else
40 return false;
41 #endif
44 } // namespace gfx
45 } // namespace mozilla