aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--browser.c1
-rw-r--r--dither.c193
-rw-r--r--dither.h6
-rw-r--r--fb-gui.c75
-rw-r--r--ida.c2
-rw-r--r--meson.build4
-rw-r--r--viewer.c143
-rw-r--r--x11.c167
-rw-r--r--x11.h14
9 files changed, 106 insertions, 499 deletions
diff --git a/browser.c b/browser.c
index 34322e5..a200d0c 100644
--- a/browser.c
+++ b/browser.c
@@ -37,7 +37,6 @@
#include "browser.h"
#include "filter.h"
#include "x11.h"
-#include "dither.h"
#include "selections.h"
#include "filebutton.h"
#include "misc.h"
diff --git a/dither.c b/dither.c
deleted file mode 100644
index 2eaeb31..0000000
--- a/dither.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * ordered dither rotines
- *
- * stolen from The GIMP and trimmed for speed
- *
- */
-
-#include <stdlib.h>
-#include "dither.h"
-
-#define DITHER_LEVEL 8
-
-void (*dither_line)(unsigned char *, unsigned char *, int, int);
-
-static long red_mult, green_mult;
-static long red_dither[256];
-static long green_dither[256];
-static long blue_dither[256];
-static long gray_dither[256];
-
-typedef unsigned long vector[DITHER_LEVEL];
-typedef vector matrix[DITHER_LEVEL];
-
-#if DITHER_LEVEL == 8
-#define DITHER_MASK 7
-static matrix DM =
-{
- {0, 32, 8, 40, 2, 34, 10, 42},
- {48, 16, 56, 24, 50, 18, 58, 26},
- {12, 44, 4, 36, 14, 46, 6, 38},
- {60, 28, 52, 20, 62, 30, 54, 22},
- {3, 35, 11, 43, 1, 33, 9, 41},
- {51, 19, 59, 27, 49, 17, 57, 25},
- {15, 47, 7, 39, 13, 45, 5, 37},
- {63, 31, 55, 23, 61, 29, 53, 21}
-};
-
-#endif
-
-#if DITHER_LEVEL == 4
-#define DITHER_MASK 3
-static matrix DM =
-{
- {0, 8, 2, 10},
- {12, 4, 14, 6},
- {3, 11, 1, 9},
- {15, 7, 13, 5}
-};
-
-#endif
-
-void
-init_dither(int shades_r, int shades_g, int shades_b, int shades_gray)
-{
- int i, j;
- unsigned char low_shade, high_shade;
- unsigned short index;
- float red_colors_per_shade;
- float green_colors_per_shade;
- float blue_colors_per_shade;
- float gray_colors_per_shade;
-
- red_mult = shades_g * shades_b;
- green_mult = shades_b;
-
- red_colors_per_shade = 256.0 / (shades_r - 1);
- green_colors_per_shade = 256.0 / (shades_g - 1);
- blue_colors_per_shade = 256.0 / (shades_b - 1);
- gray_colors_per_shade = 256.0 / (shades_gray - 1);
-
- /* this avoids a shift when checking these values */
- for (i = 0; i < DITHER_LEVEL; i++)
- for (j = 0; j < DITHER_LEVEL; j++)
- DM[i][j] *= 0x10000;
-
- /* setup arrays containing three bytes of information for red, green, & blue */
- /* the arrays contain :
- * 1st byte: low end shade value
- * 2nd byte: high end shade value
- * 3rd & 4th bytes: ordered dither matrix index
- */
-
- for (i = 0; i < 256; i++) {
-
- /* setup the red information */
- {
- low_shade = (unsigned char) (i / red_colors_per_shade);
- high_shade = low_shade + 1;
-
- index = (unsigned short)
- (((i - low_shade * red_colors_per_shade) / red_colors_per_shade) *
- (DITHER_LEVEL * DITHER_LEVEL + 1));
-
- low_shade *= red_mult;
- high_shade *= red_mult;
-
- red_dither[i] = (index << 16) + (high_shade << 8) + (low_shade);
- }
-
- /* setup the green information */
- {
- low_shade = (unsigned char) (i / green_colors_per_shade);
- high_shade = low_shade + 1;
-
- index = (unsigned short)
- (((i - low_shade * green_colors_per_shade) / green_colors_per_shade) *
- (DITHER_LEVEL * DITHER_LEVEL + 1));
-
- low_shade *= green_mult;
- high_shade *= green_mult;
-
- green_dither[i] = (index << 16) + (high_shade << 8) + (low_shade);
- }
-
- /* setup the blue information */
- {
- low_shade = (unsigned char) (i / blue_colors_per_shade);
- high_shade = low_shade + 1;
-
- index = (unsigned short)
- (((i - low_shade * blue_colors_per_shade) / blue_colors_per_shade) *
- (DITHER_LEVEL * DITHER_LEVEL + 1));
-
- blue_dither[i] = (index << 16) + (high_shade << 8) + (low_shade);
- }
-
- /* setup the gray information */
- {
- low_shade = (unsigned char) (i / gray_colors_per_shade);
- high_shade = low_shade + 1;
-
- index = (unsigned short)
- (((i - low_shade * gray_colors_per_shade) / gray_colors_per_shade) *
- (DITHER_LEVEL * DITHER_LEVEL + 1));
-
- gray_dither[i] = (index << 16) + (high_shade << 8) + (low_shade);
- }
- }
-}
-
-void
-dither_line_color(unsigned char *src, unsigned char *dest, int y, int width)
-{
- register long a, b;
- long *ymod, xmod;
-
- ymod = DM[y & DITHER_MASK];
-
- while (width--) {
- xmod = width & DITHER_MASK;
-
- b = red_dither[*(src++)];
- if (ymod[xmod] < b)
- b >>= 8;
-
- a = green_dither[*(src++)];
- if (ymod[xmod] < a)
- a >>= 8;
- b += a;
-
- a = blue_dither[*(src++)];
- if (ymod[xmod] < a)
- a >>= 8;
- b += a;
-
- *(dest++) = b & 0xff;
- }
-}
-
-void
-dither_line_gray(unsigned char *src, unsigned char *dest, int y, int width)
-{
- long *ymod, xmod;
- register long a,g;
-
- ymod = DM[y & DITHER_MASK];
-
- while (width--) {
- xmod = width & DITHER_MASK;
-
-#if 1
- g = (src[0]*3 + src[1]*6 + src[2]) / 10;
- a = gray_dither[g];
- src += 3;
-#else
- a = gray_dither[*(src++)];
-#endif
- if (ymod[xmod] < a)
- a >>= 8;
-
- *(dest++) = a & 0xff;
- }
-}
diff --git a/dither.h b/dither.h
deleted file mode 100644
index b209de6..0000000
--- a/dither.h
+++ /dev/null
@@ -1,6 +0,0 @@
-
-extern void (*dither_line)(unsigned char *, unsigned char *, int, int);
-
-void init_dither(int, int, int, int);
-void dither_line_color(unsigned char *, unsigned char *, int, int);
-void dither_line_gray(unsigned char *, unsigned char *, int, int);
diff --git a/fb-gui.c b/fb-gui.c
index 3665f2c..86619a8 100644
--- a/fb-gui.c
+++ b/fb-gui.c
@@ -13,7 +13,6 @@
#include "vt.h"
#include "fbtools.h"
-#include "dither.h"
#include "fb-gui.h"
static int ys = 3;
@@ -56,30 +55,28 @@ static void shadow_render_line(gfxstate *gfx, int line,
int x;
switch (gfx->bits_per_pixel) {
- case 8:
- dither_line(buffer, ptr, line, swidth);
- break;
case 15:
case 16:
for (x = 0; x < swidth; x++) {
- ptr2[x] = s_lut_red[buffer[x*3]] |
- s_lut_green[buffer[x*3+1]] |
- s_lut_blue[buffer[x*3+2]];
+ ptr2[x] =
+ s_lut_red[buffer[x*4+2]] |
+ s_lut_green[buffer[x*4+1]] |
+ s_lut_blue[buffer[x*4+0]];
}
break;
case 24:
for (x = 0; x < swidth; x++) {
- ptr[3*x+2] = buffer[3*x+0];
- ptr[3*x+1] = buffer[3*x+1];
- ptr[3*x+0] = buffer[3*x+2];
+ ptr[3*x+2] = buffer[4*x+2];
+ ptr[3*x+1] = buffer[4*x+1];
+ ptr[3*x+0] = buffer[4*x+0];
}
break;
case 32:
for (x = 0; x < swidth; x++) {
ptr4[x] = s_lut_transp[255] |
- s_lut_red[buffer[x*3]] |
- s_lut_green[buffer[x*3+1]] |
- s_lut_blue[buffer[x*3+2]];
+ s_lut_red[buffer[x*4+2]] |
+ s_lut_green[buffer[x*4+1]] |
+ s_lut_blue[buffer[x*4+0]];
}
break;
}
@@ -110,7 +107,7 @@ void shadow_clear_lines(int first, int last)
int i;
for (i = first; i <= last; i++) {
- memset(shadow[i],0,3*swidth);
+ memset(shadow[i],0,4*swidth);
sdirty[i]++;
}
}
@@ -139,15 +136,11 @@ void shadow_init(gfxstate *gfx)
sdirty = malloc(sizeof(unsigned int) * sheight);
memset(sdirty,0, sizeof(unsigned int) * sheight);
for (i = 0; i < sheight; i++)
- shadow[i] = malloc(swidth*3);
+ shadow[i] = malloc(swidth*4);
shadow_clear();
/* init rendering */
switch (gfx->bits_per_pixel) {
- case 8:
- init_dither(8, 8, 4, 2);
- dither_line = dither_line_color;
- break;
case 15:
case 16:
case 24:
@@ -178,7 +171,7 @@ void shadow_fini(void)
static void shadow_setpixel(int x, int y)
{
- unsigned char *dest = shadow[y] + 3*x;
+ unsigned char *dest = shadow[y] + 4*x;
if (x < 0)
return;
@@ -229,22 +222,36 @@ void shadow_draw_rect(int x1, int x2, int y1,int y2)
void shadow_draw_rgbdata(int x, int y, int pixels, unsigned char *rgb)
{
- unsigned char *dest = shadow[y] + 3*x;
+ unsigned char *dest = shadow[y] + 4*x;
+ int i;
- memcpy(dest,rgb,3*pixels);
+ for (i = 0; i < pixels; i++) {
+ dest[0] = rgb[2];
+ dest[1] = rgb[1];
+ dest[2] = rgb[0];
+ dest[4] = 0;
+ dest += 4;
+ rgb += 3;
+ }
sdirty[y]++;
}
void shadow_merge_rgbdata(int x, int y, int pixels, int weight,
unsigned char *rgb)
{
- unsigned char *dest = shadow[y] + 3*x;
- int i = 3*pixels;
+ unsigned char *dest = shadow[y] + 4*x;
+ int i;
weight = weight * 256 / 100;
- while (i-- > 0)
- *(dest++) += *(rgb++) * weight >> 8;
+ for (i = 0; i < pixels; i++) {
+ dest[0] += rgb[2] * weight >> 8;
+ dest[1] += rgb[1] * weight >> 8;
+ dest[2] += rgb[0] * weight >> 8;
+ dest[4] = 0;
+ dest += 4;
+ rgb += 3;
+ }
sdirty[y]++;
}
@@ -274,8 +281,8 @@ void shadow_darkify(int x1, int x2, int y1,int y2, int percent)
for (y = y1; y <= y2; y++) {
sdirty[y]++;
ptr = shadow[y];
- ptr += 3*x1;
- x = 3*(x2-x1+1);
+ ptr += 4*x1;
+ x = 4*(x2-x1+1);
while (x-- > 0) {
*ptr = (*ptr * percent) >> 8;
ptr++;
@@ -307,9 +314,9 @@ void shadow_reverse(int x1, int x2, int y1,int y2)
sdirty[y]++;
ptr = shadow[y];
for (x = x1; x <= x2; x++) {
- ptr[3*x+0] = 255-ptr[3*x+0];
- ptr[3*x+1] = 255-ptr[3*x+1];
- ptr[3*x+2] = 255-ptr[3*x+2];
+ ptr[4*x+0] = 255-ptr[4*x+0];
+ ptr[4*x+1] = 255-ptr[4*x+1];
+ ptr[4*x+2] = 255-ptr[4*x+2];
}
}
}
@@ -330,10 +337,10 @@ static void shadow_draw_glyph(FT_Bitmap *bitmap, int sx, int sy)
if (sy+y >= sheight)
continue;
sdirty[sy+y]++;
- dst = shadow[sy+y] + sx*3;
+ dst = shadow[sy+y] + sx*4;
switch (bitmap->pixel_mode) {
case FT_PIXEL_MODE_MONO:
- for (x = 0; x < bitmap->width; x++, dst += 3) {
+ for (x = 0; x < bitmap->width; x++, dst += 4) {
if (sx+x < 0)
continue;
if (sx+x >= swidth)
@@ -347,7 +354,7 @@ static void shadow_draw_glyph(FT_Bitmap *bitmap, int sx, int sy)
}
break;
case FT_PIXEL_MODE_GRAY:
- for (x = 0; x < bitmap->width; x++, dst += 3) {
+ for (x = 0; x < bitmap->width; x++, dst += 4) {
if (sx+x < 0)
continue;
if (sx+x >= swidth)
diff --git a/ida.c b/ida.c
index 457a46c..f2487de 100644
--- a/ida.c
+++ b/ida.c
@@ -1832,7 +1832,7 @@ main(int argc, char *argv[])
display_cb,NULL);
}
XtVaGetValues(app_shell, XtNbackground,&background, NULL);
- x11_color_init(app_shell,&gray);
+ x11_color_init(app_shell);
x11_icons_init(dpy, background /* x11_gray */);
stderr_init();
ipc_init();
diff --git a/meson.build b/meson.build
index f287b77..cd9cc49 100644
--- a/meson.build
+++ b/meson.build
@@ -85,7 +85,7 @@ add_global_arguments(['-include', 'config.h'], language : 'c')
fbi_srcs = [ 'fbi.c', 'fb-gui.c', 'desktop.c',
'parseconfig.c', 'fbiconfig.c',
'vt.c', 'kbd.c', 'fbtools.c', 'drmtools.c',
- 'dither.c', 'filter.c', 'op.c', 'jpegtools.c',
+ 'filter.c', 'op.c', 'jpegtools.c',
trans_src, read_srcs ]
fbi_deps = [ freetype_dep, fontconf_dep,
drm_dep, pixman_dep,
@@ -158,7 +158,7 @@ ida_logo = custom_target('ida-logo',
output : ['logo.h'],
command : [ hexify, '@INPUT@', '@OUTPUT@'])
ida_srcs = [ 'ida.c', 'man.c', 'hex.c', 'x11.c', 'viewer.c',
- 'dither.c', 'icons.c', 'parseconfig.c', 'idaconfig.c',
+ 'icons.c', 'parseconfig.c', 'idaconfig.c',
'fileops.c', 'desktop.c', 'RegEdit.c', 'selections.c',
'xdnd.c', 'filebutton.c', 'filelist.c', 'browser.c',
'jpegtools.c', 'op.c', 'filter.c', 'lut.c', 'color.c',
diff --git a/viewer.c b/viewer.c
index 419c361..ab4b31c 100644
--- a/viewer.c
+++ b/viewer.c
@@ -16,7 +16,6 @@
#include "ida.h"
#include "x11.h"
-#include "dither.h"
#include "readers.h"
#include "viewer.h"
#include "hex.h"
@@ -46,7 +45,7 @@ Cursor ptrs[POINTER_COUNT];
Pixmap image_to_pixmap(struct ida_image *img)
{
- unsigned char line[256],*src;
+ unsigned char *src;
XImage *ximage;
void *shm;
Pixmap pix;
@@ -56,17 +55,11 @@ Pixmap image_to_pixmap(struct ida_image *img)
ximage = x11_create_ximage(app_shell, img->i.width, img->i.height, &shm);
for (y = 0; y < img->i.height; y++) {
src = ida_image_scanline(img, y);
- if (display_type == PSEUDOCOLOR) {
- dither_line(src, line, y, img->i.width);
- for (x = 0; x < img->i.width; x++)
- XPutPixel(ximage, x, y, x11_map[line[x]]);
- } else {
- for (x = 0; x < img->i.width; x++, src += 3) {
- pix = x11_lut_red[src[0]] |
- x11_lut_green[src[1]] |
- x11_lut_blue[src[2]];
- XPutPixel(ximage, x, y, pix);
- }
+ for (x = 0; x < img->i.width; x++, src += 3) {
+ pix = x11_lut_red[src[0]] |
+ x11_lut_green[src[1]] |
+ x11_lut_blue[src[2]];
+ XPutPixel(ximage, x, y, pix);
}
}
pix = XCreatePixmap(dpy,XtWindow(app_shell),img->i.width, img->i.height,
@@ -94,7 +87,7 @@ int viewer_i2s(int zoom, int val)
static void
viewer_renderline(struct ida_viewer *ida, char *scanline)
{
- unsigned char *src,*dst,*rgb;
+ unsigned char *src;
unsigned long pix;
unsigned int x,s,scrline;
@@ -102,18 +95,11 @@ viewer_renderline(struct ida_viewer *ida, char *scanline)
if (0 == ida->zoom) {
/* as-is */
- if (display_type == PSEUDOCOLOR) {
- dst = ida->dither_line;
- dither_line(src, dst, ida->line, ida->scrwidth);
- for (x = 0; x < ida->scrwidth; x++, dst++)
- XPutPixel(ida->ximage, x, ida->line, x11_map[*dst]);
- } else {
- for (x = 0; x < ida->scrwidth; x++, src += 3) {
- pix = x11_lut_red[src[0]] |
- x11_lut_green[src[1]] |
- x11_lut_blue[src[2]];
- XPutPixel(ida->ximage, x, ida->line, pix);
- }
+ for (x = 0; x < ida->scrwidth; x++, src += 3) {
+ pix = x11_lut_red[src[0]] |
+ x11_lut_green[src[1]] |
+ x11_lut_blue[src[2]];
+ XPutPixel(ida->ximage, x, ida->line, pix);
}
} else if (ida->zoom < 0) {
@@ -122,81 +108,48 @@ viewer_renderline(struct ida_viewer *ida, char *scanline)
if (s-1 != (ida->line % s))
return;
scrline = ida->line/s;
- if (display_type == PSEUDOCOLOR) {
- rgb = ida->rgb_line;
- for (x = 0; x < ida->scrwidth; x++, rgb += 3, src += 3*s) {
- rgb[0] = src[0];
- rgb[1] = src[1];
- rgb[2] = src[2];
- }
- rgb = ida->rgb_line;
- dst = ida->dither_line;
- dither_line(rgb, dst, scrline, ida->scrwidth);
- for (x = 0; x < ida->scrwidth; x++, dst++)
- XPutPixel(ida->ximage, x, scrline, x11_map[*dst]);
- } else {
#if 0
- /* just drop pixels */
- for (x = 0; x < ida->scrwidth; x++, src += 3*s) {
- pix = x11_lut_red[src[0]] |
- x11_lut_green[src[1]] |
- x11_lut_blue[src[2]];
- XPutPixel(ida->ximage, x, scrline, pix);
- }
+ /* just drop pixels */
+ for (x = 0; x < ida->scrwidth; x++, src += 3*s) {
+ pix = x11_lut_red[src[0]] |
+ x11_lut_green[src[1]] |
+ x11_lut_blue[src[2]];
+ XPutPixel(ida->ximage, x, scrline, pix);
+ }
#else
- /* horizontal interpolation (vertical is much harder ...) */
- for (x = 0; x < ida->scrwidth; x++, src += 3*s) {
- int red,green,blue,count,ix;
- red = 0;
- green = 0;
- blue = 0;
- count = 0;
- for (ix = 0; ix < 3*s; ix += 3) {
- red += src[ix+0];
- green += src[ix+1];
- blue += src[ix+2];
- count += 1;
- }
- pix = x11_lut_red[red/count] |
- x11_lut_green[green/count] |
- x11_lut_blue[blue/count];
- XPutPixel(ida->ximage, x, scrline, pix);
- }
+ /* horizontal interpolation (vertical is much harder ...) */
+ for (x = 0; x < ida->scrwidth; x++, src += 3*s) {
+ int red,green,blue,count,ix;
+ red = 0;
+ green = 0;
+ blue = 0;
+ count = 0;
+ for (ix = 0; ix < 3*s; ix += 3) {
+ red += src[ix+0];
+ green += src[ix+1];
+ blue += src[ix+2];
+ count += 1;
+ }
+ pix = x11_lut_red[red/count] |
+ x11_lut_green[green/count] |
+ x11_lut_blue[blue/count];
+ XPutPixel(ida->ximage, x, scrline, pix);
+ }
#endif
- }
-
+
} else {
/* zoom in */
s = ida->zoom+1;
- if (display_type == PSEUDOCOLOR) {
- rgb = ida->rgb_line;
- for (x = 0; x < ida->scrwidth; rgb += 3) {
- rgb[0] = src[0];
- rgb[1] = src[1];
- rgb[2] = src[2];
- x++;
- if (0 == (x%s))
- src += 3;
- }
- for (scrline = ida->line*s; scrline < ida->line*s+s; scrline++) {
- rgb = ida->rgb_line;
- dst = ida->dither_line;
- dither_line(rgb, dst, scrline, ida->scrwidth);
- for (x = 0; x < ida->scrwidth; x++, dst++)
- XPutPixel(ida->ximage, x, scrline, x11_map[*dst]);
- }
- } else {
- for (scrline = ida->line*s; scrline < ida->line*s+s; scrline++) {
- src = scanline;
- for (x = 0; x < ida->scrwidth; src += 3) {
- unsigned int i;
- pix = x11_lut_red[src[0]] |
- x11_lut_green[src[1]] |
- x11_lut_blue[src[2]];
- for (i = 0; i < s; i++, x++)
- XPutPixel(ida->ximage, x, scrline, pix);
- }
- }
+ for (scrline = ida->line*s; scrline < ida->line*s+s; scrline++) {
+ src = scanline;
+ for (x = 0; x < ida->scrwidth; src += 3) {
+ unsigned int i;
+ pix = x11_lut_red[src[0]] |
+ x11_lut_green[src[1]] |
+ x11_lut_blue[src[2]];
+ for (i = 0; i < s; i++, x++)
+ XPutPixel(ida->ximage, x, scrline, pix);
+ }
}
}
}
diff --git a/x11.c b/x11.c
index 6d1f9cb..9613ef9 100644
--- a/x11.c
+++ b/x11.c
@@ -34,7 +34,6 @@
#include <X11/extensions/XShm.h>
#include "x11.h"
-#include "dither.h"
extern Display *dpy;
@@ -46,85 +45,17 @@ int display_type = 0;
int display_depth = 0;
XVisualInfo *info;
-/* PseudoColor: ditherresult => colormap-entry */
-int x11_colors;
-int x11_grays;
-unsigned long *x11_map;
-unsigned long x11_map_color[256];
-unsigned long x11_map_gray[64];
-
unsigned long x11_red;
unsigned long x11_green;
unsigned long x11_blue;
+unsigned long x11_gray;
int have_shmem = 0;
-/*
- * - xv uses 4:8:4 for truecolor images.
- * - The GIMP 0.99.9 uses 6:6:4, but the 6 intervals for red+green are
- * choosen somehow wired :-(
- * - ImageMagick tries to optimize the palette for each image individual
- */
-static int try_red[] = {4, 6, 6, 5, 4};
-static int try_green[] = {8, 6, 6, 5, 4};
-static int try_blue[] = {4, 6, 4, 5, 4};
-
/* TrueColor: r,g,b => X11-color */
unsigned long x11_lut_red[256];
unsigned long x11_lut_green[256];
unsigned long x11_lut_blue[256];
-unsigned long x11_lut_gray[256];
-
-static int
-x11_alloc_grays(Display * dpy, Colormap cmap, unsigned long *colors, int gray)
-{
- XColor akt_color;
- int i;
-
- for (i = 0; i < gray; i++) {
- akt_color.red = i * 65535 / (gray - 1);
- akt_color.green = i * 65535 / (gray - 1);
- akt_color.blue = i * 65535 / (gray - 1);
-
- if (!XAllocColor(dpy, cmap, &akt_color)) {
- /* failed, free them */
- XFreeColors(dpy, cmap, colors, i, 0);
- return 1;
- }
- colors[i] = akt_color.pixel;
-#if 0
- fprintf(stderr, "%2lx: %04x %04x %04x\n",
- akt_color.pixel,akt_color.red,akt_color.green,akt_color.red);
-#endif
- }
- return 0;
-}
-
-static int
-x11_alloc_colorcube(Display * dpy, Colormap cmap, unsigned long *colors,
- int red, int green, int blue)
-{
- XColor akt_color;
- int i;
-
- for (i = 0; i < red * green * blue; i++) {
- akt_color.red = ((i / (green * blue)) % red) * 65535 / (red - 1);
- akt_color.green = ((i / blue) % green) * 65535 / (green - 1);
- akt_color.blue = (i % blue) * 65535 / (blue - 1);
-#if 0
- fprintf(stderr, "%04x %04x %04x\n",
- akt_color.red, akt_color.green, akt_color.red);
-#endif
-
- if (!XAllocColor(dpy, cmap, &akt_color)) {
- /* failed, free them */
- XFreeColors(dpy, cmap, colors, i, 0);
- return 1;
- }
- colors[i] = akt_color.pixel;
- }
- return 0;
-}
static unsigned long
x11_alloc_color(Display * dpy, Colormap cmap, int red, int green, int blue)
@@ -179,23 +110,19 @@ x11_create_lut(unsigned long red_mask,
x11_lut_red[i] = (i >> (8 - rgb_red_bits)) << rgb_red_shift;
x11_lut_green[i] = (i >> (8 - rgb_green_bits)) << rgb_green_shift;
x11_lut_blue[i] = (i >> (8 - rgb_blue_bits)) << rgb_blue_shift;
- x11_lut_gray[i] =
- x11_lut_red[i] | x11_lut_green[i] | x11_lut_blue[i];
}
}
int
-x11_color_init(Widget shell, int *gray)
+x11_color_init(Widget shell)
{
Screen *scr;
Colormap cmap;
XVisualInfo template;
- unsigned int found, i;
+ unsigned int found;
scr = XtScreen(shell);
cmap = DefaultColormapOfScreen(scr);
- if (0 == x11_grays)
- x11_grays = 8;
/* Ask for visual type */
template.screen = XDefaultScreen(dpy);
@@ -210,51 +137,9 @@ x11_color_init(Widget shell, int *gray)
/* display_depth = (info->depth+7)/8; */
if (info->class == TrueColor) {
/* TrueColor */
- *gray = 0; /* XXX testing... */
display_depth = 4;
display_type = TRUECOLOR;
x11_create_lut(info->red_mask, info->green_mask, info->blue_mask);
- x11_black = x11_alloc_color(dpy, cmap, 0, 0, 0);
- x11_gray = x11_alloc_color(dpy, cmap, 0xc400, 0xc400, 0xc400);
- x11_lightgray = x11_alloc_color(dpy, cmap, 0xe000, 0xe000, 0xe000);
- x11_white = x11_alloc_color(dpy, cmap, 0xffff, 0xffff, 0xffff);
- } else if (info->class == PseudoColor && info->depth == 8) {
- /* 8bit PseudoColor */
- display_depth = 1;
- display_type = PSEUDOCOLOR;
- if (0 != x11_alloc_grays(dpy, cmap, x11_map_gray, x11_grays)) {
- fprintf(stderr, "sorry, can't allocate %d grays\n", x11_grays);
- exit(1);
- }
- if (!*gray) {
- for (i = 0; i < sizeof(try_red) / sizeof(int); i++) {
- if (0 == x11_alloc_colorcube
- (dpy, cmap, x11_map_color,
- try_red[i], try_green[i], try_blue[i])) {
- x11_colors = try_red[i] * try_green[i] * try_blue[i];
- init_dither(try_red[i], try_green[i], try_blue[i], x11_grays);
- break;
- }
- }
- if (i == sizeof(try_red) / sizeof(int)) {
- *gray = 1;
- fprintf(stderr, "failed to allocate enouth colors, "
- "using grayscaled\n");
- }
- }
- if (*gray)
- init_dither(2, 2, 2, x11_grays);
- } else if (info->class == StaticGray || info->class == GrayScale) {
- /* Grayscale */
- display_depth = 1;
- display_type = PSEUDOCOLOR;
- x11_grays = 64;
- *gray = 1;
- init_dither(2, 2, 2, x11_grays);
- if (0 != x11_alloc_grays(dpy, cmap, x11_map_gray, x11_grays)) {
- fprintf(stderr, "sorry, can't allocate %d grays\n", x11_grays);
- exit(1);
- }
} else {
fprintf(stderr, "sorry, can't handle visual\n");
exit(1);
@@ -264,14 +149,7 @@ x11_color_init(Widget shell, int *gray)
x11_red = x11_alloc_color(dpy, cmap, 65535, 0, 0);
x11_green = x11_alloc_color(dpy, cmap, 0, 65535, 0);
x11_blue = x11_alloc_color(dpy, cmap, 0, 0, 65535);
-
- if (*gray) {
- x11_map = x11_map_gray;
- dither_line = dither_line_gray;
- } else {
- x11_map = x11_map_color;
- dither_line = dither_line_color;
- }
+ x11_gray = x11_alloc_color(dpy, cmap, 0xc400, 0xc400, 0xc400);
return display_type;
}
@@ -395,7 +273,6 @@ x11_create_pixmap(Widget shell, unsigned char *byte_data,
unsigned long *long_data = (unsigned long *) byte_data;
int x, y;
void *shm;
- unsigned long *map = gray ? x11_map_gray : x11_map;
Screen *scr = XtScreen(shell);
@@ -411,12 +288,8 @@ x11_create_pixmap(Widget shell, unsigned char *byte_data,
return 0;
}
for (y = 0; y < height; y++)
- if (display_type == TRUECOLOR)
- for (x = 0; x < width; x++)
- XPutPixel(ximage, x, y, *(long_data++));
- else
- for (x = 0; x < width; x++)
- XPutPixel(ximage, x, y, map[(int) (*(byte_data++))]);
+ for (x = 0; x < width; x++)
+ XPutPixel(ximage, x, y, *(long_data++));
XPUTIMAGE(dpy, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
@@ -432,26 +305,10 @@ x11_data_to_ximage(unsigned char *data, unsigned char *ximage,
unsigned long *d;
int i, n;
- if (display_type == PSEUDOCOLOR) {
- if (gray) {
- for (i = 0; i < y; i++)
- dither_line_gray(data + x * i, ximage + x * i, i + sy, x);
- } else {
- for (i = 0; i < y; i++)
- dither_line(data + 3 * x * i, ximage + x * i, i + sy, x);
- }
- } else {
- d = (unsigned long *) ximage;
- if (gray) {
- n = x * y;
- for (i = 0; i < n; i++)
- *(d++) = x11_lut_gray[data[i]];
- } else {
- n = 3 * x * y;
- for (i = 0; i < n; i += 3)
- *(d++) = x11_lut_red[data[i]] |
- x11_lut_green[data[i + 1]] |
- x11_lut_blue[data[i + 2]];
- }
- }
+ d = (unsigned long *) ximage;
+ n = 3 * x * y;
+ for (i = 0; i < n; i += 3)
+ *(d++) = x11_lut_red[data[i]] |
+ x11_lut_green[data[i + 1]] |
+ x11_lut_blue[data[i + 2]];
}
diff --git a/x11.h b/x11.h
index bbc28ea..769eeab 100644
--- a/x11.h
+++ b/x11.h
@@ -5,28 +5,18 @@ extern int display_type;
extern int display_depth;
extern XVisualInfo *info;
-extern int x11_grays;
-extern unsigned long *x11_map;
-
extern unsigned long x11_lut_red[256];
extern unsigned long x11_lut_green[256];
extern unsigned long x11_lut_blue[256];
-extern unsigned long x11_lut_gray[256];
-extern unsigned long x11_map_color[256];
-extern unsigned long x11_map_gray[64];
-
-#define x11_black x11_map_gray[0]
-#define x11_gray x11_map_gray[47*x11_grays/64]
-#define x11_lightgray x11_map_gray[55*x11_grays/64]
-#define x11_white x11_map_gray[63*x11_grays/64]
extern unsigned long x11_red;
extern unsigned long x11_green;
extern unsigned long x11_blue;
+extern unsigned long x11_gray;
extern int have_shmem;
-int x11_color_init(Widget shell, int *gray);
+int x11_color_init(Widget shell);
void x11_data_to_ximage(unsigned char *rgb, unsigned char *ximage,
int x, int y, int sy, int gray);