@@ -97,8 +97,7 @@ static void dealloc_canvas_and_buffers(struct vo *vo)
9797 }
9898
9999 if (priv -> frame ) {
100- talloc_free (priv -> frame );
101- priv -> frame = NULL ;
100+ TA_FREEP (& priv -> frame );
102101 }
103102}
104103
@@ -253,6 +252,10 @@ static int update_chafa_canvas(struct vo *vo, struct mp_image_params *params)
253252 if (mp_sws_reinit (priv -> sws ) < 0 )
254253 return -1 ;
255254
255+ gchar * * envp = g_get_environ ();
256+ priv -> term_info = chafa_term_db_detect (chafa_term_db_get_default (), envp );
257+ g_strfreev (envp );
258+
256259 priv -> config = chafa_canvas_config_new ();
257260
258261 // Set geometry based on terminal character cells
@@ -267,10 +270,16 @@ static int update_chafa_canvas(struct vo *vo, struct mp_image_params *params)
267270
268271 if (priv -> opts .canvas_mode >= 0 && priv -> opts .canvas_mode < CHAFA_CANVAS_MODE_MAX ) {
269272 chafa_canvas_config_set_canvas_mode (priv -> config , priv -> opts .canvas_mode );
273+ } else {
274+ ChafaCanvasMode mode = chafa_term_info_get_best_canvas_mode (priv -> term_info );
275+ chafa_canvas_config_set_canvas_mode (priv -> config , mode );
270276 }
271277
272278 if (priv -> opts .dither_mode >= 0 && priv -> opts .dither_mode < CHAFA_DITHER_MODE_MAX ) {
273279 chafa_canvas_config_set_dither_mode (priv -> config , priv -> opts .dither_mode );
280+ } else {
281+ ChafaPixelMode mode = chafa_term_info_get_best_pixel_mode (priv -> term_info );
282+ chafa_canvas_config_set_pixel_mode (priv -> config , mode );
274283 }
275284
276285 if (priv -> opts .work_factor > 0 ) {
@@ -398,7 +407,7 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame)
398407 priv -> frame -> stride [0 ]);
399408
400409 if (mpi )
401- talloc_free ( mpi );
410+ TA_FREEP ( & mpi );
402411
403412done :
404413 return VO_TRUE ;
@@ -423,6 +432,7 @@ static void flip_page(struct vo *vo)
423432
424433 chafa_canvas_print_rows (priv -> canvas , priv -> term_info , & output , & rows );
425434
435+ chafa_strwrite (TERM_ESC_SYNC_UPDATE_BEGIN );
426436
427437 for (int i = 0 ; output [i ]; i ++ )
428438 {
@@ -433,6 +443,8 @@ static void flip_page(struct vo *vo)
433443 chafa_write (output [i ]-> str , output [i ]-> len , stdout );
434444 }
435445
446+ chafa_strwrite (TERM_ESC_SYNC_UPDATE_END );
447+
436448 chafa_free_gstring_array (output );
437449}
438450
@@ -455,10 +467,6 @@ static int preinit(struct vo *vo)
455467 priv -> config = NULL ;
456468 priv -> symbol_map = NULL ;
457469
458- gchar * * envp = g_get_environ ();
459- priv -> term_info = chafa_term_db_detect (chafa_term_db_get_default (), envp );
460- g_strfreev (envp );
461-
462470 // Comment from Chafa repo
463471 /* Chafa may create and destroy GThreadPools multiple times while rendering
464472 * an image. This reduces thread churn and saves a decent amount of CPU. */
@@ -512,8 +520,8 @@ const struct vo_driver video_out_chafa = {
512520 .uninit = uninit ,
513521 .priv_size = sizeof (struct priv ),
514522 .priv_defaults = & (const struct priv ) {
515- .opts .pixel_mode = CHAFA_PIXEL_MODE_SYMBOLS ,
516- .opts .canvas_mode = CHAFA_CANVAS_MODE_TRUECOLOR ,
523+ .opts .pixel_mode = CHAFA_PIXEL_MODE_MAX ,
524+ .opts .canvas_mode = CHAFA_CANVAS_MODE_MAX ,
517525 .opts .dither_mode = CHAFA_DITHER_MODE_NONE ,
518526 .opts .work_factor = 50 ,
519527 .opts .pad_y = -1 ,
@@ -525,11 +533,13 @@ const struct vo_driver video_out_chafa = {
525533 {"width" , OPT_INT (opts .width )},
526534 {"height" , OPT_INT (opts .height )},
527535 {"pixel-mode" , OPT_CHOICE (opts .pixel_mode ,
536+ {"auto" , CHAFA_PIXEL_MODE_MAX },
528537 {"symbols" , CHAFA_PIXEL_MODE_SYMBOLS },
529538 {"sixels" , CHAFA_PIXEL_MODE_SIXELS },
530539 {"kitty" , CHAFA_PIXEL_MODE_KITTY },
531540 {"iterm2" , CHAFA_PIXEL_MODE_ITERM2 })},
532541 {"canvas-mode" , OPT_CHOICE (opts .canvas_mode ,
542+ {"auto" , CHAFA_CANVAS_MODE_MAX },
533543 {"truecolor" , CHAFA_CANVAS_MODE_TRUECOLOR },
534544 {"256" , CHAFA_CANVAS_MODE_INDEXED_256 },
535545 {"240" , CHAFA_CANVAS_MODE_INDEXED_240 },
0 commit comments