| 1 |
/* |
| 2 |
* Copyright 2023 Google LLC |
| 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 |
#ifndef SkAvifDecoder_DEFINED |
| 8 |
#define SkAvifDecoder_DEFINED |
| 9 |
|
| 10 |
#include "include/codec/SkCodec.h" |
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/private/base/SkAPI.h" |
| 13 |
|
| 14 |
class SkData; |
| 15 |
class SkStream; |
| 16 |
|
| 17 |
#include <memory> |
| 18 |
|
| 19 |
namespace SkAvifDecoder { |
| 20 |
|
| 21 |
namespace LibAvif { |
| 22 |
|
| 23 |
/** Returns true if this data claims to be an AVIF image. */ |
| 24 |
SK_API bool IsAvif(const void*, size_t); |
| 25 |
|
| 26 |
/** |
| 27 |
* Attempts to decode the given bytes as an AVIF. |
| 28 |
* |
| 29 |
* If the bytes are not an AVIF, returns nullptr. |
| 30 |
* |
| 31 |
* DecodeContext is ignored |
| 32 |
*/ |
| 33 |
SK_API std::unique_ptr<SkCodec> Decode(std::unique_ptr<SkStream>, |
| 34 |
SkCodec::Result*, |
| 35 |
SkCodecs::DecodeContext = nullptr); |
| 36 |
SK_API std::unique_ptr<SkCodec> Decode(sk_sp<const SkData>, |
| 37 |
SkCodec::Result*, |
| 38 |
SkCodecs::DecodeContext = nullptr); |
| 39 |
|
| 40 |
inline constexpr SkCodecs::Decoder Decoder() { |
| 41 |
return { "avif", IsAvif, Decode }; |
| 42 |
} |
| 43 |
|
| 44 |
} // namespace LibAvif |
| 45 |
|
| 46 |
// This function is in the root SkAvifDecoder namespace. It simply routes |
| 47 |
// everything through the LibAvif namespace and exists for backwards |
| 48 |
// compatibility. |
| 49 |
inline constexpr SkCodecs::Decoder Decoder() { |
| 50 |
return { "avif", LibAvif::IsAvif, LibAvif::Decode }; |
| 51 |
} |
| 52 |
|
| 53 |
namespace CrabbyAvif { |
| 54 |
|
| 55 |
/** Returns true if this data claims to be an AVIF image. */ |
| 56 |
SK_API bool IsAvif(const void*, size_t); |
| 57 |
|
| 58 |
/** |
| 59 |
* Attempts to decode the given bytes as an AVIF. |
| 60 |
* |
| 61 |
* If the bytes are not an AVIF, returns nullptr. |
| 62 |
* |
| 63 |
* DecodeContext is ignored |
| 64 |
*/ |
| 65 |
SK_API std::unique_ptr<SkCodec> Decode(std::unique_ptr<SkStream>, |
| 66 |
SkCodec::Result*, |
| 67 |
SkCodecs::DecodeContext = nullptr); |
| 68 |
SK_API std::unique_ptr<SkCodec> Decode(sk_sp<const SkData>, |
| 69 |
SkCodec::Result*, |
| 70 |
SkCodecs::DecodeContext = nullptr); |
| 71 |
|
| 72 |
inline constexpr SkCodecs::Decoder Decoder() { |
| 73 |
return { "avif", IsAvif, Decode }; |
| 74 |
} |
| 75 |
|
| 76 |
} // namespace CrabbyAvif |
| 77 |
|
| 78 |
} // namespace SkAvifDecoder |
| 79 |
|
| 80 |
#endif // SkAvifDecoder_DEFINED |