Debian Codegraph @

include/codec/SkPngDecoder.h

raw
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 SkPngDecoder_DEFINED
8 #define SkPngDecoder_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 SkPngDecoder {
20
21 /** Returns true if this data claims to be a PNG image. */
22 SK_API bool IsPng(const void*, size_t);
23
24 /**
25 * Attempts to decode the given bytes as a PNG.
26 *
27 * If the bytes are not a PNG, returns nullptr.
28 *
29 * DecodeContext, if non-null, is expected to be a SkPngChunkReader*
30 */
31 SK_API std::unique_ptr<SkCodec> Decode(std::unique_ptr<SkStream>,
32 SkCodec::Result*,
33 SkCodecs::DecodeContext = nullptr);
34 SK_API std::unique_ptr<SkCodec> Decode(sk_sp<const SkData>,
35 SkCodec::Result*,
36 SkCodecs::DecodeContext = nullptr);
37
38 // TODO: remove after client migration
39 inline std::unique_ptr<SkCodec> Decode(sk_sp<SkData> data,
40 SkCodec::Result* result,
41 SkCodecs::DecodeContext ctx = nullptr) {
42 return Decode(sk_sp<const SkData>(static_cast<const SkData*>(data.release())), result, ctx);
43 }
44
45 inline constexpr SkCodecs::Decoder Decoder() {
46 return { "png", IsPng, Decode };
47 }
48
49 } // namespace SkPngDecoder
50
51 #endif // SkPngDecoder_DEFINED