Blame examples/gifdec.h

Packit 9c6abc
// Copyright 2014 Google Inc. All Rights Reserved.
Packit 9c6abc
//
Packit 9c6abc
// Use of this source code is governed by a BSD-style license
Packit 9c6abc
// that can be found in the COPYING file in the root of the source
Packit 9c6abc
// tree. An additional intellectual property rights grant can be found
Packit 9c6abc
// in the file PATENTS. All contributing project authors may
Packit 9c6abc
// be found in the AUTHORS file in the root of the source tree.
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
//
Packit 9c6abc
// GIF decode.
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_EXAMPLES_GIFDEC_H_
Packit 9c6abc
#define WEBP_EXAMPLES_GIFDEC_H_
Packit 9c6abc
Packit 9c6abc
#include <stdio.h>
Packit 9c6abc
#include "webp/types.h"
Packit 9c6abc
Packit 9c6abc
#ifdef HAVE_CONFIG_H
Packit 9c6abc
#include "webp/config.h"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#ifdef WEBP_HAVE_GIF
Packit 9c6abc
#include <gif_lib.h>
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
extern "C" {
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
// GIFLIB_MAJOR is only defined in libgif >= 4.2.0.
Packit 9c6abc
#if defined(GIFLIB_MAJOR) && defined(GIFLIB_MINOR)
Packit 9c6abc
# define LOCAL_GIF_VERSION ((GIFLIB_MAJOR << 8) | GIFLIB_MINOR)
Packit 9c6abc
# define LOCAL_GIF_PREREQ(maj, min) \
Packit 9c6abc
    (LOCAL_GIF_VERSION >= (((maj) << 8) | (min)))
Packit 9c6abc
#else
Packit 9c6abc
# define LOCAL_GIF_VERSION 0
Packit 9c6abc
# define LOCAL_GIF_PREREQ(maj, min) 0
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#define GIF_INDEX_INVALID (-1)
Packit 9c6abc
Packit 9c6abc
typedef enum GIFDisposeMethod {
Packit 9c6abc
  GIF_DISPOSE_NONE,
Packit 9c6abc
  GIF_DISPOSE_BACKGROUND,
Packit 9c6abc
  GIF_DISPOSE_RESTORE_PREVIOUS
Packit 9c6abc
} GIFDisposeMethod;
Packit 9c6abc
Packit 9c6abc
typedef struct {
Packit 9c6abc
  int x_offset, y_offset, width, height;
Packit 9c6abc
} GIFFrameRect;
Packit 9c6abc
Packit 9c6abc
struct WebPData;
Packit 9c6abc
struct WebPPicture;
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_HAVE_GIF
Packit 9c6abc
struct ColorMapObject;
Packit 9c6abc
struct GifFileType;
Packit 9c6abc
typedef unsigned char GifByteType;
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
// Given the index of background color and transparent color, returns the
Packit 9c6abc
// corresponding background color (in BGRA format) in 'bgcolor'.
Packit 9c6abc
void GIFGetBackgroundColor(const struct ColorMapObject* const color_map,
Packit 9c6abc
                           int bgcolor_index, int transparent_index,
Packit 9c6abc
                           uint32_t* const bgcolor);
Packit 9c6abc
Packit 9c6abc
// Parses the given graphics extension data to get frame duration (in 1ms
Packit 9c6abc
// units), dispose method and transparent color index.
Packit 9c6abc
// Returns true on success.
Packit 9c6abc
int GIFReadGraphicsExtension(const GifByteType* const buf, int* const duration,
Packit 9c6abc
                             GIFDisposeMethod* const dispose,
Packit 9c6abc
                             int* const transparent_index);
Packit 9c6abc
Packit 9c6abc
// Reads the next GIF frame from 'gif' into 'picture'. Also, returns the GIF
Packit 9c6abc
// frame dimensions and offsets in 'rect'.
Packit 9c6abc
// Returns true on success.
Packit 9c6abc
int GIFReadFrame(struct GifFileType* const gif, int transparent_index,
Packit 9c6abc
                 GIFFrameRect* const gif_rect,
Packit 9c6abc
                 struct WebPPicture* const picture);
Packit 9c6abc
Packit 9c6abc
// Parses loop count from the given Netscape extension data.
Packit 9c6abc
int GIFReadLoopCount(struct GifFileType* const gif, GifByteType** const buf,
Packit 9c6abc
                     int* const loop_count);
Packit 9c6abc
Packit 9c6abc
// Parses the given ICC or XMP extension data and stores it into 'metadata'.
Packit 9c6abc
// Returns true on success.
Packit 9c6abc
int GIFReadMetadata(struct GifFileType* const gif, GifByteType** const buf,
Packit 9c6abc
                    struct WebPData* const metadata);
Packit 9c6abc
Packit 9c6abc
// Dispose the pixels within 'rect' of 'curr_canvas' based on 'dispose' method
Packit 9c6abc
// and 'prev_canvas'.
Packit 9c6abc
void GIFDisposeFrame(GIFDisposeMethod dispose, const GIFFrameRect* const rect,
Packit 9c6abc
                     const struct WebPPicture* const prev_canvas,
Packit 9c6abc
                     struct WebPPicture* const curr_canvas);
Packit 9c6abc
Packit 9c6abc
// Given 'src' picture and its frame rectangle 'rect', blend it into 'dst'.
Packit 9c6abc
void GIFBlendFrames(const struct WebPPicture* const src,
Packit 9c6abc
                    const GIFFrameRect* const rect,
Packit 9c6abc
                    struct WebPPicture* const dst);
Packit 9c6abc
Packit 9c6abc
// Prints an error string based on 'gif_error'.
Packit 9c6abc
void GIFDisplayError(const struct GifFileType* const gif, int gif_error);
Packit 9c6abc
Packit 9c6abc
// In the given 'pic', clear the pixels in 'rect' to transparent color.
Packit 9c6abc
void GIFClearPic(struct WebPPicture* const pic, const GIFFrameRect* const rect);
Packit 9c6abc
Packit 9c6abc
// Copy pixels from 'src' to 'dst' honoring strides. 'src' and 'dst' are assumed
Packit 9c6abc
// to be already allocated.
Packit 9c6abc
void GIFCopyPixels(const struct WebPPicture* const src,
Packit 9c6abc
                   struct WebPPicture* const dst);
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
}    // extern "C"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#endif  // WEBP_EXAMPLES_GIFDEC_H_