blob: 7d4494ae6edb5181c4f91fac92460db90d4636ec [file]
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef THIRD_PARTY_CREDENTIO_FORMATS_PNG_READER_H_
#define THIRD_PARTY_CREDENTIO_FORMATS_PNG_READER_H_
#include <cstdint>
#include <string>
#include "absl/functional/function_ref.h"
#include "absl/status/status.h"
#include "riegeli/bytes/reader.h"
namespace credentio {
struct PngChunk {
uint64_t offset;
uint64_t length;
std::string type;
uint32_t data_length;
};
inline bool operator==(const PngChunk& lhs, const PngChunk& rhs) {
return lhs.offset == rhs.offset && lhs.length == rhs.length &&
lhs.type == rhs.type && lhs.data_length == rhs.data_length;
}
// The function should return an OK status to continue iteration, or a non-OK
// status to abort iteration.
using PngChunkProcessor = absl::FunctionRef<absl::Status(const PngChunk&)>;
// Iterates over all PNG Chunks in the given reader, calling the given function
// for each box. The method will seek to position 0 in the reader before
// iterating.
absl::Status IterateOverPngChunks(riegeli::Reader& reader,
PngChunkProcessor processor);
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_FORMATS_PNG_READER_H_