Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: third_party/libwebp/webp/mux.h

Issue 1546003002: libwebp: update to 0.5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 'defines' exists Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 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 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 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // RIFF container manipulation for WebP images. 10 // RIFF container manipulation and encoding for WebP images.
11 // 11 //
12 // Authors: Urvang (urvang@google.com) 12 // Authors: Urvang (urvang@google.com)
13 // Vikas (vikasa@google.com) 13 // Vikas (vikasa@google.com)
14 14
15 #ifndef WEBP_WEBP_MUX_H_
16 #define WEBP_WEBP_MUX_H_
17
18 #include "./mux_types.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #define WEBP_MUX_ABI_VERSION 0x0106 // MAJOR(8b) + MINOR(8b)
25
26 //------------------------------------------------------------------------------
27 // Mux API
28 //
15 // This API allows manipulation of WebP container images containing features 29 // This API allows manipulation of WebP container images containing features
16 // like color profile, metadata, animation and fragmented images. 30 // like color profile, metadata, animation and fragmented images.
17 // 31 //
18 // Code Example#1: Create a WebPMux object with image data, color profile and 32 // Code Example#1: Create a WebPMux object with image data, color profile and
19 // XMP metadata. 33 // XMP metadata.
20 /* 34 /*
21 int copy_data = 0; 35 int copy_data = 0;
22 WebPMux* mux = WebPMuxNew(); 36 WebPMux* mux = WebPMuxNew();
23 // ... (Prepare image data). 37 // ... (Prepare image data).
24 WebPMuxSetImage(mux, &image, copy_data); 38 WebPMuxSetImage(mux, &image, copy_data);
(...skipping 14 matching lines...) Expand all
39 // ... (Read data from file). 53 // ... (Read data from file).
40 WebPMux* mux = WebPMuxCreate(&data, copy_data); 54 WebPMux* mux = WebPMuxCreate(&data, copy_data);
41 WebPMuxGetFrame(mux, 1, &image); 55 WebPMuxGetFrame(mux, 1, &image);
42 // ... (Consume image; e.g. call WebPDecode() to decode the data). 56 // ... (Consume image; e.g. call WebPDecode() to decode the data).
43 WebPMuxGetChunk(mux, "ICCP", &icc_profile); 57 WebPMuxGetChunk(mux, "ICCP", &icc_profile);
44 // ... (Consume icc_data). 58 // ... (Consume icc_data).
45 WebPMuxDelete(mux); 59 WebPMuxDelete(mux);
46 free(data); 60 free(data);
47 */ 61 */
48 62
49 #ifndef WEBP_WEBP_MUX_H_
50 #define WEBP_WEBP_MUX_H_
51
52 #include "./mux_types.h"
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 #define WEBP_MUX_ABI_VERSION 0x0101 // MAJOR(8b) + MINOR(8b)
59
60 // Note: forward declaring enumerations is not allowed in (strict) C and C++, 63 // Note: forward declaring enumerations is not allowed in (strict) C and C++,
61 // the types are left here for reference. 64 // the types are left here for reference.
62 // typedef enum WebPMuxError WebPMuxError; 65 // typedef enum WebPMuxError WebPMuxError;
63 // typedef enum WebPChunkId WebPChunkId; 66 // typedef enum WebPChunkId WebPChunkId;
64 typedef struct WebPMux WebPMux; // main opaque object. 67 typedef struct WebPMux WebPMux; // main opaque object.
65 typedef struct WebPMuxFrameInfo WebPMuxFrameInfo; 68 typedef struct WebPMuxFrameInfo WebPMuxFrameInfo;
66 typedef struct WebPMuxAnimParams WebPMuxAnimParams; 69 typedef struct WebPMuxAnimParams WebPMuxAnimParams;
70 typedef struct WebPAnimEncoderOptions WebPAnimEncoderOptions;
67 71
68 // Error codes 72 // Error codes
69 typedef enum WebPMuxError { 73 typedef enum WebPMuxError {
70 WEBP_MUX_OK = 1, 74 WEBP_MUX_OK = 1,
71 WEBP_MUX_NOT_FOUND = 0, 75 WEBP_MUX_NOT_FOUND = 0,
72 WEBP_MUX_INVALID_ARGUMENT = -1, 76 WEBP_MUX_INVALID_ARGUMENT = -1,
73 WEBP_MUX_BAD_DATA = -2, 77 WEBP_MUX_BAD_DATA = -2,
74 WEBP_MUX_MEMORY_ERROR = -3, 78 WEBP_MUX_MEMORY_ERROR = -3,
75 WEBP_MUX_NOT_ENOUGH_DATA = -4 79 WEBP_MUX_NOT_ENOUGH_DATA = -4
76 } WebPMuxError; 80 } WebPMuxError;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // Returns: 307 // Returns:
304 // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL. 308 // WEBP_MUX_INVALID_ARGUMENT - if mux or params is NULL.
305 // WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object. 309 // WEBP_MUX_NOT_FOUND - if ANIM chunk is not present in mux object.
306 // WEBP_MUX_OK - on success. 310 // WEBP_MUX_OK - on success.
307 WEBP_EXTERN(WebPMuxError) WebPMuxGetAnimationParams( 311 WEBP_EXTERN(WebPMuxError) WebPMuxGetAnimationParams(
308 const WebPMux* mux, WebPMuxAnimParams* params); 312 const WebPMux* mux, WebPMuxAnimParams* params);
309 313
310 //------------------------------------------------------------------------------ 314 //------------------------------------------------------------------------------
311 // Misc Utilities. 315 // Misc Utilities.
312 316
313 #if WEBP_MUX_ABI_VERSION > 0x0101
314 // Sets the canvas size for the mux object. The width and height can be 317 // Sets the canvas size for the mux object. The width and height can be
315 // specified explicitly or left as zero (0, 0). 318 // specified explicitly or left as zero (0, 0).
316 // * When width and height are specified explicitly, then this frame bound is 319 // * When width and height are specified explicitly, then this frame bound is
317 // enforced during subsequent calls to WebPMuxAssemble() and an error is 320 // enforced during subsequent calls to WebPMuxAssemble() and an error is
318 // reported if any animated frame does not completely fit within the canvas. 321 // reported if any animated frame does not completely fit within the canvas.
319 // * When unspecified (0, 0), the constructed canvas will get the frame bounds 322 // * When unspecified (0, 0), the constructed canvas will get the frame bounds
320 // from the bounding-box over all frames after calling WebPMuxAssemble(). 323 // from the bounding-box over all frames after calling WebPMuxAssemble().
321 // Parameters: 324 // Parameters:
322 // mux - (in) object to which the canvas size is to be set 325 // mux - (in) object to which the canvas size is to be set
323 // width - (in) canvas width 326 // width - (in) canvas width
324 // height - (in) canvas height 327 // height - (in) canvas height
325 // Returns: 328 // Returns:
326 // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or 329 // WEBP_MUX_INVALID_ARGUMENT - if mux is NULL; or
327 // width or height are invalid or out of bounds 330 // width or height are invalid or out of bounds
328 // WEBP_MUX_OK - on success. 331 // WEBP_MUX_OK - on success.
329 WEBP_EXTERN(WebPMuxError) WebPMuxSetCanvasSize(WebPMux* mux, 332 WEBP_EXTERN(WebPMuxError) WebPMuxSetCanvasSize(WebPMux* mux,
330 int width, int height); 333 int width, int height);
331 #endif
332 334
333 // Gets the canvas size from the mux object. 335 // Gets the canvas size from the mux object.
334 // Note: This method assumes that the VP8X chunk, if present, is up-to-date. 336 // Note: This method assumes that the VP8X chunk, if present, is up-to-date.
335 // That is, the mux object hasn't been modified since the last call to 337 // That is, the mux object hasn't been modified since the last call to
336 // WebPMuxAssemble() or WebPMuxCreate(). 338 // WebPMuxAssemble() or WebPMuxCreate().
337 // Parameters: 339 // Parameters:
338 // mux - (in) object from which the canvas size is to be fetched 340 // mux - (in) object from which the canvas size is to be fetched
339 // width - (out) canvas width 341 // width - (out) canvas width
340 // height - (out) canvas height 342 // height - (out) canvas height
341 // Returns: 343 // Returns:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // assembled_data - (out) assembled WebP data 386 // assembled_data - (out) assembled WebP data
385 // Returns: 387 // Returns:
386 // WEBP_MUX_BAD_DATA - if mux object is invalid. 388 // WEBP_MUX_BAD_DATA - if mux object is invalid.
387 // WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL. 389 // WEBP_MUX_INVALID_ARGUMENT - if mux or assembled_data is NULL.
388 // WEBP_MUX_MEMORY_ERROR - on memory allocation error. 390 // WEBP_MUX_MEMORY_ERROR - on memory allocation error.
389 // WEBP_MUX_OK - on success. 391 // WEBP_MUX_OK - on success.
390 WEBP_EXTERN(WebPMuxError) WebPMuxAssemble(WebPMux* mux, 392 WEBP_EXTERN(WebPMuxError) WebPMuxAssemble(WebPMux* mux,
391 WebPData* assembled_data); 393 WebPData* assembled_data);
392 394
393 //------------------------------------------------------------------------------ 395 //------------------------------------------------------------------------------
396 // WebPAnimEncoder API
397 //
398 // This API allows encoding (possibly) animated WebP images.
399 //
400 // Code Example:
401 /*
402 WebPAnimEncoderOptions enc_options;
403 WebPAnimEncoderOptionsInit(&enc_options);
404 // Tune 'enc_options' as needed.
405 WebPAnimEncoder* enc = WebPAnimEncoderNew(width, height, &enc_options);
406 while(<there are more frames>) {
407 WebPConfig config;
408 WebPConfigInit(&config);
409 // Tune 'config' as needed.
410 WebPAnimEncoderAdd(enc, frame, timestamp_ms, &config);
411 }
412 WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL);
413 WebPAnimEncoderAssemble(enc, webp_data);
414 WebPAnimEncoderDelete(enc);
415 // Write the 'webp_data' to a file, or re-mux it further.
416 */
417
418 typedef struct WebPAnimEncoder WebPAnimEncoder; // Main opaque object.
419
420 // Forward declarations. Defined in encode.h.
421 struct WebPPicture;
422 struct WebPConfig;
423
424 // Global options.
425 struct WebPAnimEncoderOptions {
426 WebPMuxAnimParams anim_params; // Animation parameters.
427 int minimize_size; // If true, minimize the output size (slow). Implicitly
428 // disables key-frame insertion.
429 int kmin;
430 int kmax; // Minimum and maximum distance between consecutive key
431 // frames in the output. The library may insert some key
432 // frames as needed to satisfy this criteria.
433 // Note that these conditions should hold: kmax > kmin
434 // and kmin >= kmax / 2 + 1. Also, if kmin == 0, then
435 // key-frame insertion is disabled; and if kmax == 0,
436 // then all frames will be key-frames.
437 int allow_mixed; // If true, use mixed compression mode; may choose
438 // either lossy and lossless for each frame.
439 int verbose; // If true, print info and warning messages to stderr.
440
441 uint32_t padding[4]; // Padding for later use.
442 };
443
444 // Internal, version-checked, entry point.
445 WEBP_EXTERN(int) WebPAnimEncoderOptionsInitInternal(
446 WebPAnimEncoderOptions*, int);
447
448 // Should always be called, to initialize a fresh WebPAnimEncoderOptions
449 // structure before modification. Returns false in case of version mismatch.
450 // WebPAnimEncoderOptionsInit() must have succeeded before using the
451 // 'enc_options' object.
452 static WEBP_INLINE int WebPAnimEncoderOptionsInit(
453 WebPAnimEncoderOptions* enc_options) {
454 return WebPAnimEncoderOptionsInitInternal(enc_options, WEBP_MUX_ABI_VERSION);
455 }
456
457 // Internal, version-checked, entry point.
458 WEBP_EXTERN(WebPAnimEncoder*) WebPAnimEncoderNewInternal(
459 int, int, const WebPAnimEncoderOptions*, int);
460
461 // Creates and initializes a WebPAnimEncoder object.
462 // Parameters:
463 // width/height - (in) canvas width and height of the animation.
464 // enc_options - (in) encoding options; can be passed NULL to pick
465 // reasonable defaults.
466 // Returns:
467 // A pointer to the newly created WebPAnimEncoder object.
468 // Or NULL in case of memory error.
469 static WEBP_INLINE WebPAnimEncoder* WebPAnimEncoderNew(
470 int width, int height, const WebPAnimEncoderOptions* enc_options) {
471 return WebPAnimEncoderNewInternal(width, height, enc_options,
472 WEBP_MUX_ABI_VERSION);
473 }
474
475 // Optimize the given frame for WebP, encode it and add it to the
476 // WebPAnimEncoder object.
477 // The last call to 'WebPAnimEncoderAdd' should be with frame = NULL, which
478 // indicates that no more frames are to be added. This call is also used to
479 // determine the duration of the last frame.
480 // Parameters:
481 // enc - (in/out) object to which the frame is to be added.
482 // frame - (in/out) frame data in ARGB or YUV(A) format. If it is in YUV(A)
483 // format, it will be converted to ARGB, which incurs a small loss.
484 // timestamp_ms - (in) timestamp of this frame in milliseconds.
485 // Duration of a frame would be calculated as
486 // "timestamp of next frame - timestamp of this frame".
487 // Hence, timestamps should be in non-decreasing order.
488 // config - (in) encoding options; can be passed NULL to pick
489 // reasonable defaults.
490 // Returns:
491 // On error, returns false and frame->error_code is set appropriately.
492 // Otherwise, returns true.
493 WEBP_EXTERN(int) WebPAnimEncoderAdd(
494 WebPAnimEncoder* enc, struct WebPPicture* frame, int timestamp_ms,
495 const struct WebPConfig* config);
496
497 // Assemble all frames added so far into a WebP bitstream.
498 // This call should be preceded by a call to 'WebPAnimEncoderAdd' with
499 // frame = NULL; if not, the duration of the last frame will be internally
500 // estimated.
501 // Parameters:
502 // enc - (in/out) object from which the frames are to be assembled.
503 // webp_data - (out) generated WebP bitstream.
504 // Returns:
505 // True on success.
506 WEBP_EXTERN(int) WebPAnimEncoderAssemble(WebPAnimEncoder* enc,
507 WebPData* webp_data);
508
509 // Get error string corresponding to the most recent call using 'enc'. The
510 // returned string is owned by 'enc' and is valid only until the next call to
511 // WebPAnimEncoderAdd() or WebPAnimEncoderAssemble() or WebPAnimEncoderDelete().
512 // Parameters:
513 // enc - (in/out) object from which the error string is to be fetched.
514 // Returns:
515 // NULL if 'enc' is NULL. Otherwise, returns the error string if the last call
516 // to 'enc' had an error, or an empty string if the last call was a success.
517 WEBP_EXTERN(const char*) WebPAnimEncoderGetError(WebPAnimEncoder* enc);
518
519 // Deletes the WebPAnimEncoder object.
520 // Parameters:
521 // enc - (in/out) object to be deleted
522 WEBP_EXTERN(void) WebPAnimEncoderDelete(WebPAnimEncoder* enc);
523
524 //------------------------------------------------------------------------------
394 525
395 #ifdef __cplusplus 526 #ifdef __cplusplus
396 } // extern "C" 527 } // extern "C"
397 #endif 528 #endif
398 529
399 #endif /* WEBP_WEBP_MUX_H_ */ 530 #endif /* WEBP_WEBP_MUX_H_ */
OLDNEW
« third_party/libwebp/libwebp.gyp ('K') | « third_party/libwebp/webp/format_constants.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698