.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "notcurses_visual" "3" "v2.2.3" "" "" .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_NONE_HIRES, NCSCALE_SCALE_HIRES, } 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_PIXEL, // pixel graphics } 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]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_media_defblitter(const struct notcurses \f[R]\f[I]nc\f[R]\f[B], ncscale_e \f[R]\f[I]scaling\f[R]\f[B]);\f[R] .PP \f[B]int ncplane_qrcode(struct ncplane* \f[R]\f[I]n\f[R]\f[B], int* \f[R]\f[I]ymax\f[R]\f[B], int* \f[R]\f[I]xmax\f[R]\f[B], const void* \f[R]\f[I]data\f[R]\f[B], size_t \f[R]\f[I]len\f[R]\f[B])\f[R] .PP \f[B]int notcurses_check_pixel_support(struct notcurses* \f[R]\f[I]nc\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--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]. .PP \f[B]ncplane_qrcode\f[R] draws an ISO/IEC 18004:2015 QR Code for the \f[B]len\f[R] bytes of \f[B]data\f[R] using \f[B]NCBLIT_2x1\f[R] (this is the only blitter that will work with QR Code scanners, due to its 1:1 aspect ratio). .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_PIXEL\f[R]: Adds pixel graphics. .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. \f[B]NCBLIT_BRAILLE\f[R] doesn\[aq]t tend to work out very well for images, but (depending on the font) can be very good for plots. .PP A string can be transformed to a blitter with \f[B]notcurses_lex_blitter\f[R], recognizing \f[B]ascii\f[R], \f[B]half\f[R], \f[B]quad\f[R], \f[B]sex\f[R], \f[B]fourstep\f[R], \f[B]braille\f[R], \f[B]eightstep\f[R], and \f[B]pixel\f[R]. Conversion in the opposite direction is performed with \f[B]notcurses_str_blitter\f[R]. .PP In the absence of scaling, for a given set of pixels, more rows and columns in the blitter will result in a smaller output image. An image rendered with \f[B]NCBLIT_1x1\f[R] will be twice as tall as the same image rendered with \f[B]NCBLIT_2x1\f[R], which will be twice as wide as the same image rendered with \f[B]NCBLIT_2x2\f[R]. The same image rendered with \f[B]NCBLIT_3x2\f[R] will be one-third as tall and one-half as wide as the original \f[B]NCBLIT_1x1\f[R] render (again, this depends on \f[B]NCSCALE_NONE\f[R]). If the output size is held constant (using for instance \f[B]NCSCALE_SCALE_HIRES\f[R] and a large image), more rows and columns will result in more effective resolution. .PP A string can be transformed to a scaling mode with \f[B]notcurses_lex_scalemode\f[R], recognizing \f[B]stretch\f[R], \f[B]scalehi\f[R], \f[B]hires\f[R], \f[B]scale\f[R], and \f[B]none\f[R]. Conversion in the opposite direction is performed with \f[B]notcurses_str_scalemode\f[R]. .PP Assuming a cell is twice as tall as it is wide, \f[B]NCBLIT_1x1\f[R] (and indeed any NxN blitter) will stretch an image by a factor of 2 in the vertical dimension. \f[B]NCBLIT_2x1\f[R] will not distort the image whatsoever, as it maps a vector two pixels high and one pixel wide to a single cell. \f[B]NCBLIT_3x2\f[R] will stretch an image by a factor of 1.5. .PP The cell\[aq]s dimension in pixels is ideally evenly divisible by the blitter geometry. If \f[B]NCBLIT_3x2\f[R] is used together with a cell 8 pixels wide and 14 pixels tall, two of the vertical segments will be 5 pixels tall, while one will be 4 pixels tall. Such unequal distributions are more likely with larger blitter geometries. Likewise, there are only ever two colors available to us in a given cell. \f[B]NCBLIT_1x1\f[R] and \f[B]NCBLIT_2x2\f[R] can be perfectly represented with two colors per cell. Blitters of higher geometry are increasingly likely to require some degree of interpolation. Transparency is always honored with complete fidelity. .PP Finally, rendering operates slightly differently when two planes have both been blitted, and one lies atop the other. See \f[B]notcurses_render(3)\f[R] for more information. .SH PIXEL BLITTING .PP Some terminals support pixel-based output, either via Sixel or some bespoke mechanism. Checking for Sixel support requires interrogating the terminal and reading a response. This takes time, and will never complete if the terminal doesn\[aq]t respond. Before \f[B]NCBLIT_PIXEL\f[R] can be used, it is thus necessary to check for support with \f[B]notcurses_check_pixel_support\f[R]. If this function has not successfully returned, attempts to use \f[B]NCBLIT_PIXEL\f[R] will fall back to \f[B]NCBLIT_3x2\f[R] (or fail, if \f[B]NCVISUAL_OPTION_NODEGRADE\f[R] is used). .SH RETURN VALUES .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_media_defblitter\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]. If \f[B]\f[BI]scale\f[B]\f[R] is \f[B]NCSCALE_NONE\f[R] or \f[B]NCSCALE_SCALE\f[R], the aspect-preserving \f[B]NCBLIT_2x1\f[R] will be returned. If sextants are available (see \f[B]notcurses_cansextant\f[R]), this will be \f[B]NCBLIT_3x2\f[R], or otherwise \f[B]NCBLIT_2x2\f[R]. .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 Bad font support can ruin \f[B]NCBLIT_2x2\f[R], \f[B]NCBLIT_3x2\f[R], \f[B]NCBLIT_4x1\f[R], \f[B]NCBLIT_BRAILLE\f[R], and \f[B]NCBLIT_8x1\f[R]. Braille glyphs ought ideally draw only the raised dots, rather than drawing all eight dots with two different styles. It\[aq]s often best for the emulator to draw these glyphs itself. .SH SEE ALSO .PP \f[B]notcurses(3)\f[R], \f[B]notcurses_capabilities(3)\f[R], \f[B]notcurses_plane(3)\f[R], \f[B]notcurses_render(3)\f[R], \f[B]utf-8(7)\f[R] .SH AUTHORS nick black .