diff --git a/src/lib/libav.c b/src/lib/libav.c index 0af2d1cde..d4fd412c8 100644 --- a/src/lib/libav.c +++ b/src/lib/libav.c @@ -29,7 +29,7 @@ void ncvisual_destroy(ncvisual* ncv){ } } -static void +/* static void print_frame_summary(const AVCodecContext* cctx, const AVFrame* f){ char pfmt[128]; av_get_pix_fmt_string(pfmt, sizeof(pfmt), f->format); @@ -65,7 +65,7 @@ print_frame_summary(const AVCodecContext* cctx, const AVFrame* f){ f->best_effort_timestamp, f->key_frame ? "" : "non-", f->quality); -} +}*/ AVFrame* ncvisual_decode(struct ncvisual* nc, int* averr){ bool have_frame = false; @@ -151,6 +151,10 @@ ncvisual* ncplane_visual_open(struct ncplane* nc, const char* filename, int* ave memset(ncv, 0, sizeof(*ncv)); ncv->ncp = nc; ncplane_dim_yx(nc, &ncv->dstheight, &ncv->dstwidth); + // FIXME we only want to do this if we're not already large enough to + // faithfully reproduce the image, methinks? + //ncv->dstwidth *= 2; + ncv->dstheight *= 2; *averr = avformat_open_input(&ncv->fmtctx, filename, NULL, NULL); if(*averr < 0){ fprintf(stderr, "Couldn't open %s (%s)\n", filename, av_err2str(*averr)); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 491aa6b4f..7da49541f 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1553,23 +1553,38 @@ int ncvisual_render(const ncvisual* ncv){ ncplane_cursor_move_yx(ncv->ncp, 0, 0); const int linesize = f->linesize[0]; const unsigned char* data = f->data[0]; - for(y = 0 ; y < f->height && y < dimy ; ++y){ + for(y = 0 ; y < f->height / 2 && y < dimy ; ++y){ for(x = 0 ; x < f->width && x < dimx ; ++x){ int bpp = av_get_bits_per_pixel(av_pix_fmt_desc_get(f->format)); - const unsigned char* rgbbase = data + (linesize * y) + (x * bpp / CHAR_BIT); + const unsigned char* rgbbase_up = data + (linesize * (y * 2)) + (x * bpp / CHAR_BIT); + const unsigned char* rgbbase_down = data + (linesize * (y * 2 + 1)) + (x * bpp / CHAR_BIT); /*fprintf(stderr, "[%04d/%04d] %p bpp: %d lsize: %d %02x %02x %02x %02x\n", y, x, rgbbase, bpp, linesize, rgbbase[0], rgbbase[1], rgbbase[2], rgbbase[3]);*/ cell c = CELL_TRIVIAL_INITIALIZER; - if(!rgbbase[3]){ - cell_fg_default(&c); + // use the default for the background, as that's the only way it's + // effective in that case anyway + if(!rgbbase_up[3] || !rgbbase_down[3]){ cell_bg_default(&c); - if(cell_load(ncv->ncp, &c, " ") <= 0){ - return -1; + if(!rgbbase_up[3] && !rgbbase_down[3]){ + if(cell_load(ncv->ncp, &c, " ") <= 0){ + return -1; + } + cell_fg_default(&c); + }else if(!rgbbase_up[3]){ // down has the color + if(cell_load(ncv->ncp, &c, "\u2584") <= 0){ // lower half block + return -1; + } + cell_set_fg(&c, rgbbase_down[0], rgbbase_down[1], rgbbase_down[2]); + }else{ // up has the color + if(cell_load(ncv->ncp, &c, "\u2580") <= 0){ // upper half block + return -1; + } + cell_set_fg(&c, rgbbase_up[0], rgbbase_up[1], rgbbase_up[2]); } }else{ - cell_set_fg(&c, rgbbase[0], rgbbase[1], rgbbase[2]); - cell_set_bg(&c, rgbbase[0], rgbbase[1], rgbbase[2]); - if(cell_load(ncv->ncp, &c, "▓") <= 0){ + cell_set_fg(&c, rgbbase_up[0], rgbbase_up[1], rgbbase_up[2]); + cell_set_bg(&c, rgbbase_down[0], rgbbase_down[1], rgbbase_down[2]); + if(cell_load(ncv->ncp, &c, "\u2580") <= 0){ // upper half block return -1; } }