mux.h 22 KB

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