diff --git a/TODO b/TODO index 7092581..926c31d 100644 --- a/TODO +++ b/TODO @@ -33,5 +33,14 @@ Misc Documentation - o Everything is still to do. + o Everything is still to do + + +cacaview + + o Aspect ratio + + o File browser + + o Handle GIF and PNG transparency with checkered background diff --git a/doc/cacaview.1 b/doc/cacaview.1 index e69de29..829c118 100644 --- a/doc/cacaview.1 +++ b/doc/cacaview.1 @@ -0,0 +1,51 @@ +.TH cacaview 1 "2003-11-30" "libcaca" +.SH NAME +cacaview \- ASCII image browser +.SH SYNOPSIS +.B cacaview [FILE...] +.RI +.SH DESCRIPTION +.B cacaview +is a lightweight text mode image viewer. It renders images using colour +ASCII characters. It is a powerful add-on to famous console programs such +as the mutt email client, the slrn newsreader and the links or w3m web +browsers. +.PP +.B cacaview +can load the most widespread image formats: PNG, JPEG, GIF, PNG, BMP etc. +.PP +You can zoom and scroll the image around for more details, and choose four +different dithering modes. All commands are accessible through a single +key press. +.SH KEYS +.TP +.B ? +show the help screen +.TP +.B n, p +switch to next image, previous image +.TP +.B Left, Right, Up, Down or h, l, k, j +scroll the image around +.TP +.B +, - +zoom in and out +.TP +.B z +reset the zoom level to normal +.TP +.B d +toggle the dithering mode (no dithering, 4x4 ordered dithering, 8x8 ordered +dithering and random dithering) +.TP +.B q +exit the program +.SH EXAMPLE +cacaview /usr/share/pixmaps/*.* +.SH BUGS +There is no support for aspect ratio yet. Also, since there is no way +yet to load an image from +.B cacaview +it is completely useless when run without an argument. +.SH AUTHOR +This manual page was written by Sam Hocevar . diff --git a/examples/Makefile.am b/examples/Makefile.am index 077fbd5..bda25ab 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -27,7 +27,7 @@ if USE_IMLIB2 cacaview = cacaview cacaview_SOURCES = view.c cacaview_LDADD = ../src/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -cacaview_CPPFLAGS = -I$(top_srcdir)/src +cacaview_CPPFLAGS = -I$(top_srcdir)/src -DX_DISPLAY_MISSING=1 cacaview_CFLAGS = `imlib2-config --cflags` cacaview_LDFLAGS = `imlib2-config --libs` endif diff --git a/examples/view.c b/examples/view.c index ca13ff8..5332481 100644 --- a/examples/view.c +++ b/examples/view.c @@ -26,8 +26,8 @@ #include #include #include +#include -#define X_DISPLAY_MISSING 1 #include #include "caca.h" @@ -101,10 +101,13 @@ int main(int argc, char **argv) reload = 1; break; case CACA_EVENT_KEY_PRESS | 'd': - case CACA_EVENT_KEY_PRESS | 'D': dithering = (dithering + 1) % 4; update = 1; break; + case CACA_EVENT_KEY_PRESS | 'D': + dithering = (dithering - 1) % 4; + update = 1; + break; case CACA_EVENT_KEY_PRESS | '+': zoom++; if(zoom > 48) zoom = 48; else update = 1; @@ -143,7 +146,7 @@ int main(int argc, char **argv) update = 1; break; case CACA_EVENT_KEY_PRESS | '?': - help = !help; + help = 1; update = 1; break; case CACA_EVENT_KEY_PRESS | 'q': @@ -173,82 +176,86 @@ int main(int argc, char **argv) free(buffer); } - if(update) + if(!update) { - caca_clear(); - caca_set_dithering(dithering); - caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); + usleep(10000); + continue; + } - if(!items) - caca_printf(ww / 2 - 5, wh / 2, " No image. "); - else if(!image) - { - char *buffer = malloc(ww + 1); - snprintf(buffer, ww, " Error loading `%s'. ", list[current]); - buffer[ww] = '\0'; - caca_putstr((ww - strlen(buffer)) / 2, wh / 2, buffer); - free(buffer); - } - else if(zoom < 0) - { - int xo = (ww - 1) / 2; - int yo = (wh - 1) / 2; - int xn = (ww - 1) / (2 - zoom); - int yn = (wh - 1) / (2 - zoom); - caca_draw_bitmap(xo - xn, yo - yn, xo + xn, yo + yn, - bitmap, pixels); - } - else if(zoom > 0) - { - struct caca_bitmap *newbitmap; - int xn = w / (2 + zoom); - int yn = h / (2 + zoom); - if(x < xn) x = xn; - if(y < yn) y = yn; - if(xn + x > w) x = w - xn; - if(yn + y > h) y = h - yn; - newbitmap = caca_create_bitmap(32, 2 * xn, 2 * yn, 4 * w, - 0x00ff0000, 0x0000ff00, 0x000000ff); - caca_draw_bitmap(0, 0, ww - 1, wh - 1, newbitmap, - pixels + 4 * (x - xn) + 4 * w * (y - yn)); - caca_free_bitmap(newbitmap); - } - else - { - caca_draw_bitmap(0, 0, ww - 1, wh - 1, bitmap, pixels); - } + caca_clear(); + caca_set_dithering(dithering); + caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); - caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); - caca_draw_line(0, 0, ww - 1, 0, ' '); - caca_draw_line(0, wh - 1, ww - 1, wh - 1, '-'); - caca_putstr(0, 0, "q:Quit +/-/x:Zoom h/j/k/l: Move " - "d:Dithering ?:Help"); - caca_printf(3, wh - 1, "cacaview %s", VERSION); - caca_printf(ww / 2 - 5, wh - 1, "(dithering: %s)", - caca_get_dithering_name(dithering)); - caca_printf(ww - 14, wh - 1, - "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); - - if(help) - { - caca_putstr(2, 2, " +: zoom in "); - caca_putstr(2, 3, " -: zoom out "); - caca_putstr(2, 4, " x: reset zoom "); - caca_putstr(2, 5, " ------------------- "); - caca_putstr(2, 6, " hjkl: move view "); - caca_putstr(2, 7, " arrows: move view "); - caca_putstr(2, 8, " ------------------- "); - caca_putstr(2, 9, " d: dithering method "); - caca_putstr(2, 10, " ------------------- "); - caca_putstr(2, 11, " ?: help "); - caca_putstr(2, 12, " q: quit "); - - help = 0; - } + if(!items) + caca_printf(ww / 2 - 5, wh / 2, " No image. "); + else if(!image) + { + char *buffer = malloc(ww + 1); + snprintf(buffer, ww, " Error loading `%s'. ", list[current]); + buffer[ww] = '\0'; + caca_putstr((ww - strlen(buffer)) / 2, wh / 2, buffer); + free(buffer); + } + else if(zoom < 0) + { + int xo = (ww - 1) / 2; + int yo = (wh - 1) / 2; + int xn = (ww - 1) / (2 - zoom); + int yn = (wh - 1) / (2 - zoom); + caca_draw_bitmap(xo - xn, yo - yn, xo + xn, yo + yn, + bitmap, pixels); + } + else if(zoom > 0) + { + struct caca_bitmap *newbitmap; + int xn = w / (2 + zoom); + int yn = h / (2 + zoom); + if(x < xn) x = xn; + if(y < yn) y = yn; + if(xn + x > w) x = w - xn; + if(yn + y > h) y = h - yn; + newbitmap = caca_create_bitmap(32, 2 * xn, 2 * yn, 4 * w, + 0x00ff0000, 0x0000ff00, 0x000000ff); + caca_draw_bitmap(0, 0, ww - 1, wh - 1, newbitmap, + pixels + 4 * (x - xn) + 4 * w * (y - yn)); + caca_free_bitmap(newbitmap); + } + else + { + caca_draw_bitmap(0, 0, ww - 1, wh - 1, bitmap, pixels); + } - caca_refresh(); - update = 0; + caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE); + caca_draw_line(0, 0, ww - 1, 0, ' '); + caca_draw_line(0, wh - 1, ww - 1, wh - 1, '-'); + caca_putstr(0, 0, "q:Quit n/p:Next/Prev +/-/x:Zoom " + "h/j/k/l: Move d:Dithering"); + caca_putstr(ww - strlen("?:Help"), 0, "?:Help"); + caca_printf(3, wh - 1, "cacaview %s", VERSION); + caca_printf(ww / 2 - 5, wh - 1, "(%s dithering)", + caca_get_dithering_name(dithering)); + caca_printf(ww - 14, wh - 1, + "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); + + if(help) + { + caca_putstr(ww - 22, 2, " +: zoom in "); + caca_putstr(ww - 22, 3, " -: zoom out "); + caca_putstr(ww - 22, 4, " x: reset zoom "); + caca_putstr(ww - 22, 5, " ------------------- "); + caca_putstr(ww - 22, 6, " hjkl: move view "); + caca_putstr(ww - 22, 7, " arrows: move view "); + caca_putstr(ww - 22, 8, " ------------------- "); + caca_putstr(ww - 22, 9, " d: dithering method "); + caca_putstr(ww - 22, 10, " ------------------- "); + caca_putstr(ww - 22, 11, " ?: help "); + caca_putstr(ww - 22, 12, " q: quit "); + + help = 0; } + + caca_refresh(); + update = 0; } if(bitmap) diff --git a/src/caca.c b/src/caca.c index e18de06..62632c4 100644 --- a/src/caca.c +++ b/src/caca.c @@ -184,9 +184,9 @@ const char *caca_get_dithering_name(enum caca_dithering dithering) { static const char *dithering_names[] = { - "none", - "ordered 4x4", - "ordered 8x8", + "no", + "4x4 ordered", + "8x8 ordered", "random" };