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 | |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "webp/types.h" |
| 22 | |
| 23 | struct DecodedFrame { |
| 24 | std::vector<uint8_t> rgba; // Decoded and reconstructed full frame. |
| 25 | int duration; // Frame duration in milliseconds. |
| 26 | bool is_key_frame; // True if this frame is a key-frame. |
| 27 | }; |
| 28 | |
| 29 | struct AnimatedImage { |
| 30 | uint32_t canvas_width; |
| 31 | uint32_t canvas_height; |
| 32 | uint32_t bgcolor; |
| 33 | uint32_t loop_count; |
| 34 | std::vector<DecodedFrame> frames; |
| 35 | }; |
| 36 | |
| 37 | // Read animated image file into 'AnimatedImage' struct. |
| 38 | // If 'dump_frames' is true, dump frames to 'dump_folder'. |
| 39 | bool ReadAnimatedImage(const char filename[], AnimatedImage* const image, |
| 40 | bool dump_frames, const char dump_folder[]); |
| 41 | |
| 42 | // Given two RGBA buffers, calculate max pixel difference and PSNR. |
| 43 | void GetDiffAndPSNR(const uint8_t rgba1[], const uint8_t rgba2[], |
| 44 | uint32_t width, uint32_t height, int* const max_diff, |
| 45 | double* const psnr); |
| 46 | |
| 47 | #endif // WEBP_EXAMPLES_ANIM_UTIL_H_ |