--- qiv-2.1_bdd/event.c 2009-03-28 12:43:20.000000000 +0100 +++ qiv-2.1/event.c 2009-03-28 13:22:45.000000000 +0100 @@ -10,13 +10,16 @@ #include #include #include +#include +#include +#include #include "qiv.h" #define STEP 3 //When using KP arrow, number of step for seeing all the image. static int jumping; static int extcommand; // [lc] -static char jcmd[100]; +static char jcmd[100]; static int jidx; static int cursor_timeout; static gboolean displaying_textwindow = FALSE; @@ -917,7 +920,7 @@ /* BDD */ /* gdk_imlib_rotate_image(q->im, -1); */ /* gdk_imlib_flip_image_vertical(q->im); */ - gdk_pixbuf_rotate_simple(q->im, COUNTERCLOCKWISE); + gdk_pixbuf_rotate_simple(q->im, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); gdk_pixbuf_flip(q->im, FALSE); snprintf(infotext, sizeof infotext, "(Rotated left)"); swap(&q->orig_w, &q->orig_h); --- qiv-2.1_bdd/image.c 2009-03-28 12:43:20.000000000 +0100 +++ qiv-2.1/image.c 2009-03-28 12:47:57.000000000 +0100 @@ -103,7 +103,7 @@ void qiv_load_image(qiv_image *q) { - GdkImlibColor color; + qiv_color_modifier color; struct stat statbuf; const char * image_name = image_names[ image_idx]; GError *gerror; --- qiv-2.1_bdd/qiv.h 2009-03-28 12:43:20.000000000 +0100 +++ qiv-2.1/qiv.h 2009-03-28 13:33:03.000000000 +0100 @@ -38,11 +38,22 @@ #define FILENAME_LEN 1024 #define MAX_DELETE 1024 +typedef struct _color_data qiv_color_modifier; + +struct _color_data +{ + unsigned char rmap[256], gmap[256], bmap[256]; + int gamma; + int brightness; + int contrast; +}; + typedef struct _qiv_image { - GdkImlibColorModifier mod; /* Image modifier (for brightness..) */ + qiv_color_modifier mod; /* Image modifier (for brightness..) */ + /*GdkImlibColorModifier mod*/; /* Image modifier (for brightness..) */ GdkPixmap *p; /* Pixmap of the image to display */ /* BDD */ -/* GdkImlibImage *im; /* Image */ */ +/* GdkImlibImage *im; Image */ GdkPixbuf *im; /* Image */ GdkWindow *win; /* Main window for windowed and fullscreen mode */ int error; /* 1 if Imlib couldn't load image */ @@ -66,10 +77,11 @@ } qiv_image; typedef struct _qiv_mgl { - GdkImlibColorModifier mod; /* Image modifier (for brightness..) */ + qiv_color_modifier mod; /* Image modifier (for brightness..) */ + /*GdkImlibColorModifier mod; *//* Image modifier (for brightness..) */ GdkPixmap *p; /* Pixmap of the image to display */ /* BDD */ -/* GdkImlibImage *im; /* Image */ */ +/* GdkImlibImage *im; Image */ GdkPixbuf *im; /* Image */ GdkWindow *win; /* window for magnify */ gint win_x, win_y, win_w, win_h; /* window coordinates */ @@ -205,3 +217,5 @@ extern int rreaddir(const char *, int); extern int rreadfile(const char *); extern int find_image(int images, char **image_names, char *name); +extern void calc_map_tables(qiv_color_modifier *); // [tw] +extern void apply_colormap (qiv_image *); // [tw] --- qiv-2.1_bdd/utils.c 2009-03-06 04:30:04.000000000 +0100 +++ qiv-2.1/utils.c 2009-03-28 13:32:30.000000000 +0100 @@ -17,6 +17,7 @@ #include #include #include +#include #include "qiv.h" #include "xmalloc.h" @@ -28,6 +29,78 @@ #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif +/* calculate mapping tables for color value + * according to brightness, contrast, gamma + * (partly from Imlib1) (TW) */ +void calc_map_tables(qiv_color_modifier * qcm) +{ + int i; + double g, b, c, ii, v; + + if (!qcm) + return; + + g = ((double)qcm->gamma) / 256; + b = ((double)qcm->brightness) / 256; + c = ((double)qcm->contrast) / 256; + if (g < 0.01) + g = 0.01; + + for (i = 0; i < 256; i++) + { + ii = ((double)i) / 256; + v = ((ii - 0.5) * c) + 0.5 + (b - 1); + if (v > 0) + v = pow(((ii - 0.5) * c) + 0.5 + (b - 1), 1 / g) * 256; + else + v = 0; + if (v > 255) + v = 255; + else if (v < 0) + v = 0; + qcm->rmap[i] = (unsigned char)v; + qcm->gmap[i] = (unsigned char)v; + qcm->bmap[i] = (unsigned char)v; + } +} + +/* apply the color mapping settings to + * the pixbuf RGB data (TW) */ +void apply_colormap (qiv_image * q) +{ + int width, height, rowstride, n_channels; + guchar *pixels, *p, *pixels_ori, *p_ori; + int x,y; + + GdkPixbuf *pixbuf, *pixbuf_ori; + + pixbuf = q->im; + pixbuf_ori = q->im; + + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + width = gdk_pixbuf_get_width (pixbuf); + height = gdk_pixbuf_get_height (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + /* this makes of course only sense, if there is + * a copy of the original pixbuf kept. (TW) */ + pixels = gdk_pixbuf_get_pixels (pixbuf); + pixels_ori = gdk_pixbuf_get_pixels (pixbuf_ori); + + for(x=0; x< width; x++) + { + for(y=0; y< height; y++) + { + p = pixels + y * rowstride + x * n_channels; + p_ori = pixels_ori + y * rowstride + x * n_channels; + p[0] = q->mod.rmap[p_ori[0]]; + p[1] = q->mod.gmap[p_ori[1]]; + p[2] = q->mod.bmap[p_ori[2]]; + } + } +} + + /* move current image to .qiv-trash */ int move2trash() {