webp_dev/sys/
webp.rs

1#![allow(non_upper_case_globals)]
2use std::ffi::{CString, c_void};
3use std::os::raw::{c_char, c_int};
4use libc::{size_t, c_float};
5
6///////////////////////////////////////////////////////////////////////////////
7// WEBP STRUCTS
8///////////////////////////////////////////////////////////////////////////////
9
10/// Structure for storing auxiliary statistics.
11pub type WebPAuxStats = crate::raw::webp::WebPAuxStats;
12
13/// Features gathered from the bitstream.
14pub type WebPBitstreamFeatures = crate::raw::webp::WebPBitstreamFeatures;
15
16/// Compression parameters.
17pub type WebPConfig = crate::raw::webp::WebPConfig;
18
19/// WebPDecBuffer: Generic structure for describing the output sample buffer.
20pub type WebPDecBuffer = crate::raw::webp::WebPDecBuffer;
21
22/// Main object storing the configuration for advanced decoding.
23pub type WebPDecoderConfig = crate::raw::webp::WebPDecoderConfig;
24
25/// Decoding options
26pub type WebPDecoderOptions = crate::raw::webp::WebPDecoderOptions;
27
28pub type WebPIDecoder = crate::raw::webp::WebPIDecoder;
29
30/// WebPMemoryWrite: a special WebPWriterFunction that writes to memory using
31/// the following WebPMemoryWriter object (to be set as a custom_ptr).
32pub type WebPMemoryWriter = crate::raw::webp::WebPMemoryWriter;
33
34/// Main exchange structure (input samples, output bytes, statistics)
35pub type WebPPicture = crate::raw::webp::WebPPicture;
36
37/// WebPDecBuffer: Generic structure for describing the output sample buffer.
38pub type WebPRGBABuffer = crate::raw::webp::WebPRGBABuffer;
39
40/// WebPDecBuffer: Generic structure for describing the output sample buffer.
41pub type WebPYUVABuffer = crate::raw::webp::WebPYUVABuffer;
42
43
44///////////////////////////////////////////////////////////////////////////////
45// TYPE-DEFS
46///////////////////////////////////////////////////////////////////////////////
47
48/// Enumeration of the status codes.
49pub type VP8StatusCode = crate::raw::webp::VP8StatusCode;
50
51/// Colorspaces.
52/// 
53/// Note: the naming describes the byte-ordering of packed samples in memory.
54/// For instance, MODE_BGRA relates to samples ordered as B,G,R,A,B,G,R,A,...
55/// Non-capital names (e.g.:MODE_Argb) relates to pre-multiplied RGB channels.
56/// RGBA-4444 and RGB-565 colorspaces are represented by following byte-order:
57/// RGBA-4444: [r3 r2 r1 r0 g3 g2 g1 g0], [b3 b2 b1 b0 a3 a2 a1 a0], ...
58/// RGB-565: [r4 r3 r2 r1 r0 g5 g4 g3], [g2 g1 g0 b4 b3 b2 b1 b0], ...
59/// In the case WEBP_SWAP_16BITS_CSP is defined, the bytes are swapped for
60/// these two modes:
61/// RGBA-4444: [b3 b2 b1 b0 a3 a2 a1 a0], [r3 r2 r1 r0 g3 g2 g1 g0], ...
62/// RGB-565: [g2 g1 g0 b4 b3 b2 b1 b0], [r4 r3 r2 r1 r0 g5 g4 g3], ...
63pub type WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE;
64
65/// Color spaces.
66pub type WebPEncCSP = crate::raw::webp::WebPEncCSP;
67
68/// Encoding error conditions.
69pub type WebPEncodingError = crate::raw::webp::WebPEncodingError;
70
71/// Image characteristics hint for the underlying encoder.
72pub type WebPImageHint = crate::raw::webp::WebPImageHint;
73
74/// Enumerate some predefined settings for WebPConfig, depending on the type
75/// of source picture.
76/// 
77/// These presets are used when calling WebPConfigPreset().
78pub type WebPPreset = crate::raw::webp::WebPPreset;
79
80/// Progress hook, called from time to time to report progress.
81/// 
82/// It can return
83/// false to request an abort of the encoding process, or true otherwise if
84/// everything is OK.
85pub type WebPProgressHook = crate::raw::webp::WebPProgressHook;
86
87/// Signature for output function.
88/// 
89/// Should return true if writing was successful.
90/// data/data_size is the segment of data to write, and 'picture' is for
91/// reference (and so one can make use of picture->custom_ptr).
92pub type WebPWriterFunction = crate::raw::webp::WebPWriterFunction;
93
94///////////////////////////////////////////////////////////////////////////////
95// WEBP CONSTANTS
96///////////////////////////////////////////////////////////////////////////////
97
98pub const MODE_ARGB: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_ARGB;
99pub const MODE_Argb: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_Argb;
100pub const MODE_BGR: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_BGR;
101pub const MODE_BGRA: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_BGRA;
102pub const MODE_LAST: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_LAST;
103pub const MODE_RGB: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_RGB;
104pub const MODE_RGBA: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_RGBA;
105pub const MODE_RGBA_4444: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_RGBA_4444;
106pub const MODE_RGB_565: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_RGB_565;
107pub const MODE_YUV: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_YUV;
108pub const MODE_YUVA: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_YUVA;
109pub const MODE_bgrA: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_bgrA;
110pub const MODE_rgbA: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_rgbA;
111pub const MODE_rgbA_4444: WebPCSPMode = crate::raw::webp::WEBP_CSP_MODE_MODE_rgbA_4444;
112
113pub const WEBP_DECODER_ABI_VERSION: u32 = crate::raw::webp::WEBP_DECODER_ABI_VERSION;
114pub const WEBP_ENCODER_ABI_VERSION: u32 = crate::raw::webp::WEBP_ENCODER_ABI_VERSION;
115
116pub const WEBP_MAX_DIMENSION: u32 = crate::raw::webp::WEBP_MAX_DIMENSION;
117
118pub const WEBP_CSP_ALPHA_BIT: WebPEncCSP = crate::raw::webp::WebPEncCSP_WEBP_CSP_ALPHA_BIT;
119pub const WEBP_CSP_UV_MASK: WebPEncCSP = crate::raw::webp::WebPEncCSP_WEBP_CSP_UV_MASK;
120pub const WEBP_YUV420: WebPEncCSP = crate::raw::webp::WebPEncCSP_WEBP_YUV420;
121pub const WEBP_YUV420A: WebPEncCSP = crate::raw::webp::WebPEncCSP_WEBP_YUV420A;
122
123pub const VP8_ENC_OK: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_OK;
124pub const VP8_ENC_ERROR_OUT_OF_MEMORY: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_OUT_OF_MEMORY;
125pub const VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY;
126pub const VP8_ENC_ERROR_NULL_PARAMETER: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_NULL_PARAMETER;
127pub const VP8_ENC_ERROR_INVALID_CONFIGURATION: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_INVALID_CONFIGURATION;
128pub const VP8_ENC_ERROR_BAD_DIMENSION: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_BAD_DIMENSION;
129pub const VP8_ENC_ERROR_PARTITION_OVERFLOW: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_PARTITION_OVERFLOW;
130pub const VP8_ENC_ERROR_BAD_WRITE: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_BAD_WRITE;
131pub const VP8_ENC_ERROR_FILE_TOO_BIG: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_FILE_TOO_BIG;
132pub const VP8_ENC_ERROR_USER_ABORT: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_USER_ABORT;
133pub const VP8_ENC_ERROR_LAST: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_LAST;
134pub const VP8_ENC_ERROR_PARTITION0_OVERFLOW: WebPEncodingError = crate::raw::webp::WebPEncodingError_VP8_ENC_ERROR_PARTITION0_OVERFLOW;
135
136pub const WEBP_HINT_DEFAULT: WebPImageHint = crate::raw::webp::WebPImageHint_WEBP_HINT_DEFAULT;
137pub const WEBP_HINT_GRAPH: WebPImageHint = crate::raw::webp::WebPImageHint_WEBP_HINT_GRAPH;
138pub const WEBP_HINT_LAST: WebPImageHint = crate::raw::webp::WebPImageHint_WEBP_HINT_LAST;
139pub const WEBP_HINT_PHOTO: WebPImageHint = crate::raw::webp::WebPImageHint_WEBP_HINT_PHOTO;
140pub const WEBP_HINT_PICTURE: WebPImageHint = crate::raw::webp::WebPImageHint_WEBP_HINT_PICTURE;
141
142pub const WEBP_PRESET_DEFAULT: WebPPreset = crate::raw::webp::WebPPreset_WEBP_PRESET_DEFAULT;
143pub const WEBP_PRESET_DRAWING: WebPPreset = crate::raw::webp::WebPPreset_WEBP_PRESET_DRAWING;
144pub const WEBP_PRESET_ICON: WebPPreset = crate::raw::webp::WebPPreset_WEBP_PRESET_ICON;
145pub const WEBP_PRESET_PHOTO: WebPPreset = crate::raw::webp::WebPPreset_WEBP_PRESET_PHOTO;
146pub const WEBP_PRESET_PICTURE: WebPPreset = crate::raw::webp::WebPPreset_WEBP_PRESET_PICTURE;
147pub const WEBP_PRESET_TEXT: WebPPreset = crate::raw::webp::WebPPreset_WEBP_PRESET_TEXT;
148
149///////////////////////////////////////////////////////////////////////////////
150// WEBP FUNCTIONS
151///////////////////////////////////////////////////////////////////////////////
152
153
154// Remove the transparency information (if present) by blending the color with
155// the background color 'background_rgb' (specified as 24bit RGB triplet).
156// After this call, all alpha values are reset to 0xff.
157pub unsafe fn webp_blend_alpha(pic: *mut WebPPicture, background_rgb: u32) {
158    crate::raw::webp::WebPBlendAlpha(pic, background_rgb)
159}
160
161/// Helper function: given a width x height plane of RGBA or YUV(A) samples
162/// clean-up or smoothen the YUV or RGB samples under fully transparent area,
163/// to help compressibility (no guarantee, though).
164pub unsafe fn webp_cleanup_transparent_area(picture: *mut WebPPicture) {
165    crate::raw::webp::WebPCleanupTransparentArea(picture)
166}
167
168/// Internal, version-checked, entry point
169pub unsafe fn webp_config_init_internal(
170    arg1: *mut WebPConfig,
171    arg2: WebPPreset,
172    arg3: f32,
173    arg4: ::std::os::raw::c_int,
174) -> c_int {
175    crate::raw::webp::WebPConfigInitInternal(arg1, arg2, arg3, arg4)
176}
177
178/// Activate the lossless compression mode with the desired efficiency level
179/// between 0 (fastest, lowest compression) and 9 (slower, best compression).
180/// 
181/// A good default level is '6', providing a fair tradeoff between compression
182/// speed and final compressed size.
183/// This function will overwrite several fields from config: 'method', 'quality'
184/// and 'lossless'. Returns false in case of parameter error.
185pub unsafe fn webp_config_lossless_preset(
186    config: *mut WebPConfig,
187    level: ::std::os::raw::c_int,
188) -> c_int {
189    crate::raw::webp::WebPConfigLosslessPreset(config, level)
190}
191
192/// Non-incremental version. This version decodes the full data at once, taking
193/// 'config' into account.
194/// 
195/// Returns decoding status (which should be VP8_STATUS_OK
196/// if the decoding was successful). Note that 'config' cannot be NULL.
197pub unsafe fn webp_decode(
198    data: *const u8,
199    data_size: usize,
200    config: *mut WebPDecoderConfig,
201) -> VP8StatusCode {
202    crate::raw::webp::WebPDecode(data, data_size, config)
203}
204
205/// Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data.
206pub unsafe fn webp_decode_argb(
207    data: *const u8,
208    data_size: usize,
209    width: *mut ::std::os::raw::c_int,
210    height: *mut ::std::os::raw::c_int,
211) -> *mut u8 {
212    crate::raw::webp::WebPDecodeARGB(data, data_size, width, height)
213}
214
215pub unsafe fn webp_decode_argb_into(
216    data: *const u8,
217    data_size: usize,
218    output_buffer: *mut u8,
219    output_buffer_size: usize,
220    output_stride: ::std::os::raw::c_int,
221) -> *mut u8 {
222    crate::raw::webp::WebPDecodeARGBInto(
223        data,
224        data_size,
225        output_buffer,
226        output_buffer_size,
227        output_stride,
228    )
229}
230
231/// Same as WebPDecodeRGB, but returning B, G, R, B, G, R... ordered data.
232pub unsafe fn webp_decode_bgr(
233    data: *const u8,
234    data_size: usize,
235    width: *mut ::std::os::raw::c_int,
236    height: *mut ::std::os::raw::c_int,
237) -> *mut u8 {
238    crate::raw::webp::WebPDecodeBGR(
239        data,
240        data_size,
241        width,
242        height,
243    )
244}
245
246/// Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data.
247pub unsafe fn webp_decode_bgra(
248    data: *const u8,
249    data_size: usize,
250    width: *mut ::std::os::raw::c_int,
251    height: *mut ::std::os::raw::c_int,
252) -> *mut u8 {
253    crate::raw::webp::WebPDecodeBGRA(
254        data,
255        data_size,
256        width,
257        height,
258    )
259}
260
261pub unsafe fn webp_decodebgra_into(
262    data: *const u8,
263    data_size: usize,
264    output_buffer: *mut u8,
265    output_buffer_size: usize,
266    output_stride: ::std::os::raw::c_int,
267) -> *mut u8 {
268    crate::raw::webp::WebPDecodeBGRAInto(
269        data,
270        data_size,
271        output_buffer,
272        output_buffer_size,
273        output_stride,
274    )
275}
276
277pub unsafe fn webp_decode_bgr_into(
278    data: *const u8,
279    data_size: usize,
280    output_buffer: *mut u8,
281    output_buffer_size: usize,
282    output_stride: ::std::os::raw::c_int,
283) -> *mut u8 {
284    crate::raw::webp::WebPDecodeBGRInto(
285        data,
286        data_size,
287        output_buffer,
288        output_buffer_size,
289        output_stride,
290    )
291}
292
293/// Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data.
294/// If the bitstream contains transparency, it is ignored.
295pub unsafe fn webp_decode_rgb(
296    data: *const u8,
297    data_size: usize,
298    width: *mut ::std::os::raw::c_int,
299    height: *mut ::std::os::raw::c_int,
300) -> *mut u8 {
301    crate::raw::webp::WebPDecodeRGB(
302        data,
303        data_size,
304        width,
305        height,
306    )
307}
308
309/// Decodes WebP images pointed to by 'data' and returns RGBA samples, along
310/// with the dimensions in *width and *height.
311/// 
312/// The ordering of samples in
313/// memory is R, G, B, A, R, G, B, A... in scan order (endian-independent).
314/// The returned pointer should be deleted calling WebPFree().
315/// Returns NULL in case of error.
316pub unsafe fn webp_decode_rgba(
317    data: *const u8,
318    data_size: usize,
319    width: *mut ::std::os::raw::c_int,
320    height: *mut ::std::os::raw::c_int,
321) -> *mut u8 {
322    crate::raw::webp::WebPDecodeRGBA(
323        data,
324        data_size,
325        width,
326        height,
327    )
328}
329
330/// These five functions are variants of the above ones, that decode the image
331/// directly into a pre-allocated buffer 'output_buffer'.
332/// 
333/// The maximum storage
334/// available in this buffer is indicated by 'output_buffer_size'. If this
335/// storage is not sufficient (or an error occurred), NULL is returned.
336/// Otherwise, output_buffer is returned, for convenience.
337/// The parameter 'output_stride' specifies the distance (in bytes)
338/// between scanlines. Hence, output_buffer_size is expected to be at least
339/// output_stride x picture-height.
340pub unsafe fn webp_decode_rgba_into(
341    data: *const u8,
342    data_size: usize,
343    output_buffer: *mut u8,
344    output_buffer_size: usize,
345    output_stride: ::std::os::raw::c_int,
346) -> *mut u8 {
347    crate::raw::webp::WebPDecodeRGBAInto(
348        data,
349        data_size,
350        output_buffer,
351        output_buffer_size,
352        output_stride,
353    )
354}
355
356/// RGB and BGR variants. Here too the transparency information, if present,
357/// will be dropped and ignored.
358pub unsafe fn webp_decode_rgb_into(
359    data: *const u8,
360    data_size: usize,
361    output_buffer: *mut u8,
362    output_buffer_size: usize,
363    output_stride: ::std::os::raw::c_int,
364) -> *mut u8 {
365    crate::raw::webp::WebPDecodeRGBInto(
366        data,
367        data_size,
368        output_buffer,
369        output_buffer_size,
370        output_stride,
371    )
372}
373
374/// Decode WebP images pointed to by 'data' to Y'UV format(*).
375/// 
376/// The pointer
377/// returned is the Y samples buffer. Upon return, *u and *v will point to
378/// the U and V chroma data. These U and V buffers need NOT be passed to
379/// WebPFree(), unlike the returned Y luma one. The dimension of the U and V
380/// planes are both (*width + 1) / 2 and (*height + 1)/ 2.
381/// Upon return, the Y buffer has a stride returned as '*stride', while U and V
382/// have a common stride returned as '*uv_stride'.
383/// Return NULL in case of error.
384/// (*) Also named Y'CbCr. See: http://en.wikipedia.org/wiki/YCbCr
385pub unsafe fn webp_decode_yuv(
386    data: *const u8,
387    data_size: usize,
388    width: *mut ::std::os::raw::c_int,
389    height: *mut ::std::os::raw::c_int,
390    u: *mut *mut u8,
391    v: *mut *mut u8,
392    stride: *mut ::std::os::raw::c_int,
393    uv_stride: *mut ::std::os::raw::c_int,
394) -> *mut u8 {
395    crate::raw::webp::WebPDecodeYUV(
396        data,
397        data_size,
398        width,
399        height,
400        u,
401        v,
402        stride,
403        uv_stride,
404    )
405}
406
407/// WebPDecodeYUVInto() is a variant of WebPDecodeYUV() that operates directly
408/// into pre-allocated luma/chroma plane buffers.
409/// 
410/// This function requires the
411/// strides to be passed: one for the luma plane and one for each of the
412/// chroma ones. The size of each plane buffer is passed as 'luma_size',
413/// 'u_size' and 'v_size' respectively.
414/// Pointer to the luma plane ('*luma') is returned or NULL if an error occurred
415/// during decoding (or because some buffers were found to be too small).
416pub unsafe fn webp_decode_yuv_into(
417    data: *const u8,
418    data_size: usize,
419    luma: *mut u8,
420    luma_size: usize,
421    luma_stride: ::std::os::raw::c_int,
422    u: *mut u8,
423    u_size: usize,
424    u_stride: ::std::os::raw::c_int,
425    v: *mut u8,
426    v_size: usize,
427    v_stride: ::std::os::raw::c_int,
428) -> *mut u8 {
429    crate::raw::webp::WebPDecodeYUVInto(
430        data,
431        data_size,
432        luma,
433        luma_size,
434        luma_stride,
435        u,
436        u_size,
437        u_stride,
438        v,
439        v_size,
440        v_stride,
441    )
442}
443
444/// Main call
445/// 
446/// Main encoding call, after config and picture have been initialized.
447/// 'picture' must be less than 16384x16384 in dimension (cf WEBP_MAX_DIMENSION),
448/// and the 'config' object must be a valid one.
449/// Returns false in case of error, true otherwise.
450/// In case of error, picture->error_code is updated accordingly.
451/// 'picture' can hold the source samples in both YUV(A) or ARGB input, depending
452/// on the value of 'picture->use_argb'. It is highly recommended to use
453/// the former for lossy encoding, and the latter for lossless encoding
454/// (when config.lossless is true). Automatic conversion from one format to
455/// another is provided but they both incur some loss.
456pub unsafe fn webp_encode(
457    config: *const WebPConfig,
458    picture: *mut WebPPicture,
459) -> c_int {
460    crate::raw::webp::WebPEncode(config, picture)
461}
462
463/// One-stop-shop call! No questions asked:
464pub unsafe fn webp_encode_bgr(
465    bgr: *const u8,
466    width: ::std::os::raw::c_int,
467    height: ::std::os::raw::c_int,
468    stride: ::std::os::raw::c_int,
469    quality_factor: f32,
470    output: *mut *mut u8,
471) -> usize {
472    crate::raw::webp::WebPEncodeBGR(
473        bgr,
474        width,
475        height,
476        stride,
477        quality_factor,
478        output,
479    )
480}
481
482/// One-stop-shop call! No questions asked:
483pub unsafe fn webp_encode_bgra(
484    bgra: *const u8,
485    width: ::std::os::raw::c_int,
486    height: ::std::os::raw::c_int,
487    stride: ::std::os::raw::c_int,
488    quality_factor: f32,
489    output: *mut *mut u8,
490) -> usize {
491    crate::raw::webp::WebPEncodeBGRA(
492        bgra,
493        width,
494        height,
495        stride,
496        quality_factor,
497        output,
498    )
499}
500
501/// One-stop-shop call! No questions asked:
502pub unsafe fn webp_encode_lossless_bgr(
503    bgr: *const u8,
504    width: ::std::os::raw::c_int,
505    height: ::std::os::raw::c_int,
506    stride: ::std::os::raw::c_int,
507    output: *mut *mut u8,
508) -> usize {
509    crate::raw::webp::WebPEncodeLosslessBGR(
510        bgr,
511        width,
512        height,
513        stride,
514        output,
515    )
516}
517
518/// One-stop-shop call! No questions asked:
519pub unsafe fn webp_encode_lossless_bgra(
520    rgba: *const u8,
521    width: ::std::os::raw::c_int,
522    height: ::std::os::raw::c_int,
523    stride: ::std::os::raw::c_int,
524    output: *mut *mut u8,
525) -> usize {
526    crate::raw::webp::WebPEncodeLosslessBGRA(
527        rgba,
528        width,
529        height,
530        stride,
531        output,
532    )
533}
534
535/// One-stop-shop call! No questions asked:
536pub unsafe fn webp_encode_lossless_rgb(
537    rgb: *const u8,
538    width: ::std::os::raw::c_int,
539    height: ::std::os::raw::c_int,
540    stride: ::std::os::raw::c_int,
541    output: *mut *mut u8,
542) -> usize {
543    crate::raw::webp::WebPEncodeLosslessRGB(
544        rgb,
545        width,
546        height,
547        stride,
548        output,
549    )
550}
551
552/// One-stop-shop call! No questions asked:
553pub unsafe fn webp_encode_lossless_rgba(
554    rgba: *const u8,
555    width: ::std::os::raw::c_int,
556    height: ::std::os::raw::c_int,
557    stride: ::std::os::raw::c_int,
558    output: *mut *mut u8,
559) -> usize {
560    crate::raw::webp::WebPEncodeLosslessRGBA(
561        rgba,
562        width,
563        height,
564        stride,
565        output,
566    )
567}
568
569/// One-stop-shop call! No questions asked:
570pub unsafe fn webp_encode_rgb(
571    rgb: *const u8,
572    width: ::std::os::raw::c_int,
573    height: ::std::os::raw::c_int,
574    stride: ::std::os::raw::c_int,
575    quality_factor: f32,
576    output: *mut *mut u8,
577) -> usize {
578    crate::raw::webp::WebPEncodeRGB(
579        rgb,
580        width,
581        height,
582        stride,
583        quality_factor,
584        output,
585    )
586}
587
588/// One-stop-shop call! No questions asked:
589pub unsafe fn webp_encode_rgba(
590    rgba: *const u8,
591    width: ::std::os::raw::c_int,
592    height: ::std::os::raw::c_int,
593    stride: ::std::os::raw::c_int,
594    quality_factor: f32,
595    output: *mut *mut u8,
596) -> usize {
597    crate::raw::webp::WebPEncodeRGBA(
598        rgba,
599        width,
600        height,
601        stride,
602        quality_factor,
603        output,
604    )
605}
606
607/// Releases memory returned by the WebPDecode*() functions (from decode.h).
608pub unsafe fn webp_free(ptr: *mut ::std::os::raw::c_void) {
609    crate::raw::webp::WebPFree(ptr)
610}
611
612/// Free any memory associated with the buffer. Must always be called last.
613/// 
614/// Note: doesn't free the 'buffer' structure itself.
615pub unsafe fn webp_free_dec_buffer(buffer: *mut WebPDecBuffer) {
616    crate::raw::webp::WebPFreeDecBuffer(buffer)
617}
618
619/// Return the decoder's version number, packed in hexadecimal using 8bits for
620/// each of major/minor/revision.
621/// 
622/// E.g: v2.5.7 is 0x020507.
623pub unsafe fn webp_get_decoder_version() -> c_int {
624    crate::raw::webp::WebPGetDecoderVersion()
625}
626
627/// Return the encoder's version number, packed in hexadecimal using 8bits for
628/// each of major/minor/revision.
629/// 
630/// E.g: v2.5.7 is 0x020507.
631pub unsafe fn webp_get_encoder_version() -> c_int {
632    crate::raw::webp::WebPGetEncoderVersion()
633}
634
635/// Internal, version-checked, entry point.
636pub unsafe fn webp_get_features_internal(
637    arg1: *const u8,
638    arg2: usize,
639    arg3: *mut WebPBitstreamFeatures,
640    arg4: ::std::os::raw::c_int,
641) -> VP8StatusCode {
642    crate::raw::webp::WebPGetFeaturesInternal(
643        arg1,
644        arg2,
645        arg3,
646        arg4,
647    )
648}
649
650/// Retrieve basic header information: width, height.
651/// 
652/// This function will also validate the header, returning true on success,
653/// false otherwise. '*width' and '*height' are only valid on successful return.
654/// Pointers 'width' and 'height' can be passed NULL if deemed irrelevant.
655/// Note: The following chunk sequences (before the raw VP8/VP8L data) are
656/// considered valid by this function:
657/// RIFF + VP8(L)
658/// RIFF + VP8X + (optional chunks) + VP8(L)
659/// ALPH + VP8 <-- Not a valid WebP format: only allowed for internal purpose.
660/// VP8(L)     <-- Not a valid WebP format: only allowed for internal purpose.
661pub unsafe fn webp_get_info(
662    data: *const u8,
663    data_size: usize,
664    width: *mut ::std::os::raw::c_int,
665    height: *mut ::std::os::raw::c_int,
666) -> c_int {
667    crate::raw::webp::WebPGetInfo(
668        data,
669        data_size,
670        width,
671        height,
672    )
673}
674
675/// Copies and decodes the next available data.
676/// 
677/// Returns VP8_STATUS_OK when
678/// the image is successfully decoded. Returns VP8_STATUS_SUSPENDED when more
679/// data is expected. Returns error in other cases.
680pub unsafe fn webp_iappend(
681    idec: *mut WebPIDecoder,
682    data: *const u8,
683    data_size: usize
684) -> VP8StatusCode {
685    crate::raw::webp::WebPIAppend(
686        idec,
687        data,
688        data_size,
689    )
690}
691
692/// Returns the RGB/A image decoded so far.
693/// 
694/// Returns NULL if output params
695/// are not initialized yet. The RGB/A output type corresponds to the colorspace
696/// specified during call to WebPINewDecoder() or WebPINewRGB().
697/// *last_y is the index of last decoded row in raster scan order. Some pointers
698/// (*last_y, *width etc.) can be NULL if corresponding information is not
699/// needed. The values in these pointers are only valid on successful (non-NULL)
700/// return.
701pub unsafe fn webp_idec_get_rgb(
702    idec: *const WebPIDecoder,
703    last_y: *mut ::std::os::raw::c_int,
704    width: *mut ::std::os::raw::c_int,
705    height: *mut ::std::os::raw::c_int,
706    stride: *mut ::std::os::raw::c_int,
707) -> *mut u8 {
708    crate::raw::webp::WebPIDecGetRGB(
709        idec,
710        last_y,
711        width,
712        height,
713        stride,
714    )
715}
716
717/// Same as above function to get a YUVA image.
718/// 
719/// Returns pointer to the luma
720/// plane or NULL in case of error. If there is no alpha information
721/// the alpha pointer '*a' will be returned NULL.
722pub unsafe fn webp_idec_get_yuva(
723    idec: *const WebPIDecoder,
724    last_y: *mut ::std::os::raw::c_int,
725    u: *mut *mut u8,
726    v: *mut *mut u8,
727    a: *mut *mut u8,
728    width: *mut ::std::os::raw::c_int,
729    height: *mut ::std::os::raw::c_int,
730    stride: *mut ::std::os::raw::c_int,
731    uv_stride: *mut ::std::os::raw::c_int,
732    a_stride: *mut ::std::os::raw::c_int,
733) -> *mut u8 {
734    crate::raw::webp::WebPIDecGetYUVA(
735        idec,
736        last_y,
737        u,
738        v,
739        a,
740        width,
741        height,
742        stride,
743        uv_stride,
744        a_stride,
745    )
746}
747
748/// Instantiate a new incremental decoder object with the requested
749/// configuration.
750/// 
751/// The bitstream can be passed using 'data' and 'data_size'
752/// parameter, in which case the features will be parsed and stored into
753/// config->input. Otherwise, 'data' can be NULL and no parsing will occur.
754/// Note that 'config' can be NULL too, in which case a default configuration
755/// is used. If 'config' is not NULL, it must outlive the WebPIDecoder object
756/// as some references to its fields will be used. No internal copy of 'config'
757/// is made.
758/// The return WebPIDecoder object must always be deleted calling WebPIDelete().
759/// Returns NULL in case of error (and config->status will then reflect
760/// the error condition, if available).
761pub unsafe fn webp_idecode(
762    data: *const u8,
763    data_size: usize,
764    config: *mut WebPDecoderConfig,
765) -> *mut WebPIDecoder {
766    crate::raw::webp::WebPIDecode(
767        data,
768        data_size,
769        config,
770    )
771}
772
773/// Generic call to retrieve information about the displayable area.
774/// 
775/// If non NULL, the left/right/width/height pointers are filled with the visible
776/// rectangular area so far.
777/// Returns NULL in case the incremental decoder object is in an invalid state.
778/// Otherwise returns the pointer to the internal representation. This structure
779/// is read-only, tied to WebPIDecoder's lifespan and should not be modified.
780pub unsafe fn webp_idecoded_area(
781    idec: *const WebPIDecoder,
782    left: *mut ::std::os::raw::c_int,
783    top: *mut ::std::os::raw::c_int,
784    width: *mut ::std::os::raw::c_int,
785    height: *mut ::std::os::raw::c_int,
786) -> *const WebPDecBuffer {
787    crate::raw::webp::WebPIDecodedArea(
788        idec,
789        left,
790        top,
791        width,
792        height,
793    )
794}
795
796/// Deletes the WebPIDecoder object and associated memory.
797/// 
798/// Must always be called if WebPINewDecoder, WebPINewRGB or WebPINewYUV
799/// succeeded.
800pub unsafe fn webp_idelete(idec: *mut WebPIDecoder) {
801    crate::raw::webp::WebPIDelete(idec)
802}
803
804/// Creates a new incremental decoder with the supplied buffer parameter.
805/// 
806/// This output_buffer can be passed NULL, in which case a default output buffer
807/// is used (with MODE_RGB). Otherwise, an internal reference to 'output_buffer'
808/// is kept, which means that the lifespan of 'output_buffer' must be larger than
809/// that of the returned WebPIDecoder object.
810/// The supplied 'output_buffer' content MUST NOT be changed between calls to
811/// WebPIAppend() or WebPIUpdate() unless 'output_buffer.is_external_memory' is
812/// not set to 0. In such a case, it is allowed to modify the pointers, size and
813/// stride of output_buffer.u.RGBA or output_buffer.u.YUVA, provided they remain
814/// within valid bounds.
815/// All other fields of WebPDecBuffer MUST remain constant between calls.
816/// Returns NULL if the allocation failed.
817pub unsafe fn webp_inew_decoder(output_buffer: *mut WebPDecBuffer) -> *mut WebPIDecoder {
818    crate::raw::webp::WebPINewDecoder(output_buffer)
819}
820
821/// This function allocates and initializes an incremental-decoder object, which
822/// will output the RGB/A samples specified by 'csp' into a preallocated
823/// buffer 'output_buffer'.
824/// 
825/// The size of this buffer is at least
826/// 'output_buffer_size' and the stride (distance in bytes between two scanlines)
827/// is specified by 'output_stride'.
828/// Additionally, output_buffer can be passed NULL in which case the output
829/// buffer will be allocated automatically when the decoding starts. The
830/// colorspace 'csp' is taken into account for allocating this buffer. All other
831/// parameters are ignored.
832/// Returns NULL if the allocation failed, or if some parameters are invalid.
833pub unsafe fn webp_inew_rgb(
834    csp: WebPCSPMode,
835    output_buffer: *mut u8,
836    output_buffer_size: usize,
837    output_stride: ::std::os::raw::c_int,
838) -> *mut WebPIDecoder {
839    crate::raw::webp::WebPINewRGB(
840        csp,
841        output_buffer,
842        output_buffer_size,
843        output_stride,
844    )
845}
846
847/// Deprecated version of the above, without the alpha plane.
848/// 
849/// Kept for backward compatibility.
850pub unsafe fn webp_inew_yuv(
851    luma: *mut u8,
852    luma_size: usize,
853    luma_stride: ::std::os::raw::c_int,
854    u: *mut u8,
855    u_size: usize,
856    u_stride: ::std::os::raw::c_int,
857    v: *mut u8,
858    v_size: usize,
859    v_stride: ::std::os::raw::c_int,
860) -> *mut WebPIDecoder {
861    crate::raw::webp::WebPINewYUV(
862        luma,
863        luma_size,
864        luma_stride,
865        u,
866        u_size,
867        u_stride,
868        v,
869        v_size,
870        v_stride,
871    )
872}
873
874/// This function allocates and initializes an incremental-decoder object, which
875/// will output the raw luma/chroma samples into a preallocated planes if
876/// supplied.
877/// 
878/// The luma plane is specified by its pointer 'luma', its size
879/// 'luma_size' and its stride 'luma_stride'. Similarly, the chroma-u plane
880/// is specified by the 'u', 'u_size' and 'u_stride' parameters, and the chroma-v
881/// plane by 'v' and 'v_size'. And same for the alpha-plane. The 'a' pointer
882/// can be pass NULL in case one is not interested in the transparency plane.
883/// Conversely, 'luma' can be passed NULL if no preallocated planes are supplied.
884/// In this case, the output buffer will be automatically allocated (using
885/// MODE_YUVA) when decoding starts. All parameters are then ignored.
886/// Returns NULL if the allocation failed or if a parameter is invalid.
887pub unsafe fn webp_inew_yuva(
888    luma: *mut u8,
889    luma_size: usize,
890    luma_stride: ::std::os::raw::c_int,
891    u: *mut u8,
892    u_size: usize,
893    u_stride: ::std::os::raw::c_int,
894    v: *mut u8,
895    v_size: usize,
896    v_stride: ::std::os::raw::c_int,
897    a: *mut u8,
898    a_size: usize,
899    a_stride: ::std::os::raw::c_int,
900) -> *mut WebPIDecoder {
901    crate::raw::webp::WebPINewYUVA(
902        luma,
903        luma_size,
904        luma_stride,
905        u,
906        u_size,
907        u_stride,
908        v,
909        v_size,
910        v_stride,
911        a,
912        a_size,
913        a_stride,
914    )
915}
916
917/// A variant of the above function to be used when data buffer contains
918/// partial data from the beginning.
919/// 
920/// In this case data buffer is not copied
921/// to the internal memory.
922/// Note that the value of the 'data' pointer can change between calls to
923/// WebPIUpdate, for instance when the data buffer is resized to fit larger data.
924pub unsafe fn webp_iupdate(
925    idec: *mut WebPIDecoder,
926    data: *const u8,
927    data_size: usize,
928) -> VP8StatusCode {
929    crate::raw::webp::WebPIUpdate(idec, data, data_size)
930}
931
932/// Internal, version-checked, entry point
933pub unsafe fn webp_init_dec_buffer_internal(
934    arg1: *mut WebPDecBuffer,
935    arg2: ::std::os::raw::c_int,
936) -> c_int {
937    crate::raw::webp::WebPInitDecBufferInternal(arg1, arg2)
938}
939
940/// Internal, version-checked, entry point
941pub unsafe fn webp_init_decoder_config_internal(
942    arg1: *mut WebPDecoderConfig,
943    arg2: ::std::os::raw::c_int,
944) -> c_int {
945    crate::raw::webp::WebPInitDecoderConfigInternal(arg1, arg2)
946}
947
948/// WebPMemoryWrite: a special WebPWriterFunction that writes to memory using
949/// the following WebPMemoryWriter object (to be set as a custom_ptr).
950pub unsafe fn webp_memory_write(
951    data: *const u8,
952    data_size: usize,
953    picture: *const WebPPicture,
954) -> c_int {
955    crate::raw::webp::WebPMemoryWrite(data, data_size, picture)
956}
957
958/// The following must be called to deallocate writer->mem memory.
959/// 
960/// The 'writer'
961/// object itself is not deallocated.
962pub unsafe fn webp_memory_writer_clear(writer: *mut WebPMemoryWriter) {
963    crate::raw::webp::WebPMemoryWriterClear(writer)
964}
965
966/// The following must be called first before any use.
967pub unsafe fn webp_memory_writer_init(writer: *mut WebPMemoryWriter) {
968    crate::raw::webp::WebPMemoryWriterInit(writer)
969}
970
971/// Converts picture->argb data to the YUV420A format.
972/// 
973/// The 'colorspace'
974/// parameter is deprecated and should be equal to WEBP_YUV420.
975/// Upon return, picture->use_argb is set to false. The presence of real
976/// non-opaque transparent values is detected, and 'colorspace' will be
977/// adjusted accordingly. Note that this method is lossy.
978/// Returns false in case of error.
979pub unsafe fn webp_picture_argb_to_yuva(
980    picture: *mut WebPPicture,
981    arg1: WebPEncCSP,
982) -> c_int {
983    crate::raw::webp::WebPPictureARGBToYUVA(picture, arg1)
984}
985
986/// Same as WebPPictureARGBToYUVA(), but the conversion is done using
987/// pseudo-random dithering with a strength 'dithering' between
988/// 0.0 (no dithering) and 1.0 (maximum dithering).
989/// 
990/// This is useful for photographic picture.
991pub unsafe fn webp_picture_argb_to_yuva_dithered(
992    picture: *mut WebPPicture,
993    colorspace: WebPEncCSP,
994    dithering: f32,
995) -> c_int {
996    crate::raw::webp::WebPPictureARGBToYUVADithered(
997        picture,
998        colorspace,
999        dithering,
1000    )
1001}
1002
1003
1004/// Convenience allocation / deallocation based on picture->width/height
1005/// 
1006/// Allocate y/u/v buffers as per colorspace/width/height specification.
1007/// Note! This function will free the previous buffer if needed.
1008/// Returns false in case of memory error.
1009pub unsafe fn webp_picture_alloc(picture: *mut WebPPicture) -> c_int {
1010    crate::raw::webp::WebPPictureAlloc(picture)
1011}
1012
1013/// Copy the pixels of *src into *dst, using WebPPictureAlloc.
1014/// 
1015/// Upon return, *dst
1016/// will fully own the copied pixels (this is not a view). The 'dst' picture need
1017/// not be initialized as its content is overwritten.
1018/// Returns false in case of memory allocation error.
1019pub unsafe fn webp_picture_copy(src: *const WebPPicture, dst: *mut WebPPicture) -> c_int {
1020    crate::raw::webp::WebPPictureCopy(src, dst)
1021}
1022
1023/// self-crops a picture to the rectangle defined by top/left/width/height.
1024/// 
1025/// Returns false in case of memory allocation error, or if the rectangle is
1026/// outside of the source picture.
1027/// The rectangle for the view is defined by the top-left corner pixel
1028/// coordinates (left, top) as well as its width and height. This rectangle
1029/// must be fully be comprised inside the 'src' source picture. If the source
1030/// picture uses the YUV420 colorspace, the top and left coordinates will be
1031/// snapped to even values.
1032pub unsafe fn webp_picture_crop(
1033    picture: *mut WebPPicture,
1034    left: ::std::os::raw::c_int,
1035    top: ::std::os::raw::c_int,
1036    width: ::std::os::raw::c_int,
1037    height: ::std::os::raw::c_int,
1038) -> c_int {
1039    crate::raw::webp::WebPPictureCrop(
1040        picture,
1041        left,
1042        top,
1043        width,
1044        height,
1045    )
1046}
1047
1048/// Compute PSNR, SSIM or LSIM distortion metric between two pictures.
1049/// 
1050/// Results
1051/// are in dB, stored in result[] in the B/G/R/A/All order. The distortion is
1052/// always performed using ARGB samples. Hence if the input is YUV(A), the
1053/// picture will be internally converted to ARGB (just for the measurement).
1054/// Warning: this function is rather CPU-intensive.
1055pub unsafe fn webp_picture_distortion(
1056    src: *const WebPPicture,
1057    ref_: *const WebPPicture,
1058    metric_type: ::std::os::raw::c_int,
1059    result: *mut f32,
1060) -> c_int {
1061    crate::raw::webp::WebPPictureDistortion(
1062        src,
1063        ref_,
1064        metric_type,
1065        result,
1066    )
1067}
1068
1069/// Release the memory allocated by WebPPictureAlloc() or WebPPictureImport*().
1070/// 
1071/// Note that this function does _not_ free the memory used by the 'picture'
1072/// object itself.
1073/// Besides memory (which is reclaimed) all other fields of 'picture' are
1074/// preserved.
1075pub unsafe fn webp_picture_free(picture: *mut WebPPicture) {
1076    crate::raw::webp::WebPPictureFree(picture)
1077}
1078
1079/// Scan the picture 'picture' for the presence of non fully opaque alpha values.
1080/// 
1081/// Returns true in such case. Otherwise returns false (indicating that the
1082/// alpha plane can be ignored altogether e.g.).
1083pub unsafe fn webp_picture_has_transparency(picture: *const WebPPicture) -> c_int {
1084    crate::raw::webp::WebPPictureHasTransparency(picture)
1085}
1086
1087pub unsafe fn webp_picture_import_bgr(
1088    picture: *mut WebPPicture,
1089    bgr: *const u8,
1090    bgr_stride: ::std::os::raw::c_int,
1091) -> c_int {
1092    crate::raw::webp::WebPPictureImportBGR(
1093        picture,
1094        bgr,
1095        bgr_stride,
1096    )
1097}
1098
1099pub unsafe fn webp_picture_import_bgra(
1100    picture: *mut WebPPicture,
1101    bgra: *const u8,
1102    bgra_stride: ::std::os::raw::c_int,
1103) -> c_int {
1104    crate::raw::webp::WebPPictureImportBGRA(
1105        picture,
1106        bgra,
1107        bgra_stride,
1108    )
1109}
1110
1111pub unsafe fn webp_picture_import_bgrx(
1112    picture: *mut WebPPicture,
1113    bgrx: *const u8,
1114    bgrx_stride: ::std::os::raw::c_int,
1115) -> c_int {
1116    crate::raw::webp::WebPPictureImportBGRX(
1117        picture,
1118        bgrx,
1119        bgrx_stride,
1120    )
1121}
1122
1123/// Colorspace conversion function to import RGB samples.
1124/// 
1125/// Previous buffer will be free'd, if any.
1126/// *rgb buffer should have a size of at least height * rgb_stride.
1127/// Returns false in case of memory error.
1128pub unsafe fn webp_picture_import_rgb(
1129    picture: *mut WebPPicture,
1130    rgb: *const u8,
1131    rgb_stride: ::std::os::raw::c_int,
1132) -> c_int {
1133    crate::raw::webp::WebPPictureImportRGB(
1134        picture,
1135        rgb,
1136        rgb_stride,
1137    )
1138}
1139
1140/// Same as `webp_picture_import_rgb`, but for RGBA buffer.
1141pub unsafe fn webp_picture_import_rgba(
1142    picture: *mut WebPPicture,
1143    rgba: *const u8,
1144    rgba_stride: ::std::os::raw::c_int,
1145) -> c_int {
1146    crate::raw::webp::WebPPictureImportRGBA(
1147        picture,
1148        rgba,
1149        rgba_stride,
1150    )
1151}
1152
1153/// Imports the RGB direct from the 32-bit format
1154/// input buffer ignoring the alpha channel.
1155/// 
1156/// Avoids needing to copy the data
1157/// to a temporary 24-bit RGB buffer to import the RGB only.
1158pub unsafe fn webp_picture_import_rgbx(
1159    picture: *mut WebPPicture,
1160    rgbx: *const u8,
1161    rgbx_stride: ::std::os::raw::c_int,
1162) -> c_int {
1163    crate::raw::webp::WebPPictureImportRGBX(
1164        picture,
1165        rgbx,
1166        rgbx_stride,
1167    )
1168}
1169
1170/// Internal, version-checked, entry point
1171pub unsafe fn webp_picture_init_internal(
1172    arg1: *mut WebPPicture,
1173    arg2: ::std::os::raw::c_int,
1174) -> c_int {
1175    crate::raw::webp::WebPPictureInitInternal(arg1, arg2)
1176}
1177
1178/// Returns true if the 'picture' is actually a view and therefore does
1179/// not own the memory for pixels.
1180pub unsafe fn webp_picture_is_view(picture: *const WebPPicture) -> c_int {
1181    crate::raw::webp::WebPPictureIsView(picture)
1182}
1183
1184/// Rescale a picture to new dimension width x height.
1185/// 
1186/// If either 'width' or 'height' (but not both) is 0 the corresponding
1187/// dimension will be calculated preserving the aspect ratio.
1188/// No gamma correction is applied.
1189/// Returns false in case of error (invalid parameter or insufficient memory).
1190pub unsafe fn webp_picture_rescale(
1191    pic: *mut WebPPicture,
1192    width: ::std::os::raw::c_int,
1193    height: ::std::os::raw::c_int,
1194) -> c_int {
1195    crate::raw::webp::WebPPictureRescale(pic, width, height)
1196}
1197
1198/// Performs 'sharp' RGBA->YUVA420 downsampling and colorspace conversion.
1199/// 
1200/// Downsampling is handled with extra care in case of color clipping. This
1201/// method is roughly 2x slower than WebPPictureARGBToYUVA() but produces better
1202/// and sharper YUV representation.
1203/// Returns false in case of error.
1204pub unsafe fn webp_picture_sharp_argb_to_yuva(picture: *mut WebPPicture) -> c_int {
1205    crate::raw::webp::WebPPictureSharpARGBToYUVA(picture)
1206}
1207
1208/// kept for backward compatibility
1209pub unsafe fn webp_picture_smart_argb_to_yuva(picture: *mut WebPPicture) -> c_int {
1210    crate::raw::webp::WebPPictureSmartARGBToYUVA(picture)
1211}
1212
1213/// Extracts a view from 'src' picture into 'dst'.
1214/// 
1215/// The rectangle for the view
1216/// is defined by the top-left corner pixel coordinates (left, top) as well
1217/// as its width and height. This rectangle must be fully be comprised inside
1218/// the 'src' source picture. If the source picture uses the YUV420 colorspace,
1219/// the top and left coordinates will be snapped to even values.
1220/// Picture 'src' must out-live 'dst' picture. Self-extraction of view is allowed
1221/// ('src' equal to 'dst') as a mean of fast-cropping (but note that doing so,
1222/// the original dimension will be lost). Picture 'dst' need not be initialized
1223/// with WebPPictureInit() if it is different from 'src', since its content will
1224/// be overwritten.
1225/// Returns false in case of memory allocation error or invalid parameters.
1226pub unsafe fn webp_picture_view(
1227    src: *const WebPPicture,
1228    left: ::std::os::raw::c_int,
1229    top: ::std::os::raw::c_int,
1230    width: ::std::os::raw::c_int,
1231    height: ::std::os::raw::c_int,
1232    dst: *mut WebPPicture,
1233) -> c_int {
1234    crate::raw::webp::WebPPictureView(
1235        src,
1236        left,
1237        top,
1238        width,
1239        height,
1240        dst,
1241    )
1242}
1243
1244/// Converts picture->yuv to picture->argb and sets picture->use_argb to true.
1245/// 
1246/// The input format must be YUV_420 or YUV_420A. The conversion from YUV420 to
1247/// ARGB incurs a small loss too.
1248/// Note that the use of this colorspace is discouraged if one has access to the
1249/// raw ARGB samples, since using YUV420 is comparatively lossy.
1250/// Returns false in case of error.
1251pub unsafe fn webp_picture_yuva_to_argb(picture: *mut WebPPicture) -> c_int {
1252    crate::raw::webp::WebPPictureYUVAToARGB(picture)
1253}
1254
1255/// Compute the single distortion for packed planes of samples.
1256/// 
1257/// 'src' will be compared to 'ref', and the raw distortion stored into
1258/// '*distortion'. The refined metric (log(MSE), log(1 - ssim),...' will be
1259/// stored in '*result'.
1260/// 'x_step' is the horizontal stride (in bytes) between samples.
1261/// 'src/ref_stride' is the byte distance between rows.
1262/// Returns false in case of error (bad parameter, memory allocation error, ...).
1263pub unsafe fn webp_plane_distortion(
1264    src: *const u8,
1265    src_stride: usize,
1266    ref_: *const u8,
1267    ref_stride: usize,
1268    width: ::std::os::raw::c_int,
1269    height: ::std::os::raw::c_int,
1270    x_step: usize,
1271    type_: ::std::os::raw::c_int,
1272    distortion: *mut f32,
1273    result: *mut f32,
1274) -> c_int {
1275    crate::raw::webp::WebPPlaneDistortion(
1276        src,
1277        src_stride,
1278        ref_,
1279        ref_stride,
1280        width,
1281        height,
1282        x_step,
1283        type_,
1284        distortion,
1285        result,
1286    )
1287}
1288
1289/// Returns true if 'config' is non-NULL and all configuration parameters are
1290/// within their valid ranges.
1291pub unsafe fn webp_validate_config(config: *const WebPConfig) -> c_int {
1292    crate::raw::webp::WebPValidateConfig(config)
1293}
1294
1295#[link(name = "cbits")]
1296extern "C" {
1297    /// Should always be called, to initialize a fresh WebPConfig structure before
1298    /// modification.
1299    /// 
1300    /// Returns false in case of version mismatch. WebPConfigInit()
1301    /// must have succeeded before using the 'config' object.
1302    /// Note that the default values are lossless=0 and quality=75.
1303    pub fn webp_config_init(config: *mut WebPConfig) -> c_int;
1304
1305    /// This function will initialize the configuration according to a predefined
1306    /// set of parameters (referred to by 'preset') and a given quality factor.
1307    /// 
1308    /// This function can be called as a replacement to WebPConfigInit(). Will
1309    /// return false in case of error.
1310    pub fn webp_config_preset(
1311        config: *mut WebPConfig,
1312        preset: WebPPreset,
1313        quality: c_float,
1314    ) -> c_int;
1315
1316    /// Should always be called, to initialize the structure.
1317    /// 
1318    /// Returns false in case
1319    /// of version mismatch. WebPPictureInit() must have succeeded before using the
1320    /// 'picture' object.
1321    /// Note that, by default, use_argb is false and colorspace is WEBP_YUV420.
1322    pub fn webp_picture_init(picture: *mut WebPPicture) -> c_int;
1323}
1324
1325
1326mod test {
1327    use super::*;
1328
1329    #[test]
1330    fn test_create_webp_config() {
1331        let mut config: WebPConfig = unsafe {std::mem::zeroed()};
1332        unsafe {
1333            assert!(webp_config_init(&mut config) != 0);
1334            assert!(webp_validate_config(&mut config) != 0);
1335        };
1336    }
1337
1338    #[test]
1339    fn test_create_webp_picture() {
1340        let mut picture: WebPPicture = unsafe {std::mem::zeroed()};
1341        unsafe {
1342            webp_picture_init(&mut picture);
1343        };
1344    }
1345}