Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkImageEncoderPriv_DEFINED |
| 9 | #define SkImageEncoderPriv_DEFINED |
| 10 | |
| 11 | #include "SkImageEncoder.h" |
Matt Sarett | c367d03 | 2017-05-05 11:13:26 -0400 | [diff] [blame^] | 12 | #include "SkImageInfoPriv.h" |
| 13 | |
| 14 | static inline bool SkPixmapIsValid(const SkPixmap& src, |
| 15 | SkTransferFunctionBehavior unpremulBehavior) |
| 16 | { |
| 17 | if (SkTransferFunctionBehavior::kRespect == unpremulBehavior) { |
| 18 | if (!SkImageInfoIsValidRenderingCS(src.info())) { |
| 19 | return false; |
| 20 | } |
| 21 | } else { |
| 22 | if (!SkImageInfoIsValidAllowNumericalCS(src.info())) { |
| 23 | return false; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | if (!src.addr() || src.rowBytes() < src.info().minRowBytes()) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | return true; |
| 32 | } |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 33 | |
Matt Sarett | 84014f0 | 2017-01-10 11:28:54 -0500 | [diff] [blame] | 34 | struct SkEncodeOptions { |
Matt Sarett | cf3f234 | 2017-03-23 15:32:25 -0400 | [diff] [blame] | 35 | SkTransferFunctionBehavior fUnpremulBehavior = SkTransferFunctionBehavior::kIgnore; |
Matt Sarett | 84014f0 | 2017-01-10 11:28:54 -0500 | [diff] [blame] | 36 | }; |
| 37 | |
Hal Canary | 1fcc404 | 2016-11-30 17:07:59 -0500 | [diff] [blame] | 38 | #ifdef SK_HAS_WEBP_LIBRARY |
Matt Sarett | 5521356 | 2017-01-23 19:37:37 -0500 | [diff] [blame] | 39 | bool SkEncodeImageAsWEBP(SkWStream*, const SkPixmap&, const SkEncodeOptions&); |
Hal Canary | 1fcc404 | 2016-11-30 17:07:59 -0500 | [diff] [blame] | 40 | bool SkEncodeImageAsWEBP(SkWStream*, const SkPixmap&, int quality); |
| 41 | #else |
| 42 | #define SkEncodeImageAsWEBP(...) false |
| 43 | #endif |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 44 | |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 45 | #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
Hal Canary | 1fcc404 | 2016-11-30 17:07:59 -0500 | [diff] [blame] | 46 | bool SkEncodeImageWithCG(SkWStream*, const SkPixmap&, SkEncodedImageFormat); |
| 47 | #else |
| 48 | #define SkEncodeImageWithCG(...) false |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 49 | #endif |
| 50 | |
Hal Canary | 1fcc404 | 2016-11-30 17:07:59 -0500 | [diff] [blame] | 51 | #ifdef SK_BUILD_FOR_WIN |
| 52 | bool SkEncodeImageWithWIC(SkWStream*, const SkPixmap&, SkEncodedImageFormat, int quality); |
| 53 | #else |
| 54 | #define SkEncodeImageWithWIC(...) false |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 55 | #endif |
| 56 | |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 57 | #endif // SkImageEncoderPriv_DEFINED |