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 | | // RIFF container manipulation and encoding for WebP images. |
11 | | // |
12 | | // Authors: Urvang (urvang@google.com) |
13 | | // Vikas (vikasa@google.com) |
14 | | |
15 | | #ifndef WEBP_WEBP_MUX_H_ |
16 | | #define WEBP_WEBP_MUX_H_ |
17 | | |
18 | | #include "./mux_types.h" |
19 | | #include "./types.h" |
20 | | |
21 | | #ifdef __cplusplus |
22 | | extern "C" { |
23 | | #endif |
24 | | |
25 | 142k | #define WEBP_MUX_ABI_VERSION 0x0109 // MAJOR(8b) + MINOR(8b) |
26 | | |
27 | | //------------------------------------------------------------------------------ |
28 | | // Mux API |
29 | | // |
30 | | // This API allows manipulation of WebP container images containing features |
31 | | // like color profile, metadata, animation. |
32 | | // |
33 | | // Code Example#1: Create a WebPMux object with image data, color profile and |
34 | | // XMP metadata. |
35 | | /* |
36 | | int copy_data = 0; |
37 | | WebPMux* mux = WebPMuxNew(); |
38 | | // ... (Prepare image data). |
39 | | WebPMuxSetImage(mux, &image, copy_data); |
40 | | // ... (Prepare ICCP color profile data). |
41 | | WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data); |
42 | | // ... (Prepare XMP metadata). |
43 | | WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data); |
44 | | // Get data from mux in WebP RIFF format. |
45 | | WebPMuxAssemble(mux, &output_data); |
46 | | WebPMuxDelete(mux); |
47 | | // ... (Consume output_data; e.g. write output_data.bytes to file). |
48 | | WebPDataClear(&output_data); |
49 | | */ |
50 | | |
51 | | // Code Example#2: Get image and color profile data from a WebP file. |
52 | | /* |
53 | | int copy_data = 0; |
54 | | // ... (Read data from file). |
55 | | WebPMux* mux = WebPMuxCreate(&data, copy_data); |
56 | | WebPMuxGetFrame(mux, 1, &image); |
57 | | // ... (Consume image; e.g. call WebPDecode() to decode the data). |
58 | | WebPMuxGetChunk(mux, "ICCP", &icc_profile); |
59 | | // ... (Consume icc_data). |
60 | | WebPMuxDelete(mux); |
61 | | WebPFree(data); |
62 | | */ |
63 | | |
64 | | // Note: forward declaring enumerations is not allowed in (strict) C and C++, |
65 | | // the types are left here for reference. |
66 | | // typedef enum WebPMuxError WebPMuxError; |
67 | | // typedef enum WebPChunkId WebPChunkId; |
68 | | typedef struct WebPMux WebPMux; // main opaque object. |
69 | | typedef struct WebPMuxFrameInfo WebPMuxFrameInfo; |
70 | | typedef struct WebPMuxAnimParams WebPMuxAnimParams; |
71 | | typedef struct WebPAnimEncoderOptions WebPAnimEncoderOptions; |
72 | | |
73 | | // Error codes |
74 | | typedef enum WEBP_NODISCARD WebPMuxError { |
75 | | WEBP_MUX_OK = 1, |
76 | | WEBP_MUX_NOT_FOUND = 0, |
77 | | WEBP_MUX_INVALID_ARGUMENT = -1, |
78 | | WEBP_MUX_BAD_DATA = -2, |
79 | | WEBP_MUX_MEMORY_ERROR = -3, |
80 | | WEBP_MUX_NOT_ENOUGH_DATA = -4 |
81 | | } WebPMuxError; |
82 | | |
83 | | // IDs for different types of chunks. |
84 | | typedef enum WebPChunkId { |
85 | | WEBP_CHUNK_VP8X, // VP8X |
86 | | WEBP_CHUNK_ICCP, // ICCP |
87 | | WEBP_CHUNK_ANIM, // ANIM |
88 | | WEBP_CHUNK_ANMF, // ANMF |
89 | | WEBP_CHUNK_DEPRECATED, // (deprecated from FRGM) |
90 | | WEBP_CHUNK_ALPHA, // ALPH |
91 | | WEBP_CHUNK_IMAGE, // VP8/VP8L |
92 | | WEBP_CHUNK_EXIF, // EXIF |
93 | | WEBP_CHUNK_XMP, // XMP |
94 | | WEBP_CHUNK_UNKNOWN, // Other chunks. |
95 | | WEBP_CHUNK_NIL |
96 | | } WebPChunkId; |
97 | | |
98 | | //------------------------------------------------------------------------------ |
99 | | |
100 | | // Returns the version number of the mux library, packed in hexadecimal using |
101 | | // 8bits for each of major/minor/revision. E.g: v2.5.7 is 0x020507. |
102 | | WEBP_EXTERN int WebPGetMuxVersion(void); |
103 | | |
104 | | //------------------------------------------------------------------------------ |
105 | | // Life of a Mux object |
106 | | |
107 | | // Internal, version-checked, entry point |
108 | | WEBP_NODISCARD WEBP_EXTERN WebPMux* WebPNewInternal(int); |
109 | | |
110 | | // Creates an empty mux object. |
111 | | // Returns: |
112 | | // A pointer to the newly created empty mux object. |
113 | | // Or NULL in case of memory error. |
114 | 52 | WEBP_NODISCARD static WEBP_INLINE WebPMux* WebPMuxNew(void) { |
115 | 52 | return WebPNewInternal(WEBP_MUX_ABI_VERSION); |
116 | 52 | } |
117 | | |
118 | | // Deletes the mux object. |
119 | | // Parameters: |
120 | | // mux - (in/out) object to be deleted |
121 | | WEBP_EXTERN void WebPMuxDelete(WebPMux* mux); |
122 | | |
123 | | //------------------------------------------------------------------------------ |
124 | | // Mux creation. |
125 | | |
126 | | // Internal, version-checked, entry point |
127 | | WEBP_NODISCARD WEBP_EXTERN WebPMux* WebPMuxCreateInternal(const WebPData*, int, |
128 | | int); |
129 | | |
130 | | // Creates a mux object from raw data given in WebP RIFF format. |
131 | | // Parameters: |
132 | | // bitstream - (in) the bitstream data in WebP RIFF format |
133 | | // copy_data - (in) value 1 indicates given data WILL be copied to the mux |
134 | | // object and value 0 indicates data will NOT be copied. If the |
135 | | // data is not copied, it must exist for the lifetime of the |
136 | | // mux object. |
137 | | // Returns: |
138 | | // A pointer to the mux object created from given data - on success. |
139 | | // NULL - In case of invalid data or memory error. |
140 | | WEBP_NODISCARD static WEBP_INLINE WebPMux* WebPMuxCreate( |
141 | 142k | const WebPData* bitstream, int copy_data) { |
142 | 142k | return WebPMuxCreateInternal(bitstream, copy_data, WEBP_MUX_ABI_VERSION); |
143 | 142k | } |
144 | | |
145 | | //------------------------------------------------------------------------------ |
146 | | // Non-image chunks. |
147 | | |
148 | | // Note: Only non-image related chunks should be managed through chunk APIs. |
149 | | // (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH"). |
150 | | // To add, get and delete images, use WebPMuxSetImage(), WebPMuxPushFrame(), |
151 | | // WebPMuxGetFrame() and WebPMuxDeleteFrame(). |
152 | | |
153 | | // Adds a chunk with id 'fourcc' and data 'chunk_data' in the mux object. |
154 | | // Any existing chunk(s) with the same id will be removed. |
155 | | // Parameters: |
156 | | // mux - (in/out) object to which the chunk is to be added |
157 | | // fourcc - (in) a character array containing the fourcc of the given chunk; |
158 | | // e.g., "ICCP", "XMP ", "EXIF" etc. |
159 | | // chunk_data - (in) the chunk data to be added |
160 | | // copy_data - (in) value 1 indicates given data WILL be copied to the mux |
161 | | // object and value 0 indicates data will NOT be copied. If the |
162 | | // data is not copied, it must exist until a call to |
163 | | // WebPMuxAssemble() is made. |
164 | | // Returns: |
165 | | // WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL |
166 | | // or if fourcc corresponds to an image chunk. |
167 | | // WEBP_MUX_MEMORY_ERROR - on memory allocation error. |
168 | | // WEBP_MUX_OK - on success. |
169 | | WEBP_EXTERN WebPMuxError WebPMuxSetChunk(WebPMux* mux, const char fourcc[4], |
170 | | const WebPData* chunk_data, |
171 | | int copy_data); |
172 | | |
173 | | // Gets a reference to the data of the chunk with id 'fourcc' in the mux object. |
174 | | // The caller should NOT free the returned data. |
175 | | // The returned reference points to storage owned by 'mux' and is only valid |
176 | | // until the next call that modifies 'mux' or until WebPMuxDelete(). In |
177 | | // particular, it must not be passed back to WebPMuxSetChunk() for any value of |
178 | | // 'copy_data': that call deletes any existing chunk with the same 'fourcc', |
179 | | // releasing the referenced storage, before storing the new data. |
180 | | // Parameters: |
181 | | // mux - (in) object from which the chunk data is to be fetched |
182 | | // fourcc - (in) a character array containing the fourcc of the chunk; |
183 | | // e.g., "ICCP", "XMP ", "EXIF" etc. |
184 | | // chunk_data - (out) returned chunk data |
185 | | // Returns: |
186 | | // WEBP_MUX_INVALID_ARGUMENT - if mux, fourcc or chunk_data is NULL |
187 | | // or if fourcc corresponds to an image chunk. |
188 | | // WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given id. |
189 | | // WEBP_MUX_OK - on success. |
190 | | WEBP_EXTERN WebPMuxError WebPMuxGetChunk(const WebPMux* mux, |
191 | | const char fourcc[4], |
192 | | WebPData* chunk_data); |
193 | | |
194 | | // Deletes the chunk with the given 'fourcc' from the mux object. |
195 | | // Parameters: |
196 | | // mux - (in/out) object from which the chunk is to be deleted |
197 | | // fourcc - (in) a character array containing the fourcc of the chunk; |
198 | | // e.g., "ICCP", "XMP ", "EXIF" etc. |
199 | | // Returns: |
200 | | // WEBP_MUX_INVALID_ARGUMENT - if mux or fourcc is NULL |
201 | | // or if fourcc corresponds to an image chunk. |
202 | | // WEBP_MUX_NOT_FOUND - If mux does not contain a chunk with the given fourcc. |
203 | | // WEBP_MUX_OK - on success. |
204 | | WEBP_EXTERN WebPMuxError WebPMuxDeleteChunk(WebPMux* mux, const char fourcc[4]); |
205 | | |
206 | | //------------------------------------------------------------------------------ |
207 | | // Images. |
208 | | |
209 | | // Encapsulates data about a single frame. |
210 | | struct WebPMuxFrameInfo { |
211 | | WebPData bitstream; // image data: can be a raw VP8/VP8L bitstream |
212 | | // or a single-image WebP file. |
213 | | int x_offset; // x-offset of the frame. |
214 | | int y_offset; // y-offset of the frame. |
215 | | int duration; // duration of the frame (in milliseconds). |
216 | | |
217 | | WebPChunkId id; // frame type: should be one of WEBP_CHUNK_ANMF |
218 | | // or WEBP_CHUNK_IMAGE |
219 | | WebPMuxAnimDispose dispose_method; // Disposal method for the frame. |
220 | | WebPMuxAnimBlend blend_method; // Blend operation for the frame. |
221 | | uint32_t pad[1]; // padding for later use |
222 | | }; |
223 | | |
224 | | // Sets the (non-animated) image in the mux object. |
225 | | // Note: Any existing images (including frames) will be removed. |
226 | | // Parameters: |
227 | | // mux - (in/out) object in which the image is to be set |
228 | | // bitstream - (in) can be a raw VP8/VP8L bitstream or a single-image |
229 | | // WebP file (non-animated) |
230 | | // copy_data - (in) value 1 indicates given data WILL be copied to the mux |
231 | | // object and value 0 indicates data will NOT be copied. If the |
232 | | // data is not copied, it must exist until a call to |
233 | | // WebPMuxAssemble() is made. |
234 | | // Returns: |
235 | | // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL or bitstream is NULL. |
236 | | // WEBP_MUX_MEMORY_ERROR - on memory allocation error. |
237 | | // WEBP_MUX_OK - on success. |
238 | | WEBP_EXTERN WebPMuxError WebPMuxSetImage(WebPMux* mux, |
239 | | const WebPData* bitstream, |
240 | | int copy_data); |
241 | | |
242 | | // Adds a frame at the end of the mux object. |
243 | | // Notes: (1) frame.id should be WEBP_CHUNK_ANMF |
244 | | // (2) For setting a non-animated image, use WebPMuxSetImage() instead. |
245 | | // (3) Type of frame being pushed must be same as the frames in mux. |
246 | | // (4) As WebP only supports even offsets, any odd offset will be snapped |
247 | | // to an even location using: offset &= ~1 |
248 | | // Parameters: |
249 | | // mux - (in/out) object to which the frame is to be added |
250 | | // frame - (in) frame data. |
251 | | // copy_data - (in) value 1 indicates given data WILL be copied to the mux |
252 | | // object and value 0 indicates data will NOT be copied. If the |
253 | | // data is not copied, it must exist until a call to |
254 | | // WebPMuxAssemble() is made. |
255 | | // Returns: |
256 | | // WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL |
257 | | // or if content of 'frame' is invalid. |
258 | | // WEBP_MUX_MEMORY_ERROR - on memory allocation error. |
259 | | // WEBP_MUX_OK - on success. |
260 | | WEBP_EXTERN WebPMuxError WebPMuxPushFrame(WebPMux* mux, |
261 | | const WebPMuxFrameInfo* frame, |
262 | | int copy_data); |
263 | | |
264 | | // Gets the nth frame from the mux object. |
265 | | // The content of 'frame->bitstream' is allocated using WebPMalloc(), and NOT |
266 | | // owned by the 'mux' object. It MUST be deallocated by the caller by calling |
267 | | // WebPDataClear(). |
268 | | // nth=0 has a special meaning - last position. |
269 | | // Parameters: |
270 | | // mux - (in) object from which the info is to be fetched |
271 | | // nth - (in) index of the frame in the mux object |
272 | | // frame - (out) data of the returned frame |
273 | | // Returns: |
274 | | // WEBP_MUX_INVALID_ARGUMENT - if mux or frame is NULL. |
275 | | // WEBP_MUX_NOT_FOUND - if there are less than nth frames in the mux object. |
276 | | // WEBP_MUX_BAD_DATA - if nth frame chunk in mux is invalid. |
277 | | // WEBP_MUX_MEMORY_ERROR - on memory allocation error. |
278 | | // WEBP_MUX_OK - on success. |
279 | | WEBP_EXTERN WebPMuxError WebPMuxGetFrame(const WebPMux* mux, uint32_t nth, |
280 | | WebPMuxFrameInfo* frame); |
281 | | |
282 | | // Deletes a frame from the mux object. |
283 | | // nth=0 has a special meaning - last position. |
284 | | // Parameters: |
285 | | // mux - (in/out) object from which a frame is to be deleted |
286 | | // nth - (in) The position from which the frame is to be deleted |
287 | | // Returns: |
288 | | // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL. |
289 | | // WEBP_MUX_NOT_FOUND - If there are less than nth frames in the mux object |
290 | | // before deletion. |
291 | | // WEBP_MUX_OK - on success. |
292 | | WEBP_EXTERN WebPMuxError WebPMuxDeleteFrame(WebPMux* mux, uint32_t nth); |
293 | | |
294 | | //------------------------------------------------------------------------------ |
295 | | // Animation. |
296 | | |
297 | | // Animation parameters. |
298 | | struct WebPMuxAnimParams { |
299 | | uint32_t bgcolor; // Background color of the canvas stored (in MSB order) as: |
300 | | // Bits 00 to 07: Alpha. |
301 | | // Bits 08 to 15: Red. |
302 | | // Bits 16 to 23: Green. |
303 | | // Bits 24 to 31: Blue. |
304 | | int loop_count; // Number of times to repeat the animation [0 = infinite]. |
305 | | }; |
306 | | |
307 | | // Sets the animation parameters in the mux object. Any existing ANIM chunks |
308 | | // will be removed. |
309 | | // Parameters: |
310 | | // mux - (in/out) object in which ANIM chunk is to be set/added |
311 | | // params - (in) animation parameters. |
312 | | // Returns: |
313 | | // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. |
314 | | // WEBP_MUX_MEMORY_ERROR - on memory allocation error. |
315 | | // WEBP_MUX_OK - on success. |
316 | | WEBP_EXTERN WebPMuxError |
317 | | WebPMuxSetAnimationParams(WebPMux* mux, const WebPMuxAnimParams* params); |
318 | | |
319 | | // Gets the animation parameters from the mux object. |
320 | | // Parameters: |
321 | | // mux - (in) object from which the animation parameters to be fetched |
322 | | // params - (out) animation parameters extracted from the ANIM chunk |
323 | | // Returns: |
324 | | // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. |
325 | | // WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object. |
326 | | // WEBP_MUX_OK - on success. |
327 | | WEBP_EXTERN WebPMuxError WebPMuxGetAnimationParams(const WebPMux* mux, |
328 | | WebPMuxAnimParams* params); |
329 | | |
330 | | //------------------------------------------------------------------------------ |
331 | | // Misc Utilities. |
332 | | |
333 | | // Sets the canvas size for the mux object. The width and height can be |
334 | | // specified explicitly or left as zero (0, 0). |
335 | | // * When width and height are specified explicitly, then this frame bound is |
336 | | // enforced during subsequent calls to WebPMuxAssemble() and an error is |
337 | | // reported if any animated frame does not completely fit within the canvas. |
338 | | // * When unspecified (0, 0), the constructed canvas will get the frame bounds |
339 | | // from the bounding-box over all frames after calling WebPMuxAssemble(). |
340 | | // Parameters: |
341 | | // mux - (in) object to which the canvas size is to be set |
342 | | // width - (in) canvas width |
343 | | // height - (in) canvas height |
344 | | // Returns: |
345 | | // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or |
346 | | // width or height are invalid or out of bounds |
347 | | // WEBP_MUX_OK - on success. |
348 | | WEBP_EXTERN WebPMuxError WebPMuxSetCanvasSize(WebPMux* mux, int width, |
349 | | int height); |
350 | | |
351 | | // Gets the canvas size from the mux object. |
352 | | // Note: This method assumes that the VP8X chunk, if present, is up-to-date. |
353 | | // That is, the mux object hasn't been modified since the last call to |
354 | | // WebPMuxAssemble() or WebPMuxCreate(). |
355 | | // Parameters: |
356 | | // mux - (in) object from which the canvas size is to be fetched |
357 | | // width - (out) canvas width |
358 | | // height - (out) canvas height |
359 | | // Returns: |
360 | | // WEBP_MUX_INVALID_ARGUMENT - if mux, width or height is NULL. |
361 | | // WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. |
362 | | // WEBP_MUX_OK - on success. |
363 | | WEBP_EXTERN WebPMuxError WebPMuxGetCanvasSize(const WebPMux* mux, int* width, |
364 | | int* height); |
365 | | |
366 | | // Gets the feature flags from the mux object. |
367 | | // Note: This method assumes that the VP8X chunk, if present, is up-to-date. |
368 | | // That is, the mux object hasn't been modified since the last call to |
369 | | // WebPMuxAssemble() or WebPMuxCreate(). |
370 | | // Parameters: |
371 | | // mux - (in) object from which the features are to be fetched |
372 | | // flags - (out) the flags specifying which features are present in the |
373 | | // mux object. This will be an OR of various flag values. |
374 | | // Enum 'WebPFeatureFlags' can be used to test individual flag values. |
375 | | // Returns: |
376 | | // WEBP_MUX_INVALID_ARGUMENT - if mux or flags is NULL. |
377 | | // WEBP_MUX_BAD_DATA - if VP8X/VP8/VP8L chunk or canvas size is invalid. |
378 | | // WEBP_MUX_OK - on success. |
379 | | WEBP_EXTERN WebPMuxError WebPMuxGetFeatures(const WebPMux* mux, |
380 | | uint32_t* flags); |
381 | | |
382 | | // Gets number of chunks with the given 'id' in the mux object. |
383 | | // Parameters: |
384 | | // mux - (in) object from which the info is to be fetched |
385 | | // id - (in) chunk id specifying the type of chunk |
386 | | // num_elements - (out) number of chunks with the given chunk id |
387 | | // Returns: |
388 | | // WEBP_MUX_INVALID_ARGUMENT - if mux, or num_elements is NULL. |
389 | | // WEBP_MUX_OK - on success. |
390 | | WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux, WebPChunkId id, |
391 | | int* num_elements); |
392 | | |
393 | | // Assembles all chunks in WebP RIFF format and returns in 'assembled_data'. |
394 | | // This function also validates the mux object. |
395 | | // Note: The content of 'assembled_data' will be ignored and overwritten. |
396 | | // Also, the content of 'assembled_data' is allocated using WebPMalloc(), and |
397 | | // NOT owned by the 'mux' object. It MUST be deallocated by the caller by |
398 | | // calling WebPDataClear(). It's always safe to call WebPDataClear() upon |
399 | | // return, even in case of error. |
400 | | // Parameters: |
401 | | // mux - (in/out) object whose chunks are to be assembled |
402 | | // assembled_data - (out) assembled WebP data |
403 | | // Returns: |
404 | | // WEBP_MUX_BAD_DATA - if mux object is invalid. |
405 | | // WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL. |
406 | | // WEBP_MUX_MEMORY_ERROR - on memory allocation error. |
407 | | // WEBP_MUX_OK - on success. |
408 | | WEBP_EXTERN WebPMuxError WebPMuxAssemble(WebPMux* mux, |
409 | | WebPData* assembled_data); |
410 | | |
411 | | //------------------------------------------------------------------------------ |
412 | | // WebPAnimEncoder API |
413 | | // |
414 | | // This API allows encoding (possibly) animated WebP images. |
415 | | // |
416 | | // Code Example: |
417 | | /* |
418 | | WebPAnimEncoderOptions enc_options; |
419 | | WebPAnimEncoderOptionsInit(&enc_options); |
420 | | // Tune 'enc_options' as needed. |
421 | | WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options); |
422 | | while(<there are more frames>) { |
423 | | WebPConfig config; |
424 | | WebPConfigInit(&config); |
425 | | // Tune 'config' as needed. |
426 | | WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config); |
427 | | } |
428 | | WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL); |
429 | | WebPAnimEncoderAssemble(enc, webp_data); |
430 | | WebPAnimEncoderDelete(enc); |
431 | | // Write the 'webp_data' to a file, or re-mux it further. |
432 | | */ |
433 | | |
434 | | typedef struct WebPAnimEncoder WebPAnimEncoder; // Main opaque object. |
435 | | |
436 | | // Forward declarations. Defined in encode.h. |
437 | | struct WebPPicture; |
438 | | struct WebPConfig; |
439 | | |
440 | | // Global options. |
441 | | struct WebPAnimEncoderOptions { |
442 | | WebPMuxAnimParams anim_params; // Animation parameters. |
443 | | int minimize_size; // If true, minimize the output size (slow). Implicitly |
444 | | // disables key-frame insertion. |
445 | | int kmin; |
446 | | int kmax; // Minimum and maximum distance between consecutive key |
447 | | // frames in the output. The library may insert some key |
448 | | // frames as needed to satisfy this criteria. |
449 | | // Note that these conditions should hold: kmax > kmin |
450 | | // and kmin >= kmax / 2 + 1. Also, if kmax <= 0, then |
451 | | // key-frame insertion is disabled; and if kmax == 1, |
452 | | // then all frames will be key-frames (kmin value does |
453 | | // not matter for these special cases). |
454 | | int allow_mixed; // If true, use mixed compression mode; may choose |
455 | | // either lossy and lossless for each frame. |
456 | | int verbose; // If true, print info and warning messages to stderr. |
457 | | |
458 | | uint32_t padding[4]; // Padding for later use. |
459 | | }; |
460 | | |
461 | | // Internal, version-checked, entry point. |
462 | | WEBP_EXTERN int WebPAnimEncoderOptionsInitInternal(WebPAnimEncoderOptions*, |
463 | | int); |
464 | | |
465 | | // Should always be called, to initialize a fresh WebPAnimEncoderOptions |
466 | | // structure before modification. Returns false in case of version mismatch. |
467 | | // WebPAnimEncoderOptionsInit() must have succeeded before using the |
468 | | // 'enc_options' object. |
469 | | WEBP_NODISCARD static WEBP_INLINE int WebPAnimEncoderOptionsInit( |
470 | 0 | WebPAnimEncoderOptions* enc_options) { |
471 | 0 | return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION); |
472 | 0 | } |
473 | | |
474 | | // Internal, version-checked, entry point. |
475 | | WEBP_EXTERN WebPAnimEncoder* WebPAnimEncoderNewInternal( |
476 | | int, int, const WebPAnimEncoderOptions*, int); |
477 | | |
478 | | // Creates and initializes a WebPAnimEncoder object. |
479 | | // Parameters: |
480 | | // width/height - (in) canvas width and height of the animation. |
481 | | // enc_options - (in) encoding options; can be passed NULL to pick |
482 | | // reasonable defaults. |
483 | | // Returns: |
484 | | // A pointer to the newly created WebPAnimEncoder object. |
485 | | // Or NULL in case of memory error. |
486 | | static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew( |
487 | 0 | int width, int height, const WebPAnimEncoderOptions* enc_options) { |
488 | 0 | return WebPAnimEncoderNewInternal(width, height, enc_options, |
489 | 0 | WEBP_MUX_ABI_VERSION); |
490 | 0 | } |
491 | | |
492 | | // Optimize the given frame for WebP, encode it and add it to the |
493 | | // WebPAnimEncoder object. |
494 | | // The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which |
495 | | // indicates that no more frames are to be added. This call is also used to |
496 | | // determine the duration of the last frame. |
497 | | // Parameters: |
498 | | // enc - (in/out) object to which the frame is to be added. |
499 | | // frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A) |
500 | | // format, it will be converted to ARGB, which incurs a small loss. |
501 | | // timestamp_ms - (in) timestamp of this frame in milliseconds. |
502 | | // Duration of a frame would be calculated as |
503 | | // "timestamp of next frame - timestamp of this frame". |
504 | | // Hence, timestamps should be in non-decreasing order. |
505 | | // config - (in) encoding options; can be passed NULL to pick |
506 | | // reasonable defaults. |
507 | | // Returns: |
508 | | // On error, returns false and frame->error_code is set appropriately. |
509 | | // Otherwise, returns true. |
510 | | WEBP_NODISCARD WEBP_EXTERN int WebPAnimEncoderAdd( |
511 | | WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms, |
512 | | const struct WebPConfig* config); |
513 | | |
514 | | // Assemble all frames added so far into a WebP bitstream. |
515 | | // This call should be preceded by a call to 'WebPAnimEncoderAdd' with |
516 | | // frame = NULL; if not, the duration of the last frame will be internally |
517 | | // estimated. |
518 | | // Parameters: |
519 | | // enc - (in/out) object from which the frames are to be assembled. |
520 | | // webp_data - (out) generated WebP bitstream. |
521 | | // Returns: |
522 | | // True on success. |
523 | | WEBP_NODISCARD WEBP_EXTERN int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, |
524 | | WebPData* webp_data); |
525 | | |
526 | | // Get error string corresponding to the most recent call using 'enc'. The |
527 | | // returned string is owned by 'enc' and is valid only until the next call to |
528 | | // WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete(). |
529 | | // Parameters: |
530 | | // enc - (in/out) object from which the error string is to be fetched. |
531 | | // Returns: |
532 | | // NULL if 'enc' is NULL. Otherwise, returns the error string if the last call |
533 | | // to 'enc' had an error, or an empty string if the last call was a success. |
534 | | WEBP_EXTERN const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc); |
535 | | |
536 | | // Deletes the WebPAnimEncoder object. |
537 | | // Parameters: |
538 | | // enc - (in/out) object to be deleted |
539 | | WEBP_EXTERN void WebPAnimEncoderDelete(WebPAnimEncoder* enc); |
540 | | |
541 | | //------------------------------------------------------------------------------ |
542 | | // Non-image chunks. |
543 | | |
544 | | // Note: Only non-image related chunks should be managed through chunk APIs. |
545 | | // (Image related chunks are: "ANMF", "VP8 ", "VP8L" and "ALPH"). |
546 | | |
547 | | // Adds a chunk with id 'fourcc' and data 'chunk_data' in the enc object. |
548 | | // Any existing chunk(s) with the same id will be removed. |
549 | | // Parameters: |
550 | | // enc - (in/out) object to which the chunk is to be added |
551 | | // fourcc - (in) a character array containing the fourcc of the given chunk; |
552 | | // e.g., "ICCP", "XMP ", "EXIF", etc. |
553 | | // chunk_data - (in) the chunk data to be added |
554 | | // copy_data - (in) value 1 indicates given data WILL be copied to the enc |
555 | | // object and value 0 indicates data will NOT be copied. If the |
556 | | // data is not copied, it must exist until a call to |
557 | | // WebPAnimEncoderAssemble() is made. |
558 | | // Returns: |
559 | | // WEBP_MUX_INVALID_ARGUMENT - if enc, fourcc or chunk_data is NULL. |
560 | | // WEBP_MUX_MEMORY_ERROR - on memory allocation error. |
561 | | // WEBP_MUX_OK - on success. |
562 | | WEBP_EXTERN WebPMuxError WebPAnimEncoderSetChunk(WebPAnimEncoder* enc, |
563 | | const char fourcc[4], |
564 | | const WebPData* chunk_data, |
565 | | int copy_data); |
566 | | |
567 | | // Gets a reference to the data of the chunk with id 'fourcc' in the enc object. |
568 | | // The caller should NOT free the returned data. |
569 | | // The returned reference points to storage owned by 'enc' and is only valid |
570 | | // until the next call that modifies 'enc' or until WebPAnimEncoderDelete(). In |
571 | | // particular, it must not be passed back to WebPAnimEncoderSetChunk() for any |
572 | | // value of 'copy_data': that call deletes any existing chunk with the same |
573 | | // 'fourcc', releasing the referenced storage, before storing the new data. |
574 | | // Parameters: |
575 | | // enc - (in) object from which the chunk data is to be fetched |
576 | | // fourcc - (in) a character array containing the fourcc of the chunk; |
577 | | // e.g., "ICCP", "XMP ", "EXIF", etc. |
578 | | // chunk_data - (out) returned chunk data |
579 | | // Returns: |
580 | | // WEBP_MUX_INVALID_ARGUMENT - if enc, fourcc or chunk_data is NULL. |
581 | | // WEBP_MUX_NOT_FOUND - If enc does not contain a chunk with the given id. |
582 | | // WEBP_MUX_OK - on success. |
583 | | WEBP_EXTERN WebPMuxError WebPAnimEncoderGetChunk(const WebPAnimEncoder* enc, |
584 | | const char fourcc[4], |
585 | | WebPData* chunk_data); |
586 | | |
587 | | // Deletes the chunk with the given 'fourcc' from the enc object. |
588 | | // Parameters: |
589 | | // enc - (in/out) object from which the chunk is to be deleted |
590 | | // fourcc - (in) a character array containing the fourcc of the chunk; |
591 | | // e.g., "ICCP", "XMP ", "EXIF", etc. |
592 | | // Returns: |
593 | | // WEBP_MUX_INVALID_ARGUMENT - if enc or fourcc is NULL. |
594 | | // WEBP_MUX_NOT_FOUND - If enc does not contain a chunk with the given fourcc. |
595 | | // WEBP_MUX_OK - on success. |
596 | | WEBP_EXTERN WebPMuxError WebPAnimEncoderDeleteChunk(WebPAnimEncoder* enc, |
597 | | const char fourcc[4]); |
598 | | |
599 | | //------------------------------------------------------------------------------ |
600 | | |
601 | | #ifdef __cplusplus |
602 | | } // extern "C" |
603 | | #endif |
604 | | |
605 | | #endif // WEBP_WEBP_MUX_H_ |