blob: 09672ff46888bb6bcd67c33604f48c0975ddd0c1 [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_JPEG_READER_H_
#define THIRD_PARTY_CREDENTIO_FORMATS_JPEG_READER_H_
#include <cstdint>
#include <iosfwd>
#include <optional>
#include <string>
#include "absl/functional/function_ref.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "riegeli/bytes/reader.h"
namespace credentio {
struct JpegJumbfData {
// Offset for this data is contained within
// `JpegApp11Segment::payload_offset`.
uint32_t lbox;
uint32_t tbox;
uint64_t xlbox;
// Offset and length of the data contained in the JUMBF segment.
uint64_t payload_offset;
uint64_t payload_length;
friend bool operator==(const JpegJumbfData&, const JpegJumbfData&) = default;
};
void PrintTo(const JpegJumbfData& x, ::std::ostream* os);
struct JpegApp11Segment {
uint16_t extension_type;
uint16_t segment_id;
uint32_t sequence_number;
// Offset and length of the data contained in the APP11 segment.
uint64_t payload_offset;
uint64_t payload_length;
std::optional<JpegJumbfData> jumbf_data;
friend bool operator==(const JpegApp11Segment&,
const JpegApp11Segment&) = default;
};
void PrintTo(const JpegApp11Segment& x, ::std::ostream* os);
struct JpegSegment {
uint64_t offset;
uint16_t marker; // Marker code for the segment.
std::string marker_label; // Human-readable label for the marker.
uint64_t length;
// Offset and length of the data contained in the segment.
uint64_t payload_offset;
uint64_t payload_length;
std::optional<JpegApp11Segment> app11_info;
friend bool operator==(const JpegSegment&, const JpegSegment&) = default;
};
void PrintTo(const JpegSegment& x, ::std::ostream* os);
using JpegSegmentProcessor =
absl::FunctionRef<absl::StatusOr<bool>(const JpegSegment&)>;
// Iterates over all JPEG segments in the given reader, calling the given
// function for each segment. The method will NOT seek to position 0 in the
// reader before iterating, it will start from the current position.
absl::Status IterateOverJpegSegments(riegeli::Reader& reader,
JpegSegmentProcessor processor,
int64_t end_offset = -1);
} // namespace credentio
#endif // THIRD_PARTY_CREDENTIO_FORMATS_JPEG_READER_H_