libwebp_sys/
mux_types.rs

1use std::mem;
2use std::os::raw::*;
3
4use libc::{memcpy, memset};
5
6#[cfg(feature = "1_1")]
7use crate::{WebPFree, WebPMalloc};
8#[cfg(not(feature = "1_1"))]
9use libc::{free as WebPFree, malloc as WebPMalloc};
10
11#[allow(non_camel_case_types)]
12pub type WebPFeatureFlags = u32;
13
14#[cfg(not(feature = "0_6"))]
15#[deprecated(note = "Removed as of libwebp 0.6.0")]
16pub const FRAGMENTS_FLAG: WebPFeatureFlags = 0x00000001;
17pub const ANIMATION_FLAG: WebPFeatureFlags = 0x00000002;
18pub const XMP_FLAG: WebPFeatureFlags = 0x00000004;
19pub const EXIF_FLAG: WebPFeatureFlags = 0x00000008;
20pub const ALPHA_FLAG: WebPFeatureFlags = 0x00000010;
21pub const ICCP_FLAG: WebPFeatureFlags = 0x00000020;
22#[cfg(feature = "0_6")]
23pub const ALL_VALID_FLAGS: WebPFeatureFlags = 0x0000003E;
24
25#[allow(non_camel_case_types)]
26pub type WebPMuxAnimDispose = u32;
27
28pub const WEBP_MUX_DISPOSE_NONE: WebPMuxAnimDispose = 0;
29pub const WEBP_MUX_DISPOSE_BACKGROUND: WebPMuxAnimDispose = 1;
30
31#[allow(non_camel_case_types)]
32pub type WebPMuxAnimBlend = u32;
33
34pub const WEBP_MUX_BLEND: WebPMuxAnimBlend = 0;
35pub const WEBP_MUX_NO_BLEND: WebPMuxAnimBlend = 1;
36
37#[repr(C)]
38#[derive(Debug, Clone, Copy)]
39pub struct WebPData {
40    pub bytes: *const u8,
41    pub size: usize,
42}
43
44#[allow(non_snake_case)]
45#[inline]
46pub unsafe extern "C" fn WebPDataInit(webp_data: *mut WebPData) {
47    if !webp_data.is_null() {
48        memset(webp_data as *mut c_void, 0, mem::size_of::<WebPData>());
49    }
50}
51
52// Clears the contents of the 'webp_data' object by calling free(). Does not
53// deallocate the object itself.
54#[allow(non_snake_case)]
55#[inline]
56pub unsafe extern "C" fn WebPDataClear(webp_data: *mut WebPData) {
57    if !webp_data.is_null() {
58        WebPFree((*webp_data).bytes as *mut c_void);
59        WebPDataInit(webp_data);
60    }
61}
62
63// Allocates necessary storage for 'dst' and copies the contents of 'src'.
64// Returns true on success.
65#[allow(non_snake_case)]
66#[cfg_attr(feature = "must-use", must_use)]
67#[inline]
68pub unsafe extern "C" fn WebPDataCopy(src: *const WebPData, dst: *mut WebPData) -> c_int {
69    if src.is_null() || dst.is_null() {
70        return 0;
71    }
72    WebPDataInit(dst);
73    if !(*src).bytes.is_null() && (*src).size != 0 {
74        (*dst).bytes = WebPMalloc((*src).size) as *mut u8;
75        if (*dst).bytes.is_null() {
76            return 0;
77        }
78        memcpy(
79            (*dst).bytes as *mut c_void,
80            (*src).bytes as *const c_void,
81            (*src).size,
82        );
83        (*dst).size = (*src).size;
84    }
85    return 1;
86}