Urvang Joshi | d538cea | 2013-09-12 13:41:09 -0700 | [diff] [blame] | 1 | // 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) |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | //------------------------------------------------------------------------------ |
Urvang Joshi | 38efdc2 | 2013-10-14 14:39:46 -0700 | [diff] [blame] | 26 | // Helper utilities. |
| 27 | |
| 28 | #define WEBP_UTIL_TRANSPARENT_COLOR 0x00ffffff |
| 29 | |
| 30 | struct WebPPicture; |
| 31 | |
| 32 | typedef struct { |
| 33 | int x_offset, y_offset, width, height; |
| 34 | } WebPFrameRect; |
| 35 | |
| 36 | // Clear pixels in 'picture' within given 'rect' to transparent color. |
| 37 | void WebPUtilClearPic(struct WebPPicture* const picture, |
| 38 | const WebPFrameRect* const rect); |
| 39 | |
| 40 | //------------------------------------------------------------------------------ |
Urvang Joshi | d538cea | 2013-09-12 13:41:09 -0700 | [diff] [blame] | 41 | // Frame cache. |
| 42 | |
| 43 | typedef 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. |
| 47 | // Use WebPFrameCacheDelete() to deallocate the 'cache'. |
Urvang Joshi | 38efdc2 | 2013-10-14 14:39:46 -0700 | [diff] [blame] | 48 | WebPFrameCache* WebPFrameCacheNew(int width, int height, |
| 49 | size_t kmin, size_t kmax); |
Urvang Joshi | d538cea | 2013-09-12 13:41:09 -0700 | [diff] [blame] | 50 | |
| 51 | // Release all the frame data from 'cache' and free 'cache'. |
| 52 | void WebPFrameCacheDelete(WebPFrameCache* const cache); |
| 53 | |
Urvang Joshi | 38efdc2 | 2013-10-14 14:39:46 -0700 | [diff] [blame] | 54 | // Given an image described by 'frame', 'info' and 'orig_rect', optimize it for |
| 55 | // WebP, encode it and add it to 'cache'. |
| 56 | // This takes care of frame disposal too, according to 'info->dispose_method'. |
Urvang Joshi | d538cea | 2013-09-12 13:41:09 -0700 | [diff] [blame] | 57 | int WebPFrameCacheAddFrame(WebPFrameCache* const cache, |
| 58 | const WebPConfig* const config, |
Urvang Joshi | 38efdc2 | 2013-10-14 14:39:46 -0700 | [diff] [blame] | 59 | const WebPFrameRect* const orig_rect, |
| 60 | WebPPicture* const frame, |
| 61 | WebPMuxFrameInfo* const info); |
Urvang Joshi | d538cea | 2013-09-12 13:41:09 -0700 | [diff] [blame] | 62 | |
| 63 | // Flush the *ready* frames from cache and add them to 'mux'. If 'verbose' is |
| 64 | // true, prints the information about these frames. |
| 65 | WebPMuxError WebPFrameCacheFlush(WebPFrameCache* const cache, int verbose, |
| 66 | WebPMux* const mux); |
| 67 | |
| 68 | // Similar to 'WebPFrameCacheFlushFrames()', but flushes *all* the frames. |
| 69 | WebPMuxError WebPFrameCacheFlushAll(WebPFrameCache* const cache, int verbose, |
| 70 | WebPMux* const mux); |
| 71 | |
Urvang Joshi | d538cea | 2013-09-12 13:41:09 -0700 | [diff] [blame] | 72 | //------------------------------------------------------------------------------ |
| 73 | |
| 74 | #if defined(__cplusplus) || defined(c_plusplus) |
| 75 | } // extern "C" |
| 76 | #endif |
| 77 | |
| 78 | #endif // WEBP_EXAMPLES_GIF2WEBP_UTIL_H_ |