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 19 #include "webp/types.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 typedef enum { 26 ANIM_GIF, 27 ANIM_WEBP 28 } AnimatedFileFormat; 29 30 typedef struct { 31 uint8_t* rgba; // Decoded and reconstructed full frame. 32 int duration; // Frame duration in milliseconds. 33 int is_key_frame; // True if this frame is a key-frame. 34 } DecodedFrame; 35 36 typedef struct { 37 AnimatedFileFormat format; 38 uint32_t canvas_width; 39 uint32_t canvas_height; 40 uint32_t bgcolor; 41 uint32_t loop_count; 42 DecodedFrame* frames; 43 uint32_t num_frames; 44 void* raw_mem; 45 } AnimatedImage; 46 47 // Deallocate everything in 'image' (but not the object itself). 48 void ClearAnimatedImage(AnimatedImage* const image); 49 50 // Read animated image file into 'AnimatedImage' struct. 51 // If 'dump_frames' is true, dump frames to 'dump_folder'. 52 // Previous content of 'image' is obliterated. 53 // Upon successful return, content of 'image' must be deleted by 54 // calling 'ClearAnimatedImage'. 55 int ReadAnimatedImage(const char filename[], AnimatedImage* const image, 56 int dump_frames, const char dump_folder[]); 57 58 // Given two RGBA buffers, calculate max pixel difference and PSNR. 59 // If 'premultiply' is true, R/G/B values will be pre-multiplied by the 60 // transparency before comparison. 61 void GetDiffAndPSNR(const uint8_t rgba1[], const uint8_t rgba2[], 62 uint32_t width, uint32_t height, int premultiply, 63 int* const max_diff, double* const psnr); 64 65 // Return library versions used by anim_util. 66 void GetAnimatedImageVersions(int* const decoder_version, 67 int* const demux_version); 68 69 #ifdef __cplusplus 70 } // extern "C" 71 #endif 72 73 #endif // WEBP_EXAMPLES_ANIM_UTIL_H_ 74