pub struct MtmdBitmap { /* private fields */ }Expand description
An image or audio bitmap ready for multimodal encoding.
§Image bitmaps
The raw pixel data must be in RGBRGBRGB… (interleaved) format. The total
number of bytes must be nx * ny * 3.
§Audio bitmaps
The raw sample data must be little-endian f32 PCM samples. The total
number of bytes must be n_samples * 4.
Implementations§
Source§impl MtmdBitmap
impl MtmdBitmap
Sourcepub fn from_rgb(nx: u32, ny: u32, data: &[u8]) -> Result<Self>
pub fn from_rgb(nx: u32, ny: u32, data: &[u8]) -> Result<Self>
Create a bitmap from raw RGB pixel data.
nx– image width in pixelsny– image height in pixelsdata– raw pixel bytes in RGBRGB… format; must benx * ny * 3bytes
§Errors
Returns MtmdError::BitmapCreateFailed if the underlying C call
returns null.
Sourcepub fn from_audio(samples: &[f32]) -> Result<Self>
pub fn from_audio(samples: &[f32]) -> Result<Self>
Create an audio bitmap from PCM f32 samples.
samples– slice of PCM float samples
§Errors
Returns MtmdError::BitmapCreateFailed if the underlying C call
returns null.
Sourcepub fn from_file(ctx: &MtmdContext, path: impl AsRef<Path>) -> Result<Self>
pub fn from_file(ctx: &MtmdContext, path: impl AsRef<Path>) -> Result<Self>
Load a bitmap from a file (image or audio).
Supported image formats: JPEG, PNG, BMP, GIF, and others handled by
stb_image. Supported audio formats: WAV, MP3, FLAC (via miniaudio).
§Errors
Returns MtmdError::BitmapCreateFailed if the file cannot be loaded.
Sourcepub fn from_buf(ctx: &MtmdContext, buf: &[u8]) -> Result<Self>
pub fn from_buf(ctx: &MtmdContext, buf: &[u8]) -> Result<Self>
Load a bitmap from an in-memory buffer containing a file.
The format is auto-detected (image vs audio via magic bytes).
§Errors
Returns MtmdError::BitmapCreateFailed if decoding fails.
Sourcepub fn set_mergeable(&mut self, mergeable: bool)
pub fn set_mergeable(&mut self, mergeable: bool)
Mark this bitmap as mergeable with an adjacent mergeable bitmap.
Video-capable models such as Qwen-VL merge consecutive frames into one
chunk (a temporal merge). MtmdVideo::read_next already sets this on
the frames it produces; you only need it when you build frames yourself
with Self::from_rgb and expect them to merge. Without it each frame
becomes its own chunk, which costs tokens and loses temporal structure.
Wraps mtmd_bitmap_set_mergeable.
Sourcepub fn is_audio(&self) -> bool
pub fn is_audio(&self) -> bool
Returns true if this bitmap contains audio (rather than image) data.