Flutter Engine
The Flutter Engine
SkRawDecoder.h
Go to the documentation of this file.
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 SkRawDecoder_DEFINED
8#define SkRawDecoder_DEFINED
9
13
14class SkData;
15class SkStream;
16
17#include <memory>
18
19namespace SkRawDecoder {
20
21inline bool IsRaw(const void*, size_t) {
22 // Raw formats are tricky to detect just by reading in the first several bytes.
23 // For example, PIEX might need to read 10k bytes to detect Sony's arw format
24 // https://github.com/google/piex/blob/f1e15dd837c04347504149f71db67a78fbeddc73/src/image_type_recognition/image_type_recognition_lite.cc#L152
25 // Thus, we just assume everything might be a RAW file and check it last.
26 return true;
27}
28
29/**
30 * Attempts to decode the given bytes as a raw image.
31 *
32 * If the bytes are not a raw, returns nullptr.
33 *
34 * DecodeContext is ignored
35 */
36SK_API std::unique_ptr<SkCodec> Decode(std::unique_ptr<SkStream>,
38 SkCodecs::DecodeContext = nullptr);
39SK_API std::unique_ptr<SkCodec> Decode(sk_sp<SkData>,
41 SkCodecs::DecodeContext = nullptr);
42
43// This decoder will always be checked last, no matter when it is registered.
44inline constexpr SkCodecs::Decoder Decoder() {
45 return { "raw", IsRaw, Decode };
46}
47
48} // namespace SkRawDecoder
49
50#endif // SkRawDecoder_DEFINED
#define SK_API
Definition: SkAPI.h:35
Result
Definition: SkCodec.h:76
Definition: SkData.h:25
void * DecodeContext
Definition: SkCodec.h:1047
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
Definition: SkRawCodec.cpp:835
bool IsRaw(const void *, size_t)
Definition: SkRawDecoder.h:21
constexpr SkCodecs::Decoder Decoder()
Definition: SkRawDecoder.h:44