Line data Source code
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/. */
4 :
5 : #include "Scale.h"
6 :
7 : #ifdef USE_SKIA
8 : #include "HelpersSkia.h"
9 : #include "skia/src/core/SkBitmapScaler.h"
10 : #endif
11 :
12 : namespace mozilla {
13 : namespace gfx {
14 :
15 0 : bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride,
16 : uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride,
17 : SurfaceFormat format)
18 : {
19 : #ifdef USE_SKIA
20 0 : SkPixmap srcPixmap(MakeSkiaImageInfo(IntSize(srcWidth, srcHeight), format),
21 0 : srcData, srcStride);
22 :
23 : // Rescaler is compatible with N32 only. Convert to N32 if needed.
24 0 : SkBitmap tmpBitmap;
25 0 : if (srcPixmap.colorType() != kN32_SkColorType) {
26 0 : if (!tmpBitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(srcWidth, srcHeight)) ||
27 0 : !tmpBitmap.writePixels(srcPixmap) ||
28 0 : !tmpBitmap.peekPixels(&srcPixmap)) {
29 0 : return false;
30 : }
31 : }
32 :
33 0 : SkPixmap dstPixmap(SkImageInfo::MakeN32Premul(dstWidth, dstHeight), dstData, dstStride);
34 0 : return SkBitmapScaler::Resize(dstPixmap, srcPixmap, SkBitmapScaler::RESIZE_LANCZOS3);
35 : #else
36 : return false;
37 : #endif
38 : }
39 :
40 : } // namespace gfx
41 : } // namespace mozilla
|