1
// Copyright 2011 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
// Internal header for mux library.
12
// Author: Urvang (urvang@google.com)
14
#ifndef WEBP_MUX_MUXI_H_
15
#define WEBP_MUX_MUXI_H_
18
#include "../dec/vp8i.h"
19
#include "../dec/vp8li.h"
20
#include "../webp/mux.h"
26
//------------------------------------------------------------------------------
27
// Defines and constants.
29
#define MUX_MAJ_VERSION 0
30
#define MUX_MIN_VERSION 2
31
#define MUX_REV_VERSION 1
34
typedef struct WebPChunk WebPChunk;
37
int owner_; // True if *data_ memory is owned internally.
38
// VP8X, ANIM, and other internally created chunks
39
// like ANMF/FRGM are always owned.
44
// MuxImage object. Store a full WebP image (including ANMF/FRGM chunk, ALPH
45
// chunk and VP8/VP8L chunk),
46
typedef struct WebPMuxImage WebPMuxImage;
48
WebPChunk* header_; // Corresponds to WEBP_CHUNK_ANMF/WEBP_CHUNK_FRGM.
49
WebPChunk* alpha_; // Corresponds to WEBP_CHUNK_ALPHA.
50
WebPChunk* img_; // Corresponds to WEBP_CHUNK_IMAGE.
51
WebPChunk* unknown_; // Corresponds to WEBP_CHUNK_UNKNOWN.
54
int has_alpha_; // Through ALPH chunk or as part of VP8L.
55
int is_partial_; // True if only some of the chunks are filled.
59
// Main mux object. Stores data chunks.
61
WebPMuxImage* images_;
73
// CHUNK_INDEX enum: used for indexing within 'kChunks' (defined below) only.
74
// Note: the reason for having two enums ('WebPChunkId' and 'CHUNK_INDEX') is to
75
// allow two different chunks to have the same id (e.g. WebPChunkId
76
// 'WEBP_CHUNK_IMAGE' can correspond to CHUNK_INDEX 'IDX_VP8' or 'IDX_VP8L').
94
#define NIL_TAG 0x00000000u // To signal void chunk.
102
extern const ChunkInfo kChunks[IDX_LAST_CHUNK];
104
//------------------------------------------------------------------------------
105
// Chunk object management.
108
void ChunkInit(WebPChunk* const chunk);
110
// Get chunk index from chunk tag. Returns IDX_UNKNOWN if not found.
111
CHUNK_INDEX ChunkGetIndexFromTag(uint32_t tag);
113
// Get chunk id from chunk tag. Returns WEBP_CHUNK_UNKNOWN if not found.
114
WebPChunkId ChunkGetIdFromTag(uint32_t tag);
116
// Convert a fourcc string to a tag.
117
uint32_t ChunkGetTagFromFourCC(const char fourcc[4]);
119
// Get chunk index from fourcc. Returns IDX_UNKNOWN if given fourcc is unknown.
120
CHUNK_INDEX ChunkGetIndexFromFourCC(const char fourcc[4]);
122
// Search for nth chunk with given 'tag' in the chunk list.
123
// nth = 0 means "last of the list".
124
WebPChunk* ChunkSearchList(WebPChunk* first, uint32_t nth, uint32_t tag);
126
// Fill the chunk with the given data.
127
WebPMuxError ChunkAssignData(WebPChunk* chunk, const WebPData* const data,
128
int copy_data, uint32_t tag);
130
// Sets 'chunk' at nth position in the 'chunk_list'.
131
// nth = 0 has the special meaning "last of the list".
132
// On success ownership is transferred from 'chunk' to the 'chunk_list'.
133
WebPMuxError ChunkSetNth(WebPChunk* chunk, WebPChunk** chunk_list,
136
// Releases chunk and returns chunk->next_.
137
WebPChunk* ChunkRelease(WebPChunk* const chunk);
139
// Deletes given chunk & returns chunk->next_.
140
WebPChunk* ChunkDelete(WebPChunk* const chunk);
142
// Deletes all chunks in the given chunk list.
143
void ChunkListDelete(WebPChunk** const chunk_list);
145
// Returns size of the chunk including chunk header and padding byte (if any).
146
static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) {
147
return CHUNK_HEADER_SIZE + ((chunk_size + 1) & ~1U);
150
// Size of a chunk including header and padding.
151
static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) {
152
const size_t data_size = chunk->data_.size;
153
assert(data_size < MAX_CHUNK_PAYLOAD);
154
return SizeWithPadding(data_size);
157
// Total size of a list of chunks.
158
size_t ChunkListDiskSize(const WebPChunk* chunk_list);
160
// Write out the given list of chunks into 'dst'.
161
uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst);
163
//------------------------------------------------------------------------------
164
// MuxImage object management.
167
void MuxImageInit(WebPMuxImage* const wpi);
169
// Releases image 'wpi' and returns wpi->next.
170
WebPMuxImage* MuxImageRelease(WebPMuxImage* const wpi);
172
// Delete image 'wpi' and return the next image in the list or NULL.
173
// 'wpi' can be NULL.
174
WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi);
176
// Count number of images matching the given tag id in the 'wpi_list'.
177
// If id == WEBP_CHUNK_NIL, all images will be matched.
178
int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id);
180
// Update width/height/has_alpha info from chunks within wpi.
181
// Also remove ALPH chunk if not needed.
182
int MuxImageFinalize(WebPMuxImage* const wpi);
184
// Check if given ID corresponds to an image related chunk.
185
static WEBP_INLINE int IsWPI(WebPChunkId id) {
187
case WEBP_CHUNK_ANMF:
188
case WEBP_CHUNK_FRGM:
189
case WEBP_CHUNK_ALPHA:
190
case WEBP_CHUNK_IMAGE: return 1;
195
// Pushes 'wpi' at the end of 'wpi_list'.
196
WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list);
198
// Delete nth image in the image list.
199
WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth);
201
// Get nth image in the image list.
202
WebPMuxError MuxImageGetNth(const WebPMuxImage** wpi_list, uint32_t nth,
205
// Total size of the given image.
206
size_t MuxImageDiskSize(const WebPMuxImage* const wpi);
208
// Write out the given image into 'dst'.
209
uint8_t* MuxImageEmit(const WebPMuxImage* const wpi, uint8_t* dst);
211
//------------------------------------------------------------------------------
212
// Helper methods for mux.
214
// Checks if the given image list contains at least one image with alpha.
215
int MuxHasAlpha(const WebPMuxImage* images);
217
// Write out RIFF header into 'data', given total data size 'size'.
218
uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size);
220
// Returns the list where chunk with given ID is to be inserted in mux.
221
WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id);
223
// Validates the given mux object.
224
WebPMuxError MuxValidate(const WebPMux* const mux);
226
//------------------------------------------------------------------------------
232
#endif /* WEBP_MUX_MUXI_H_ */