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
impl MtmdBitmap
Sourcepub fn from_image_data(
nx: u32,
ny: u32,
data: &[u8],
) -> Result<Self, MtmdBitmapError>
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 matchnx * ny * 3NullResult- 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());Sourcepub fn from_audio_data(data: &[f32]) -> Result<Self, MtmdBitmapError>
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 setupSourcepub fn from_file(ctx: &MtmdContext, path: &str) -> Result<Self, MtmdBitmapError>
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
CStringError- Path contains null bytesNullResult- File could not be loaded or processed
Sourcepub fn from_buffer(
ctx: &MtmdContext,
data: &[u8],
) -> Result<Self, MtmdBitmapError>
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
Trait Implementations§
Source§impl Clone for MtmdBitmap
impl Clone for MtmdBitmap
Source§fn clone(&self) -> MtmdBitmap
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MtmdBitmap
impl Debug for MtmdBitmap
Source§impl Drop for MtmdBitmap
impl Drop for MtmdBitmap
impl Send for MtmdBitmap
impl Sync for MtmdBitmap
Auto Trait Implementations§
impl Freeze for MtmdBitmap
impl RefUnwindSafe for MtmdBitmap
impl Unpin for MtmdBitmap
impl UnsafeUnpin for MtmdBitmap
impl UnwindSafe for MtmdBitmap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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