Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | // Utilities for animated images |
| 11 | |
| 12 | #ifndef WEBP_EXAMPLES_ANIM_UTIL_H_ |
| 13 | #define WEBP_EXAMPLES_ANIM_UTIL_H_ |
| 14 | |
| 15 | #ifdef HAVE_CONFIG_H |
| 16 | #include "webp/config.h" |
| 17 | #endif |
| 18 | |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 19 | #include "webp/types.h" |
| 20 | |
Pascal Massimino | 96201e5 | 2015-11-06 07:47:03 +0100 | [diff] [blame] | 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 24 | |
Pascal Massimino | 96201e5 | 2015-11-06 07:47:03 +0100 | [diff] [blame] | 25 | typedef struct { |
| 26 | uint8_t* rgba; // Decoded and reconstructed full frame. |
| 27 | int duration; // Frame duration in milliseconds. |
| 28 | int is_key_frame; // True if this frame is a key-frame. |
| 29 | } DecodedFrame; |
| 30 | |
| 31 | typedef struct { |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 32 | uint32_t canvas_width; |
| 33 | uint32_t canvas_height; |
| 34 | uint32_t bgcolor; |
| 35 | uint32_t loop_count; |
Pascal Massimino | 96201e5 | 2015-11-06 07:47:03 +0100 | [diff] [blame] | 36 | DecodedFrame* frames; |
| 37 | uint32_t num_frames; |
| 38 | void* raw_mem; |
| 39 | } AnimatedImage; |
| 40 | |
| 41 | // Deallocate everything in 'image' (but not the object itself). |
| 42 | void ClearAnimatedImage(AnimatedImage* const image); |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 43 | |
| 44 | // Read animated image file into 'AnimatedImage' struct. |
| 45 | // If 'dump_frames' is true, dump frames to 'dump_folder'. |
Pascal Massimino | 96201e5 | 2015-11-06 07:47:03 +0100 | [diff] [blame] | 46 | // Previous content of 'image' is obliterated. |
| 47 | // Upon successful return, content of 'image' must be deleted by |
| 48 | // calling 'ClearAnimatedImage'. |
| 49 | int ReadAnimatedImage(const char filename[], AnimatedImage* const image, |
| 50 | int dump_frames, const char dump_folder[]); |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 51 | |
| 52 | // Given two RGBA buffers, calculate max pixel difference and PSNR. |
Pascal Massimino | acb297e | 2015-07-07 22:45:49 +0000 | [diff] [blame] | 53 | // If 'premultiply' is true, R/G/B values will be pre-multiplied by the |
| 54 | // transparency before comparison. |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 55 | void GetDiffAndPSNR(const uint8_t rgba1[], const uint8_t rgba2[], |
Pascal Massimino | 96201e5 | 2015-11-06 07:47:03 +0100 | [diff] [blame] | 56 | uint32_t width, uint32_t height, int premultiply, |
Pascal Massimino | acb297e | 2015-07-07 22:45:49 +0000 | [diff] [blame] | 57 | int* const max_diff, double* const psnr); |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 58 | |
Pascal Massimino | 96201e5 | 2015-11-06 07:47:03 +0100 | [diff] [blame] | 59 | #ifdef __cplusplus |
| 60 | } // extern "C" |
| 61 | #endif |
| 62 | |
Urvang Joshi | acd7b5a | 2015-05-01 16:11:49 -0700 | [diff] [blame] | 63 | #endif // WEBP_EXAMPLES_ANIM_UTIL_H_ |