• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
readChunk(const char tag[],const void * data,size_t length)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<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     }
35 
36     return true;
37 }
38