gifdec.h (4008B)
1 // Copyright 2014 Google Inc. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the COPYING file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 // ----------------------------------------------------------------------------- 9 // 10 // GIF decode. 11 12 #ifndef WEBP_EXAMPLES_GIFDEC_H_ 13 #define WEBP_EXAMPLES_GIFDEC_H_ 14 15 #include <stdio.h> 16 17 #include "webp/types.h" 18 19 #ifdef HAVE_CONFIG_H 20 #include "webp/config.h" 21 #endif 22 23 #ifdef WEBP_HAVE_GIF 24 #include <gif_lib.h> 25 #endif 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 // GIFLIB_MAJOR is only defined in libgif >= 4.2.0. 32 #if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR) 33 # define LOCAL_GIF_VERSION ((GIFLIB_MAJOR << 8) | GIFLIB_MINOR) 34 # define LOCAL_GIF_PREREQ(maj, min) \ 35 (LOCAL_GIF_VERSION >= (((maj) << 8) | (min))) 36 #else 37 # define LOCAL_GIF_VERSION 0 38 # define LOCAL_GIF_PREREQ(maj, min) 0 39 #endif 40 41 #define GIF_INDEX_INVALID (-1) 42 43 typedef enum GIFDisposeMethod { 44 GIF_DISPOSE_NONE, 45 GIF_DISPOSE_BACKGROUND, 46 GIF_DISPOSE_RESTORE_PREVIOUS 47 } GIFDisposeMethod; 48 49 typedef struct { 50 int x_offset, y_offset, width, height; 51 } GIFFrameRect; 52 53 struct WebPData; 54 struct WebPPicture; 55 56 #ifndef WEBP_HAVE_GIF 57 struct ColorMapObject; 58 struct GifFileType; 59 typedef unsigned char GifByteType; 60 #endif 61 62 // Given the index of background color and transparent color, returns the 63 // corresponding background color (in BGRA format) in 'bgcolor'. 64 void GIFGetBackgroundColor(const struct ColorMapObject* const color_map, 65 int bgcolor_index, int transparent_index, 66 uint32_t* const bgcolor); 67 68 // Parses the given graphics extension data to get frame duration (in 1ms 69 // units), dispose method and transparent color index. 70 // Returns true on success. 71 int GIFReadGraphicsExtension(const GifByteType* const buf, int* const duration, 72 GIFDisposeMethod* const dispose, 73 int* const transparent_index); 74 75 // Reads the next GIF frame from 'gif' into 'picture'. Also, returns the GIF 76 // frame dimensions and offsets in 'rect'. 77 // Returns true on success. 78 int GIFReadFrame(struct GifFileType* const gif, int transparent_index, 79 GIFFrameRect* const gif_rect, 80 struct WebPPicture* const picture); 81 82 // Parses loop count from the given Netscape extension data. 83 int GIFReadLoopCount(struct GifFileType* const gif, GifByteType** const buf, 84 int* const loop_count); 85 86 // Parses the given ICC or XMP extension data and stores it into 'metadata'. 87 // Returns true on success. 88 int GIFReadMetadata(struct GifFileType* const gif, GifByteType** const buf, 89 struct WebPData* const metadata); 90 91 // Dispose the pixels within 'rect' of 'curr_canvas' based on 'dispose' method 92 // and 'prev_canvas'. 93 void GIFDisposeFrame(GIFDisposeMethod dispose, const GIFFrameRect* const rect, 94 const struct WebPPicture* const prev_canvas, 95 struct WebPPicture* const curr_canvas); 96 97 // Given 'src' picture and its frame rectangle 'rect', blend it into 'dst'. 98 void GIFBlendFrames(const struct WebPPicture* const src, 99 const GIFFrameRect* const rect, 100 struct WebPPicture* const dst); 101 102 // Prints an error string based on 'gif_error'. 103 void GIFDisplayError(const struct GifFileType* const gif, int gif_error); 104 105 // In the given 'pic', clear the pixels in 'rect' to transparent color. 106 void GIFClearPic(struct WebPPicture* const pic, const GIFFrameRect* const rect); 107 108 // Copy pixels from 'src' to 'dst' honoring strides. 'src' and 'dst' are assumed 109 // to be already allocated. 110 void GIFCopyPixels(const struct WebPPicture* const src, 111 struct WebPPicture* const dst); 112 113 #ifdef __cplusplus 114 } // extern "C" 115 #endif 116 117 #endif // WEBP_EXAMPLES_GIFDEC_H_