2015-05-02 01:11:49 +02:00
|
|
|
// Copyright 2015 Google Inc. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Utilities for animated images
|
|
|
|
|
|
|
|
#ifndef WEBP_EXAMPLES_ANIM_UTIL_H_
|
|
|
|
#define WEBP_EXAMPLES_ANIM_UTIL_H_
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "webp/config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "webp/types.h"
|
|
|
|
|
2015-11-06 07:47:03 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-05-10 02:36:13 +02:00
|
|
|
typedef enum {
|
|
|
|
ANIM_GIF,
|
|
|
|
ANIM_WEBP
|
|
|
|
} AnimatedFileFormat;
|
|
|
|
|
2015-11-06 07:47:03 +01:00
|
|
|
typedef struct {
|
|
|
|
uint8_t* rgba; // Decoded and reconstructed full frame.
|
2015-05-02 01:11:49 +02:00
|
|
|
int duration; // Frame duration in milliseconds.
|
2015-11-06 07:47:03 +01:00
|
|
|
int is_key_frame; // True if this frame is a key-frame.
|
|
|
|
} DecodedFrame;
|
2015-05-02 01:11:49 +02:00
|
|
|
|
2015-11-06 07:47:03 +01:00
|
|
|
typedef struct {
|
2018-05-10 02:36:13 +02:00
|
|
|
AnimatedFileFormat format;
|
2015-05-02 01:11:49 +02:00
|
|
|
uint32_t canvas_width;
|
|
|
|
uint32_t canvas_height;
|
|
|
|
uint32_t bgcolor;
|
|
|
|
uint32_t loop_count;
|
2015-11-06 07:47:03 +01:00
|
|
|
DecodedFrame* frames;
|
|
|
|
uint32_t num_frames;
|
|
|
|
void* raw_mem;
|
|
|
|
} AnimatedImage;
|
|
|
|
|
|
|
|
// Deallocate everything in 'image' (but not the object itself).
|
|
|
|
void ClearAnimatedImage(AnimatedImage* const image);
|
2015-05-02 01:11:49 +02:00
|
|
|
|
|
|
|
// Read animated image file into 'AnimatedImage' struct.
|
|
|
|
// If 'dump_frames' is true, dump frames to 'dump_folder'.
|
2015-11-06 07:47:03 +01:00
|
|
|
// Previous content of 'image' is obliterated.
|
|
|
|
// Upon successful return, content of 'image' must be deleted by
|
|
|
|
// calling 'ClearAnimatedImage'.
|
|
|
|
int ReadAnimatedImage(const char filename[], AnimatedImage* const image,
|
|
|
|
int dump_frames, const char dump_folder[]);
|
2015-05-02 01:11:49 +02:00
|
|
|
|
|
|
|
// Given two RGBA buffers, calculate max pixel difference and PSNR.
|
2015-07-08 00:45:49 +02:00
|
|
|
// If 'premultiply' is true, R/G/B values will be pre-multiplied by the
|
|
|
|
// transparency before comparison.
|
2015-05-02 01:11:49 +02:00
|
|
|
void GetDiffAndPSNR(const uint8_t rgba1[], const uint8_t rgba2[],
|
2015-11-06 07:47:03 +01:00
|
|
|
uint32_t width, uint32_t height, int premultiply,
|
2015-07-08 00:45:49 +02:00
|
|
|
int* const max_diff, double* const psnr);
|
2015-05-02 01:11:49 +02:00
|
|
|
|
2015-11-06 07:47:03 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2015-05-02 01:11:49 +02:00
|
|
|
#endif // WEBP_EXAMPLES_ANIM_UTIL_H_
|