|
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/SkBitmap.h" |
|
10 #include "image_operations.h" |
|
11 #endif |
|
12 |
|
13 namespace mozilla { |
|
14 namespace gfx { |
|
15 |
|
16 bool Scale(uint8_t* srcData, int32_t srcWidth, int32_t srcHeight, int32_t srcStride, |
|
17 uint8_t* dstData, int32_t dstWidth, int32_t dstHeight, int32_t dstStride, |
|
18 SurfaceFormat format) |
|
19 { |
|
20 #ifdef USE_SKIA |
|
21 SkAlphaType alphaType; |
|
22 if (format == SurfaceFormat::B8G8R8A8) { |
|
23 alphaType = kPremul_SkAlphaType; |
|
24 } else { |
|
25 alphaType = kOpaque_SkAlphaType; |
|
26 } |
|
27 |
|
28 SkBitmap::Config config = GfxFormatToSkiaConfig(format); |
|
29 |
|
30 SkBitmap imgSrc; |
|
31 imgSrc.setConfig(config, srcWidth, srcHeight, srcStride, alphaType); |
|
32 imgSrc.setPixels(srcData); |
|
33 |
|
34 // Rescaler is compatible with 32 bpp only. Convert to RGB32 if needed. |
|
35 if (config != SkBitmap::kARGB_8888_Config) { |
|
36 imgSrc.copyTo(&imgSrc, kRGBA_8888_SkColorType); |
|
37 } |
|
38 |
|
39 // This returns an SkBitmap backed by dstData; since it also wrote to dstData, |
|
40 // we don't need to look at that SkBitmap. |
|
41 SkBitmap result = skia::ImageOperations::Resize(imgSrc, |
|
42 skia::ImageOperations::RESIZE_BEST, |
|
43 dstWidth, dstHeight, |
|
44 dstData); |
|
45 |
|
46 return !result.isNull(); |
|
47 #else |
|
48 return false; |
|
49 #endif |
|
50 } |
|
51 |
|
52 } |
|
53 } |