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