Browse Source

* src/caca.c:

+ Minor change to the dithering names.
  * TODO:
    + Added cacaview TODO.
  * doc/cacaview.1:
    + Wrote a manpage for cacaview.
  * examples/Makefile.am:
    + Moved the -DX_DISPLAY_MISSING=1 here.
  * examples/view.c:
    + Capital 'D' cycles through dithering modes in reverse order.
    + Sleep when there is nothing to do.
    + Cosmetic code reorganisation.
tags/v0.99.beta14
Sam Hocevar sam 21 years ago
parent
commit
82685f90e5
5 changed files with 146 additions and 79 deletions
  1. +10
    -1
      TODO
  2. +51
    -0
      doc/cacaview.1
  3. +1
    -1
      examples/Makefile.am
  4. +81
    -74
      examples/view.c
  5. +3
    -3
      src/caca.c

+ 10
- 1
TODO View File

@@ -33,5 +33,14 @@ Misc


Documentation 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



+ 51
- 0
doc/cacaview.1 View File

@@ -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 <sam@zoy.org>.

+ 1
- 1
examples/Makefile.am View File

@@ -27,7 +27,7 @@ if USE_IMLIB2
cacaview = cacaview cacaview = cacaview
cacaview_SOURCES = view.c cacaview_SOURCES = view.c
cacaview_LDADD = ../src/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) 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_CFLAGS = `imlib2-config --cflags`
cacaview_LDFLAGS = `imlib2-config --libs` cacaview_LDFLAGS = `imlib2-config --libs`
endif endif


+ 81
- 74
examples/view.c View File

@@ -26,8 +26,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <malloc.h> #include <malloc.h>
#include <unistd.h>


#define X_DISPLAY_MISSING 1
#include <Imlib2.h> #include <Imlib2.h>


#include "caca.h" #include "caca.h"
@@ -101,10 +101,13 @@ int main(int argc, char **argv)
reload = 1; reload = 1;
break; break;
case CACA_EVENT_KEY_PRESS | 'd': case CACA_EVENT_KEY_PRESS | 'd':
case CACA_EVENT_KEY_PRESS | 'D':
dithering = (dithering + 1) % 4; dithering = (dithering + 1) % 4;
update = 1; update = 1;
break; break;
case CACA_EVENT_KEY_PRESS | 'D':
dithering = (dithering - 1) % 4;
update = 1;
break;
case CACA_EVENT_KEY_PRESS | '+': case CACA_EVENT_KEY_PRESS | '+':
zoom++; zoom++;
if(zoom > 48) zoom = 48; else update = 1; if(zoom > 48) zoom = 48; else update = 1;
@@ -143,7 +146,7 @@ int main(int argc, char **argv)
update = 1; update = 1;
break; break;
case CACA_EVENT_KEY_PRESS | '?': case CACA_EVENT_KEY_PRESS | '?':
help = !help;
help = 1;
update = 1; update = 1;
break; break;
case CACA_EVENT_KEY_PRESS | 'q': case CACA_EVENT_KEY_PRESS | 'q':
@@ -173,82 +176,86 @@ int main(int argc, char **argv)
free(buffer); 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) if(bitmap)


+ 3
- 3
src/caca.c View File

@@ -184,9 +184,9 @@ const char *caca_get_dithering_name(enum caca_dithering dithering)
{ {
static const char *dithering_names[] = static const char *dithering_names[] =
{ {
"none",
"ordered 4x4",
"ordered 8x8",
"no",
"4x4 ordered",
"8x8 ordered",
"random" "random"
}; };




Loading…
Cancel
Save