blob: dbc9792c94113c56deec7d6b88722a3c13a2f2d7 [file] [log] [blame]
Urvang Joshiacd7b5a2015-05-01 16:11:49 -07001// 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 Joshiacd7b5a2015-05-01 16:11:49 -070019#include "webp/types.h"
20
Pascal Massimino96201e52015-11-06 07:47:03 +010021#ifdef __cplusplus
22extern "C" {
23#endif
Urvang Joshiacd7b5a2015-05-01 16:11:49 -070024
Pascal Massimino96201e52015-11-06 07:47:03 +010025typedef 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
31typedef struct {
Urvang Joshiacd7b5a2015-05-01 16:11:49 -070032 uint32_t canvas_width;
33 uint32_t canvas_height;
34 uint32_t bgcolor;
35 uint32_t loop_count;
Pascal Massimino96201e52015-11-06 07:47:03 +010036 DecodedFrame* frames;
37 uint32_t num_frames;
38 void* raw_mem;
39} AnimatedImage;
40
41// Deallocate everything in 'image' (but not the object itself).
42void ClearAnimatedImage(AnimatedImage* const image);
Urvang Joshiacd7b5a2015-05-01 16:11:49 -070043
44// Read animated image file into 'AnimatedImage' struct.
45// If 'dump_frames' is true, dump frames to 'dump_folder'.
Pascal Massimino96201e52015-11-06 07:47:03 +010046// Previous content of 'image' is obliterated.
47// Upon successful return, content of 'image' must be deleted by
48// calling 'ClearAnimatedImage'.
49int ReadAnimatedImage(const char filename[], AnimatedImage* const image,
50 int dump_frames, const char dump_folder[]);
Urvang Joshiacd7b5a2015-05-01 16:11:49 -070051
52// Given two RGBA buffers, calculate max pixel difference and PSNR.
Pascal Massiminoacb297e2015-07-07 22:45:49 +000053// If 'premultiply' is true, R/G/B values will be pre-multiplied by the
54// transparency before comparison.
Urvang Joshiacd7b5a2015-05-01 16:11:49 -070055void GetDiffAndPSNR(const uint8_t rgba1[], const uint8_t rgba2[],
Pascal Massimino96201e52015-11-06 07:47:03 +010056 uint32_t width, uint32_t height, int premultiply,
Pascal Massiminoacb297e2015-07-07 22:45:49 +000057 int* const max_diff, double* const psnr);
Urvang Joshiacd7b5a2015-05-01 16:11:49 -070058
Pascal Massimino96201e52015-11-06 07:47:03 +010059#ifdef __cplusplus
60} // extern "C"
61#endif
62
Urvang Joshiacd7b5a2015-05-01 16:11:49 -070063#endif // WEBP_EXAMPLES_ANIM_UTIL_H_