blob: 94f12d5ec0136ee19fdf55ad18a02e037621921c [file] [log] [blame]
Urvang Joshid538cea2013-09-12 13:41:09 -07001// Copyright 2013 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// Helper structs and methods for gif2webp tool.
11//
12// Author: Urvang (urvang@google.com)
13
14#ifndef WEBP_EXAMPLES_GIF2WEBP_UTIL_H_
15#define WEBP_EXAMPLES_GIF2WEBP_UTIL_H_
16
17#include <stdlib.h>
18
19#include "webp/mux.h"
20
James Zern605a7122013-11-25 14:43:12 -080021#ifdef __cplusplus
Urvang Joshid538cea2013-09-12 13:41:09 -070022extern "C" {
23#endif
24
25//------------------------------------------------------------------------------
Urvang Joshi38efdc22013-10-14 14:39:46 -070026// Helper utilities.
27
28#define WEBP_UTIL_TRANSPARENT_COLOR 0x00ffffff
29
30struct WebPPicture;
31
32typedef struct {
33 int x_offset, y_offset, width, height;
34} WebPFrameRect;
35
36// Clear pixels in 'picture' within given 'rect' to transparent color.
37void WebPUtilClearPic(struct WebPPicture* const picture,
38 const WebPFrameRect* const rect);
39
40//------------------------------------------------------------------------------
Urvang Joshid538cea2013-09-12 13:41:09 -070041// Frame cache.
42
43typedef struct WebPFrameCache WebPFrameCache;
44
45// Given the minimum distance between key frames 'kmin' and maximum distance
46// between key frames 'kmax', returns an appropriately allocated cache object.
Urvang Joshi73f52132013-11-17 18:04:07 -080047// If 'allow_mixed' is true, the subsequent calls to WebPFrameCacheAddFrame()
48// will heuristically pick lossy or lossless compression for each frame.
Urvang Joshid538cea2013-09-12 13:41:09 -070049// Use WebPFrameCacheDelete() to deallocate the 'cache'.
Urvang Joshi38efdc22013-10-14 14:39:46 -070050WebPFrameCache* WebPFrameCacheNew(int width, int height,
Urvang Joshi73f52132013-11-17 18:04:07 -080051 size_t kmin, size_t kmax, int allow_mixed);
Urvang Joshid538cea2013-09-12 13:41:09 -070052
53// Release all the frame data from 'cache' and free 'cache'.
54void WebPFrameCacheDelete(WebPFrameCache* const cache);
55
Urvang Joshi38efdc22013-10-14 14:39:46 -070056// Given an image described by 'frame', 'info' and 'orig_rect', optimize it for
skalf05fe002014-06-11 23:26:47 +020057// WebP, encode it and add it to 'cache'. 'orig_rect' can be NULL.
Urvang Joshi38efdc22013-10-14 14:39:46 -070058// This takes care of frame disposal too, according to 'info->dispose_method'.
skalf05fe002014-06-11 23:26:47 +020059// Returns false in case of error (and sets frame->error_code accordingly).
Urvang Joshid538cea2013-09-12 13:41:09 -070060int WebPFrameCacheAddFrame(WebPFrameCache* const cache,
61 const WebPConfig* const config,
Urvang Joshi38efdc22013-10-14 14:39:46 -070062 const WebPFrameRect* const orig_rect,
63 WebPPicture* const frame,
64 WebPMuxFrameInfo* const info);
Urvang Joshid538cea2013-09-12 13:41:09 -070065
66// Flush the *ready* frames from cache and add them to 'mux'. If 'verbose' is
67// true, prints the information about these frames.
68WebPMuxError WebPFrameCacheFlush(WebPFrameCache* const cache, int verbose,
69 WebPMux* const mux);
70
71// Similar to 'WebPFrameCacheFlushFrames()', but flushes *all* the frames.
72WebPMuxError WebPFrameCacheFlushAll(WebPFrameCache* const cache, int verbose,
73 WebPMux* const mux);
74
Urvang Joshid538cea2013-09-12 13:41:09 -070075//------------------------------------------------------------------------------
76
James Zern605a7122013-11-25 14:43:12 -080077#ifdef __cplusplus
Urvang Joshid538cea2013-09-12 13:41:09 -070078} // extern "C"
79#endif
80
81#endif // WEBP_EXAMPLES_GIF2WEBP_UTIL_H_