Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline images #1466

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ AC_ARG_WITH([themes],
[AS_HELP_STRING([--with-themes[[=PATH]]], [install themes (default yes)])])
AC_ARG_ENABLE([icons-and-clipboard],
[AS_HELP_STRING([--enable-icons-and-clipboard], [enable GTK tray icons and clipboard paste support])])
AC_ARG_ENABLE([inline-images],
[AS_HELP_STRING([--enable-inline-images], [enable inline display of images])])

### plugins

Expand Down Expand Up @@ -323,6 +325,16 @@ if test "x$enable_omemo" != xno; then
AM_COND_IF([BUILD_OMEMO], [AC_DEFINE([HAVE_OMEMO], [1], [Have OMEMO])])
fi

if test "x$enable_inline_images" = xyes; then
PKG_CHECK_MODULES([pixbuf], [gdk-pixbuf-2.0], [],
[AC_MSG_ERROR([gdk-pixbuf-2.0 from glib-2.0 is required for inline image support])])

PKG_CHECK_MODULES([chafa], [chafa >= 1.4.1], [],
[AC_MSG_ERROR([chafa >= 1.4.1 needed for inline image support])])

AC_DEFINE([HAVE_INLINE_IMAGE], [1], [Have inline image])
fi

AS_IF([test "x$with_themes" = xno],
[THEMES_INSTALL="false"],
[THEMES_INSTALL="true"])
Expand Down Expand Up @@ -359,9 +371,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)
Expand Down
3 changes: 3 additions & 0 deletions src/ui/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ cons_about(void)
getmaxyx(stdscr, rows, cols);

if (prefs_get_boolean(PREF_SPLASH)) {
#ifdef HAVE_INLINE_IMAGE
win_pictest(console);
#endif
_cons_splash_logo();
} else {

Expand Down
64 changes: 64 additions & 0 deletions src/ui/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
#include <curses.h>
#endif

#ifdef HAVE_INLINE_IMAGE
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <chafa.h>
#endif

#include "log.h"
#include "config/theme.h"
#include "config/preferences.h"
Expand Down Expand Up @@ -1953,3 +1958,62 @@ win_insert_last_read_position_marker(ProfWin* window, char* id)

g_date_time_unref(time);
}

#ifdef HAVE_INLINE_IMAGE
void
win_pictest(ProfWin* window)
{
gchar *path = get_expanded_path("~/test.png");
GdkPixbuf *file = gdk_pixbuf_new_from_file (path, NULL);
if (file == NULL) {
win_println(window, THEME_ERROR, "!", "pictest");
g_free(path);
return;
}
g_free(path);

ChafaCanvasConfig *config;
ChafaCanvas *canvas;
ChafaSymbolMap *symbol_map;

symbol_map = chafa_symbol_map_new ();
chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_ASCII);
//chafa_symbol_map_add_by_tags (symbol_map, CHAFA_SYMBOL_TAG_ALL);
//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);

// calculate how much space we have on curent screen
gint width = getmaxx(stdscr);
gint height = screen_mainwin_row_end() - screen_mainwin_row_end();
// get recommended canvas size. image will be scaled accordingly
chafa_calc_canvas_geometry(gdk_pixbuf_get_width(file), gdk_pixbuf_get_height(file),
&width,
&height,
0.5,
TRUE,
FALSE);

// 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, width, height);
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);

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_println(window, THEME_DEFAULT, "!", gs->str);
}
#endif
4 changes: 4 additions & 0 deletions src/ui/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ 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);

#ifdef HAVE_INLINE_IMAGE
void win_pictest(ProfWin* window);
#endif

#endif