1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Test displaying of inline pictures

First tests with libchafa for displaying pictures inline.
We choose to use ASCII art for now. Reason is that the regular method
uses color escape codes and ncurses will just print those codes and not
use the colors.

Regards https://github.com/profanity-im/profanity/issues/1301
This commit is contained in:
Michael Vetter 2020-12-18 22:47:37 +01:00
parent 5bb2f47d45
commit c67bce4480
4 changed files with 62 additions and 2 deletions

View File

@ -191,6 +191,9 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.62.0], [],
[AC_MSG_ERROR([glib 2.62.0 or higher is required for profanity])])
PKG_CHECK_MODULES([gio], [gio-2.0], [],
[AC_MSG_ERROR([libgio-2.0 from glib-2.0 is required for profanity])])
#TODO: only under cond
PKG_CHECK_MODULES([pixbuf], [gdk-pixbuf-2.0], [],
[AC_MSG_ERROR([gdk-pixbuf-2.0 from glib-2.0 is required for profanity])])
### Check for other profanity dependencies
AC_SEARCH_LIBS([fmod], [m], [],
@ -203,6 +206,10 @@ PKG_CHECK_MODULES([curl], [libcurl], [],
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.22.0], [],
[AC_MSG_ERROR([sqlite3 3.22.0 or higher is required for profanity])])
#TODO: only under cond
PKG_CHECK_MODULES([chafa], [chafa >= 1.4.1], [],
[AC_MSG_ERROR([chafa needed])])
AS_IF([test "x$enable_icons_and_clipboard" != xno],
[PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.24.0],
[AC_DEFINE([HAVE_GTK], [1], [libgtk module])],
@ -359,9 +366,9 @@ AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
AS_IF([test "x$PLATFORM" = xosx],
[AM_CFLAGS="$AM_CFLAGS -Qunused-arguments"])
AM_LDFLAGS="$AM_LDFLAGS -export-dynamic"
AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $gio_CFLAGS $curl_CFLAGS $libnotify_CFLAGS $PYTHON_CPPFLAGS ${GTK_CFLAGS} ${SQLITE_CFLAGS}"
AM_CPPFLAGS="$AM_CPPFLAGS $glib_CFLAGS $gio_CFLAGS $curl_CFLAGS $libnotify_CFLAGS $PYTHON_CPPFLAGS ${GTK_CFLAGS} ${SQLITE_CFLAGS} ${chafa_CFLAGS}"
AM_CPPFLAGS="$AM_CPPFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\" -DICONS_PATH=\"\\\"$ICONS_PATH\\\"\""
LIBS="$glib_LIBS $gio_LIBS $curl_LIBS $libnotify_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS $PYTHON_LDFLAGS ${GTK_LIBS} ${SQLITE_LIBS} $LIBS"
LIBS="$glib_LIBS $gio_LIBS $curl_LIBS $libnotify_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS $PYTHON_LDFLAGS ${GTK_LIBS} ${SQLITE_LIBS} ${chafa_LIBS} $LIBS"
AC_SUBST(AM_LDFLAGS)
AC_SUBST(AM_CFLAGS)

View File

@ -407,6 +407,7 @@ cons_about(void)
getmaxyx(stdscr, rows, cols);
if (prefs_get_boolean(PREF_SPLASH)) {
win_pictest(console);
_cons_splash_logo();
} else {

View File

@ -44,6 +44,10 @@
#include <glib.h>
//TODO: ifdef
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <chafa.h>
#ifdef HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
#elif HAVE_NCURSES_H
@ -1953,3 +1957,48 @@ win_insert_last_read_position_marker(ProfWin* window, char* id)
g_date_time_unref(time);
}
void
win_pictest(ProfWin* window)
{
GdkPixbuf *file = gdk_pixbuf_new_from_file ("/home/michael/Pictures/test.png", NULL);
//GdkPixbuf *file = gdk_pixbuf_new_from_file ("/home/michael/ask2.png", NULL);
if (file == NULL) {
win_println(window, THEME_ERROR, "!", "pictest");
return;
}
ChafaCanvasConfig *config;
ChafaCanvas *canvas;
ChafaSymbolMap *symbol_map;
symbol_map = chafa_symbol_map_new ();
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_ALL);
chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_ASCII);
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_BRAILLE);
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_BLOCK | CHAFA_SYMBOL_TAG_BORDER);
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_BLOCK | CHAFA_SYMBOL_TAG_BORDER | CHAFA_SYMBOL_TAG_SPACE);
// TODO: use chafa_calc_canvas_geometry() to get recommended canvas size
// TODO: could be a that a user shrinks its terminal. then we would need to redraw I guess?
config = chafa_canvas_config_new ();
//chafa_canvas_config_set_geometry (config, 23, 12);
chafa_canvas_config_set_geometry (config, 100, 65);
chafa_canvas_config_set_symbol_map (config, symbol_map);
// mono for now (no escape code)
chafa_canvas_config_set_canvas_mode (config, CHAFA_CANVAS_MODE_FGBG);
canvas = chafa_canvas_new (config);
//CHAFA_PIXEL_RGBA8_UNASSOCIATED,
guchar *pixels = gdk_pixbuf_get_pixels (file);
chafa_canvas_draw_all_pixels (canvas,
CHAFA_PIXEL_ARGB8_UNASSOCIATED,
pixels,
gdk_pixbuf_get_width(file),
gdk_pixbuf_get_height(file),
gdk_pixbuf_get_rowstride(file));
GString *gs = chafa_canvas_build_ansi (canvas);
win_print(window, THEME_DEFAULT, "!", gs->str);
}

View File

@ -93,4 +93,7 @@ void win_sub_page_up(ProfWin* window);
void win_insert_last_read_position_marker(ProfWin* window, char* id);
void win_remove_entry_message(ProfWin* window, const char* const id);
// TODO: ifdef
void win_pictest(ProfWin* window);
#endif