Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
exifite.c File Reference

Allocation-free EXIF parsing, serialization and bounded JPEG streaming. More...

#include "exifite.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
Include dependency graph for exifite.c:

Go to the source code of this file.

Data Structures

struct  jpeg_removal
 Original-file interval occupied by one discarded EXIF segment. More...
struct  jpeg_edit_plan
 Bounded edit list produced by the same parser used for streaming rewrites. More...
struct  jpeg_stream
 One bounded read-ahead buffer shared by JPEG inspection and rewriting. More...

Macros

#define EXIF_CAMERA_POINTER   0x8769U
 Standard primary-IFD link to the camera/EXIF directory.
#define EXIF_GPS_POINTER   0x8825U
 Standard primary-IFD link to the GPS directory.
#define EXIF_MAX_INPUT_ENTRIES   256U
 Bounds validation work and its stack-based duplicate-tag table.
#define TIFF_HEADER_SIZE   8U
 Fixed TIFF layout widths, expressed separately from JPEG framing.
#define TIFF_ENTRY_SIZE   12U
 Bytes occupied by one TIFF directory entry.
#define TIFF_INLINE_SIZE   4U
 Maximum TIFF value length stored directly in a directory entry.
#define TIFF_DIRECTORY_COUNT_SIZE   2U
 Bytes occupied by a TIFF directory's entry count.
#define TIFF_DIRECTORY_NEXT_SIZE   4U
 Bytes occupied by the next-directory link after an entry table.
#define JPEG_MAX_HEADER_SEGMENTS   1024U
 Limit on JPEG header segments inspected before reaching image data.
#define JPEG_MAX_HEADER_BYTES   (4U * 1024U * 1024U)
 Limit on ordinary JPEG header segment bytes inspected.
#define JPEG_STREAM_CAPACITY   8192U
 Read-ahead capacity independent of image dimensions.

Functions

static int invalid (void)
 Use one predictable error for invalid arguments and malformed values.
static uint16_t read_short (const unsigned char *data, bool little)
 Read two already-checked bytes without alignment or host-endian assumptions.
static uint32_t read_long (const unsigned char *data, bool little)
 Read four checked bytes; casts precede shifts to avoid signed promotion.
void exif_encode_short (unsigned char *data, uint16_t value)
 Encode a 16-bit value in the writer's little-endian representation.
void exif_encode_long (unsigned char *data, uint32_t value)
 Encode a 32-bit value in the writer's little-endian representation.
static size_t format_size (uint16_t format)
 Map TIFF's numbered representations to their component byte widths.
static bool range (size_t total, size_t offset, size_t length)
 Check a byte span without forming a potentially overflowing end offset.
static bool overlaps (const void *first, size_t first_size, const void *second, size_t second_size)
 Detect caller-buffer aliasing without adding lengths to addresses.
static bool entry_value (const struct exif_view *view, size_t offset, struct exif_value *value)
 Resolve one TIFF entry into checked, borrowed value bytes.
static bool validate_directory (struct exif_view *view, enum exif_directory directory)
 Validate one bounded IFD and discover the two supported child links.
int exif_parse (struct exif_view *view, const unsigned char *payload, size_t size)
 Validate an EXIF APP1 payload and create a borrowed view.
bool exif_get (const struct exif_view *view, enum exif_directory directory, uint16_t tag, struct exif_value *value)
 Look up a directory-local tag without copying its bytes.
bool exif_value_unsigned (const struct exif_value *value, size_t index, uint32_t *result)
 Decode one BYTE, SHORT or LONG component without an unaligned load.
static double signed_long (uint32_t value)
 Interpret a TIFF signed component without an implementation-defined cast.
bool exif_value_rational (const struct exif_value *value, size_t index, double *result)
 Decode one unsigned or signed rational component as a double.
size_t exif_text_length (const struct exif_value *value)
 Count text bytes after trimming trailing NUL padding only.
void exif_document_init (struct exif_document *document)
 Start a fresh upright sRGB/Y-Cb-Cr document with EXIF 2.32 defaults.
bool exif_document_get (const struct exif_document *document, enum exif_directory directory, uint16_t tag, struct exif_value *value)
 Borrow a field from the current writable document.
int exif_document_remove (struct exif_document *document, enum exif_directory directory, uint16_t tag)
 Remove a tag and reclaim its packed value storage.
unsigned char * exif_document_reserve (struct exif_document *document, enum exif_directory directory, uint16_t tag, enum exif_format format, uint32_t count)
 Create or replace a field with zeroed, bounded value storage.
int exif_document_ascii (struct exif_document *document, enum exif_directory directory, uint16_t tag, const char *text)
 Replace an ASCII field, including its terminating NUL byte.
int exif_document_rational (struct exif_document *document, enum exif_directory directory, uint16_t tag, uint32_t numerator, uint32_t denominator)
 Store an unsigned measurement as an exact numerator/denominator pair.
static bool supported (enum exif_directory directory, uint16_t tag)
 Select standard fields retained by the default import policy.
static bool import_directory (struct exif_document *document, const struct exif_view *view, enum exif_directory directory, exif_tag_selector select, void *context)
 Copy supported fields from one directory into writer storage.
int exif_document_import_custom (struct exif_document *document, const struct exif_view *view, exif_tag_selector select, void *context)
 Import standard fields plus additional tags selected by the caller.
int exif_document_import (struct exif_document *document, const struct exif_view *view)
 Rebuild a writable document from supported Sensoraia fields.
static bool valid_document_entry (const struct exif_document *document, const struct exif_item *entry)
 Validate a writer field before calculating offsets or touching output.
static bool entry_precedes (const struct exif_item *first, const struct exif_item *second)
 Compare the wire ordering of two directory-local fields.
int exif_serialize (const struct exif_document *document, unsigned char *payload, size_t capacity, size_t *size)
 Serialize a document into one complete EXIF APP1 payload.
static bool read_exact (FILE *input, unsigned char *buffer, size_t size)
 Read an entire declared span or report truncation.
static bool skip_exact (FILE *input, size_t size)
 Consume unwanted bytes without trusting a seek past end-of-file.
static int read_exif_stream (FILE *input, unsigned char *payload, size_t capacity, size_t *size)
 Extract the unique EXIF payload from a caller-owned JPEG stream.
int exif_read_stream (FILE *input, unsigned char *payload, size_t capacity, size_t *size)
 Read capture EXIF from an already-open JPEG without reopening its path.
int exif_read_jpeg (const char *filename, unsigned char *payload, size_t capacity, size_t *size)
 Read the single EXIF APP1 segment before the first JPEG scan.
static bool stream_fill (struct jpeg_stream *stream)
 Refill only after buffered bytes have been consumed.
static int stream_byte (struct jpeg_stream *stream)
 Read a marker/header byte while preserving buffered cursor ownership.
static bool stream_write (struct jpeg_stream *stream, const unsigned char *data, size_t size)
 Share byte emission between real rewrites and write-free validation.
static bool stream_put_byte (struct jpeg_stream *stream, int byte)
 Emit one framing byte, or do nothing during preflight.
static off_t stream_offset (const struct jpeg_stream *stream)
 Recover the logical offset rather than the read-ahead descriptor offset.
static bool stream_copy (struct jpeg_stream *stream, size_t size, bool emit)
 Copy or discard exactly one declared span in bounded chunks.
static bool marker_prefix (struct jpeg_stream *stream, size_t count, int marker)
 Emit a marker together with its original fill-byte count.
static bool stream_marker (struct jpeg_stream *stream, bool entropy, size_t *prefix, int *marker)
 Find a structural marker, optionally copying preceding entropy bytes.
static bool frame_marker (int marker)
 Recognize SOF markers while excluding other codes in the same range.
static bool stream_read (struct jpeg_stream *stream, unsigned char *data, size_t size)
 Read a short fixed-size header across read-ahead buffer boundaries.
static bool stream_frame_header (struct jpeg_stream *stream, size_t payload_size, unsigned char header[6])
 Read and validate the common six-byte start-of-frame header.
static bool stream_segment_header (struct jpeg_stream *stream, size_t prefix, int marker, size_t payload_size)
 Emit a segment prefix and its two-byte big-endian JPEG length.
int exif_jpeg_dimensions (FILE *input, uint32_t *width, uint32_t *height, unsigned *components)
 Inspect the frame header without allocating or decoding image pixels.
static bool rewrite_jpeg_stream (struct jpeg_stream *stream, const unsigned char *payload, size_t size)
 Rewrite JPEG framing using caller-owned streams and validated EXIF.
int exif_rewrite_jpeg (FILE *input, FILE *output, const unsigned char *payload, size_t size)
 Stream a JPEG with one new EXIF segment instead of its old EXIF records.
static int relocate_jpeg_range (int descriptor, off_t start, off_t end, off_t displacement)
 Move one retained interval without overwriting its unread source bytes.
static int relocate_jpeg_spans (int descriptor, const struct jpeg_edit_plan *plan, off_t original_size, off_t inserted_size, bool backwards)
 Move only the spans whose final positions differ from their originals.
int exif_update_jpeg (FILE *file, const unsigned char *payload, size_t size)
 Replace EXIF in a regular JPEG file without a temporary file.

Variables

static const unsigned char exif_signature [] = {'E', 'x', 'i', 'f', 0, 0}
 APP1 identifier; its terminators are part of the on-disk signature.

Detailed Description

Allocation-free EXIF parsing, serialization and bounded JPEG streaming.

The implementation keeps three jobs separate: validate borrowed TIFF bytes, collect caller-owned values, then stream JPEG markers around a serialized APP1 payload. That separation lets us check each boundary without allocating image-sized buffers or interpreting manufacturer-specific pointer structures.

See also
exifite.h for public contracts and storage ownership.

Definition in file exifite.c.

Macro Definition Documentation

◆ EXIF_CAMERA_POINTER

#define EXIF_CAMERA_POINTER   0x8769U

Standard primary-IFD link to the camera/EXIF directory.

Definition at line 38 of file exifite.c.

◆ EXIF_GPS_POINTER

#define EXIF_GPS_POINTER   0x8825U

Standard primary-IFD link to the GPS directory.

Definition at line 40 of file exifite.c.

◆ EXIF_MAX_INPUT_ENTRIES

#define EXIF_MAX_INPUT_ENTRIES   256U

Bounds validation work and its stack-based duplicate-tag table.

Input may contain more fields than our writer, but cannot demand unbounded memory or quadratic validation work from the embedded board.

Definition at line 44 of file exifite.c.

◆ JPEG_MAX_HEADER_BYTES

#define JPEG_MAX_HEADER_BYTES   (4U * 1024U * 1024U)

Limit on ordinary JPEG header segment bytes inspected.

Definition at line 59 of file exifite.c.

◆ JPEG_MAX_HEADER_SEGMENTS

#define JPEG_MAX_HEADER_SEGMENTS   1024U

Limit on JPEG header segments inspected before reaching image data.

Definition at line 57 of file exifite.c.

◆ JPEG_STREAM_CAPACITY

#define JPEG_STREAM_CAPACITY   8192U

Read-ahead capacity independent of image dimensions.

Definition at line 61 of file exifite.c.

◆ TIFF_DIRECTORY_COUNT_SIZE

#define TIFF_DIRECTORY_COUNT_SIZE   2U

Bytes occupied by a TIFF directory's entry count.

Definition at line 53 of file exifite.c.

◆ TIFF_DIRECTORY_NEXT_SIZE

#define TIFF_DIRECTORY_NEXT_SIZE   4U

Bytes occupied by the next-directory link after an entry table.

Definition at line 55 of file exifite.c.

◆ TIFF_ENTRY_SIZE

#define TIFF_ENTRY_SIZE   12U

Bytes occupied by one TIFF directory entry.

Definition at line 49 of file exifite.c.

◆ TIFF_HEADER_SIZE

#define TIFF_HEADER_SIZE   8U

Fixed TIFF layout widths, expressed separately from JPEG framing.

Definition at line 47 of file exifite.c.

◆ TIFF_INLINE_SIZE

#define TIFF_INLINE_SIZE   4U

Maximum TIFF value length stored directly in a directory entry.

Definition at line 51 of file exifite.c.

Function Documentation

◆ entry_precedes()

bool entry_precedes ( const struct exif_item * first,
const struct exif_item * second )
static

Compare the wire ordering of two directory-local fields.

Parameters
[in]firstCandidate field.
[in]secondField currently ahead of the candidate.
Returns
True when the candidate belongs before the existing field.

Definition at line 730 of file exifite.c.

◆ entry_value()

bool entry_value ( const struct exif_view * view,
size_t offset,
struct exif_value * value )
static

Resolve one TIFF entry into checked, borrowed value bytes.

Parameters
[in]viewTIFF storage and declared byte order.
[in]offsetTIFF-relative offset of the twelve-byte directory entry.
[out]valueField descriptor; use only when validation succeeds.
Returns
True for a supported, fully accessible representation.

TIFF stores values of at most four bytes directly in the entry; larger values use an offset relative to the TIFF header. Count validation precedes multiplication, so an untrusted component count cannot overflow.

Definition at line 167 of file exifite.c.

◆ format_size()

size_t format_size ( uint16_t format)
static

Map TIFF's numbered representations to their component byte widths.

Parameters
[in]formatOn-disk TIFF type identifier.
Returns
Component width, or zero for an unsupported type.

The table includes ordinary TIFF types beyond our named enum values so unknown but structurally valid input fields can be checked and then ignored.

Definition at line 119 of file exifite.c.

◆ frame_marker()

bool frame_marker ( int marker)
static

Recognize SOF markers while excluding other codes in the same range.

Parameters
[in]markerJPEG marker code without its 0xff prefix.
Returns
True for a start-of-frame marker.

DHT, JPG and DAC share the 0xc0..0xcf range but do not carry dimensions.

Definition at line 1246 of file exifite.c.

◆ import_directory()

bool import_directory ( struct exif_document * document,
const struct exif_view * view,
enum exif_directory directory,
exif_tag_selector select,
void * context )
static

Copy supported fields from one directory into writer storage.

Parameters
[in,out]documentInitialized destination document.
[in]viewSource bytes and input byte order.
[in]directoryDirectory whose fields should be imported.
[in]selectOptional caller selection for additional fields.
[in]contextBorrowed selection state.
Returns
True on success, false when the caller must reset the partial import.

Keeping rollback in the public wrapper makes this routine responsible only for traversal and byte-order conversion, not document lifecycle.

Definition at line 619 of file exifite.c.

◆ invalid()

int invalid ( void )
static

Use one predictable error for invalid arguments and malformed values.

Returns
Always -1, after setting errno to EINVAL.

Definition at line 69 of file exifite.c.

◆ marker_prefix()

bool marker_prefix ( struct jpeg_stream * stream,
size_t count,
int marker )
static

Emit a marker together with its original fill-byte count.

Parameters
[in,out]streamState containing a writable output stream.
[in]countNumber of leading 0xff bytes, including the marker prefix.
[in]markerMarker code, or stuffed zero when copying scan data.
Returns
True when all bytes were written.

Retaining legal fill bytes avoids unnecessary changes to unrelated JPEG framing while replacement EXIF gets its own single-prefix marker.

Definition at line 1176 of file exifite.c.

◆ overlaps()

bool overlaps ( const void * first,
size_t first_size,
const void * second,
size_t second_size )
static

Detect caller-buffer aliasing without adding lengths to addresses.

Parameters
[in]firstFirst storage address.
[in]first_sizeFirst storage length in bytes.
[in]secondSecond storage address.
[in]second_sizeSecond storage length in bytes.
Returns
True for overlapping nonempty spans.

Address differences avoid wraparound at the end of an address space. This uses the flat uintptr_t address representation of our Linux targets.

Definition at line 147 of file exifite.c.

◆ range()

bool range ( size_t total,
size_t offset,
size_t length )
static

Check a byte span without forming a potentially overflowing end offset.

Parameters
[in]totalAccessible bytes in the enclosing storage.
[in]offsetProposed starting offset.
[in]lengthProposed span length.
Returns
True when the entire span fits.

Check the start first; only then is the subtraction safe. Keep this order when extending the parser with another field or pointer check.

Definition at line 133 of file exifite.c.

◆ read_exact()

bool read_exact ( FILE * input,
unsigned char * buffer,
size_t size )
static

Read an entire declared span or report truncation.

Parameters
[in,out]inputReadable stream at the span's first byte.
[out]bufferStorage for at least size bytes.
[in]sizeExact byte count required.
Returns
True only when every requested byte was read.

Definition at line 884 of file exifite.c.

◆ read_exif_stream()

int read_exif_stream ( FILE * input,
unsigned char * payload,
size_t capacity,
size_t * size )
static

Extract the unique EXIF payload from a caller-owned JPEG stream.

Parameters
[in,out]inputReadable stream at start-of-image; not closed here.
[out]payloadDestination for the selected APP1 payload.
[in]capacityWritable payload capacity in bytes.
[out]sizeSelected payload length; the public wrapper clears it on failure.
Returns
Zero on success, otherwise -1 with errno describing the parse failure.

Ownership stays with the wrapper so every parse exit can be a plain return, while file closing and error preservation remain in one place.

Definition at line 918 of file exifite.c.

◆ read_long()

uint32_t read_long ( const unsigned char * data,
bool little )
static

Read four checked bytes; casts precede shifts to avoid signed promotion.

Parameters
[in]dataAt least four accessible bytes.
[in]littleByte order declared by the input TIFF header.
Returns
Decoded unsigned 32-bit value.

Definition at line 91 of file exifite.c.

◆ read_short()

uint16_t read_short ( const unsigned char * data,
bool little )
static

Read two already-checked bytes without alignment or host-endian assumptions.

Parameters
[in]dataAt least two accessible bytes.
[in]littleTrue for little-endian TIFF, false for big-endian TIFF.
Returns
Decoded unsigned 16-bit value.

Definition at line 80 of file exifite.c.

◆ relocate_jpeg_range()

int relocate_jpeg_range ( int descriptor,
off_t start,
off_t end,
off_t displacement )
static

Move one retained interval without overwriting its unread source bytes.

Parameters
[in]descriptorOpen read/write regular file.
[in]startOriginal interval start, inclusive.
[in]endOriginal interval end, exclusive.
[in]displacementSigned destination offset relative to the source.
Returns
Zero on success, otherwise -1 with errno set.

Growth copies backward; shrinkage copies forward. Positional I/O avoids stream seeks per block. Short transfers and EINTR are handled without assuming that one system call completes the block. A zero-byte transfer is an I/O error.

Definition at line 1545 of file exifite.c.

◆ relocate_jpeg_spans()

int relocate_jpeg_spans ( int descriptor,
const struct jpeg_edit_plan * plan,
off_t original_size,
off_t inserted_size,
bool backwards )
static

Move only the spans whose final positions differ from their originals.

Parameters
[in]descriptorOpen read/write regular file.
[in]planValidated ordered removal intervals and insertion location.
[in]original_sizeOriginal file size, including bytes after EOI.
[in]inserted_sizeReplacement segment size, including marker and length.
[in]backwardsTrue for right-shifted spans, false for left-shifted spans.
Returns
Zero on success, otherwise -1 with errno set.

After the one insertion, displacement only decreases as old EXIF is removed. Right-shifted spans therefore precede left-shifted spans. Copying the former from the end and the latter from the start protects every unread span, even when EXIF occurs between progressive scans and displacement changes sign. Zero-displacement spans need no writes; this is the cheap repeated-update path.

Definition at line 1615 of file exifite.c.

◆ rewrite_jpeg_stream()

bool rewrite_jpeg_stream ( struct jpeg_stream * stream,
const unsigned char * payload,
size_t size )
static

Rewrite JPEG framing using caller-owned streams and validated EXIF.

Parameters
[in,out]streamBuffered source and destination state.
[in]payloadValidated replacement APP1 bytes.
[in]sizeReplacement payload length.
Returns
True after a complete frame/scan/EOI stream, false on framing or I/O failure.

This routine owns no resources. Early returns keep the scan-state transitions visible; the public wrapper supplies one error-classification path.

Definition at line 1378 of file exifite.c.

◆ signed_long()

double signed_long ( uint32_t value)
static

Interpret a TIFF signed component without an implementation-defined cast.

Parameters
[in]valueUnsigned bit representation of a 32-bit signed integer.
Returns
Its signed mathematical value, exactly representable as a double.

Subtracting 2^32 handles negative values, including INT32_MIN, without signed overflow. This keeps signed rational handling portable between compilers.

Definition at line 378 of file exifite.c.

◆ skip_exact()

bool skip_exact ( FILE * input,
size_t size )
static

Consume unwanted bytes without trusting a seek past end-of-file.

Parameters
[in,out]inputReadable stream positioned before the unwanted span.
[in]sizeBytes that must actually exist.
Returns
True after consuming the span, false for a short read.

A seek can succeed beyond EOF; reading bounded chunks makes a truncated JPEG segment fail instead of hiding the missing bytes from the header parser.

Definition at line 896 of file exifite.c.

◆ stream_byte()

int stream_byte ( struct jpeg_stream * stream)
static

Read a marker/header byte while preserving buffered cursor ownership.

Parameters
[in,out]streamRead-ahead state.
Returns
Next unsigned byte as an int, or EOF when no byte is available.

Definition at line 1105 of file exifite.c.

◆ stream_copy()

bool stream_copy ( struct jpeg_stream * stream,
size_t size,
bool emit )
static

Copy or discard exactly one declared span in bounded chunks.

Parameters
[in,out]streamInput cursor and optional writable output stream.
[in]sizeBytes to consume; short input is an error.
[in]emitTrue to write bytes, false to discard an old EXIF segment.
Returns
True after consuming the full span, false on read/write failure.

Both paths consume existing read-ahead first, so changing from marker parsing to bulk copying never loses or reads the same bytes twice.

Definition at line 1149 of file exifite.c.

◆ stream_fill()

bool stream_fill ( struct jpeg_stream * stream)
static

Refill only after buffered bytes have been consumed.

Parameters
[in,out]streamRead-ahead state.
Returns
True when at least one byte remains, false on EOF or read error.

Callers distinguish EOF from I/O failure with ferror() where needed.

Definition at line 1090 of file exifite.c.

◆ stream_frame_header()

bool stream_frame_header ( struct jpeg_stream * stream,
size_t payload_size,
unsigned char header[6] )
static

Read and validate the common six-byte start-of-frame header.

Parameters
[in,out]streamSource cursor immediately after the segment length.
[in]payload_sizeFull frame payload length, including component descriptors.
[out]headerPrecision, height, width and component count bytes.
Returns
True for the bounded frame representation supported by this module.

Inspection and rewriting use the same checks so they cannot disagree about which dimensions or component counts are safe to publish.

Definition at line 1277 of file exifite.c.

◆ stream_marker()

bool stream_marker ( struct jpeg_stream * stream,
bool entropy,
size_t * prefix,
int * marker )
static

Find a structural marker, optionally copying preceding entropy bytes.

Parameters
[in,out]streamBuffered cursor; entropy mode requires a writable output.
[in]entropyTrue inside a scan, false between marker segments.
[out]prefixMarker-prefix/fill count for the caller to retain or discard.
[out]markerStructural marker code, not yet emitted.
Returns
True on a marker, false on malformed framing or I/O failure.

Inside scans, 0xff/0x00 is a stuffed data byte and restart markers do not end the scan. Handle these here so the rewrite loop sees only markers whose segments it must inspect. Prefix reads may cross buffer boundaries.

Definition at line 1199 of file exifite.c.

◆ stream_offset()

off_t stream_offset ( const struct jpeg_stream * stream)
static

Recover the logical offset rather than the read-ahead descriptor offset.

Parameters
[in]streamParser state for a seekable regular file.
Returns
Offset of the next unconsumed byte, or -1 on a positioning error.

Definition at line 1135 of file exifite.c.

◆ stream_put_byte()

bool stream_put_byte ( struct jpeg_stream * stream,
int byte )
static

Emit one framing byte, or do nothing during preflight.

Parameters
[in,out]streamParser state with optional output.
[in]byteByte value to emit.
Returns
True on successful emission or validation-only traversal.

Definition at line 1126 of file exifite.c.

◆ stream_read()

bool stream_read ( struct jpeg_stream * stream,
unsigned char * data,
size_t size )
static

Read a short fixed-size header across read-ahead buffer boundaries.

Parameters
[in,out]streamBuffered source state.
[out]dataStorage for at least the requested byte count.
[in]sizeExact byte count to read.
Returns
True when the complete header was available.

Definition at line 1257 of file exifite.c.

◆ stream_segment_header()

bool stream_segment_header ( struct jpeg_stream * stream,
size_t prefix,
int marker,
size_t payload_size )
static

Emit a segment prefix and its two-byte big-endian JPEG length.

Parameters
[in,out]streamState containing a writable output stream.
[in]prefixNumber of prefix/fill bytes to preserve.
[in]markerSegment marker code.
[in]payload_sizeSegment bytes excluding the two length bytes.
Returns
True when the complete framing was written.
Precondition
Payload length is already bounded by the JPEG segment limit.

Definition at line 1300 of file exifite.c.

◆ stream_write()

bool stream_write ( struct jpeg_stream * stream,
const unsigned char * data,
size_t size )
static

Share byte emission between real rewrites and write-free validation.

Parameters
[in,out]streamParser state with optional output.
[in]dataBytes to emit only when an output exists.
[in]sizeAccessible byte count.
Returns
True on complete emission or validation-only traversal.

Definition at line 1116 of file exifite.c.

◆ supported()

bool supported ( enum exif_directory directory,
uint16_t tag )
static

Select standard fields retained by the default import policy.

Parameters
[in]directoryDirectory containing the field.
[in]tagDirectory-local tag identifier.
Returns
True when the field belongs in an imported writer document.

Byte-for-byte copying is not enough for vendor records with private offsets. An explicit allowlist keeps imports small and avoids pretending to preserve structures we neither interpret nor need. Defaults are rebuilt separately.

Definition at line 595 of file exifite.c.

◆ valid_document_entry()

bool valid_document_entry ( const struct exif_document * document,
const struct exif_item * entry )
static

Validate a writer field before calculating offsets or touching output.

Parameters
[in]documentSource document whose storage has already been bounded.
[in]entryField descriptor to check against that storage.
Returns
True when the representation can be serialized safely.

Definition at line 700 of file exifite.c.

◆ validate_directory()

bool validate_directory ( struct exif_view * view,
enum exif_directory directory )
static

Validate one bounded IFD and discover the two supported child links.

Parameters
[in,out]viewCandidate view; primary-directory links fill child offsets.
[in]directoryDirectory identity to validate.
Returns
True for an absent directory or a valid directory table and its values.

Duplicate tags are ambiguous, so reject them rather than let readers disagree over which value wins. A small bounded scan avoids heap-backed sets and does not assume that camera entries arrive sorted.

Definition at line 213 of file exifite.c.

Variable Documentation

◆ exif_signature

const unsigned char exif_signature[] = {'E', 'x', 'i', 'f', 0, 0}
static

APP1 identifier; its terminators are part of the on-disk signature.

Definition at line 64 of file exifite.c.