gif_engine/gif_engine.h file

Contents

Typedefs

using gif_allocator = void*(*)(void*pointer, size_t size)
An allocator function type matching that of realloc.
using gif_deallocator = void(*)(void*allocation)
A deallocator function type matching that of free.

Functions

auto gif_parse(const void* buffer, size_t buffer_size, gif_details* details, gif_allocator allocator) -> gif_parse_result
Parses the GIF file located at buffer.
auto gif_decode(gif_details* details, gif_allocator allocator) -> gif_decode_result
Decodes the frame data parsed by gif_parse.
void gif_free_details(const gif_details* details, gif_deallocator deallocator)
Frees the gif_details struct populated by gif_parse.
auto gif_result_code_to_string(gif_result_code code) -> const char*
Returns the string representation of gif_result_code values.

Function documentation

gif_parse_result gif_parse(const void* buffer, size_t buffer_size, gif_details* details, gif_allocator allocator)

Parses the GIF file located at buffer.

This function will parse the contents of buffer in a way that makes OOB reads impossible, if the provided buffer and buffer_size arguments are valid. Because this function must allocate, the user can provide an allocator function using the allocator arguments, which is a pointer to a function with a signature matching that of realloc. The details argument is a pointer to a gif_details struct, which need not be zero initialized, because this function does zero initialization as its first step. Typical usage of this function looks as follows:

gif_details details;
gif_parse_result result = gif_parse(buffer, buffer_size, &details, &realloc);

The code member of the returned gif_parse_result object holds the result of the parsing process. If the code is GIF_SUCCESS, then the data member will hold the number of bytes remaining after the tail block in the buffer. Note that the number of bytes is a size_t value memcpy'd into this field, so you have to copy it out in a similar manner:

size_t leftover_bytes;
memcpy(&leftover_bytes, &result.data, sizeof(size_t));

If the code member is GIF_REALLOC_FAIL, then the pointer that caused the allocator function to fail in a realloc context (i.e. when the first argument isn't NULL) will be returned in the data member as is.

This function is thread-safe.

gif_decode_result gif_decode(gif_details* details, gif_allocator allocator)

Decodes the frame data parsed by gif_parse.

This function is not yet implemented.

void gif_free_details(const gif_details* details, gif_deallocator deallocator)

Frees the gif_details struct populated by gif_parse.

This function should be called even if the gif_parse function did not succeed.

const char* gif_result_code_to_string(gif_result_code code)

Returns the string representation of gif_result_code values.

The returned value will be NULL for unknown values.