Debian Codegraph @

src/codec/SkPngCompositeChunkReader.cpp

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
8 #include "src/codec/SkPngCompositeChunkReader.h"
9 #include <cstring>
10
11 class SkData;
12
13 bool SkPngCompositeChunkReader::readChunk(const char tag[], const void* data, size_t length) {
14 if (fChunkReader && !fChunkReader->readChunk(tag, data, length)) {
15 // Only fail if the client's chunk reader failed; If we don't have a
16 // chunk reader we would still need to grab gainmap chunks
17 return false;
18 }
19
20 // If we found a chunk but there's no data, then just skip it!
21 if (data == nullptr || length == 0) {
22 return true;
23 }
24
25 if (strcmp("gmAP", tag) == 0) {
26 SkMemoryStream stream(data, length);
27 sk_sp<const SkData> streamData = stream.getData();
28 SkGainmapInfo info;
29 if (SkGainmapInfo::Parse(streamData.get(), info)) {
30 fGainmapInfo.emplace(std::move(info));
31 }
32 } else if (strcmp("gdAT", tag) == 0) {
33 fGainmapStream = SkMemoryStream::MakeCopy(data, length);
34 } else if (strcmp("cLLI", tag) == 0) {
35 auto sk_data = SkData::MakeWithoutCopy(data, length);
36 skhdr::ContentLightLevelInformation clli;
37 if (clli.parsePngChunk(sk_data.get())) {
38 fHdrMetadata.setContentLightLevelInformation(clli);
39 }
40 } else if (strcmp("mDCV", tag) == 0) {
41 auto sk_data = SkData::MakeWithoutCopy(data, length);
42 skhdr::MasteringDisplayColorVolume mdcv;
43 if (mdcv.parse(sk_data.get())) {
44 fHdrMetadata.setMasteringDisplayColorVolume(mdcv);
45 }
46 }
47 return true;
48 }