Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2004 Richard Wilson <richard.wilson@netsurf-browser.org>
  3.  * Copyright 2008 Sean Fox <dyntryx@gmail.com>
  4.  *
  5.  * This file is part of NetSurf's libnsgif, http://www.netsurf-browser.org/
  6.  * Licenced under the MIT License,
  7.  *                http://www.opensource.org/licenses/mit-license.php
  8.  */
  9.  
  10. /** \file
  11.  * Progressive animated GIF file decoding (interface).
  12.  */
  13.  
  14. #ifndef _LIBNSGIF_H_
  15. #define _LIBNSGIF_H_
  16.  
  17. #include <stdbool.h>
  18. #include <inttypes.h>
  19.  
  20. /*      Error return values
  21. */
  22. typedef enum {
  23.         GIF_WORKING = 1,
  24.         GIF_OK = 0,
  25.         GIF_INSUFFICIENT_FRAME_DATA = -1,
  26.         GIF_FRAME_DATA_ERROR = -2,
  27.         GIF_INSUFFICIENT_DATA = -3,
  28.         GIF_DATA_ERROR = -4,
  29.         GIF_INSUFFICIENT_MEMORY = -5,
  30.         GIF_FRAME_NO_DISPLAY = -6,
  31.         GIF_END_OF_FRAME = -7
  32. } gif_result;
  33.  
  34. /*      The GIF frame data
  35. */
  36. typedef struct gif_frame {
  37.         bool display;                           /**< whether the frame should be displayed/animated */
  38.         unsigned int frame_delay;               /**< delay (in cs) before animating the frame */
  39.         /**     Internal members are listed below
  40.         */
  41.         unsigned int frame_pointer;             /**< offset (in bytes) to the GIF frame data */
  42.         bool virgin;                            /**< whether the frame has previously been used */
  43.         bool opaque;                            /**< whether the frame is totally opaque */
  44.         bool redraw_required;                   /**< whether a forcable screen redraw is required */
  45.         unsigned char disposal_method;          /**< how the previous frame should be disposed; affects plotting */
  46.         bool transparency;                      /**< whether we acknoledge transparency */
  47.         unsigned char transparency_index;       /**< the index designating a transparent pixel */
  48.         unsigned int redraw_x;                  /**< x co-ordinate of redraw rectangle */
  49.         unsigned int redraw_y;                  /**< y co-ordinate of redraw rectangle */
  50.         unsigned int redraw_width;              /**< width of redraw rectangle */
  51.         unsigned int redraw_height;             /**< height of redraw rectangle */
  52. } gif_frame;
  53.  
  54. /*      API for Bitmap callbacks
  55. */
  56. typedef void* (*gif_bitmap_cb_create)(int width, int height);
  57. typedef void (*gif_bitmap_cb_destroy)(void *bitmap);
  58. typedef unsigned char* (*gif_bitmap_cb_get_buffer)(void *bitmap);
  59. typedef void (*gif_bitmap_cb_set_opaque)(void *bitmap, bool opaque);
  60. typedef bool (*gif_bitmap_cb_test_opaque)(void *bitmap);
  61. typedef void (*gif_bitmap_cb_modified)(void *bitmap);
  62.  
  63. /*      The Bitmap callbacks function table
  64. */
  65. typedef struct gif_bitmap_callback_vt {
  66.         gif_bitmap_cb_create bitmap_create;             /**< Create a bitmap. */
  67.         gif_bitmap_cb_destroy bitmap_destroy;           /**< Free a bitmap. */
  68.         gif_bitmap_cb_get_buffer bitmap_get_buffer;     /**< Return a pointer to the pixel data in a bitmap. */
  69.         /**     Members below are optional
  70.         */
  71.         gif_bitmap_cb_set_opaque bitmap_set_opaque;     /**< Sets whether a bitmap should be plotted opaque. */
  72.         gif_bitmap_cb_test_opaque bitmap_test_opaque;   /**< Tests whether a bitmap has an opaque alpha channel. */
  73.         gif_bitmap_cb_modified bitmap_modified; /**< The bitmap image has changed, so flush any persistant cache. */
  74. } gif_bitmap_callback_vt;
  75.  
  76. /*      The GIF animation data
  77. */
  78. typedef struct gif_animation {
  79.         gif_bitmap_callback_vt bitmap_callbacks;        /**< callbacks for bitmap functions */
  80.         unsigned char *gif_data;                        /**< pointer to GIF data */
  81.         unsigned int width;                             /**< width of GIF (may increase during decoding) */
  82.         unsigned int height;                            /**< heigth of GIF (may increase during decoding) */
  83.         unsigned int frame_count;                       /**< number of frames decoded */
  84.         unsigned int frame_count_partial;               /**< number of frames partially decoded */
  85.         gif_frame *frames;                              /**< decoded frames */
  86.         int decoded_frame;                              /**< current frame decoded to bitmap */
  87.         void *frame_image;                              /**< currently decoded image; stored as bitmap from bitmap_create callback */
  88.         int loop_count;                                 /**< number of times to loop animation */
  89.         gif_result current_error;                       /**< current error type, or 0 for none*/
  90.         /**     Internal members are listed below
  91.         */
  92.         unsigned int buffer_position;                   /**< current index into GIF data */
  93.         unsigned int buffer_size;                       /**< total number of bytes of GIF data available */
  94.         unsigned int frame_holders;                     /**< current number of frame holders */
  95.         unsigned int background_index;                  /**< index in the colour table for the background colour */
  96.         unsigned int aspect_ratio;                      /**< image aspect ratio (ignored) */
  97.         unsigned int colour_table_size;         /**< size of colour table (in entries) */
  98.         bool global_colours;                            /**< whether the GIF has a global colour table */
  99.         unsigned int *global_colour_table;              /**< global colour table */
  100.         unsigned int *local_colour_table;               /**< local colour table */
  101. } gif_animation;
  102.  
  103. void gif_create(gif_animation *gif, gif_bitmap_callback_vt *bitmap_callbacks);
  104. gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data);
  105. gif_result gif_decode_frame(gif_animation *gif, unsigned int frame);
  106. void gif_finalise(gif_animation *gif);
  107.  
  108. #endif
  109.