Skip to main content

wechat_media/
lib.rs

1//! Bounded media inspection shared by native transport and official profiles.
2//! Source bytes, including application trailers, are never rewritten here.
3//! WXGF inspection decodes a representative still only. Its animation timing,
4//! frame count and alpha semantics remain unknown; the original stays WXGF.
5
6mod image;
7mod video;
8mod wxgf;
9
10pub use image::ImageInspection;
11pub use video::inspect_video_container;
12pub use wxgf::wxgf_preview;
13
14pub const MAX_IMAGE_BYTES: usize = 16 * 1024 * 1024;
15/// Native ordinary-file plaintext limit, shared by transport and local storage.
16pub const MAX_FILE_BYTES: usize = 512 * 1024 * 1024;
17/// Initial source/original-video limit; normal playback is prepared separately.
18pub const MAX_VIDEO_SOURCE_BYTES: usize = 50 * 1024 * 1024;
19
20#[derive(Debug)]
21pub struct DecodedImage {
22    pub bytes: Vec<u8>,
23    pub inspection: ImageInspection,
24}
25
26/// Inspect the retained source. For WXGF, dimensions describe its still preview;
27/// `frames` does not establish the source's animation frame count.
28pub fn inspect_image(bytes: &[u8]) -> anyhow::Result<ImageInspection> {
29    if bytes.starts_with(b"wxgf") {
30        let mut inspection = wxgf_preview(bytes)?.inspection;
31        inspection.content_type = "image/x-wxgf".into();
32        inspection.animation_preserved = false;
33        return Ok(inspection);
34    }
35    image::inspect_standard_image(bytes)
36}