blob: 03ef87de1d2228514b98a28c7a9363359fd1e440 [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
21#if defined(__cplusplus) || defined(c_plusplus)
22extern "C" {
23#endif
24
25//------------------------------------------------------------------------------
26// Frame cache.
27
28typedef struct WebPFrameCache WebPFrameCache;
29
30// Given the minimum distance between key frames 'kmin' and maximum distance
31// between key frames 'kmax', returns an appropriately allocated cache object.
32// Use WebPFrameCacheDelete() to deallocate the 'cache'.
33WebPFrameCache* WebPFrameCacheNew(size_t kmin, size_t kmax);
34
35// Release all the frame data from 'cache' and free 'cache'.
36void WebPFrameCacheDelete(WebPFrameCache* const cache);
37
38// Add encoded frame in the cache. 'sub_frame_info' and 'sub_frame_pic' are used
39// to encode the frame rectangle, while 'key_frame_info' and 'key_frame_pic' are
40// used to encode the key frame. Either 'sub_frame_pic' (and 'sub_frame_info')
41// or 'key_frame_pic' (and 'key_frame_info') can be NULL; in which case the
42// corresponding variant will be omitted.
43// Returns true on success.
44int WebPFrameCacheAddFrame(WebPFrameCache* const cache,
45 const WebPConfig* const config,
46 const WebPMuxFrameInfo* const sub_frame_info,
47 WebPPicture* const sub_frame_pic,
48 const WebPMuxFrameInfo* const key_frame_info,
49 WebPPicture* const key_frame_pic);
50
51// Flush the *ready* frames from cache and add them to 'mux'. If 'verbose' is
52// true, prints the information about these frames.
53WebPMuxError WebPFrameCacheFlush(WebPFrameCache* const cache, int verbose,
54 WebPMux* const mux);
55
56// Similar to 'WebPFrameCacheFlushFrames()', but flushes *all* the frames.
57WebPMuxError WebPFrameCacheFlushAll(WebPFrameCache* const cache, int verbose,
58 WebPMux* const mux);
59
60// Returns true if subsequent call to WebPFrameCacheAddFrame() should
61// incorporate a potential keyframe.
62int WebPFrameCacheShouldTryKeyFrame(const WebPFrameCache* const cache);
63
64//------------------------------------------------------------------------------
65// Frame rectangle and related utilities.
66
67#define TRANSPARENT_COLOR 0x00ffffff
68
69typedef struct {
70 int x_offset, y_offset, width, height;
71} WebPFrameRect;
72
73struct WebPPicture;
74
75// Clear pixels in 'picture' within given 'rect' to transparent color.
76void WebPUtilClearPic(struct WebPPicture* const picture,
77 const WebPFrameRect* const rect);
78
79// Copy pixels from 'src' to 'dst' honoring strides. 'src' and 'dst' are assumed
80// to be already allocated.
81void WebPUtilCopyPixels(const struct WebPPicture* const src,
82 WebPPicture* const dst);
83
84// Given 'src' picture and its frame rectangle 'rect', blend it into 'dst'.
85void WebPUtilBlendPixels(const struct WebPPicture* const src,
86 const WebPFrameRect* const src_rect,
87 struct WebPPicture* const dst);
88
Urvang Joshi606c4302013-09-30 16:48:39 -070089// Replace transparent pixels within 'dst_rect' of 'dst' by those in the 'src'.
90void WebPUtilReduceTransparency(const struct WebPPicture* const src,
91 const WebPFrameRect* const dst_rect,
92 struct WebPPicture* const dst);
93
skal00125192013-10-08 15:04:52 +020094// Replace similar blocks of pixels by a 'see-through' transparent block
95// with uniform average color.
96void WebPUtilFlattenSimilarBlocks(const WebPPicture* const src,
97 const WebPFrameRect* const rect,
98 WebPPicture* const dst);
99
Urvang Joshid538cea2013-09-12 13:41:09 -0700100//------------------------------------------------------------------------------
101// Key frame related.
102
103// Returns true if 'curr' frame with frame rectangle 'curr_rect' is a key frame,
104// that is, it can be decoded independently of 'prev' canvas.
105int WebPUtilIsKeyFrame(const WebPPicture* const curr,
106 const WebPFrameRect* const curr_rect,
107 const WebPPicture* const prev);
108
109// Given 'prev' frame and current frame rectangle 'rect', convert 'curr' frame
110// to a key frame.
111void WebPUtilConvertToKeyFrame(const WebPPicture* const prev,
112 WebPFrameRect* const rect,
113 WebPPicture* const curr);
114
115//------------------------------------------------------------------------------
116
117#if defined(__cplusplus) || defined(c_plusplus)
118} // extern "C"
119#endif
120
121#endif // WEBP_EXAMPLES_GIF2WEBP_UTIL_H_