1
// Copyright 2012 Google Inc. All Rights Reserved.
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
// -----------------------------------------------------------------------------
10
// Data-types common to the mux and demux libraries.
12
// Author: Urvang (urvang@google.com)
14
#ifndef WEBP_WEBP_MUX_TYPES_H_
15
#define WEBP_WEBP_MUX_TYPES_H_
17
#include <stdlib.h> // free()
18
#include <string.h> // memset()
21
#if defined(__cplusplus) || defined(c_plusplus)
25
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
26
// the types are left here for reference.
27
// typedef enum WebPFeatureFlags WebPFeatureFlags;
28
// typedef enum WebPMuxAnimDispose WebPMuxAnimDispose;
29
typedef struct WebPData WebPData;
31
// VP8X Feature Flags.
32
typedef enum WebPFeatureFlags {
33
FRAGMENTS_FLAG = 0x00000001,
34
ANIMATION_FLAG = 0x00000002,
35
XMP_FLAG = 0x00000004,
36
EXIF_FLAG = 0x00000008,
37
ALPHA_FLAG = 0x00000010,
38
ICCP_FLAG = 0x00000020
41
// Dispose method (animation only). Indicates how the area used by the current
42
// frame is to be treated before rendering the next frame on the canvas.
43
typedef enum WebPMuxAnimDispose {
44
WEBP_MUX_DISPOSE_NONE, // Do not dispose.
45
WEBP_MUX_DISPOSE_BACKGROUND // Dispose to background color.
48
// Data type used to describe 'raw' data, e.g., chunk data
49
// (ICC profile, metadata) and WebP compressed image data.
55
// Initializes the contents of the 'webp_data' object with default values.
56
static WEBP_INLINE void WebPDataInit(WebPData* webp_data) {
57
if (webp_data != NULL) {
58
memset(webp_data, 0, sizeof(*webp_data));
62
// Clears the contents of the 'webp_data' object by calling free(). Does not
63
// deallocate the object itself.
64
static WEBP_INLINE void WebPDataClear(WebPData* webp_data) {
65
if (webp_data != NULL) {
66
free((void*)webp_data->bytes);
67
WebPDataInit(webp_data);
71
// Allocates necessary storage for 'dst' and copies the contents of 'src'.
72
// Returns true on success.
73
static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) {
74
if (src == NULL || dst == NULL) return 0;
76
if (src->bytes != NULL && src->size != 0) {
77
dst->bytes = (uint8_t*)malloc(src->size);
78
if (dst->bytes == NULL) return 0;
79
memcpy((void*)dst->bytes, src->bytes, src->size);
80
dst->size = src->size;
85
#if defined(__cplusplus) || defined(c_plusplus)
89
#endif /* WEBP_WEBP_MUX_TYPES_H_ */