Loading...
Searching...
No Matches
exifite.c
Go to the documentation of this file.
401 if (!value || !value->data || (value->format != EXIF_ASCII && value->format != EXIF_UNDEFINED)) {
438 data = exif_document_reserve(document, EXIF_CAMERA, EXIF_COMPONENTS_CONFIGURATION, EXIF_UNDEFINED,
454 if (!document || document->count > EXIF_MAX_ENTRIES || document->used > sizeof(document->data) ||
476 if (!document || document->count > EXIF_MAX_ENTRIES || document->used > sizeof(document->data) ||
508unsigned char *exif_document_reserve(struct exif_document *document, enum exif_directory directory,
543int exif_document_ascii(struct exif_document *document, enum exif_directory directory, uint16_t tag,
674 if (!document || !view || !view->tiff || view->size > EXIF_MAX_PAYLOAD - sizeof(exif_signature) ||
736int exif_serialize(const struct exif_document *document, unsigned char *payload, size_t capacity,
1199static bool stream_marker(struct jpeg_stream *stream, bool entropy, size_t *prefix, int *marker)
1523 if (input == NULL || output == NULL || input == output || exif_parse(&view, payload, size) != 0) {
static bool start(uint32_t session)
Admit a nonzero session and discard correlation from the previous one.
Definition dipla_camera_backend.c:170
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.
Definition exifite.c:1300
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.
Definition exifite.c:1378
static size_t format_size(uint16_t format)
Map TIFF's numbered representations to their component byte widths.
Definition exifite.c:119
#define EXIF_CAMERA_POINTER
Standard primary-IFD link to the camera/EXIF directory.
Definition exifite.c:38
static bool read_exact(FILE *input, unsigned char *buffer, size_t size)
Read an entire declared span or report truncation.
Definition exifite.c:884
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.
Definition exifite.c:1545
static uint32_t read_long(const unsigned char *data, bool little)
Read four checked bytes; casts precede shifts to avoid signed promotion.
Definition exifite.c:91
static bool validate_directory(struct exif_view *view, enum exif_directory directory)
Validate one bounded IFD and discover the two supported child links.
Definition exifite.c:213
static int stream_byte(struct jpeg_stream *stream)
Read a marker/header byte while preserving buffered cursor ownership.
Definition exifite.c:1105
static off_t stream_offset(const struct jpeg_stream *stream)
Recover the logical offset rather than the read-ahead descriptor offset.
Definition exifite.c:1135
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.
Definition exifite.c:700
#define JPEG_MAX_HEADER_SEGMENTS
Limit on JPEG header segments inspected before reaching image data.
Definition exifite.c:57
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.
Definition exifite.c:147
static uint16_t read_short(const unsigned char *data, bool little)
Read two already-checked bytes without alignment or host-endian assumptions.
Definition exifite.c:80
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.
Definition exifite.c:918
#define TIFF_DIRECTORY_NEXT_SIZE
Bytes occupied by the next-directory link after an entry table.
Definition exifite.c:55
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.
Definition exifite.c:1277
static bool marker_prefix(struct jpeg_stream *stream, size_t count, int marker)
Emit a marker together with its original fill-byte count.
Definition exifite.c:1176
#define JPEG_MAX_HEADER_BYTES
Limit on ordinary JPEG header segment bytes inspected.
Definition exifite.c:59
static bool stream_put_byte(struct jpeg_stream *stream, int byte)
Emit one framing byte, or do nothing during preflight.
Definition exifite.c:1126
static bool frame_marker(int marker)
Recognize SOF markers while excluding other codes in the same range.
Definition exifite.c:1246
#define EXIF_MAX_INPUT_ENTRIES
Bounds validation work and its stack-based duplicate-tag table.
Definition exifite.c:44
static int invalid(void)
Use one predictable error for invalid arguments and malformed values.
Definition exifite.c:69
static double signed_long(uint32_t value)
Interpret a TIFF signed component without an implementation-defined cast.
Definition exifite.c:378
static bool stream_fill(struct jpeg_stream *stream)
Refill only after buffered bytes have been consumed.
Definition exifite.c:1090
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.
Definition exifite.c:1257
#define TIFF_HEADER_SIZE
Fixed TIFF layout widths, expressed separately from JPEG framing.
Definition exifite.c:47
#define JPEG_STREAM_CAPACITY
Read-ahead capacity independent of image dimensions.
Definition exifite.c:61
#define TIFF_DIRECTORY_COUNT_SIZE
Bytes occupied by a TIFF directory's entry count.
Definition exifite.c:53
static bool stream_marker(struct jpeg_stream *stream, bool entropy, size_t *prefix, int *marker)
Find a structural marker, optionally copying preceding entropy bytes.
Definition exifite.c:1199
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.
Definition exifite.c:1116
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.
Definition exifite.c:619
#define TIFF_INLINE_SIZE
Maximum TIFF value length stored directly in a directory entry.
Definition exifite.c:51
static bool range(size_t total, size_t offset, size_t length)
Check a byte span without forming a potentially overflowing end offset.
Definition exifite.c:133
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.
Definition exifite.c:167
static bool stream_copy(struct jpeg_stream *stream, size_t size, bool emit)
Copy or discard exactly one declared span in bounded chunks.
Definition exifite.c:1149
static const unsigned char exif_signature[]
APP1 identifier; its terminators are part of the on-disk signature.
Definition exifite.c:64
static bool entry_precedes(const struct exif_item *first, const struct exif_item *second)
Compare the wire ordering of two directory-local fields.
Definition exifite.c:730
static bool supported(enum exif_directory directory, uint16_t tag)
Select standard fields retained by the default import policy.
Definition exifite.c:595
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.
Definition exifite.c:1615
static bool skip_exact(FILE *input, size_t size)
Consume unwanted bytes without trusting a seek past end-of-file.
Definition exifite.c:896
Bounded C11 EXIF metadata and JPEG streaming interfaces.
int exif_document_import(struct exif_document *document, const struct exif_view *view)
Rebuild a writable document from supported Sensoraia fields.
Definition exifite.c:690
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.
Definition exifite.c:736
void exif_document_init(struct exif_document *document)
Start a fresh upright sRGB/Y-Cb-Cr document with EXIF 2.32 defaults.
Definition exifite.c:412
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.
Definition exifite.c:339
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.
Definition exifite.c:508
void exif_encode_long(unsigned char *data, uint32_t value)
Encode a 32-bit value in the writer's little-endian representation.
Definition exifite.c:106
int exif_parse(struct exif_view *view, const unsigned char *payload, size_t size)
Validate an EXIF APP1 payload and create a borrowed view.
Definition exifite.c:257
int exif_document_remove(struct exif_document *document, enum exif_directory directory, uint16_t tag)
Remove a tag and reclaim its packed value storage.
Definition exifite.c:473
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.
Definition exifite.c:310
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.
Definition exifite.c:1022
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.
Definition exifite.c:572
bool(* exif_tag_selector)(void *context, enum exif_directory directory, uint16_t tag)
Caller policy for additional, directory-local fields to import.
Definition exifite.h:247
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.
Definition exifite.c:447
#define EXIF_MAX_PAYLOAD
APP1 payload ceiling: the JPEG length includes its own two bytes.
Definition exifite.h:51
int exif_jpeg_dimensions(FILE *input, uint32_t *width, uint32_t *height, unsigned *components)
Inspect the frame header without allocating or decoding image pixels.
Definition exifite.c:1309
#define EXIF_MAX_ENTRIES
Writer entry budget, including the standard initialization tags.
Definition exifite.h:54
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.
Definition exifite.c:1013
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.
Definition exifite.c:543
bool exif_value_rational(const struct exif_value *value, size_t index, double *result)
Decode one unsigned or signed rational component as a double.
Definition exifite.c:383
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.
Definition exifite.c:671
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.
Definition exifite.c:1518
size_t exif_text_length(const struct exif_value *value)
Count text bytes after trimming trailing NUL padding only.
Definition exifite.c:399
void exif_encode_short(unsigned char *data, uint16_t value)
Encode a 16-bit value in the writer's little-endian representation.
Definition exifite.c:99
int exif_update_jpeg(FILE *file, const unsigned char *payload, size_t size)
Replace EXIF in a regular JPEG file without a temporary file.
Definition exifite.c:1649
uint8_t marker[LWIR_THERMAL_HEADER_BYTES+LWIR_THERMAL_CHUNK_CAPACITY]
Definition lwir_image.c:62
Writer bookkeeping for one field inside the document's value storage.
Definition exifite.h:142
Borrowed bytes plus enough type information for safe interpretation.
Definition exifite.h:119
Bounded edit list produced by the same parser used for streaming rewrites.
Definition exifite.c:1064
struct jpeg_removal removals[JPEG_MAX_HEADER_SEGMENTS]
Definition exifite.c:1067
One bounded read-ahead buffer shared by JPEG inspection and rewriting.
Definition exifite.c:1074