GIF image decoder.
More...
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "libnsgif.h"
#include "utils/log.h"
|
static int | gif_next_code (gif_animation *gif, int code_size) |
|
static gif_result | gif_clear_codes_LZW (gif_animation *gif) |
|
static gif_result | gif_initialise_LZW (gif_animation *gif, int initial_code_size) |
|
static bool | gif_next_LZW (gif_animation *gif) |
|
static gif_result | gif_initialise_sprite (gif_animation *gif, unsigned int width, unsigned int height) |
|
static gif_result | gif_initialise_frame_extensions (gif_animation *gif, const int frame) |
|
static gif_result | gif_initialise_frame (gif_animation *gif) |
|
static gif_result | gif_skip_frame_extensions (gif_animation *gif) |
|
static unsigned int | gif_interlaced_line (int height, int y) |
|
static gif_result | gif_internal_decode_frame (gif_animation *gif, unsigned int frame, bool clear_image) |
|
void | gif_create (gif_animation *gif, gif_bitmap_callback_vt *bitmap_callbacks) |
|
gif_result | gif_initialise (gif_animation *gif, size_t size, unsigned char *data) |
|
gif_result | gif_decode_frame (gif_animation *gif, unsigned int frame) |
|
void | gif_finalise (gif_animation *gif) |
|
GIF image decoder.
The GIF format is thoroughly documented; a full description can be found at http://www.w3.org/Graphics/GIF/spec-gif89a.txt
- Todo:
- Plain text and comment extensions should be implemented.
#define GIF_BLOCK_TERMINATOR 0x00 |
#define GIF_COLOUR_TABLE_MASK 0x80 |
#define GIF_COLOUR_TABLE_SIZE_MASK 0x07 |
#define GIF_DISPOSAL_MASK 0x1c |
#define GIF_EXTENSION_APPLICATION 0xff |
#define GIF_EXTENSION_COMMENT 0xfe |
#define GIF_EXTENSION_GRAPHIC_CONTROL 0xf9 |
#define GIF_EXTENSION_INTRODUCER 0x21 |
#define GIF_EXTENSION_PLAIN_TEXT 0x01 |
#define GIF_FRAME_CLEAR 2 |
#define GIF_FRAME_COMBINE 1 |
#define GIF_FRAME_QUIRKS_RESTORE 4 |
#define GIF_FRAME_RESTORE 3 |
#define GIF_IMAGE_SEPARATOR 0x2c |
#define GIF_INTERLACE_MASK 0x40 |
#define GIF_INVALID_FRAME -1 |
Internal flag that a frame is invalid/unprocessed
#define GIF_MAX_COLOURS 256 |
Maximum colour table size
Maximum LZW bits available
#define GIF_PROCESS_COLOURS 0xaa000000 |
Internal flag that the colour table needs to be processed
#define GIF_STANDARD_HEADER_SIZE 13 |
#define GIF_TRANSPARENCY_MASK 0x01 |
#define GIF_TRANSPARENT_COLOUR 0x00 |
Clear LZW code dictionary
- Parameters
-
- Returns
- GIF_OK or error code.
Decodes a GIF frame.
- Returns
- Error return value. If a frame does not contain any image data, GIF_OK is returned and gif->current_error is set to GIF_FRAME_NO_DISPLAY
- GIF_FRAME_DATA_ERROR for GIF frame data error
- GIF_INSUFFICIENT_FRAME_DATA for insufficient data to complete the frame
- GIF_DATA_ERROR for GIF error (invalid frame header)
- GIF_INSUFFICIENT_DATA for insufficient data to do anything
- GIF_INSUFFICIENT_MEMORY for insufficient memory to process
- GIF_OK for successful decoding
Releases any workspace held by a gif
Initialises any workspace held by the animation and attempts to decode any information that hasn't already been decoded. If an error occurs, all previously decoded frames are retained.
- Returns
- Error return value.
- GIF_FRAME_DATA_ERROR for GIF frame data error
- GIF_INSUFFICIENT_FRAME_DATA for insufficient data to process any more frames
- GIF_INSUFFICIENT_MEMORY for memory error
- GIF_DATA_ERROR for GIF error
- GIF_INSUFFICIENT_DATA for insufficient data to do anything
- GIF_OK for successful decoding
- GIF_WORKING for successful decoding if more frames are expected
Attempts to initialise the next frame
- Parameters
-
- Returns
- error code
- GIF_INSUFFICIENT_DATA for insufficient data to do anything
- GIF_FRAME_DATA_ERROR for GIF frame data error
- GIF_INSUFFICIENT_MEMORY for insufficient memory to process
- GIF_INSUFFICIENT_FRAME_DATA for insufficient data to complete the frame
- GIF_DATA_ERROR for GIF error (invalid frame header)
- GIF_OK for successful decoding
- GIF_WORKING for successful decoding if more frames are expected
Attempts to initialise the frame's extensions
- Parameters
-
gif | The animation context |
frame | The frame number |
- Returns
- GIF_INSUFFICIENT_FRAME_DATA for insufficient data to complete the frame GIF_OK for successful initialisation.
Initialise LZW
This initialises a LZW context ready to commence decompression.
- Parameters
-
initial_code_size | The size of codes used on clearing of code dictionary |
Updates the sprite memory size
- Parameters
-
gif | The animation context |
width | The width of the sprite |
height | The height of the sprite |
- Returns
- GIF_INSUFFICIENT_MEMORY for a memory error GIF_OK for success
static unsigned int gif_interlaced_line |
( |
int |
height, |
|
|
int |
y |
|
) |
| |
|
static |
decode a gif frame
- Parameters
-
gif | gif animation context. |
frame | The frame number to decode. |
clear_image | flag for image data being cleared instead of plotted. |
get the next LZW code from the GIF
reads codes from the input data stream coping with GIF data sub blocking
- Parameters
-
gif | The GIF context |
code_size | The number of bitsin the current LZW code |
- Returns
- The next code to process or error return code
fill the LZW stack with decompressed data
- Parameters
-
- Returns
- true on sucessful decode of the next LZW code else false.
Skips the frame's extensions (which have been previously initialised)
- Parameters
-
- Returns
- GIF_INSUFFICIENT_FRAME_DATA for insufficient data to complete the frame GIF_OK for successful decoding
Initial value:= {
.zero_data_block = false,
}