Coverage Report

Created: 2024-05-20 07:14

/src/skia/include/codec/SkRawDecoder.h
Line
Count
Source
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
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 SkRawDecoder {
20
21
33.4k
inline 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
33.4k
    return true;
27
33.4k
}
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
 */
36
SK_API std::unique_ptr<SkCodec> Decode(std::unique_ptr<SkStream>,
37
                                       SkCodec::Result*,
38
                                       SkCodecs::DecodeContext = nullptr);
39
SK_API std::unique_ptr<SkCodec> Decode(sk_sp<SkData>,
40
                                       SkCodec::Result*,
41
                                       SkCodecs::DecodeContext = nullptr);
42
43
// This decoder will always be checked last, no matter when it is registered.
44
7
inline constexpr SkCodecs::Decoder Decoder() {
45
7
    return { "raw", IsRaw, Decode };
46
7
}
47
48
}  // namespace SkRawDecoder
49
50
#endif  // SkRawDecoder_DEFINED