1// Copyright 2012 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// Data-types common to the mux and demux libraries.
11//
12// Author: Urvang (urvang@google.com)
13
14#ifndef WEBP_WEBP_MUX_TYPES_H_
15#define WEBP_WEBP_MUX_TYPES_H_
16
17#include <string.h> // memset()
18#include "./types.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24// Note: forward declaring enumerations is not allowed in (strict) C and C++,
25// the types are left here for reference.
26// typedef enum WebPFeatureFlags WebPFeatureFlags;
27// typedef enum WebPMuxAnimDispose WebPMuxAnimDispose;
28// typedef enum WebPMuxAnimBlend WebPMuxAnimBlend;
29typedef struct WebPData WebPData;
30
31// VP8X Feature Flags.
32typedef enum WebPFeatureFlags {
33 ANIMATION_FLAG = 0x00000002,
34 XMP_FLAG = 0x00000004,
35 EXIF_FLAG = 0x00000008,
36 ALPHA_FLAG = 0x00000010,
37 ICCP_FLAG = 0x00000020,
38
39 ALL_VALID_FLAGS = 0x0000003e
40} WebPFeatureFlags;
41
42// Dispose method (animation only). Indicates how the area used by the current
43// frame is to be treated before rendering the next frame on the canvas.
44typedef enum WebPMuxAnimDispose {
45 WEBP_MUX_DISPOSE_NONE, // Do not dispose.
46 WEBP_MUX_DISPOSE_BACKGROUND // Dispose to background color.
47} WebPMuxAnimDispose;
48
49// Blend operation (animation only). Indicates how transparent pixels of the
50// current frame are blended with those of the previous canvas.
51typedef enum WebPMuxAnimBlend {
52 WEBP_MUX_BLEND, // Blend.
53 WEBP_MUX_NO_BLEND // Do not blend.
54} WebPMuxAnimBlend;
55
56// Data type used to describe 'raw' data, e.g., chunk data
57// (ICC profile, metadata) and WebP compressed image data.
58// 'bytes' memory must be allocated using WebPMalloc() and such.
59struct WebPData {
60 const uint8_t* bytes;
61 size_t size;
62};
63
64// Initializes the contents of the 'webp_data' object with default values.
65static WEBP_INLINE void WebPDataInit(WebPData* webp_data) {
66 if (webp_data != NULL) {
67 memset(s: webp_data, c: 0, n: sizeof(*webp_data));
68 }
69}
70
71// Clears the contents of the 'webp_data' object by calling WebPFree().
72// Does not deallocate the object itself.
73static WEBP_INLINE void WebPDataClear(WebPData* webp_data) {
74 if (webp_data != NULL) {
75 WebPFree(ptr: (void*)webp_data->bytes);
76 WebPDataInit(webp_data);
77 }
78}
79
80// Allocates necessary storage for 'dst' and copies the contents of 'src'.
81// Returns true on success.
82static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) {
83 if (src == NULL || dst == NULL) return 0;
84 WebPDataInit(webp_data: dst);
85 if (src->bytes != NULL && src->size != 0) {
86 dst->bytes = (uint8_t*)WebPMalloc(size: src->size);
87 if (dst->bytes == NULL) return 0;
88 memcpy(dest: (void*)dst->bytes, src: src->bytes, n: src->size);
89 dst->size = src->size;
90 }
91 return 1;
92}
93
94#ifdef __cplusplus
95} // extern "C"
96#endif
97
98#endif // WEBP_WEBP_MUX_TYPES_H_
99

source code of qtimageformats/src/3rdparty/libwebp/src/webp/mux_types.h