1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
//! `NcVisual*` methods and associated functions.
use core::ptr::{null, null_mut};
#[cfg(not(feature = "std"))]
use alloc::format;
use core::ffi::c_void;
use crate::{
c_api::{self, NcResult_i32, NCRESULT_ERR},
cstring, error, error_ref_mut, Nc, NcBlitter, NcDirect, NcError, NcPalette, NcPixel, NcPlane,
NcResult, NcRgba, NcScale, NcTime, NcVisual, NcVisualGeometry, NcVisualOptions,
};
/// # NcVisual Constructors & destructors
impl NcVisual {
/// Like [from_rgba][NcVisual#method.from_rgba], but 'bgra' is arranged as BGRA.
///
/// *C style function: [ncvisual_from_bgra()][c_api::ncvisual_from_bgra].*
pub fn from_bgra<'a>(
bgra: &[u8],
rows: u32,
rowstride: u32,
cols: u32,
) -> NcResult<&'a mut NcVisual> {
error_ref_mut![
unsafe {
c_api::ncvisual_from_bgra(
bgra.as_ptr() as *const c_void,
rows as i32,
rowstride as i32,
cols as i32,
)
},
&format![
"NcVisual::from_bgra(bgra, {}, {}, {})",
rows, rowstride, cols
]
]
}
/// Opens an `NcVisual` at `file`, extracts the codec and parameters and
/// decodes the first image to memory.
///
/// *C style function: [ncvisual_from_file()][c_api::ncvisual_from_file].*
pub fn from_file<'a>(file: &str) -> NcResult<&'a mut NcVisual> {
let cs = cstring![file];
error_ref_mut![
unsafe { c_api::ncvisual_from_file(cs.as_ptr()) },
&format!("NcVisual::from_file({})", file)
]
}
/// Promotes an `NcPlane` to an `NcVisual`.
///
/// The plane may contain only spaces, half blocks, and full blocks.
/// This will be checked, and any other glyph will result in an error.
///
/// This function exists so that planes can be subjected to `NcVisual`
/// transformations.
///
/// If possible, it's better to create the `NcVisual` from memory using
/// [`from_rgba`][NcVisual#method.from_rgba].
///
/// Use `None` for either or both of `beg_y` and `beg_x` in order to
/// use the current cursor position along that axis.
///
/// Use `None` for either or both of `len_y` and `len_x` in order to
/// go through the boundary of the plane in that axis (same as `0`).
///
/// *C style function: [ncvisual_from_plane()][c_api::ncvisual_from_plane].*
pub fn from_plane<'a>(
plane: &NcPlane,
blitter: impl Into<NcBlitter>,
beg_y: Option<u32>,
beg_x: Option<u32>,
len_y: Option<u32>,
len_x: Option<u32>,
) -> NcResult<&'a mut NcVisual> {
let blitter = blitter.into();
error_ref_mut![
unsafe {
c_api::ncvisual_from_plane(
plane,
blitter.into(),
beg_y.unwrap_or(u32::MAX) as i32,
beg_x.unwrap_or(u32::MAX) as i32,
len_y.unwrap_or(0),
len_x.unwrap_or(0),
)
},
&format!(
"NcVisual::from_file(plane, {}, {:?}, {:?}, {:?}, {:?})",
blitter, beg_y, beg_x, len_y, len_x
)
]
}
/// Constructs an `NcVisual` from a nul-terminated Sixel control `sequence`.
///
/// *C style function: [ncvisual_from_sixel()][c_api::ncvisual_from_sixel].*
pub fn from_sixel<'a>(sequence: &str, len_y: u32, len_x: u32) -> NcResult<&'a mut NcVisual> {
let cs = cstring![sequence];
error_ref_mut![
unsafe { c_api::ncvisual_from_file(cs.as_ptr()) },
&format!("NcVisual::from_sixel({}, {}, {})", sequence, len_y, len_x)
]
}
/// Like [`from_rgba`][NcVisual#method.from_rgba], but the pixels are
/// 4-byte RGBX. Alpha is filled in throughout using 'alpha'.
///
/// `rowstride` must be a multiple of 4.
///
/// *C style function: [ncvisual_from_rgb_loose()][c_api::ncvisual_from_rgb_loose].*
pub fn from_rgb_loose<'a>(
rgb: &[u8],
rows: u32,
rowstride: u32,
cols: u32,
alpha: u8,
) -> NcResult<&'a mut NcVisual> {
error_ref_mut![
unsafe {
c_api::ncvisual_from_rgb_loose(
rgb.as_ptr() as *const c_void,
rows as i32,
rowstride as i32,
cols as i32,
alpha as i32,
)
},
&format!(
"NcVisual::from_rgb_loose(rgba, {}, {}, {}, {})",
rows, rowstride, cols, alpha
)
]
}
/// Like [`from_rgba`][NcVisual#method.from_rgba], but the pixels are
/// 3-byte RGB. Alpha is filled in throughout using 'alpha'.
///
/// *C style function: [ncvisual_from_rgb_packed()][c_api::ncvisual_from_rgb_packed].*
pub fn from_rgb_packed<'a>(
rgb: &[u8],
rows: u32,
rowstride: u32,
cols: u32,
alpha: u8,
) -> NcResult<&'a mut NcVisual> {
error_ref_mut![
unsafe {
c_api::ncvisual_from_rgb_packed(
rgb.as_ptr() as *const c_void,
rows as i32,
rowstride as i32,
cols as i32,
alpha as i32,
)
},
&format!(
"NcVisual::from_rgb_packed(rgba, {}, {}, {}, {})",
rows, rowstride, cols, alpha
)
]
}
/// Prepares an `NcVisual`, and its underlying `NcPlane`,
/// based off RGBA content in memory at `rgba`.
///
/// `rgba` is laid out as `rows` lines, each of which is `rowstride` bytes
/// in length. Each line has `cols` 32-bit 8bpc RGBA pixels followed by
/// possible padding (there will be rowstride - cols * 4 bytes of padding).
///
/// The total size of `rgba` is thus (rows * rowstride) bytes, of which
/// (rows * cols * 4) bytes are actual non-padding data.
///
/// *C style function: [ncvisual_from_rgba()][c_api::ncvisual_from_rgba].*
pub fn from_rgba<'a>(
rgba: &[u8],
rows: u32,
rowstride: u32,
cols: u32,
) -> NcResult<&'a mut NcVisual> {
error_ref_mut![
unsafe {
c_api::ncvisual_from_rgba(
rgba.as_ptr() as *const c_void,
rows as i32,
rowstride as i32,
cols as i32,
)
},
&format!(
"NcVisual::from_rgba(rgba, {}, {}, {})",
rows, rowstride, cols
)
]
}
/// Like [`from_rgba`][NcVisual#method.from_rgba], but `data` is
/// `pstride`-byte palette-indexed pixels, arranged in `rows` lines of
/// `rowstride` bytes each, composed of `cols` pixels.
///
/// `palette` is an array of at least `palsize` [`NcChannel`][crate::NcChannel]s.
///
/// *C style function: [ncvisual_from_palidx()][c_api::ncvisual_from_palidx].*
pub fn from_palidx<'a>(
data: &[u8],
rows: u32,
rowstride: u32,
cols: u32,
//
palsize: u8,
pstride: u32,
palette: &NcPalette,
) -> NcResult<&'a mut NcVisual> {
error_ref_mut![
unsafe {
c_api::ncvisual_from_palidx(
data.as_ptr() as *const c_void,
rows as i32,
rowstride as i32,
cols as i32,
//
palsize as i32,
pstride as i32,
palette.chans.as_slice().as_ptr(),
//
// palette.len(),
//
)
},
&format!(
"NcVisual::from_palidx(data, {}, {}, {}, {}, {}, palette)",
rows, rowstride, cols, palsize, pstride
)
]
}
/// Destroys this NcVisual.
///
/// Rendered elements will not be disrupted, but the visual can be neither
/// decoded nor rendered any further.
///
/// *C style function: [ncvisual_destroy()][c_api::ncvisual_destroy].*
pub fn destroy(&mut self) {
unsafe { c_api::ncvisual_destroy(self) }
}
}
/// # NcVisual Methods
impl NcVisual {
/// Extracts the next frame from the NcVisual.
///
/// Returns 0 for normal frames, and 1 to indicate EOF.
///
/// *C style function: [ncvisual_decode()][c_api::ncvisual_decode].*
pub fn decode(&mut self) -> NcResult<NcResult_i32> {
let res = unsafe { c_api::ncvisual_decode(self) };
if res == NCRESULT_ERR {
Err(NcError::with_msg(res, "NcVisual.decode()"))
} else {
Ok(res)
}
}
/// Extracts the next frame from the NcVisual, ala [decode][NcVisual#method.decode],
/// but if we have reached the end, rewinds to the first frame.
///
/// *A subsequent [NcVisual.render]() will render the first frame,
/// as if the ncvisual had been closed and reopened.*
///
/// Returns 0 for normal frames and 1 to indicate EOF.
///
/// *C style function: [ncvisual_decode_loop()][c_api::ncvisual_decode_loop].*
pub fn decode_loop(&mut self) -> NcResult<NcResult_i32> {
let res = unsafe { c_api::ncvisual_decode_loop(self) };
if res == NCRESULT_ERR {
Err(NcError::with_msg(res, "NcVisual.decode_loop()"))
} else {
Ok(res)
}
}
/// Returns [`NcVisualGeometry`].
///
/// if [`Nc`] is not provided, only [`pix_yx`] will be filled in, with the
/// true pixel geometry of the current `NcVisual`.
///
/// Additionally [`cdim_yx`] and [`maxpixel_yx`] are only ever filled in if we
/// know them, and `maxpixel_yx` is only defined for `NcBlitter`::PIXEL.
///
/// # See also
/// - [`Nc.visual_geom`][Nc#method.visual_geom]
///
/// [`pix_yx`]: NcVisualGeometry#structfield.pix_yx
/// [`cdim_yx`]: NcVisualGeometry#structfield.cdim_yx
/// [`scale_yx`]: NcVisualGeometry#structfield.scale_yx
/// [`maxpixel_yx`]: NcVisualGeometry#structfield.maxpixel_yx
/// [`blitter`]: NcVisualGeometry#structfield.blitter
///
/// *C style function: [ncvisual_geom()][c_api::ncvisual_geom].*
pub fn geom(
&self,
nc: Option<&Nc>,
vopts: Option<&NcVisualOptions>,
) -> NcResult<NcVisualGeometry> {
let mut vg = c_api::NcVGeom::new();
let nc_ptr: *const Nc = if let Some(nc) = nc { nc } else { null() };
let vo_ptr: *const NcVisualOptions =
if let Some(o) = vopts { o } else { &NcVisualOptions::default() };
let res = unsafe { crate::c_api::ncvisual_geom(nc_ptr, self, vo_ptr, &mut vg) };
if res <= c_api::NCRESULT_ERR {
return Err(NcError::with_msg(
res,
&format!["NcVisual.geom({:?}, {:?})", vopts, nc],
));
}
let (pix_yx, cdim_yx, rpix_yx, rcell_yx, scale_yx, maxpixel_yx, beg_yx, len_yx);
// if an `Nc` context is not provided, only `pix_yx` will be filled in.
if nc.is_none() {
pix_yx = Some((vg.pixy, vg.pixx));
cdim_yx = None;
rpix_yx = None;
rcell_yx = None;
scale_yx = None;
maxpixel_yx = None;
beg_yx = None;
len_yx = None;
} else {
// `maxpixel_yx` only is defined for `Ncblitter::PIXEL`.
if vg.blitter == NcBlitter::Pixel.into() {
maxpixel_yx = Some((vg.maxpixely, vg.maxpixelx));
} else {
maxpixel_yx = None;
}
// `beg_yx` & `len_yx` can be safely ignored if they're both all 0.
if vg.begy | vg.begx | vg.leny | vg.lenx == 0 {
beg_yx = None;
len_yx = None;
} else {
beg_yx = Some((vg.begy, vg.begx));
len_yx = Some((vg.leny, vg.lenx));
}
// valid values for the following fields can't be 0 either:
if vg.pixy | vg.pixx == 0 {
pix_yx = None;
} else {
pix_yx = Some((vg.pixy, vg.pixx));
}
if vg.cdimy | vg.cdimx == 0 {
cdim_yx = None;
} else {
cdim_yx = Some((vg.cdimy, vg.cdimx));
}
if vg.scaley | vg.scalex == 0 {
scale_yx = None;
} else {
scale_yx = Some((vg.scaley, vg.scalex));
}
if vg.rpixy | vg.rpixx == 0 {
rpix_yx = None;
} else {
rpix_yx = Some((vg.rpixy, vg.rpixx));
}
if vg.rcelly | vg.rcellx == 0 {
rcell_yx = None;
} else {
rcell_yx = Some((vg.rcelly, vg.rcellx));
}
}
let vgeometry = NcVisualGeometry {
pix_yx,
cdim_yx,
rpix_yx,
rcell_yx,
scale_yx,
maxpixel_yx,
beg_yx,
len_yx,
blitter: (vg.blitter as crate::c_api::NcBlitter_u32).into(),
};
Ok(vgeometry)
}
/// Gets the default media (not plot) blitter for this environment when using
/// the specified scaling method.
///
/// Currently, this means:
/// - if lacking UTF-8, [`NcBlitter::Ascii`].
/// - otherwise, if not using *[`NcScale::Stretch`]* then [`NcBlitter::Half`].
/// - otherwise, if sextants are not known to be good, [`NcBlitter::Quadrant`].
/// - otherwise [`NcBlitter::Sextant`]
///
/// [`QUADRANT`] and [`SEXTANT`] both distort the original aspect ratio,
/// thus they are only used alongside *[`NcScale::Stretch`]*, while [`Half`]
/// is used otherwise.
///
/// *C style function: [ncvisual_media_defblitter()][c_api::ncvisual_media_defblitter].*
///
/// [`Half`]: NcBlitter::Half
/// [`Quadrant`]: NcBlitter::Quadrant
/// [`Sextant`]: NcBlitter::Sextant
pub fn media_defblitter(nc: &Nc, scale: impl Into<NcScale>) -> NcBlitter {
unsafe { c_api::ncvisual_media_defblitter(nc, scale.into().into()).into() }
}
/// Polyfills at the specified location using `rgba`.
///
/// *C style function: [ncvisual_polyfill_yx()][c_api::ncvisual_polyfill_yx].*
pub fn polyfill_yx(&mut self, y: u32, x: u32, rgba: impl Into<NcRgba>) -> NcResult<()> {
error![
unsafe { c_api::ncvisual_polyfill_yx(self, y, x, rgba.into().into()) },
&format!["NcVisual.polyfill_yx({}, {}, rgba)", y, x]
]
}
/// Renders the decoded frame according to the provided `options`.
///
/// There are 3 options for choosing the the plane used for rendering:
/// 1. if the `options` have set the flag
/// [`NcVisualFlag::ChildPlane`][crate::NcVisualFlag#associatedconstant.ChildPlane]
/// then there must be a plane, which will be the father of the one created.
/// 2. if the flag is not set and there is no plane, a new plane is created
/// as root of a new pile.
/// 3. if the flag is not set and there is a plane, we render to it.
///
/// A subregion of the visual can be rendered using `beg_y`, `beg_x`,
/// `len_y`, and `len_x`.
///
/// It is an error to specify any region beyond the boundaries of the frame.
///
/// Returns the (possibly newly-created) plane to which we drew.
///
/// Pixels may not be blitted to the standard plane.
///
/// # Safety
/// You must be careful not to end up with multiple exclusive references
/// to the returned `NcPlane`, or with one exclusive reference
/// and one or more shared references.
///
/// *C style function: [ncvisual_blit()][c_api::ncvisual_blit].*
pub unsafe fn blit(
&mut self,
nc: &mut Nc,
options: Option<&NcVisualOptions>,
) -> NcResult<&mut NcPlane> {
let options_ptr = if let Some(o) = options { o } else { null() };
error_ref_mut![c_api::ncvisual_blit(nc, self, options_ptr), "NcVisual.blit"]
}
/// Resizes the visual to `cols` X `rows` pixels.
///
/// This is a lossy transformation, unless the size is unchanged.
///
/// *C style function: [ncvisual_resize()][c_api::ncvisual_resize].*
pub fn resize(&mut self, rows: u32, cols: u32) -> NcResult<()> {
error![
unsafe { c_api::ncvisual_resize(self, rows as i32, cols as i32) },
&format!["NcVisual.resize({}, {})", rows, cols]
]
}
/// Resizes the visual to in the image to `rows` X `cols` pixels, without
/// interpolating the color values.
///
/// The original color is retained.
///
/// *C style function:
/// [ncvisual_resize_noninterpolative()][c_api::ncvisual_resize_noninterpolative].*
pub fn resize_noninterpolative(&mut self, rows: u32, cols: u32) -> NcResult<()> {
error![
unsafe { c_api::ncvisual_resize_noninterpolative(self, rows as i32, cols as i32) },
&format!["NcVisual.resize_noninterpolative({}, {})", cols, rows]
]
}
/// Rotates the visual `rads` radians.
///
/// Only M_PI/2 and -M_PI/2 are supported at the moment,
/// but this will change. (FIXME)
///
/// *C style function: [ncvisual_rotate()][c_api::ncvisual_rotate].*
pub fn rotate(&mut self, rads: f64) -> NcResult<()> {
error![
unsafe { c_api::ncvisual_rotate(self, rads) },
&format!["NcVisual.rotate({})", rads]
]
}
/// Gets the specified pixel from this NcVisual.
///
/// *C style function: [ncvisual_at_yx()][c_api::ncvisual_at_yx].*
pub fn at_yx(&self, y: u32, x: u32) -> NcResult<NcPixel> {
let mut pixel = 0;
let res = unsafe { c_api::ncvisual_at_yx(self, y, x, &mut pixel) };
error![res, "NcVisual.at_yx()", pixel.into()]
}
/// Sets the specified pixel.
///
/// *C style function: [ncvisual_set_yx()][c_api::ncvisual_set_yx].*
pub fn set_yx(&mut self, y: u32, x: u32, pixel: impl Into<NcPixel>) -> NcResult<()> {
let pixel = pixel.into();
error![
unsafe { c_api::ncvisual_set_yx(self, y, x, pixel.into()) },
&format!["NcVisual.set_yx({}, {}, {:?})", y, x, pixel]
]
}
/// Displays frames.
///
/// *Provide as an argument to ncvisual_stream().*
///
/// If you'd like subtitles to be decoded, provide an ncplane as the curry.
/// If the curry is `None`, subtitles will not be displayed.
///
/// *C style function: [ncvisual_simple_streamer()][c_api::ncvisual_simple_streamer].*
pub fn simple_streamer(
&mut self,
options: &mut NcVisualOptions,
time: &NcTime,
curry: Option<&mut NcPlane>,
) -> NcResult<()> {
if let Some(plane) = curry {
error![
unsafe {
c_api::ncvisual_simple_streamer(
self,
options,
time,
plane as *mut _ as *mut c_void,
)
},
&format![
"NcVisual.simple_streamer({:?}, {:?}, ncplane)",
options, time
]
]
} else {
error![
unsafe { c_api::ncvisual_simple_streamer(self, options, time, null_mut()) },
&format!["NcVisual.simple_streamer({:?}, {:?}, null)", options, time]
]
}
}
// /// Streams the entirety of the media, according to its own timing.
// ///
// /// Blocking, obviously.
// ///
// /// If `streamer` is provided it will be called for each frame, and its
// /// return value handled as outlined for streamcb. If streamer() returns
// /// non-zero, the stream is aborted, and that value is returned. By
// /// convention, return a positive number to indicate intentional abort from
// /// within streamer().
// ///
// /// `timescale` allows the frame duration time to be scaled. For an NcVisual
// /// naturally running at 30FPS, a 'timescale' of 0.1 will result in 300 FPS,
// /// and a `timescale` of 10 will result in 3 FPS. It is an error to supply
// /// `timescale` less than or equal to 0.
// ///
// /// *C style function: [ncvisual_streamer()][c_api::ncvisual_streamer].*
// //
// // TODO
// pub fn streamer(
// &mut self,
// nc: &mut Nc,
// options: &NcVisualOptions,
// timescale: f32,
// streamer: Option<NcStreamCb>,
// curry: Option<&mut NcPlane>,
// ) -> NcResult<()> {
// debug_assert![timescale > 0.0];
// todo![]
// }
/// If a subtitle ought be displayed at this time, return a new plane
///
/// The returned plane is bound to `parent` and contains the subtitle,
/// which might be text or graphics (depending on the input format).
///
/// *C style function: [ncvisual_subtitle_plane()][c_api::ncvisual_subtitle_plane].*
pub fn subtitle_plane(&self, parent: &mut NcPlane) -> NcResult<&mut NcPlane> {
error_ref_mut![unsafe { c_api::ncvisual_subtitle_plane(parent, self) }]
}
}
/// # `NcDirectF` Constructors & destructors
impl NcVisual {
/// Loads media from disk, but do not yet renders it (presumably because you
/// want to get its geometry via [ncdirectf_geom()][0], or to use the same
/// file with [ncdirectf_render()][1] multiple times).
///
/// You must destroy the result with [ncdirectf_free()][2];
///
/// [0]: NcVisual#method.ncdirectf_geom
/// [1]: NcVisual#method.ncdirectf_render
/// [2]: NcVisual#method.ncdirectf_free
///
/// *C style function: [ncdirectf_from_file()][c_api::ncdirectf_from_file].*
pub fn ncdirectf_from_file<'a>(ncd: &mut NcDirect, file: &str) -> NcResult<&'a mut NcVisual> {
let cs = cstring![file];
error_ref_mut![
unsafe { c_api::ncdirectf_from_file(ncd, cs.as_ptr()) },
&format!("NcVisual::ncdirectf_from_file(ncd, {})", file)
]
}
/// Frees a [`NcVisual`] returned from [ncdirectf_from_file()][0].
///
/// [0]: NcVisual#method.ncdirectf_from_file
///
/// *C style function: [ncdirectf_free()][c_api::ncdirectf_free].*
pub fn ncdirectf_free(&mut self) {
unsafe { c_api::ncdirectf_free(self) };
}
}
/// # `NcDirectF` Methods
impl NcVisual {
/// Same as [`NcDirect.render_frame()`][0], except `frame` must already have
/// been loaded.
///
/// A loaded frame may be rendered in different ways before it is destroyed.
///
/// [0]: NcDirect#method.render_frame
///
/// *C style function: [ncdirectf_render()][c_api::ncdirectf_render].*
pub fn ncdirectf_render(
&mut self,
ncd: &mut NcDirect,
options: &NcVisualOptions,
) -> NcResult<&mut NcPlane> {
error_ref_mut![
unsafe { c_api::ncdirectf_render(ncd, self, options) },
"NcVisual.ncdirectf_render()"
]
}
/// Having loaded the `frame`, get the geometry of a potential render.
///
/// *C style function: [ncdirectf_geom()][c_api::ncdirectf_geom].*
pub fn ncdirectf_geom(
&mut self,
ncd: &mut NcDirect,
options: &NcVisualOptions,
) -> NcResult<NcVisualGeometry> {
let mut geom = c_api::NcVGeom::new();
let res = unsafe { c_api::ncdirectf_geom(ncd, self, options, &mut geom) };
error![res, "NcVisual.ncdirectf_geom()", geom.into()];
}
}