libwebp_sys/decode.rs
1use std::os::raw::*;
2use std::ptr;
3
4// MAJOR(8b) + MINOR(8b)
5cfg_if! {
6 if #[cfg(feature = "1_1")] {
7 pub const WEBP_DECODER_ABI_VERSION: c_int = 0x0209;
8 } else if #[cfg(feature = "0_5")] {
9 pub const WEBP_DECODER_ABI_VERSION: c_int = 0x0208;
10 } else {
11 pub const WEBP_DECODER_ABI_VERSION: c_int = 0x0203;
12 }
13}
14
15#[cfg(feature = "extern-types")]
16#[cfg_attr(feature = "__doc_cfg", doc(cfg(all())))]
17extern "C" {
18 pub type WebPIDecoder;
19}
20
21#[cfg(not(feature = "extern-types"))]
22#[cfg_attr(feature = "__doc_cfg", doc(cfg(all())))]
23#[repr(C)]
24pub struct WebPIDecoder(c_void);
25
26// Colorspaces
27// Note: the naming describes the byte-ordering of packed samples in memory.
28// For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,...
29// Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels.
30// RGBA-4444 and RGB-565 colorspaces are represented by following byte-order:
31// RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ...
32// RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ...
33// In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for
34// these two modes:
35// RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ...
36// RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ...
37
38#[allow(non_camel_case_types)]
39pub type WEBP_CSP_MODE = u32;
40
41pub const MODE_RGB: WEBP_CSP_MODE = 0;
42pub const MODE_RGBA: WEBP_CSP_MODE = 1;
43pub const MODE_BGR: WEBP_CSP_MODE = 2;
44pub const MODE_BGRA: WEBP_CSP_MODE = 3;
45pub const MODE_ARGB: WEBP_CSP_MODE = 4;
46pub const MODE_RGBA_4444: WEBP_CSP_MODE = 5;
47pub const MODE_RGB_565: WEBP_CSP_MODE = 6;
48// RGB-premultiplied transparent modes (alpha value is preserved)
49#[allow(non_upper_case_globals)]
50pub const MODE_rgbA: WEBP_CSP_MODE = 7;
51#[allow(non_upper_case_globals)]
52pub const MODE_bgrA: WEBP_CSP_MODE = 8;
53#[allow(non_upper_case_globals)]
54pub const MODE_Argb: WEBP_CSP_MODE = 9;
55#[allow(non_upper_case_globals)]
56pub const MODE_rgbA_4444: WEBP_CSP_MODE = 10;
57// YUV modes must come after RGB ones.
58pub const MODE_YUV: WEBP_CSP_MODE = 11;
59pub const MODE_YUVA: WEBP_CSP_MODE = 12;
60pub const MODE_LAST: WEBP_CSP_MODE = 13;
61
62// Some useful macros:
63
64#[allow(non_snake_case)]
65#[inline]
66pub extern "C" fn WebPIsPremultipliedMode(mode: WEBP_CSP_MODE) -> c_int {
67 (mode == MODE_rgbA || mode == MODE_bgrA || mode == MODE_Argb || mode == MODE_rgbA_4444) as c_int
68}
69
70#[allow(non_snake_case)]
71#[inline]
72pub extern "C" fn WebPIsAlphaMode(mode: WEBP_CSP_MODE) -> c_int {
73 (mode == MODE_RGBA
74 || mode == MODE_BGRA
75 || mode == MODE_ARGB
76 || mode == MODE_RGBA_4444
77 || mode == MODE_YUVA
78 || WebPIsPremultipliedMode(mode) != 0) as c_int
79}
80
81#[allow(non_snake_case)]
82#[inline]
83pub extern "C" fn WebPIsRGBMode(mode: WEBP_CSP_MODE) -> c_int {
84 (mode < MODE_YUV) as c_int
85}
86
87//------------------------------------------------------------------------------
88// WebPDecBuffer: Generic structure for describing the output sample buffer.
89
90/// view as RGBA
91#[repr(C)]
92#[derive(Debug, Clone, Copy)]
93pub struct WebPRGBABuffer {
94 /// pointer to RGBA samples
95 pub rgba: *mut u8,
96 /// stride in bytes from one scanline to the next.
97 pub stride: c_int,
98 /// total size of the *rgba buffer.
99 pub size: usize,
100}
101
102/// view as YUVA
103#[repr(C)]
104#[derive(Debug, Clone, Copy)]
105pub struct WebPYUVABuffer {
106 /// pointer to luma samples
107 pub y: *mut u8,
108 /// pointer to chroma U samples
109 pub u: *mut u8,
110 /// pointer to chroma V samples
111 pub v: *mut u8,
112 /// pointer to alpha samples
113 pub a: *mut u8,
114 /// luma stride
115 pub y_stride: c_int,
116 /// chroma U stride
117 pub u_stride: c_int,
118 /// chroma V stride
119 pub v_stride: c_int,
120 /// alpha stride
121 pub a_stride: c_int,
122 /// luma plane size
123 pub y_size: usize,
124 /// chroma U plane size
125 pub u_size: usize,
126 /// chroma V planes size
127 pub v_size: usize,
128 /// alpha-plane size
129 pub a_size: usize,
130}
131
132/// Output buffer
133#[repr(C)]
134#[derive(Debug, Clone, Copy)]
135pub struct WebPDecBuffer {
136 /// Colorspace.
137 pub colorspace: WEBP_CSP_MODE,
138 /// Dimension (width).
139 pub width: c_int,
140 /// Dimension (height).
141 pub height: c_int,
142 /// If non-zero, 'internal_memory' pointer is not
143 /// used. If value is '2' or more, the external
144 /// memory is considered 'slow' and multiple
145 /// read/write will be avoided.
146 pub is_external_memory: c_int,
147 /// Nameless union of buffer parameters.
148 pub u: __WebPDecBufferUnion,
149 /// padding for later use
150 pub pad: [u32; 4],
151 /// Internally allocated memory (only when
152 /// is_external_memory is 0). Should not be used
153 /// externally, but accessed via the buffer union.
154 #[doc(hidden)]
155 pub private_memory: *mut u8,
156}
157
158#[allow(non_snake_case)]
159#[repr(C)]
160#[derive(Clone, Copy)]
161pub union __WebPDecBufferUnion {
162 pub RGBA: WebPRGBABuffer,
163 pub YUVA: WebPYUVABuffer,
164}
165
166impl std::fmt::Debug for __WebPDecBufferUnion {
167 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168 f.write_str("<union>")
169 }
170}
171
172/// Enumeration of the status codes
173#[allow(non_camel_case_types)]
174// #[cfg_attr(feature = "must-use", must_use)] // meaningless for type aliases
175pub type VP8StatusCode = u32;
176
177pub const VP8_STATUS_OK: VP8StatusCode = 0;
178pub const VP8_STATUS_OUT_OF_MEMORY: VP8StatusCode = 1;
179pub const VP8_STATUS_INVALID_PARAM: VP8StatusCode = 2;
180pub const VP8_STATUS_BITSTREAM_ERROR: VP8StatusCode = 3;
181pub const VP8_STATUS_UNSUPPORTED_FEATURE: VP8StatusCode = 4;
182pub const VP8_STATUS_SUSPENDED: VP8StatusCode = 5;
183pub const VP8_STATUS_USER_ABORT: VP8StatusCode = 6;
184pub const VP8_STATUS_NOT_ENOUGH_DATA: VP8StatusCode = 7;
185
186/// Deprecated alpha-less version of WebPIDecGetYUVA(): it will ignore the
187/// alpha information (if present). Kept for backward compatibility.
188#[allow(non_snake_case)]
189#[inline]
190pub unsafe extern "C" fn WebPIDecGetYUV(
191 idec: *const WebPIDecoder,
192 last_y: *mut c_int,
193 u: *mut *mut u8,
194 v: *mut *mut u8,
195 width: *mut c_int,
196 height: *mut c_int,
197 stride: *mut c_int,
198 uv_stride: *mut c_int,
199) -> *mut u8 {
200 WebPIDecGetYUVA(
201 idec,
202 last_y,
203 u,
204 v,
205 ptr::null_mut(),
206 width,
207 height,
208 stride,
209 uv_stride,
210 ptr::null_mut(),
211 )
212}
213
214/// Features gathered from the bitstream
215#[repr(C)]
216#[derive(Debug, Clone, Copy)]
217pub struct WebPBitstreamFeatures {
218 /// Width in pixels, as read from the bitstream.
219 pub width: c_int,
220 /// Height in pixels, as read from the bitstream.
221 pub height: c_int,
222 /// True if the bitstream contains an alpha channel.
223 pub has_alpha: c_int,
224 /// True if the bitstream is an animation.
225 pub has_animation: c_int,
226 /// 0 = undefined (/mixed), 1 = lossy, 2 = lossless
227 pub format: c_int,
228 /// Unused for now. if true, using incremental decoding is not
229 /// recommended.
230 #[cfg(not(feature = "0_5"))]
231 #[deprecated(note = "Removed as of libwebp 0.5.0")]
232 pub no_incremental_decoding: c_int,
233 /// Unused for now. TODO(later)
234 #[cfg(not(feature = "0_5"))]
235 #[deprecated(note = "Removed as of libwebp 0.5.0")]
236 pub rotate: c_int,
237 /// Unused for now. should be 0 for now. TODO(later)
238 #[cfg(not(feature = "0_5"))]
239 #[deprecated(note = "Removed as of libwebp 0.5.0")]
240 pub uv_sampling: c_int,
241 /// padding for later use
242 #[cfg(not(feature = "0_5"))]
243 #[doc(hidden)]
244 pub pad: [u32; 2],
245 /// padding for later use
246 #[cfg(feature = "0_5")]
247 #[doc(hidden)]
248 pub pad: [u32; 5],
249}
250
251/// Decoding options
252#[repr(C)]
253#[derive(Debug, Clone, Copy)]
254pub struct WebPDecoderOptions {
255 /// if true, skip the in-loop filtering
256 pub bypass_filtering: c_int,
257 /// if true, use faster pointwise upsampler
258 pub no_fancy_upsampling: c_int,
259 /// if true, cropping is applied _first_
260 pub use_cropping: c_int,
261 /// left position for cropping.
262 /// Will be snapped to even value.
263 pub crop_left: c_int,
264 /// top position for cropping.
265 /// Will be snapped to even value.
266 pub crop_top: c_int,
267 /// width of the cropping area
268 pub crop_width: c_int,
269 /// height of the cropping area
270 pub crop_height: c_int,
271 /// if true, scaling is applied _afterward_
272 pub use_scaling: c_int,
273 /// final resolution width
274 pub scaled_width: c_int,
275 /// final resolution height
276 pub scaled_height: c_int,
277 /// if true, use multi-threaded decoding
278 pub use_threads: c_int,
279 /// dithering strength (0=Off, 100=full)
280 pub dithering_strength: c_int,
281 /// if true, flip output vertically
282 #[cfg(feature = "0_5")]
283 pub flip: c_int,
284 /// alpha dithering strength in [0..100]
285 #[cfg(feature = "0_5")]
286 pub alpha_dithering_strength: c_int,
287 /// Unused for now. forced rotation (to be applied _last_)
288 #[cfg(not(feature = "0_5"))]
289 #[deprecated(note = "Removed as of libwebp 0.5.0")]
290 pub force_rotation: c_int,
291 /// Unused for now. if true, discard enhancement layer
292 #[cfg(not(feature = "0_5"))]
293 #[deprecated(note = "Removed as of libwebp 0.5.0")]
294 pub no_enhancement: c_int,
295 /// padding for later use
296 #[doc(hidden)]
297 pub pad: [u32; 5],
298}
299
300/// Main object storing the configuration for advanced decoding.
301#[repr(C)]
302#[derive(Debug, Clone, Copy)]
303pub struct WebPDecoderConfig {
304 /// Immutable bitstream features (optional)
305 pub input: WebPBitstreamFeatures,
306 /// Output buffer (can point to external mem)
307 pub output: WebPDecBuffer,
308 /// Decoding options
309 pub options: WebPDecoderOptions,
310}
311
312extern "C" {
313 /// Return the decoder's version number, packed in hexadecimal using 8bits for
314 /// each of major/minor/revision. E.g: v2.5.7 is 0x020507.
315 pub fn WebPGetDecoderVersion() -> c_int;
316 /// Retrieve basic header information: width, height.
317 /// This function will also validate the header, returning true on success,
318 /// false otherwise. '*width' and '*height' are only valid on successful return.
319 /// Pointers 'width' and 'height' can be passed NULL if deemed irrelevant.
320 /// Note: The following chunk sequences (before the raw VP8/VP8L data) are
321 /// considered valid by this function:
322 /// RIFF + VP8(L)
323 /// RIFF + VP8X + (optional chunks) + VP8(L)
324 /// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
325 /// VP8(L) <-- Not a valid WebP format: only allowed for internal purpose.
326 #[cfg_attr(feature = "must-use", must_use)]
327 pub fn WebPGetInfo(
328 data: *const u8,
329 data_size: usize,
330 width: *mut c_int,
331 height: *mut c_int,
332 ) -> c_int;
333 /// Decodes WebP images pointed to by 'data' and returns RGBA samples, along
334 /// with the dimensions in *width and *height. The ordering of samples in
335 /// memory is R, G, B, A, R, G, B, A... in scan order (endian-independent).
336 /// The returned pointer should be deleted calling WebPFree().
337 /// Returns NULL in case of error.
338 #[cfg_attr(feature = "must-use", must_use)]
339 pub fn WebPDecodeRGBA(
340 data: *const u8,
341 data_size: usize,
342 width: *mut c_int,
343 height: *mut c_int,
344 ) -> *mut u8;
345 /// Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data.
346 #[cfg_attr(feature = "must-use", must_use)]
347 pub fn WebPDecodeARGB(
348 data: *const u8,
349 data_size: usize,
350 width: *mut c_int,
351 height: *mut c_int,
352 ) -> *mut u8;
353 /// Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data.
354 #[cfg_attr(feature = "must-use", must_use)]
355 pub fn WebPDecodeBGRA(
356 data: *const u8,
357 data_size: usize,
358 width: *mut c_int,
359 height: *mut c_int,
360 ) -> *mut u8;
361 /// Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data.
362 /// If the bitstream contains transparency, it is ignored.
363 #[cfg_attr(feature = "must-use", must_use)]
364 pub fn WebPDecodeRGB(
365 data: *const u8,
366 data_size: usize,
367 width: *mut c_int,
368 height: *mut c_int,
369 ) -> *mut u8;
370 /// Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data.
371 #[cfg_attr(feature = "must-use", must_use)]
372 pub fn WebPDecodeBGR(
373 data: *const u8,
374 data_size: usize,
375 width: *mut c_int,
376 height: *mut c_int,
377 ) -> *mut u8;
378 /// Decode WebP images pointed to by 'data' to Y'UV format(*). The pointer
379 /// returned is the Y samples buffer. Upon return, *u and *v will point to
380 /// the U and V chroma data. These U and V buffers need NOT be passed to
381 /// WebPFree(), unlike the returned Y luma one. The dimension of the U and V
382 /// planes are both (*width + 1) / 2 and (*height + 1) / 2.
383 /// Upon return, the Y buffer has a stride returned as '*stride', while U and V
384 /// have a common stride returned as '*uv_stride'.
385 /// 'width' and 'height' may be NULL, the other pointers must not be.
386 /// Returns NULL in case of error.
387 /// (*) Also named Y'CbCr. See: <https://en.wikipedia.org/wiki/YCbCr>
388 #[cfg_attr(feature = "must-use", must_use)]
389 pub fn WebPDecodeYUV(
390 data: *const u8,
391 data_size: usize,
392 width: *mut c_int,
393 height: *mut c_int,
394 u: *mut *mut u8,
395 v: *mut *mut u8,
396 stride: *mut c_int,
397 uv_stride: *mut c_int,
398 ) -> *mut u8;
399 // These five functions are variants of the above ones, that decode the image
400 // directly into a pre-allocated buffer 'output_buffer'. The maximum storage
401 // available in this buffer is indicated by 'output_buffer_size'. If this
402 // storage is not sufficient (or an error occurred), NULL is returned.
403 // Otherwise, output_buffer is returned, for convenience.
404 // The parameter 'output_stride' specifies the distance (in bytes)
405 // between scanlines. Hence, output_buffer_size is expected to be at least
406 // output_stride x picture-height.
407 #[cfg_attr(feature = "must-use", must_use)]
408 pub fn WebPDecodeRGBAInto(
409 data: *const u8,
410 data_size: usize,
411 output_buffer: *mut u8,
412 output_buffer_size: usize,
413 output_stride: c_int,
414 ) -> *mut u8;
415 #[cfg_attr(feature = "must-use", must_use)]
416 pub fn WebPDecodeARGBInto(
417 data: *const u8,
418 data_size: usize,
419 output_buffer: *mut u8,
420 output_buffer_size: usize,
421 output_stride: c_int,
422 ) -> *mut u8;
423 #[cfg_attr(feature = "must-use", must_use)]
424 pub fn WebPDecodeBGRAInto(
425 data: *const u8,
426 data_size: usize,
427 output_buffer: *mut u8,
428 output_buffer_size: usize,
429 output_stride: c_int,
430 ) -> *mut u8;
431 // RGB and BGR variants. Here too the transparency information, if present,
432 // will be dropped and ignored.
433 #[cfg_attr(feature = "must-use", must_use)]
434 pub fn WebPDecodeRGBInto(
435 data: *const u8,
436 data_size: usize,
437 output_buffer: *mut u8,
438 output_buffer_size: usize,
439 output_stride: c_int,
440 ) -> *mut u8;
441 #[cfg_attr(feature = "must-use", must_use)]
442 pub fn WebPDecodeBGRInto(
443 data: *const u8,
444 data_size: usize,
445 output_buffer: *mut u8,
446 output_buffer_size: usize,
447 output_stride: c_int,
448 ) -> *mut u8;
449 /// WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly
450 /// into pre-allocated luma/chroma plane buffers. This function requires the
451 /// strides to be passed: one for the luma plane and one for each of the
452 /// chroma ones. The size of each plane buffer is passed as 'luma_size',
453 /// 'u_size' and 'v_size' respectively.
454 /// Pointer to the luma plane ('*luma') is returned or NULL if an error occurred
455 /// during decoding (or because some buffers were found to be too small).
456 #[cfg_attr(feature = "must-use", must_use)]
457 pub fn WebPDecodeYUVInto(
458 data: *const u8,
459 data_size: usize,
460 luma: *mut u8,
461 luma_size: usize,
462 luma_stride: c_int,
463 u: *mut u8,
464 u_size: usize,
465 u_stride: c_int,
466 v: *mut u8,
467 v_size: usize,
468 v_stride: c_int,
469 ) -> *mut u8;
470 /// Internal, version-checked, entry point
471 #[doc(hidden)]
472 #[cfg_attr(feature = "must-use", must_use)]
473 pub fn WebPInitDecBufferInternal(_: *mut WebPDecBuffer, _: c_int) -> c_int;
474 /// Free any memory associated with the buffer. Must always be called last.
475 /// Note: doesn't free the 'buffer' structure itself.
476 pub fn WebPFreeDecBuffer(buffer: *mut WebPDecBuffer);
477 /// Creates a new incremental decoder with the supplied buffer parameter.
478 /// This output_buffer can be passed NULL, in which case a default output buffer
479 /// is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer'
480 /// is kept, which means that the lifespan of 'output_buffer' must be larger than
481 /// that of the returned WebPIDecoder object.
482 /// The supplied 'output_buffer' content MUST NOT be changed between calls to
483 /// WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is
484 /// not set to 0. In such a case, it is allowed to modify the pointers, size and
485 /// stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain
486 /// within valid bounds.
487 /// All other fields of WebPDecBuffer MUST remain constant between calls.
488 /// Returns NULL if the allocation failed.
489 #[cfg_attr(feature = "must-use", must_use)]
490 pub fn WebPINewDecoder(output_buffer: *mut WebPDecBuffer) -> *mut WebPIDecoder;
491 /// This function allocates and initializes an incremental-decoder object, which
492 /// will output the RGB/A samples specified by 'csp' into a preallocated
493 /// buffer 'output_buffer'. The size of this buffer is at least
494 /// 'output_buffer_size' and the stride (distance in bytes between two scanlines)
495 /// is specified by 'output_stride'.
496 /// Additionally, output_buffer can be passed NULL in which case the output
497 /// buffer will be allocated automatically when the decoding starts. The
498 /// colorspace 'csp' is taken into account for allocating this buffer. All other
499 /// parameters are ignored.
500 /// Returns NULL if the allocation failed, or if some parameters are invalid.
501 #[cfg_attr(feature = "must-use", must_use)]
502 pub fn WebPINewRGB(
503 csp: WEBP_CSP_MODE,
504 output_buffer: *mut u8,
505 output_buffer_size: usize,
506 output_stride: c_int,
507 ) -> *mut WebPIDecoder;
508 /// This function allocates and initializes an incremental-decoder object, which
509 /// will output the raw luma/chroma samples into a preallocated planes if
510 /// supplied. The luma plane is specified by its pointer 'luma', its size
511 /// 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane
512 /// is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v
513 /// plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer
514 /// can be pass NULL in case one is not interested in the transparency plane.
515 /// Conversely, 'luma' can be passed NULL if no preallocated planes are supplied.
516 /// In this case, the output buffer will be automatically allocated (using
517 /// MODE_YUVA) when decoding starts. All parameters are then ignored.
518 /// Returns NULL if the allocation failed or if a parameter is invalid.
519 #[cfg_attr(feature = "must-use", must_use)]
520 pub fn WebPINewYUVA(
521 luma: *mut u8,
522 luma_size: usize,
523 luma_stride: c_int,
524 u: *mut u8,
525 u_size: usize,
526 u_stride: c_int,
527 v: *mut u8,
528 v_size: usize,
529 v_stride: c_int,
530 a: *mut u8,
531 a_size: usize,
532 a_stride: c_int,
533 ) -> *mut WebPIDecoder;
534 /// Deprecated version of the above, without the alpha plane.
535 /// Kept for backward compatibility.
536 #[cfg_attr(feature = "must-use", must_use)]
537 pub fn WebPINewYUV(
538 luma: *mut u8,
539 luma_size: usize,
540 luma_stride: c_int,
541 u: *mut u8,
542 u_size: usize,
543 u_stride: c_int,
544 v: *mut u8,
545 v_size: usize,
546 v_stride: c_int,
547 ) -> *mut WebPIDecoder;
548 /// Deletes the WebPIDecoder object and associated memory. Must always be called
549 /// if WebPINewDecoder, WebPINewRGB or WebPINewYUV succeeded.
550 pub fn WebPIDelete(idec: *mut WebPIDecoder);
551 /// Copies and decodes the next available data. Returns VP8_STATUS_OK when
552 /// the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more
553 /// data is expected. Returns error in other cases.
554 pub fn WebPIAppend(idec: *mut WebPIDecoder, data: *const u8, data_size: usize)
555 -> VP8StatusCode;
556 /// A variant of the above function to be used when data buffer contains
557 /// partial data from the beginning. In this case data buffer is not copied
558 /// to the internal memory.
559 /// Note that the value of the 'data' pointer can change between calls to
560 /// WebPIUpdate, for instance when the data buffer is resized to fit larger data.
561 pub fn WebPIUpdate(idec: *mut WebPIDecoder, data: *const u8, data_size: usize)
562 -> VP8StatusCode;
563 /// Returns the RGB/A image decoded so far. Returns NULL if output params
564 /// are not initialized yet. The RGB/A output type corresponds to the colorspace
565 /// specified during call to WebPINewDecoder() or WebPINewRGB().
566 /// *last_y is the index of last decoded row in raster scan order. Some pointers
567 /// (*last_y, *width etc.) can be NULL if corresponding information is not
568 /// needed. The values in these pointers are only valid on successful (non-NULL)
569 /// return.
570 #[cfg_attr(feature = "must-use", must_use)]
571 pub fn WebPIDecGetRGB(
572 idec: *const WebPIDecoder,
573 last_y: *mut c_int,
574 width: *mut c_int,
575 height: *mut c_int,
576 stride: *mut c_int,
577 ) -> *mut u8;
578 /// Same as above function to get a YUVA image. Returns pointer to the luma
579 /// plane or NULL in case of error. If there is no alpha information
580 /// the alpha pointer '*a' will be returned NULL.
581 #[cfg_attr(feature = "must-use", must_use)]
582 pub fn WebPIDecGetYUVA(
583 idec: *const WebPIDecoder,
584 last_y: *mut c_int,
585 u: *mut *mut u8,
586 v: *mut *mut u8,
587 a: *mut *mut u8,
588 width: *mut c_int,
589 height: *mut c_int,
590 stride: *mut c_int,
591 uv_stride: *mut c_int,
592 a_stride: *mut c_int,
593 ) -> *mut u8;
594 /// Generic call to retrieve information about the displayable area.
595 /// If non NULL, the left/right/width/height pointers are filled with the visible
596 /// rectangular area so far.
597 /// Returns NULL in case the incremental decoder object is in an invalid state.
598 /// Otherwise returns the pointer to the internal representation. This structure
599 /// is read-only, tied to WebPIDecoder's lifespan and should not be modified.
600 #[cfg_attr(feature = "must-use", must_use)]
601 pub fn WebPIDecodedArea(
602 idec: *const WebPIDecoder,
603 left: *mut c_int,
604 top: *mut c_int,
605 width: *mut c_int,
606 height: *mut c_int,
607 ) -> *const WebPDecBuffer;
608 /// Internal, version-checked, entry point
609 #[doc(hidden)]
610 pub fn WebPGetFeaturesInternal(
611 _: *const u8,
612 _: usize,
613 _: *mut WebPBitstreamFeatures,
614 _: c_int,
615 ) -> VP8StatusCode;
616 /// Internal, version-checked, entry point
617 #[doc(hidden)]
618 #[cfg_attr(feature = "must-use", must_use)]
619 pub fn WebPInitDecoderConfigInternal(_: *mut WebPDecoderConfig, _: c_int) -> c_int;
620 /// Instantiate a new incremental decoder object with the requested
621 /// configuration. The bitstream can be passed using 'data' and 'data_size'
622 /// parameter, in which case the features will be parsed and stored into
623 /// config->input. Otherwise, 'data' can be NULL and no parsing will occur.
624 /// Note that 'config' can be NULL too, in which case a default configuration
625 /// is used. If 'config' is not NULL, it must outlive the WebPIDecoder object
626 /// as some references to its fields will be used. No internal copy of 'config'
627 /// is made.
628 /// The return WebPIDecoder object must always be deleted calling WebPIDelete().
629 /// Returns NULL in case of error (and config->status will then reflect
630 /// the error condition, if available).
631 #[cfg_attr(feature = "must-use", must_use)]
632 pub fn WebPIDecode(
633 data: *const u8,
634 data_size: usize,
635 config: *mut WebPDecoderConfig,
636 ) -> *mut WebPIDecoder;
637 /// Non-incremental version. This version decodes the full data at once, taking
638 /// 'config' into account. Returns decoding status (which should be VP8_STATUS_OK
639 /// if the decoding was successful). Note that 'config' cannot be NULL.
640 pub fn WebPDecode(
641 data: *const u8,
642 data_size: usize,
643 config: *mut WebPDecoderConfig,
644 ) -> VP8StatusCode;
645}
646
647/// Initialize the structure as empty. Must be called before any other use.
648/// Returns false in case of version mismatch
649#[allow(non_snake_case)]
650#[cfg_attr(feature = "must-use", must_use)]
651#[inline]
652pub unsafe extern "C" fn WebPInitDecBuffer(buffer: *mut WebPDecBuffer) -> c_int {
653 WebPInitDecBufferInternal(buffer, WEBP_DECODER_ABI_VERSION)
654}
655
656/// Retrieve features from the bitstream. The *features structure is filled
657/// with information gathered from the bitstream.
658/// Returns VP8_STATUS_OK when the features are successfully retrieved. Returns
659/// VP8_STATUS_NOT_ENOUGH_DATA when more data is needed to retrieve the
660/// features from headers. Returns error in other cases.
661/// Note: The following chunk sequences (before the raw VP8/VP8L data) are
662/// considered valid by this function:
663/// RIFF + VP8(L)
664/// RIFF + VP8X + (optional chunks) + VP8(L)
665/// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
666/// VP8(L) <-- Not a valid WebP format: only allowed for internal purpose.
667#[allow(non_snake_case)]
668#[inline]
669pub unsafe extern "C" fn WebPGetFeatures(
670 data: *const u8,
671 data_size: usize,
672 features: *mut WebPBitstreamFeatures,
673) -> VP8StatusCode {
674 WebPGetFeaturesInternal(data, data_size, features, WEBP_DECODER_ABI_VERSION)
675}
676
677/// Initialize the configuration as empty. This function must always be
678/// called first, unless WebPGetFeatures() is to be called.
679/// Returns false in case of mismatched version.
680#[allow(non_snake_case)]
681#[cfg_attr(feature = "must-use", must_use)]
682#[inline]
683pub unsafe extern "C" fn WebPInitDecoderConfig(config: *mut WebPDecoderConfig) -> c_int {
684 WebPInitDecoderConfigInternal(config, WEBP_DECODER_ABI_VERSION)
685}