blob: 602e0446f05be3b0f87ec7c29e1ad05dacba2551 [file] [edit]
// 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_TIFF_READER_H_
#define THIRD_PARTY_CREDENTIO_FORMATS_TIFF_READER_H_
#include <stdbool.h>
#include <sys/types.h>
#include <cstdint>
#include <optional>
#include <vector>
#include "absl/container/flat_hash_set.h"
#include "absl/functional/function_ref.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "formats/byte_range.h"
#include "formats/tiff/constants.h"
#include "riegeli/bytes/reader.h"
namespace credentio {
enum class TiffEndianness {
kBigEndian,
kLittleEndian,
};
struct TiffImageFileDirectoryEntry {
uint64_t offset;
uint16_t tag;
uint16_t type;
uint32_t count;
uint32_t value_or_offset;
uint64_t size() const { return SizeOfTiffType(type) * count; }
ByteRange RangeOfCount() const;
ByteRange RangeOfValue() const;
};
struct TiffImageFileDirectory {
uint32_t offset_of_pointer;
uint32_t offset;
std::vector<TiffImageFileDirectoryEntry> entries;
};
using ImageFileDirectoryProcessor = absl::FunctionRef<absl::StatusOr<bool>(
const TiffImageFileDirectory&, TiffEndianness)>;
absl::Status IterateOverImageFileDirectories(
riegeli::Reader& source, std::optional<TiffEndianness> known_endianness,
absl::flat_hash_set<uint32_t>& visited_offsets,
ImageFileDirectoryProcessor process_ifd);
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_FORMATS_TIFF_READER_H_