Debian Codegraph @

src/codec/SkPngCompositeChunkReader.h

raw
1 /*
2 * Copyright 2024 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 #ifndef SkPngCompositeChunkReader_DEFINED
8 #define SkPngCompositeChunkReader_DEFINED
9
10 #include "include/codec/SkPngChunkReader.h"
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkStream.h"
13 #include "include/private/SkGainmapInfo.h"
14 #include "include/private/SkHdrMetadata.h"
15
16 #include <cstddef>
17 #include <memory>
18 #include <optional>
19 #include <utility>
20
21 /**
22 * Reader for PNG chunks that handles the composite of:
23 * 1. Chunks currently unknown to the PNG spec, but are necessary to correctly
24 * decode certain images. For example, images that contain gainmap chunks.
25 * 2. Client-provided callbacks that may listen to other unknown chunks.
26 *
27 * The PNG api can only register one callback for unknown chunks at a time,
28 * hence this wrapper class.
29 */
30 class SkPngCompositeChunkReader : public SkPngChunkReader {
31 public:
32 explicit SkPngCompositeChunkReader(SkPngChunkReader* chunkReader)
33 : fChunkReader(SkSafeRef(chunkReader)) {}
34
35 bool readChunk(const char tag[], const void* data, size_t length) override;
36
37 std::unique_ptr<SkStream> takeGaimapStream() { return std::move(fGainmapStream); }
38
39 std::optional<SkGainmapInfo> getGainmapInfo() const { return fGainmapInfo; }
40
41 const skhdr::Metadata& getHdrMetadata() const {
42 return fHdrMetadata;
43 }
44
45 private:
46 sk_sp<SkPngChunkReader> fChunkReader = nullptr;
47 std::optional<SkGainmapInfo> fGainmapInfo;
48 std::unique_ptr<SkStream> fGainmapStream = nullptr;
49 skhdr::Metadata fHdrMetadata;
50 };
51
52 #endif // SkPngCompositeChunkReader_DEFINED