/src/libwebp/src/mux/muxi.h
Line | Count | Source |
1 | | // Copyright 2011 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 | | // Internal header for mux library. |
11 | | // |
12 | | // Author: Urvang (urvang@google.com) |
13 | | |
14 | | #ifndef WEBP_MUX_MUXI_H_ |
15 | | #define WEBP_MUX_MUXI_H_ |
16 | | |
17 | | #include <assert.h> |
18 | | #include <stdlib.h> |
19 | | |
20 | | #include "src/dec/vp8i_dec.h" |
21 | | #include "src/dec/vp8li_dec.h" |
22 | | #include "src/webp/format_constants.h" |
23 | | #include "src/webp/mux.h" |
24 | | #include "src/webp/mux_types.h" |
25 | | #include "src/webp/types.h" |
26 | | |
27 | | #ifdef __cplusplus |
28 | | extern "C" { |
29 | | #endif |
30 | | |
31 | | //------------------------------------------------------------------------------ |
32 | | // Defines and constants. |
33 | | |
34 | 0 | #define MUX_MAJ_VERSION 1 |
35 | 0 | #define MUX_MIN_VERSION 6 |
36 | 0 | #define MUX_REV_VERSION 0 |
37 | | |
38 | | // Chunk object. |
39 | | typedef struct WebPChunk WebPChunk; |
40 | | struct WebPChunk { |
41 | | uint32_t tag; |
42 | | int owner; // True if *data memory is owned internally. |
43 | | // VP8X, ANIM, and other internally created chunks |
44 | | // like ANMF are always owned. |
45 | | WebPData data; |
46 | | WebPChunk* next; |
47 | | }; |
48 | | |
49 | | // MuxImage object. Store a full WebP image (including ANMF chunk, ALPH |
50 | | // chunk and VP8/VP8L chunk), |
51 | | typedef struct WebPMuxImage WebPMuxImage; |
52 | | struct WebPMuxImage { |
53 | | WebPChunk* header; // Corresponds to WEBP_CHUNK_ANMF. |
54 | | WebPChunk* alpha; // Corresponds to WEBP_CHUNK_ALPHA. |
55 | | WebPChunk* img; // Corresponds to WEBP_CHUNK_IMAGE. |
56 | | WebPChunk* unknown; // Corresponds to WEBP_CHUNK_UNKNOWN. |
57 | | int width; |
58 | | int height; |
59 | | int has_alpha; // Through ALPH chunk or as part of VP8L. |
60 | | int is_partial; // True if only some of the chunks are filled. |
61 | | WebPMuxImage* next; |
62 | | }; |
63 | | |
64 | | // Main mux object. Stores data chunks. |
65 | | struct WebPMux { |
66 | | WebPMuxImage* images; |
67 | | WebPChunk* iccp; |
68 | | WebPChunk* exif; |
69 | | WebPChunk* xmp; |
70 | | WebPChunk* anim; |
71 | | WebPChunk* vp8x; |
72 | | |
73 | | WebPChunk* unknown; |
74 | | int canvas_width; |
75 | | int canvas_height; |
76 | | }; |
77 | | |
78 | | // CHUNK_INDEX enum: used for indexing within 'kChunks' (defined below) only. |
79 | | // Note: the reason for having two enums ('WebPChunkId' and 'CHUNK_INDEX') is to |
80 | | // allow two different chunks to have the same id (e.g. WebPChunkId |
81 | | // 'WEBP_CHUNK_IMAGE' can correspond to CHUNK_INDEX 'IDX_VP8' or 'IDX_VP8L'). |
82 | | typedef enum { |
83 | | IDX_VP8X = 0, |
84 | | IDX_ICCP, |
85 | | IDX_ANIM, |
86 | | IDX_ANMF, |
87 | | IDX_ALPHA, |
88 | | IDX_VP8, |
89 | | IDX_VP8L, |
90 | | IDX_EXIF, |
91 | | IDX_XMP, |
92 | | IDX_UNKNOWN, |
93 | | |
94 | | IDX_NIL, |
95 | | IDX_LAST_CHUNK |
96 | | } CHUNK_INDEX; |
97 | | |
98 | 102k | #define NIL_TAG 0x00000000u // To signal void chunk. |
99 | | |
100 | | typedef struct { |
101 | | uint32_t tag; |
102 | | WebPChunkId id; |
103 | | uint32_t size; |
104 | | } ChunkInfo; |
105 | | |
106 | | extern const ChunkInfo kChunks[IDX_LAST_CHUNK]; |
107 | | |
108 | | //------------------------------------------------------------------------------ |
109 | | // Chunk object management. |
110 | | |
111 | | // Initialize. |
112 | | void ChunkInit(WebPChunk* const chunk); |
113 | | |
114 | | // Get chunk index from chunk tag. Returns IDX_UNKNOWN if not found. |
115 | | CHUNK_INDEX ChunkGetIndexFromTag(uint32_t tag); |
116 | | |
117 | | // Get chunk id from chunk tag. Returns WEBP_CHUNK_UNKNOWN if not found. |
118 | | WebPChunkId ChunkGetIdFromTag(uint32_t tag); |
119 | | |
120 | | // Convert a fourcc string to a tag. |
121 | | uint32_t ChunkGetTagFromFourCC(const char fourcc[4]); |
122 | | |
123 | | // Get chunk index from fourcc. Returns IDX_UNKNOWN if given fourcc is unknown. |
124 | | CHUNK_INDEX ChunkGetIndexFromFourCC(const char fourcc[4]); |
125 | | |
126 | | // Search for nth chunk with given 'tag' in the chunk list. |
127 | | // nth = 0 means "last of the list". |
128 | | WebPChunk* ChunkSearchList(WebPChunk* first, uint32_t nth, uint32_t tag); |
129 | | |
130 | | // Fill the chunk with the given data. |
131 | | WebPMuxError ChunkAssignData(WebPChunk* chunk, const WebPData* const data, |
132 | | int copy_data, uint32_t tag); |
133 | | |
134 | | // Sets 'chunk' as the only element in 'chunk_list' if it is empty. |
135 | | // On success ownership is transferred from 'chunk' to the 'chunk_list'. |
136 | | WebPMuxError ChunkSetHead(WebPChunk* const chunk, WebPChunk** const chunk_list); |
137 | | // Sets 'chunk' at last position in the 'chunk_list'. |
138 | | // On success ownership is transferred from 'chunk' to the 'chunk_list'. |
139 | | // *chunk_list also points towards the last valid element of the initial |
140 | | // *chunk_list. |
141 | | WebPMuxError ChunkAppend(WebPChunk* const chunk, WebPChunk*** const chunk_list); |
142 | | |
143 | | // Releases chunk and returns chunk->next. |
144 | | WebPChunk* ChunkRelease(WebPChunk* const chunk); |
145 | | |
146 | | // Deletes given chunk & returns chunk->next. |
147 | | WebPChunk* ChunkDelete(WebPChunk* const chunk); |
148 | | |
149 | | // Deletes all chunks in the given chunk list. |
150 | | void ChunkListDelete(WebPChunk** const chunk_list); |
151 | | |
152 | | // Returns size of the chunk including chunk header and padding byte (if any). |
153 | 20.8k | static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) { |
154 | 20.8k | assert(chunk_size <= MAX_CHUNK_PAYLOAD); |
155 | 20.8k | return CHUNK_HEADER_SIZE + ((chunk_size + 1) & ~1U); |
156 | 20.8k | } Unexecuted instantiation: muxedit.c:SizeWithPadding muxinternal.c:SizeWithPadding Line | Count | Source | 153 | 554 | static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) { | 154 | 554 | assert(chunk_size <= MAX_CHUNK_PAYLOAD); | 155 | 554 | return CHUNK_HEADER_SIZE + ((chunk_size + 1) & ~1U); | 156 | 554 | } |
muxread.c:SizeWithPadding Line | Count | Source | 153 | 20.2k | static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) { | 154 | 20.2k | assert(chunk_size <= MAX_CHUNK_PAYLOAD); | 155 | 20.2k | return CHUNK_HEADER_SIZE + ((chunk_size + 1) & ~1U); | 156 | 20.2k | } |
|
157 | | |
158 | | // Size of a chunk including header and padding. |
159 | 10.0k | static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) { |
160 | 10.0k | const size_t data_size = chunk->data.size; |
161 | 10.0k | return SizeWithPadding(data_size); |
162 | 10.0k | } Unexecuted instantiation: muxedit.c:ChunkDiskSize muxinternal.c:ChunkDiskSize Line | Count | Source | 159 | 554 | static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) { | 160 | 554 | const size_t data_size = chunk->data.size; | 161 | 554 | return SizeWithPadding(data_size); | 162 | 554 | } |
Line | Count | Source | 159 | 9.54k | static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) { | 160 | 9.54k | const size_t data_size = chunk->data.size; | 161 | 9.54k | return SizeWithPadding(data_size); | 162 | 9.54k | } |
|
163 | | |
164 | | // Total size of a list of chunks. |
165 | | size_t ChunkListDiskSize(const WebPChunk* chunk_list); |
166 | | |
167 | | // Write out the given list of chunks into 'dst'. |
168 | | uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst); |
169 | | |
170 | | //------------------------------------------------------------------------------ |
171 | | // MuxImage object management. |
172 | | |
173 | | // Initialize. |
174 | | void MuxImageInit(WebPMuxImage* const wpi); |
175 | | |
176 | | // Releases image 'wpi' and returns wpi->next. |
177 | | WebPMuxImage* MuxImageRelease(WebPMuxImage* const wpi); |
178 | | |
179 | | // Delete image 'wpi' and return the next image in the list or NULL. |
180 | | // 'wpi' can be NULL. |
181 | | WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi); |
182 | | |
183 | | // Count number of images matching the given tag id in the 'wpi_list'. |
184 | | // If id == WEBP_CHUNK_NIL, all images will be matched. |
185 | | int MuxImageCount(const WebPMuxImage* wpi_list, WebPChunkId id); |
186 | | |
187 | | // Update width/height/has_alpha info from chunks within wpi. |
188 | | // Also remove ALPH chunk if not needed. |
189 | | int MuxImageFinalize(WebPMuxImage* const wpi); |
190 | | |
191 | | // Check if given ID corresponds to an image related chunk. |
192 | 4.55k | static WEBP_INLINE int IsWPI(WebPChunkId id) { |
193 | 4.55k | switch (id) { |
194 | 633 | case WEBP_CHUNK_ANMF: |
195 | 707 | case WEBP_CHUNK_ALPHA: |
196 | 1.21k | case WEBP_CHUNK_IMAGE: |
197 | 1.21k | return 1; |
198 | 3.33k | default: |
199 | 3.33k | return 0; |
200 | 4.55k | } |
201 | 4.55k | } Line | Count | Source | 192 | 162 | static WEBP_INLINE int IsWPI(WebPChunkId id) { | 193 | 162 | switch (id) { | 194 | 0 | case WEBP_CHUNK_ANMF: | 195 | 0 | case WEBP_CHUNK_ALPHA: | 196 | 0 | case WEBP_CHUNK_IMAGE: | 197 | 0 | return 1; | 198 | 162 | default: | 199 | 162 | return 0; | 200 | 162 | } | 201 | 162 | } |
Unexecuted instantiation: muxinternal.c:IsWPI Line | Count | Source | 192 | 4.38k | static WEBP_INLINE int IsWPI(WebPChunkId id) { | 193 | 4.38k | switch (id) { | 194 | 633 | case WEBP_CHUNK_ANMF: | 195 | 707 | case WEBP_CHUNK_ALPHA: | 196 | 1.21k | case WEBP_CHUNK_IMAGE: | 197 | 1.21k | return 1; | 198 | 3.17k | default: | 199 | 3.17k | return 0; | 200 | 4.38k | } | 201 | 4.38k | } |
|
202 | | |
203 | | // Pushes 'wpi' at the end of 'wpi_list'. |
204 | | WebPMuxError MuxImagePush(const WebPMuxImage* wpi, WebPMuxImage** wpi_list); |
205 | | |
206 | | // Delete nth image in the image list. |
207 | | WebPMuxError MuxImageDeleteNth(WebPMuxImage** wpi_list, uint32_t nth); |
208 | | |
209 | | // Get nth image in the image list. |
210 | | WebPMuxError MuxImageGetNth(const WebPMuxImage** wpi_list, uint32_t nth, |
211 | | WebPMuxImage** wpi); |
212 | | |
213 | | // Total size of the given image. |
214 | | size_t MuxImageDiskSize(const WebPMuxImage* const wpi); |
215 | | |
216 | | // Write out the given image into 'dst'. |
217 | | uint8_t* MuxImageEmit(const WebPMuxImage* const wpi, uint8_t* dst); |
218 | | |
219 | | //------------------------------------------------------------------------------ |
220 | | // Helper methods for mux. |
221 | | |
222 | | // Checks if the given image list contains at least one image with alpha. |
223 | | int MuxHasAlpha(const WebPMuxImage* images); |
224 | | |
225 | | // Write out RIFF header into 'data', given total data size 'size'. |
226 | | uint8_t* MuxEmitRiffHeader(uint8_t* const data, size_t size); |
227 | | |
228 | | // Returns the list where chunk with given ID is to be inserted in mux. |
229 | | WebPChunk** MuxGetChunkListFromId(const WebPMux* mux, WebPChunkId id); |
230 | | |
231 | | // Validates the given mux object. |
232 | | WebPMuxError MuxValidate(const WebPMux* const mux); |
233 | | |
234 | | //------------------------------------------------------------------------------ |
235 | | |
236 | | #ifdef __cplusplus |
237 | | } // extern "C" |
238 | | #endif |
239 | | |
240 | | #endif // WEBP_MUX_MUXI_H_ |