.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "notcurses_visual" "3" "v2.0.4" "" "" .hy .SH NAME .PP notcurses_visual - notcurses multimedia .SH SYNOPSIS .PP \f[B]#include \f[R] .IP .nf \f[C] typedef enum { NCSCALE_NONE, NCSCALE_SCALE, NCSCALE_STRETCH, } ncscale_e; typedef enum { NCBLIT_DEFAULT, // let the ncvisual pick NCBLIT_1x1, // spaces only NCBLIT_2x1, // halves + 1x1 NCBLIT_2x2, // quadrants + 2x1 NCBLIT_3x2, // sextants + 1x1 NCBLIT_4x1, // four vertical levels NCBLIT_BRAILLE, // 4 rows, 2 cols (braille) NCBLIT_8x1, // eight vertical levels NCBLIT_SIXEL, // 6 rows, 1 col (RGB) } ncblitter_e; #define NCVISUAL_OPTION_NODEGRADE 0x0001 #define NCVISUAL_OPTION_BLEND 0x0002 struct ncvisual_options { struct ncplane* n; ncscale_e scaling; int ***y***, x; int begy, begx; // origin of rendered section int leny, lenx; // size of rendered section ncblitter_e blitter; // glyph set to use uint64_t flags; // bitmask over NCVISUAL_OPTION_* }; typedef int\ (*streamcb)(struct notcurses*, struct ncvisual*, void*); \f[R] .fi .PP \f[B]bool notcurses_canopen_images(const struct notcurses* \f[R]\f[I]nc\f[R]\f[B]);\f[R] .PP \f[B]bool notcurses_canopen_videos(const struct notcurses* \f[R]\f[I]nc\f[R]\f[B]);\f[R] .PP \f[B]bool notcurses_cansixel(const struct notcurses* \f[R]\f[I]nc\f[R]\f[B]);\f[R] .PP \f[B]struct ncvisual* ncvisual_from_file(const char* \f[R]\f[I]file\f[R]\f[B]);\f[R] .PP \f[B]struct ncvisual* ncvisual_from_rgba(const void* \f[R]\f[I]rgba\f[R]\f[B], int \f[R]\f[I]rows\f[R]\f[B], int \f[R]\f[I]rowstride\f[R]\f[B], int \f[R]\f[I]cols\f[R]\f[B]);\f[R] .PP \f[B]struct ncvisual* ncvisual_from_bgra(const void* \f[R]\f[I]bgra\f[R]\f[B], int \f[R]\f[I]rows\f[R]\f[B], int \f[R]\f[I]rowstride\f[R]\f[B], int \f[R]\f[I]cols\f[R]\f[B]);\f[R] .PP \f[B]struct ncvisual* ncvisual_from_plane(struct ncplane* \f[R]\f[I]n\f[R]\f[B], ncblitter_e \f[R]\f[I]blit\f[R]\f[B], int \f[R]\f[I]begy\f[R]\f[B], int \f[R]\f[I]begx\f[R]\f[B], int \f[R]\f[I]leny\f[R]\f[B], int \f[R]\f[I]lenx\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_geom(const struct notcurses* \f[R]\f[I]nc\f[R]\f[B], const struct ncvisual* \f[R]\f[I]n\f[R]\f[B], const struct ncvisual_options* \f[R]\f[I]vopts\f[R]\f[B], int* \f[R]\f[I]y\f[R]\f[B], int* \f[R]\f[I]x\f[R]\f[B], int* \f[R]\f[I]toy\f[R]\f[B], int* \f[R]\f[I]tox\f[R]\f[B]);\f[R] .PP \f[B]void ncvisual_destroy(struct ncvisual* \f[R]\f[I]ncv\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_decode(struct ncvisual* \f[R]\f[I]ncv\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_decode_loop(struct ncvisual* \f[R]\f[I]ncv\f[R]\f[B]);\f[R] .PP \f[B]struct ncplane* ncvisual_render(struct notcurses* \f[R]\f[I]nc\f[R]\f[B], struct ncvisual* \f[R]\f[I]ncv\f[R]\f[B], const struct ncvisual_options* \f[R]\f[I]vopts\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_simple_streamer(struct ncplane* \f[R]\f[I]n\f[R]\f[B], struct ncvisual* \f[R]\f[I]ncv\f[R]\f[B], const struct timespec* \f[R]\f[I]disptime\f[R]\f[B], void* \f[R]\f[I]curry\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_stream(struct notcurses* \f[R]\f[I]nc\f[R]\f[B], struct ncvisual* \f[R]\f[I]ncv\f[R]\f[B], float \f[R]\f[I]timescale\f[R]\f[B], streamcb \f[R]\f[I]streamer\f[R]\f[B], const struct ncvisual_options* \f[R]\f[I]vopts\f[R]\f[B], void* \f[R]\f[I]curry\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_rotate(struct ncvisual* \f[R]\f[I]n\f[R]\f[B], double \f[R]\f[I]rads\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_resize(struct ncvisual* \f[R]\f[I]n\f[R]\f[B], int \f[R]\f[I]rows\f[R]\f[B], int \f[R]\f[I]cols\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_polyfill_yx(struct ncvisual* \f[R]\f[I]n\f[R]\f[B], int \f[R]\f[I]y\f[R]\f[B], int \f[R]\f[I]x\f[R]\f[B], uint32_t \f[R]\f[I]rgba\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_at_yx(const struct ncvisual* \f[R]\f[I]n\f[R]\f[B], int \f[R]\f[I]y\f[R]\f[B], int \f[R]\f[I]x\f[R]\f[B], uint32_t* \f[R]\f[I]pixel\f[R]\f[B]);\f[R] .PP \f[B]int ncvisual_set_yx(const struct ncvisual* \f[R]\f[I]n\f[R]\f[B], int \f[R]\f[I]y\f[R]\f[B], int \f[R]\f[I]x\f[R]\f[B], uint32_t \f[R]\f[I]pixel\f[R]\f[B]);\f[R] .PP \f[B]char* ncvisual_subtitle(const struct ncvisual* \f[R]\f[I]ncv\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_lex_scalemode(const char* \f[R]\f[I]op\f[R]\f[B], ncscale_e* \f[R]\f[I]scaling\f[R]\f[B]);\f[R] .PP \f[B]const char* notcurses_str_scalemode(ncscale_e \f[R]\f[I]scaling\f[R]\f[B]);\f[R] .PP \f[B]int notcurses_lex_blitter(const char* \f[R]\f[I]op\f[R]\f[B], ncblitter_e* \f[R]\f[I]blitter\f[R]\f[B]);\f[R] .PP \f[B]const char* notcurses_str_blitter(ncblitter_e \f[R]\f[I]blitter\f[R]\f[B]);\f[R] .PP \f[B]ncblitter_e ncvisual_default_blitter(bool \f[R]\f[I]utf8\f[R]\f[B], ncscale_e \f[R]\f[I]scaling\f[R]\f[B]);\f[R] .SH DESCRIPTION .PP An \f[B]ncvisual\f[R] is a virtual pixel framebuffer. They can be created from RGBA/BGRA data in memory (\f[B]ncvisual_from_rgba\f[R]/\f[B]ncvisual_from_bgra\f[R]), or from the content of a suitable \f[B]ncplane\f[R] (\f[B]ncvisual_from_ncplane\f[R]). If Notcurses was built against a multimedia engine (FFMpeg or OpenImageIO), image and video files can be loaded into visuals using \f[B]ncvisual_from_file\f[R]. \f[B]ncvisual_from_file\f[R] discovers the container and codecs, but does not verify that the entire file is well-formed. \f[B]ncvisual_decode\f[R] ought be invoked to recover subsequent frames, once per frame. \f[B]ncvisual_decode_loop\f[R] will return to the first frame, as if \f[B]ncvisual_decode\f[R] had never been called. .PP Once the visual is loaded, it can be transformed using \f[B]ncvisual_rotate\f[R] and \f[B]ncvisual_resize\f[R]. These are persistent operations, unlike any scaling that takes place at render time. If a subtitle is associated with the frame, it can be acquired with \f[B]ncvisual_subtitle\f[R]. .PP \f[B]ncvisual_from_rgba\f[R] and \f[B]ncvisual_from_bgra\f[R] both require a number of \f[B]rows\f[R], a number of image columns \f[B]cols\f[R], and a virtual row length of \f[B]rowstride\f[R] / 4 columns. The input data must provide 32 bits per pixel, and thus must be at least \f[B]rowstride\f[R] * \f[B]rows\f[R] bytes, of which a \f[B]cols\f[R] * \f[B]rows\f[R] * 4-byte subset is used. It is not possible to \f[B]mmap(2)\f[R] an image file and use it directly\[en]decompressed, decoded data is necessary. The resulting plane will be ceil(\f[B]rows\f[R]/2) rows, and \f[B]cols\f[R] columns. \f[B]ncvisual_from_plane\f[R] requires specification of a rectangle via \f[B]begy\f[R], \f[B]begx\f[R], \f[B]leny\f[R], and \f[B]lenx\f[R]. The only valid characters within this region are those used by the \f[B]NCBLIT_2x2\f[R] blitter, though this may change in the future. .PP \f[B]ncvisual_rotate\f[R] executes a rotation of \f[B]rads\f[R] radians, in the clockwise (positive) or counterclockwise (negative) direction. .PP \f[B]ncvisual_subtitle\f[R] will return a UTF-8-encoded subtitle corresponding to the current frame if such a subtitle was decoded. Note that a subtitle might be returned for multiple frames, or might not. .PP \f[B]ncvisual_render\f[R] blits the visual to an \f[B]ncplane\f[R], based on the contents of its \f[B]struct ncvisual_options\f[R]. If \f[B]n\f[R] is not \f[B]NULL\f[R], it specifies the plane on which to render, and \f[B]y\f[R]/\f[B]x\f[R] specify a location within that plane. Otherwise, a new plane will be created, and placed at \f[B]y\f[R]/\f[B]x\f[R] relative to the rendering area. \f[B]begy\f[R]/\f[B]begx\f[R] specify the upper left corner of a subsection of the \f[B]ncvisual\f[R] to render, while \f[B]leny\f[R]/\f[B]lenx\f[R] specify the geometry of same. \f[B]flags\f[R] is a bitfield over: .IP \[bu] 2 \f[B]NCVISUAL_OPTION_NODEGRADE\f[R] If the specified blitter is not available, fail rather than degrading. .IP \[bu] 2 \f[B]NCVISUAL_OPTION_BLEND\f[R]: Render with \f[B]CELL_ALPHA_BLEND\f[R]. .SH BLITTERS .PP The different \f[B]ncblitter_e\f[R] values select from among available glyph sets: .IP \[bu] 2 \f[B]NCBLIT_DEFAULT\f[R]: Let the \f[B]ncvisual\f[R] choose its own blitter. .IP \[bu] 2 \f[B]NCBLIT_1x1\f[R]: Spaces only. Works in ASCII, unlike other blitters. .IP \[bu] 2 \f[B]NCBLIT_2x1\f[R]: Adds the half blocks (\[u2584]\[u2580]) to \f[B]NCBLIT_1x1\f[R]. .IP \[bu] 2 \f[B]NCBLIT_2x2\f[R]: Adds left and right half blocks (\[u258C]\[u2590]) and quadrants (\[u2596]\[u2597]\[u259F]\[u2599]) to \f[B]NCBLIT_2x1\f[R]. .IP \[bu] 2 \f[B]NCBLIT_3x2\f[R]: Adds sextants to \f[B]NCBLIT_1x1\f[R]. .IP \[bu] 2 \f[B]NCBLIT_4x1\f[R]: Adds \[14] and \[34] blocks (\[u2582]\[u2586]) to \f[B]NCBLIT_2x1\f[R]. .IP \[bu] 2 \f[B]NCBLIT_BRAILLE\f[R]: 4 rows and 2 columns of braille (\[u2840]\[u2844]\[u2846]\[u2847]\[u2880]\[u28C0]\[u28C4]\[u28C6]\[u28C7]\[u28A0]\[u28E0]\[u28E4]\[u28E6]\[u28E7]\[u28B0]\[u28F0]\[u28F4]\[u28F6]\[u28F7]\[u28B8]\[u28F8]\[u28FC]\[u28FE]\[u28FF]). .IP \[bu] 2 \f[B]NCBLIT_8x1\f[R]: Adds \[18], \[38], \[58], and \[78] blocks (\[u2587]\[u2585]\[u2583]\[u2581]) to \f[B]NCBLIT_4x1\f[R]. .IP \[bu] 2 \f[B]NCBLIT_SIXEL\f[R]: Sixel, a 6-by-1 RGB pixel arrangement. .PP \f[B]NCBLIT_4x1\f[R] and \f[B]NCBLIT_8x1\f[R] are intended for use with plots, and are not really applicable for general visuals. .SH RETURN VALUES .PP \f[B]notcurses_canopen_images\f[R] and \f[B]notcurses_canopen_videos\f[R] returns true if images and videos, respecitvely, can be decoded, or false if Notcurses was built with insufficient multimedia support. .PP \f[B]ncvisual_from_file\f[R] returns an \f[B]ncvisual\f[R] object on success, or \f[B]NULL\f[R] on failure. Success indicates that the specified \f[B]file\f[R] was opened, and enough data was read to make a firm codec identification. It does not imply that the entire file is properly-formed. .PP \f[B]ncvisual_decode\f[R] returns 0 on success, or 1 on end of file, or -1 on failure. It is only necessary for multimedia-based visuals. It advances one frame for each call. \f[B]ncvisual_decode_loop\f[R] has the same return values: when called following decoding of the last frame, it will return 1, but a subsequent \f[B]ncvisual_render\f[R] will return the first frame. .PP \f[B]ncvisual_from_plane\f[R] returns \f[B]NULL\f[R] if the \f[B]ncvisual\f[R] cannot be created and bound. This is usually due to illegal content in the source \f[B]ncplane\f[R]. .PP \f[B]ncvisual_render\f[R] returns \f[B]NULL\f[R] on error, and otherwise the plane to which the visual was rendered. If \f[B]opts->n\f[R] is provided, this will be \f[B]opts->n\f[R]. Otherwise, a plane will be created, perfectly sized for the visual and the specified blitter. .PP \f[B]ncvisual_geom\f[R] returns non-zero if the \f[B]blitter\f[R] is invalid. .PP \f[B]ncvisual_default_blitter\f[R] returns the blitter selected by \f[B]NCBLIT_DEFAULT\f[R] in the specified configuration. If UTF8 is not enabled, this will always be \f[B]NCBLIT_1x1\f[R]. Otherwise, if \f[B]NCSCALE_STRETCH\f[R] is in use, this will be \f[B]NCBLIT_3x2\f[R]; if the scaling is any other value, \f[B]NCBLIT_2x1\f[R] will be used. .SH NOTES .PP Multimedia decoding requires that Notcurses be built with either FFmpeg or OpenImageIO support. What formats can be decoded is totally dependent on the linked library. OpenImageIO does not support subtitles. .SH BUGS .PP \f[B]ncvisual_rotate\f[R] currently supports only \f[B]M_PI\f[R]/2 and -\f[B]M_PI\f[R]/2 radians for \f[B]rads\f[R], but this will change soon. .PP \f[B]NCBLIT_SIXEL\f[R] is not yet implemented, and is only infrequently supported among terminals. .PP Some fonts are lacking the Braille characters necessary for \f[B]NCBLIT_BRAILLE\f[R]. .SH SEE ALSO .PP \f[B]notcurses(3)\f[R], \f[B]notcurses_plane(3)\f[R], \f[B]utf-8(7)\f[R] .SH AUTHORS nick black .