mux.h 22 KB

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