Skip to main content

MtmdBitmap

Struct MtmdBitmap 

Source
pub struct MtmdBitmap {
    pub bitmap: NonNull<mtmd_bitmap>,
}
Expand description

Safe wrapper around mtmd_bitmap.

Represents bitmap data for images or audio that can be processed by the multimodal system. For images, data is stored in RGB format. For audio, data is stored as PCM F32 samples.

Fields§

§bitmap: NonNull<mtmd_bitmap>

Raw pointer to the underlying mtmd_bitmap.

Implementations§

Source§

impl MtmdBitmap

Source

pub fn from_image_data( nx: u32, ny: u32, data: &[u8], ) -> Result<Self, MtmdBitmapError>

Create a bitmap from image data in RGB format.

§Errors
  • InvalidDataSize - Data length doesn’t match nx * ny * 3
  • NullResult - Underlying C function returned null
§Examples
use llama_cpp_bindings::mtmd::MtmdBitmap;

// Create a 2x2 red image
let red_pixel = [255, 0, 0]; // RGB values for red
let image_data = red_pixel.repeat(4); // 2x2 = 4 pixels

let bitmap = MtmdBitmap::from_image_data(2, 2, &image_data);
assert!(bitmap.is_ok());
Source

pub fn from_audio_data(data: &[f32]) -> Result<Self, MtmdBitmapError>

Create a bitmap from audio data in PCM F32 format.

§Errors
  • NullResult - Underlying C function returned null
§Examples
use llama_cpp_bindings::mtmd::MtmdBitmap;

// Create a simple sine wave audio sample
let audio_data: Vec<f32> = (0..100)
    .map(|sample_index| (sample_index as f32 * 0.1).sin())
    .collect();

let bitmap = MtmdBitmap::from_audio_data(&audio_data);
// Note: This will likely fail without proper MTMD context setup
Source

pub fn from_file(ctx: &MtmdContext, path: &str) -> Result<Self, MtmdBitmapError>

Create a bitmap from a file.

Supported formats:

  • Images: formats supported by stb_image (jpg, png, bmp, gif, etc.)
  • Audio: formats supported by miniaudio (wav, mp3, flac)
§Errors

Returns an MtmdBitmapError variant matching the wrapper’s status code.

Source

pub fn from_buffer( ctx: &MtmdContext, data: &[u8], ) -> Result<Self, MtmdBitmapError>

Create a bitmap from a buffer containing file data.

Supported formats:

  • Images: formats supported by stb_image (jpg, png, bmp, gif, etc.)
  • Audio: formats supported by miniaudio (wav, mp3, flac)
§Errors
  • NullResult - Buffer could not be processed
Source

pub fn nx(&self) -> u32

Get bitmap width in pixels.

Source

pub fn ny(&self) -> u32

Get bitmap height in pixels.

Source

pub fn data(&self) -> &[u8]

Get bitmap data as a byte slice.

For images: RGB format with length nx * ny * 3 For audio: PCM F32 format with length n_samples * 4

Source

pub fn is_audio(&self) -> bool

Check if this bitmap contains audio data (vs image data).

Source

pub fn id(&self) -> Option<String>

Get the bitmap’s optional ID string.

Source

pub fn set_id(&self, id: &str) -> Result<(), NulError>

Set the bitmap’s ID string.

§Errors

Returns an error if the ID string contains null bytes.

§Examples
bitmap.set_id("image_001")?;
assert_eq!(bitmap.id(), Some("image_001".to_string()));

Trait Implementations§

Source§

impl Clone for MtmdBitmap

Source§

fn clone(&self) -> MtmdBitmap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MtmdBitmap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MtmdBitmap

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for MtmdBitmap

Source§

impl Sync for MtmdBitmap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.