implement ncvisual_from_sixel()

pull/2501/head
nick black 2 years ago committed by nick black
parent 3d0fbc4d8f
commit aa7903b370

@ -8,7 +8,7 @@ rearrangements of Notcurses.
* Added `NCOPTION_CLI_MODE`, an alias for the bitwise OR of
`NCOPTION_SCROLLING`, `NCOPTION_NO_CLEAR_BITMAPS`,
`NCOPTION_NO_ALTERNATE_SCREEN`, and `NCOPTION_PRESERVE_CURSOR`.
* Added `ncsixel_as_rgba()`.
* Added `ncvisual_from_sixel()`.
* 3.0.1 (2021-12-14)
* Added the `NCPLANE_OPTION_VSCROLL` flag. Creating an `ncplane` with this

@ -11,12 +11,12 @@ extern "C" {
uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
#define MAXCOLORS 65535
// cast is necessary for c++ callers
uint32_t* rgba = (typeof rgba)malloc(sizeof(*rgba) * leny * lenx);
uint32_t* rgba = (uint32_t*)malloc(sizeof(*rgba) * leny * lenx);
if(rgba == NULL){
return NULL;
}
// cast is necessary for c++ callers
uint32_t* colors = (typeof colors)malloc(sizeof(*colors) * MAXCOLORS);
uint32_t* colors = (uint32_t*)malloc(sizeof(*colors) * MAXCOLORS);
if(colors == NULL){
free(rgba);
return NULL;

@ -3,6 +3,7 @@
#include "builddef.h"
#include "visual-details.h"
#include "internal.h"
#include "sixel.h"
// ncvisual core code has a basic implementation in libnotcurses-core, and can
// be augmented with a "multimedia engine" -- currently FFmpeg or OpenImageIO,
@ -796,6 +797,17 @@ ncvisual* ncvisual_from_rgba(const void* rgba, int rows, int rowstride, int cols
return ncv;
}
ncvisual* ncvisual_from_sixel(const char* s, unsigned leny, unsigned lenx){
uint32_t* rgba = ncsixel_as_rgba(s, leny, lenx);
if(rgba == NULL){
logerror("failed converting sixel to rgba");
return NULL;
}
ncvisual* ncv = ncvisual_from_rgba(rgba, leny, lenx * sizeof(*rgba), lenx);
free(rgba);
return ncv;
}
ncvisual* ncvisual_from_rgb_packed(const void* rgba, int rows, int rowstride,
int cols, int alpha){
ncvisual* ncv = ncvisual_create();

@ -144,7 +144,7 @@ int oiio_resize(ncvisual* nc, unsigned rows, unsigned cols) {
return 0;
}
int oiio_blit(struct ncvisual* ncv, unsigned rows, unsigned cols,
int oiio_blit(const ncvisual* ncv, unsigned rows, unsigned cols,
ncplane* n, const struct blitset* bset,
const blitterargs* bargs) {
//fprintf(stderr, "%d/%d -> %d/%d on the resize\n", ncv->pixy, ncv->pixx, rows, cols);

Loading…
Cancel
Save