diff options
author | Michele Calgaro <[email protected]> | 2020-09-11 14:38:47 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2020-09-11 14:38:47 +0900 |
commit | 884c8093d63402a1ad0b502244b791e3c6782be3 (patch) | |
tree | a600d4ab0d431a2bdfe4c15b70df43c14fbd8dd0 /debian/imlib/imlib-1.9.15/Imlib | |
parent | 14e1aa2006796f147f3f4811fb908a6b01e79253 (diff) | |
download | extra-dependencies-884c8093d63402a1ad0b502244b791e3c6782be3.tar.gz extra-dependencies-884c8093d63402a1ad0b502244b791e3c6782be3.zip |
Added debian extra dependency packages.
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'debian/imlib/imlib-1.9.15/Imlib')
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/ChangeLog | 185 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/Imlib.h | 79 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/Imlib_private.h | 149 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/Imlib_types.h | 191 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/Makefile.am | 46 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/Makefile.in | 559 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/cache.c | 553 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/colors.c | 271 | ||||
-rwxr-xr-x | debian/imlib/imlib-1.9.15/Imlib/install-sh | 238 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/load.c | 2081 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/misc.c | 1430 | ||||
-rwxr-xr-x | debian/imlib/imlib-1.9.15/Imlib/mkinstalldirs | 32 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/rend.c | 6906 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/save.c | 555 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/snprintf.c | 561 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/t-load.c | 38 | ||||
-rw-r--r-- | debian/imlib/imlib-1.9.15/Imlib/utils.c | 2499 |
17 files changed, 16373 insertions, 0 deletions
diff --git a/debian/imlib/imlib-1.9.15/Imlib/ChangeLog b/debian/imlib/imlib-1.9.15/Imlib/ChangeLog new file mode 100644 index 00000000..6b6970bb --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/ChangeLog @@ -0,0 +1,185 @@ +2004-09-20 Mark Crichton <[email protected]> + + * load.c: fixed BMP vunerability + +2002-03-22 Mark Crichton <[email protected]> + + * Makefile.am: Bumped up rev numbers for 1.9.14. This is a brownbag + release... + * load.c: Fixed reported bug. If Imlib thought it needed a fallback, + bad things will happen. + * utils.c: Removed the open/close_helper functions. A little less + bloat now removed. + +2002-03-13 Mark Crichton <[email protected]> + + * Makefile.am: I forgot to bump up the revision number for 1.9.12. + Oops. + * load.c (_LoadTIFF): Fixed a warning. + +2002-03-04 Mark Crichton <[email protected]> + + * load.c: Fixed ispnm to properly flag proper files. + Closes bug #64745 + +2002-03-04 Mark Crichton <[email protected]> + + * load.c, utils.c: Plugged some potential buffer overflows. + * load.c, save.c: Turned OFF the shell fallbacks. The risks don't + outweigh the benefits. + * Makefile.am: bumped up the revision number to reflect the changes + +2001-09-10 Mark Crichton <[email protected]> + + * Makefile.am: Made libimlib depend on X libs. Resolves bug + #59915 + +2001-08-29 Mark Crichton <[email protected]> + + * utils.c, save.c: Bug #56004. Improved error messages. + +2001-07-28 Mark Crichton <[email protected]> + + * load.c: Fixed PNG loader for greyscale. Resolves bug #57858 + +2001-05-29 Mark Crichton <[email protected]> + + * misc.c: Made x_error static. Resolves bug #52838 + +2001-03-27 Mark Crichton <[email protected]> + + * Imlib/Makefile.am: cosmetic changes to allow build-time changes + of variables instead of at configure. + * colors.c: Added basename replacement for systems w/o basename + (bugzilla #51998) + +1999-12-05 John Harper <[email protected]> + * rend.c (Imlib_render): stop GC caching leaking memory + +1999-10-16 Kjartan Maraas <[email protected]> + + * cache.c: (clean_caches): Remove unused variable. + * colors.c: (PaletteLUTSet): Removed unused variables. + * utils.c: (Imlib_bevel_image): Removed unused variables. + +Tue Jun 15 13:08:28 1999 Owen Taylor <[email protected]> + + * misc.c (Imlib_copy_mask): create gc's without + GraphicsExpose events, as elsewhere in imlib. + +1999-02-11 Owen Taylor <[email protected]> + + * misc.c: Don't overwrite existing locale settings, just + temporarily set LC_NUMERIC to "C", then restore it. + +1999-02-11 Tomas Ogren <[email protected]> + + * utils.c: Since when did sizeof() be the same as strlen() on char*'s? + Also changed some malloc() + strcpy() -> strdup(). + +1999-02-11 Tomas Ogren <[email protected]> + + * Recommend 1.0.3 instead of 1.0.1 (if broken 1.0.2) + +Sat Apr 11 12:30:47 1998 George Lebl <[email protected]> + + * utils.c: fixed yet one more SIGFPE on alpha + +Fri Feb 27 09:41:57 1998 Tom Tromey <[email protected]> + + * load.c (Imlib_load_image): Typo fix from Robert Wilhelm. + +1998-02-25 Raja R Harinath <[email protected]> + + * Makefile.am (DEFS): Define `SYSTEM_IMRC' too. + +1998-02-25 Federico Mena Quintero <[email protected]> + + * misc.c (Imlib_copy_image): The drawable passed to XCreateGC + should be the dest drawable, not image pixmap. This caused + BadMatches all over the place (especially in copy_mask). + (Imlib_copy_mask): Likewise. + +1998-02-24 Raja R Harinath <[email protected]> + + * Makefile.am (DEFS): New var. Moved stuff from CFLAGS. + (INCLUDES): New var. + +1998-02-24 Mark Galassi <[email protected]> + + * Makefile.am: converted the Makefile.in to a Makefile.am. + (lib_LTLIBRARIES): + (libImlib_la_SOURCES): also converted it to use libtool and + generate shared libraries. + + * load.c (Imlib_load_image): changed JPEG_PATH to DJPEG_PROG and + removed %s/djpeg, sine DJPEG_PROG is the full program path. + +1998-02-16 Federico Mena Quintero <[email protected]> + + * misc.c (Imlib_init): I create a colormap specific to the visual + the base_window will be using. This fixes BadMatch errors on + machines with multiple visual/depth combinations. + + +1998-02-17 The Rasterman <[email protected]> + + * misc.c (Imlib_init) Fixed visual stuff slightly, and Colormap + creation (so it only does so if the visual for the default and the + chosen visual mismatch), added function calls to retrieve Imlib's + visual and Colormap, plus endianess fixes for network displaying. + +1998-02-17 The Rasterman <[email protected]> + + added system imrc config retunr function + +1998-02-18 The Rasterman <[email protected]> + + Fixed load.c - missed a not (!) in an if clause + +1998-03-17 Mandrake <[email protected]> + * misc.c - boy I hate reading "Imlib Init" all the time. the fprintf + to stderr is commented out. + +1999-03-22 Pavel Machek <[email protected]> + + * utils.c (Imlib_create_image_from_xpm_data): robustness: fail if + id->x.disp is not initialized + +1999-03-23 Michael Jennings <[email protected]> + + * utils.c (Imlib_create_image_from_xpm_data): Please keep the gdk + macros in the gdk version. g_return_val_if_fail() is not valid + in Imlib. + +1999-05-11 Michael Jennings <[email protected]> + + Added support for specifying a colormap with the ImlibInitParams. + +1999-06-16 Michael Jennings <[email protected]> + + Speedups. Don't recalculate map tables or dirty pixmaps if nothing + has changed. + +1999-06-17 Michael Jennings <[email protected]> + + New function: + Imlib_bevel_image(ImlibData *, ImlibImage *, ImlibBorder *, unsigned char) + + Draws a bevel onto an image before rendering. Widths of the bevel edges + are taken from the ImlibBorder parameter. The final parameter is numerical, + true to bevel up, false to bevel down. + +1999-06-18 Michael Jennings <[email protected]> + + Another new function, related to yesterday's: + Imlib_bevel_pixmap(ImlibData *, Pixmap, int, int, ImlibBorder *, unsigned char) + + Draws a bevel onto a pixmap after rendering. Widths of the bevel edges are + taken from the ImlibBorder parameter. The final parameter is numerical, + true to bevel up, false to bevel down. The two int parameters are the width + and height, respectively, of the pixmap (in pixels, of course). + + I haven't tested this in anything but 8 bpp, so I'm hoping someone will tell me + if it's broken. + diff --git a/debian/imlib/imlib-1.9.15/Imlib/Imlib.h b/debian/imlib/imlib-1.9.15/Imlib/Imlib.h new file mode 100644 index 00000000..8ca2a39f --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/Imlib.h @@ -0,0 +1,79 @@ +#ifndef __IMLIB_H__ +#define __IMLIB_H__ + +#include <Imlib_types.h> + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + ImlibData *Imlib_init(Display * disp); + ImlibData *Imlib_init_with_params(Display * disp, ImlibInitParams * p); + int Imlib_get_render_type(ImlibData * id); + void Imlib_set_render_type(ImlibData * id, int rend_type); + int Imlib_load_colors(ImlibData * id, char *file); + ImlibImage *Imlib_load_image(ImlibData * id, char *file); + int Imlib_best_color_match(ImlibData * id, int *r, int *g, int *b); + int Imlib_render(ImlibData * id, ImlibImage * image, int width, int height); + Pixmap Imlib_copy_image(ImlibData * id, ImlibImage * image); + Pixmap Imlib_copy_mask(ImlibData * id, ImlibImage * image); + Pixmap Imlib_move_image(ImlibData * id, ImlibImage * image); + Pixmap Imlib_move_mask(ImlibData * id, ImlibImage * image); + void Imlib_destroy_image(ImlibData * id, ImlibImage * image); + void Imlib_kill_image(ImlibData * id, ImlibImage * image); + void Imlib_free_colors(ImlibData * id); + void Imlib_free_pixmap(ImlibData * id, Pixmap pixmap); + void Imlib_get_image_border(ImlibData * id, ImlibImage * image, ImlibBorder * border); + void Imlib_set_image_border(ImlibData * id, ImlibImage * image, ImlibBorder * border); + void Imlib_get_image_shape(ImlibData * id, ImlibImage * image, ImlibColor * color); + void Imlib_set_image_shape(ImlibData * id, ImlibImage * image, ImlibColor * color); + int Imlib_save_image_to_eim(ImlibData * id, ImlibImage * image, char *file); + int Imlib_add_image_to_eim(ImlibData * id, ImlibImage * image, char *file); + int Imlib_save_image_to_ppm(ImlibData * id, ImlibImage * image, char *file); + int Imlib_load_file_to_pixmap(ImlibData * id, char *filename, Pixmap * pmap, Pixmap * mask); + void Imlib_set_image_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_set_image_red_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_set_image_green_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_set_image_blue_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_get_image_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_get_image_red_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_get_image_green_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_get_image_blue_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod); + void Imlib_set_image_red_curve(ImlibData * id, ImlibImage * im, unsigned char *mod); + void Imlib_set_image_green_curve(ImlibData * id, ImlibImage * im, unsigned char *mod); + void Imlib_set_image_blue_curve(ImlibData * id, ImlibImage * im, unsigned char *mod); + void Imlib_get_image_red_curve(ImlibData * id, ImlibImage * im, unsigned char *mod); + void Imlib_get_image_green_curve(ImlibData * id, ImlibImage * im, unsigned char *mod); + void Imlib_get_image_blue_curve(ImlibData * id, ImlibImage * im, unsigned char *mod); + void Imlib_apply_modifiers_to_rgb(ImlibData * id, ImlibImage * im); + void Imlib_changed_image(ImlibData * id, ImlibImage * im); + void Imlib_apply_image(ImlibData * id, ImlibImage * im, Window p); + void Imlib_paste_image(ImlibData * id, ImlibImage * im, Window p, int x, int y, int w, int h); + void Imlib_paste_image_border(ImlibData * id, ImlibImage * im, Window p, int x, int y, int w, int h); + void Imlib_bevel_image(ImlibData *id, ImlibImage *im, ImlibBorder *bord, unsigned char up); + void Imlib_bevel_pixmap(ImlibData *id, Pixmap p, int w, int h, ImlibBorder *bord, unsigned char up); + void Imlib_flip_image_horizontal(ImlibData * id, ImlibImage * im); + void Imlib_flip_image_vertical(ImlibData * id, ImlibImage * im); + void Imlib_rotate_image(ImlibData * id, ImlibImage * im, int d); + ImlibImage *Imlib_create_image_from_data(ImlibData * id, unsigned char *data, unsigned char *alpha, int w, int h); + ImlibImage *Imlib_clone_image(ImlibData * id, ImlibImage * im); + ImlibImage *Imlib_clone_scaled_image(ImlibData * id, ImlibImage * im, int w, int h); + int Imlib_get_fallback(ImlibData * id); + void Imlib_set_fallback(ImlibData * id, int fallback); + Visual *Imlib_get_visual(ImlibData * id); + Colormap Imlib_get_colormap(ImlibData * id); + char *Imlib_get_sysconfig(ImlibData * id); + ImlibImage *Imlib_create_image_from_xpm_data(ImlibData * id, char **data); + int Imlib_data_to_pixmap(ImlibData * id, char **data, Pixmap * pmap, Pixmap * mask); + void Imlib_crop_image(ImlibData * id, ImlibImage * im, int x, int y, int w, int h); + int Imlib_save_image(ImlibData * id, ImlibImage * im, char *file, ImlibSaveInfo * info); + ImlibImage *Imlib_crop_and_clone_image(ImlibData * id, ImlibImage * im, int x, int y, int w, int h); + ImlibImage *Imlib_create_image_from_drawable(ImlibData * id, Drawable win, Pixmap mask, int x, int y, int width, int height); + ImlibImage *Imlib_inlined_png_to_image(ImlibData *id, unsigned char *data, int data_size); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/debian/imlib/imlib-1.9.15/Imlib/Imlib_private.h b/debian/imlib/imlib-1.9.15/Imlib/Imlib_private.h new file mode 100644 index 00000000..48bd81a0 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/Imlib_private.h @@ -0,0 +1,149 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <math.h> +#include <ctype.h> +#include <time.h> +#include <netinet/in.h> +#ifdef HAVE_IPC_H +#include <sys/ipc.h> +#endif +#ifdef HAVE_SHM_H +#include <sys/shm.h> +#endif +#include <sys/time.h> +#include <sys/types.h> + +#ifdef _HAVE_STRING_H +#include <string.h> +#elif _HAVE_STRINGS_H +#include <strings.h> +#endif + +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Xatom.h> +#include <X11/Xos.h> +#ifdef HAVE_XSHM_H +#include <X11/extensions/XShm.h> +#endif +#include <X11/extensions/shape.h> +#include <X11/cursorfont.h> + +#ifdef HAVE_LIBJPEG +#include <jpeglib.h> +#endif +#ifdef HAVE_LIBPNG +#include <png.h> +#endif +#ifdef HAVE_LIBTIFF +#include <tiffio.h> +#endif +#ifdef HAVE_LIBGIF +#include <gif_lib.h> +#endif + +#define BYTE_ORD_24_RGB 0 +#define BYTE_ORD_24_RBG 1 +#define BYTE_ORD_24_BRG 2 +#define BYTE_ORD_24_BGR 3 +#define BYTE_ORD_24_GRB 4 +#define BYTE_ORD_24_GBR 5 + +struct image_cache + { + char *file; + ImlibImage *im; + int refnum; + char dirty; + struct image_cache *prev; + struct image_cache *next; + }; + +struct pixmap_cache + { + ImlibImage *im; + char *file; + char dirty; + int width, height; + Pixmap pmap; + Pixmap shape_mask; + XImage *xim; + XImage *sxim; + int refnum; + struct pixmap_cache *prev; + struct pixmap_cache *next; + }; + + +int index_best_color_match(ImlibData * id, int *r, int *g, int *b); +void dirty_pixmaps(ImlibData * id, ImlibImage * im); +void dirty_images(ImlibData * id, ImlibImage * im); +void find_pixmap(ImlibData * id, ImlibImage * im, int width, int height, Pixmap * pmap, Pixmap * mask); +ImlibImage *find_image(ImlibData * id, char *file); +void free_pixmappmap(ImlibData * id, Pixmap pmap); +void free_image(ImlibData * id, ImlibImage * im); +void flush_image(ImlibData * id, ImlibImage * im); +void add_image(ImlibData * id, ImlibImage * im, char *file); +void add_pixmap(ImlibData * id, ImlibImage * im, int width, int height, XImage * xim, XImage * sxim); +void clean_caches(ImlibData * id); +void nullify_image(ImlibData * id, ImlibImage * im); + +char *_GetExtension(char *file); +void *_imlib_malloc_image(unsigned int w, unsigned int h); + + +#ifdef HAVE_LIBJPEG +unsigned char *_LoadJPEG(ImlibData * id, FILE * f, int *w, int *h); + +#endif /* HAVE_LIBJPEG */ +#ifdef HAVE_LIBPNG +unsigned char *_LoadPNG(ImlibData * id, FILE * f, int *w, int *h, int *t); + +#endif /* HAVE_LIBPNG */ +#ifdef HAVE_LIBTIFF +unsigned char *_LoadTIFF(ImlibData * id, FILE *f, char *file, int *w, int *h, int *t); + +#endif /* HAVE_LIBTIFF */ +#ifdef HAVE_LIBGIF +unsigned char *_LoadGIF(ImlibData * id, FILE *f, int *w, int *h, int *t); + +#endif /* HAVE_LIBGIF */ +unsigned char *_LoadBMP(ImlibData * id, FILE *f, int *w, int *h, int *t); +unsigned char *_LoadXPM(ImlibData * id, FILE *f, int *w, int *h, int *t); +unsigned char *_LoadPPM(ImlibData * id, FILE * f, int *w, int *h); +int ispnm(FILE *f); +int isjpeg(FILE *f); +int ispng(FILE *f); +int istiff(FILE *f); +int iseim(FILE *f); +int isgif(FILE *f); +int isxpm(FILE *f); +int isbmp(FILE *f); + +void calc_map_tables(ImlibData * id, ImlibImage * im); + +void _PaletteAlloc(ImlibData * id, int num, int *cols); + +#define INDEX_RGB(r,g,b) id->fast_rgb[(r<<10)|(g<<5)|(b)] +#define COLOR_INDEX(i) id->palette[i].pixel +#define COLOR_RGB(r,g,b) id->palette[INDEX_RGB(r,g,b)].pixel +#define ERROR_RED(rr,i) rr-id->palette[i].r; +#define ERROR_GRN(gg,i) gg-id->palette[i].g; +#define ERROR_BLU(bb,i) bb-id->palette[i].b; + +#define DITHER_ERROR(Der1,Der2,Dex,Der,Deg,Deb) \ +ter=&(Der1[Dex]);\ +(*ter)+=(Der*7)>>4;ter++;\ +(*ter)+=(Deg*7)>>4;ter++;\ +(*ter)+=(Deb*7)>>4;\ +ter=&(Der2[Dex-6]);\ +(*ter)+=(Der*3)>>4;ter++;\ +(*ter)+=(Deg*3)>>4;ter++;\ +(*ter)+=(Deb*3)>>4;ter++;\ +(*ter)+=(Der*5)>>4;ter++;\ +(*ter)+=(Deg*5)>>4;ter++;\ +(*ter)+=(Deb*5)>>4;ter++;\ +(*ter)+=Der>>4;ter++;\ +(*ter)+=Deg>>4;ter++;\ +(*ter)+=Deb>>4; diff --git a/debian/imlib/imlib-1.9.15/Imlib/Imlib_types.h b/debian/imlib/imlib-1.9.15/Imlib/Imlib_types.h new file mode 100644 index 00000000..dc496db7 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/Imlib_types.h @@ -0,0 +1,191 @@ +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Xatom.h> +#include <X11/Xos.h> +#ifdef HAVE_XSHM_H +#include <X11/extensions/XShm.h> +#endif +#include <X11/extensions/shape.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <math.h> +#include <ctype.h> +#include <time.h> +#include <netinet/in.h> +#ifdef HAVE_IPC_H +#include <sys/ipc.h> +#endif +#ifdef HAVE_SHM_H +#include <sys/shm.h> +#endif +#include <sys/time.h> +#include <sys/types.h> + +#ifdef _HAVE_STRING_H +#include <string.h> +#elif _HAVE_STRINGS_H +#include <strings.h> +#endif + +#ifndef SYSTEM_IMRC +#define SYSTEM_IMRC "/etc/imrc" +#endif /* endef SYSTEM_IMRC */ + +typedef struct _ImlibBorder ImlibBorder; +typedef struct _ImlibColor ImlibColor; +typedef struct _ImlibColorModifier ImlibColorModifier; +typedef struct _ImlibImage ImlibImage; +typedef struct _xdata Xdata; +typedef struct _ImlibData ImlibData; +typedef struct _ImlibSaveInfo ImlibSaveInfo; +typedef struct _ImlibInitParams ImlibInitParams; + +struct _ImlibBorder + { + int left, right; + int top, bottom; + }; + +struct _ImlibColor + { + int r, g, b; + int pixel; + }; + +struct _ImlibColorModifier + { + int gamma; + int brightness; + int contrast; + }; + +struct _ImlibImage + { + int rgb_width, rgb_height; + unsigned char *rgb_data; + unsigned char *alpha_data; + char *filename; +/* the below information is private */ + int width, height; + ImlibColor shape_color; + ImlibBorder border; + Pixmap pixmap; + Pixmap shape_mask; + char cache; + ImlibColorModifier mod, rmod, gmod, bmod; + unsigned char rmap[256], gmap[256], bmap[256]; + }; + +struct _xdata + { + Display *disp; + int screen; + Window root; + Visual *visual; + int depth; + int render_depth; + Colormap root_cmap; + char shm; + char shmp; + int shm_event; + XImage *last_xim; + XImage *last_sxim; +#ifdef HAVE_XSHM_H + XShmSegmentInfo last_shminfo; + XShmSegmentInfo last_sshminfo; +#endif + Window base_window; + int byte_order, bit_order; + }; + +struct _ImlibData + { + int num_colors; + ImlibColor *palette; + ImlibColor *palette_orig; + unsigned char *fast_rgb; + int *fast_err; + int *fast_erg; + int *fast_erb; + int render_type; + int max_shm; + Xdata x; + int byte_order; + struct _cache + { + char on_image; + int size_image; + int num_image; + int used_image; + struct image_cache *image; + char on_pixmap; + int size_pixmap; + int num_pixmap; + int used_pixmap; + struct pixmap_cache *pixmap; + } + cache; + char fastrend; + char hiq; + ImlibColorModifier mod, rmod, gmod, bmod; + unsigned char rmap[256], gmap[256], bmap[256]; + char fallback; + char ordered_dither; + }; + +struct _ImlibSaveInfo + { + int quality; + int scaling; + int xjustification; + int yjustification; + int page_size; + char color; + }; + +struct _ImlibInitParams + { + int flags; + int visualid; + char *palettefile; + char sharedmem; + char sharedpixmaps; + char paletteoverride; + char remap; + char fastrender; + char hiquality; + char dither; + int imagecachesize; + int pixmapcachesize; + Colormap cmap; + }; + +#define PARAMS_VISUALID 1<<0 +#define PARAMS_PALETTEFILE 1<<1 +#define PARAMS_SHAREDMEM 1<<2 +#define PARAMS_SHAREDPIXMAPS 1<<3 +#define PARAMS_PALETTEOVERRIDE 1<<4 +#define PARAMS_REMAP 1<<5 +#define PARAMS_FASTRENDER 1<<6 +#define PARAMS_HIQUALITY 1<<7 +#define PARAMS_DITHER 1<<8 +#define PARAMS_IMAGECACHESIZE 1<<9 +#define PARAMS_PIXMAPCACHESIZE 1<<10 +#define PARAMS_COLORMAP 1<<11 + +#define PAGE_SIZE_EXECUTIVE 0 +#define PAGE_SIZE_LETTER 1 +#define PAGE_SIZE_LEGAL 2 +#define PAGE_SIZE_A4 3 +#define PAGE_SIZE_A3 4 +#define PAGE_SIZE_A5 5 +#define PAGE_SIZE_FOLIO 6 + +#define RT_PLAIN_PALETTE 0 +#define RT_PLAIN_PALETTE_FAST 1 +#define RT_DITHER_PALETTE 2 +#define RT_DITHER_PALETTE_FAST 3 +#define RT_PLAIN_TRUECOL 4 +/* a special high-quality renderer for people with 15 and 16bpp that dithers */ +#define RT_DITHER_TRUECOL 5 diff --git a/debian/imlib/imlib-1.9.15/Imlib/Makefile.am b/debian/imlib/imlib-1.9.15/Imlib/Makefile.am new file mode 100644 index 00000000..ec66f8d1 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/Makefile.am @@ -0,0 +1,46 @@ +# GPL (C) 1997 The Rasterman + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# the resultant executable +lib_LTLIBRARIES = libImlib.la + +include_HEADERS = Imlib.h Imlib_private.h Imlib_types.h + +libImlib_la_SOURCES = \ + cache.c \ + colors.c \ + load.c \ + misc.c \ + rend.c \ + utils.c \ + save.c \ + snprintf.c + +libImlib_la_LDFLAGS = -version-info 10:15:9 +#libImlib_la_LDDADD = $(SUPPORT_LIBS) +libImlib_la_LIBADD = $(SUPPORT_LIBS) $(X_PRE_LIBS) \ + $(X_LIBS) $(X_EXTRA_LIBS) + +DEFS = -DSYSTEM_IMRC=\"$(sysconfdir)/imrc\" \ + -DSYSCONFDIR=\"$(sysconfdir)\" + +INCLUDES = -I. -I$(srcdir) -I.. -I$(srcdir)/.. $(X_CFLAGS) + + +check_PROGRAMS = t-load + +t_load_LDADD = libImlib.la diff --git a/debian/imlib/imlib-1.9.15/Imlib/Makefile.in b/debian/imlib/imlib-1.9.15/Imlib/Makefile.in new file mode 100644 index 00000000..52c840de --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/Makefile.in @@ -0,0 +1,559 @@ +# Makefile.in generated by automake 1.7.9 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# GPL (C) 1997 The Rasterman + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_triplet = @host@ +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ + +DEFS = -DSYSTEM_IMRC=\"$(sysconfdir)/imrc\" \ + -DSYSCONFDIR=\"$(sysconfdir)\" + +DEPDIR = @DEPDIR@ +DYNAMIC_MODULES_WORK_FALSE = @DYNAMIC_MODULES_WORK_FALSE@ +DYNAMIC_MODULES_WORK_TRUE = @DYNAMIC_MODULES_WORK_TRUE@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GDK_IMLIB = @GDK_IMLIB@ +GDK_SUPPORT_LIBS = @GDK_SUPPORT_LIBS@ +GIFLIBS = @GIFLIBS@ +GMODULE_FLAGS = @GMODULE_FLAGS@ +GMODULE_LIBS = @GMODULE_LIBS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_CONFIG = @GTK_CONFIG@ +GTK_LIBS = @GTK_LIBS@ +GX_LIBS = @GX_LIBS@ +HAVE_GIF_FALSE = @HAVE_GIF_FALSE@ +HAVE_GIF_TRUE = @HAVE_GIF_TRUE@ +HAVE_JPEG_FALSE = @HAVE_JPEG_FALSE@ +HAVE_JPEG_TRUE = @HAVE_JPEG_TRUE@ +HAVE_LIBPNG = @HAVE_LIBPNG@ +HAVE_PNG_FALSE = @HAVE_PNG_FALSE@ +HAVE_PNG_TRUE = @HAVE_PNG_TRUE@ +HAVE_TIFF_FALSE = @HAVE_TIFF_FALSE@ +HAVE_TIFF_TRUE = @HAVE_TIFF_TRUE@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JPEGLIBS = @JPEGLIBS@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@ +MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ +MAKEINFO = @MAKEINFO@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PNGLIBS = @PNGLIBS@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +SUPPORT_LIBS = @SUPPORT_LIBS@ +TIFFLIBS = @TIFFLIBS@ +VERSION = @VERSION@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +ac_ct_RANLIB = @ac_ct_RANLIB@ +ac_ct_STRIP = @ac_ct_STRIP@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +oldincludedir = @oldincludedir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ + +# the resultant executable +lib_LTLIBRARIES = libImlib.la + +include_HEADERS = Imlib.h Imlib_private.h Imlib_types.h + +libImlib_la_SOURCES = \ + cache.c \ + colors.c \ + load.c \ + misc.c \ + rend.c \ + utils.c \ + save.c \ + snprintf.c + + +libImlib_la_LDFLAGS = -version-info 10:15:9 +#libImlib_la_LDDADD = $(SUPPORT_LIBS) +libImlib_la_LIBADD = $(SUPPORT_LIBS) $(X_PRE_LIBS) \ + $(X_LIBS) $(X_EXTRA_LIBS) + + +INCLUDES = -I. -I$(srcdir) -I.. -I$(srcdir)/.. $(X_CFLAGS) + +check_PROGRAMS = t-load + +t_load_LDADD = libImlib.la +subdir = Imlib +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(lib_LTLIBRARIES) + +libImlib_la_DEPENDENCIES = +am_libImlib_la_OBJECTS = cache.lo colors.lo load.lo misc.lo rend.lo \ + utils.lo save.lo snprintf.lo +libImlib_la_OBJECTS = $(am_libImlib_la_OBJECTS) +check_PROGRAMS = t-load$(EXEEXT) +t_load_SOURCES = t-load.c +t_load_OBJECTS = t-load.$(OBJEXT) +t_load_DEPENDENCIES = libImlib.la +t_load_LDFLAGS = + +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/cache.Plo ./$(DEPDIR)/colors.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/load.Plo ./$(DEPDIR)/misc.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/rend.Plo ./$(DEPDIR)/save.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/snprintf.Plo ./$(DEPDIR)/t-load.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/utils.Plo +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \ + $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +DIST_SOURCES = $(libImlib_la_SOURCES) t-load.c +HEADERS = $(include_HEADERS) + +DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.in ChangeLog \ + Makefile.am install-sh mkinstalldirs +SOURCES = $(libImlib_la_SOURCES) t-load.c + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu Imlib/Makefile +Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) +libLTLIBRARIES_INSTALL = $(INSTALL) +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libdir) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(libdir)/$$f"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(libdir)/$$f; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p"; \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" = "$$p" && dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libImlib.la: $(libImlib_la_OBJECTS) $(libImlib_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libImlib_la_LDFLAGS) $(libImlib_la_OBJECTS) $(libImlib_la_LIBADD) $(LIBS) + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +t-load$(EXEEXT): $(t_load_OBJECTS) $(t_load_DEPENDENCIES) + @rm -f t-load$(EXEEXT) + $(LINK) $(t_load_LDFLAGS) $(t_load_OBJECTS) $(t_load_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) core *.core + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cache.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/colors.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/load.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rend.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/save.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snprintf.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t-load.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utils.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ +@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ +@am__fastdepCC_TRUE@ fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ +@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \ +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ +@am__fastdepCC_TRUE@ fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \ +@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; \ +@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \ +@am__fastdepCC_TRUE@ fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +includeHEADERS_INSTALL = $(INSTALL_HEADER) +install-includeHEADERS: $(include_HEADERS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(includedir) + @list='$(include_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(includedir)/$$f"; \ + $(includeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(includedir)/$$f; \ + done + +uninstall-includeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(include_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f $(DESTDIR)$(includedir)/$$f"; \ + rm -f $(DESTDIR)$(includedir)/$$f; \ + done + +ETAGS = etags +ETAGSFLAGS = + +CTAGS = ctags +CTAGSFLAGS = + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique + +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkinstalldirs) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) + +installdirs: + $(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir) +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \ + clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: install-includeHEADERS + +install-exec-am: install-libLTLIBRARIES + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-includeHEADERS uninstall-info-am \ + uninstall-libLTLIBRARIES + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-checkPROGRAMS \ + clean-generic clean-libLTLIBRARIES clean-libtool ctags \ + distclean distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am info info-am install \ + install-am install-data install-data-am install-exec \ + install-exec-am install-includeHEADERS install-info \ + install-info-am install-libLTLIBRARIES install-man \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool pdf \ + pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-includeHEADERS uninstall-info-am \ + uninstall-libLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/debian/imlib/imlib-1.9.15/Imlib/cache.c b/debian/imlib/imlib-1.9.15/Imlib/cache.c new file mode 100644 index 00000000..68eaa873 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/cache.c @@ -0,0 +1,553 @@ +#define _GNU_SOURCE +#include <config.h> +#include "Imlib.h" +#include "Imlib_private.h" + +/* uncomment this to compile imlib's cahce with pixmap accounting output */ +/*#define PIXMAP_ACCOUNTING*/ +/* uncomment this to compile imlib's cahce with image accounting output */ +/*#define IMAGE_ACCOUNTING*/ + +void +dirty_pixmaps(ImlibData * id, ImlibImage * im) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->im == im) && + ((!ptr->file) || ((ptr->file) && (im->filename) && + (!strcmp(im->filename, ptr->file))))) + ptr->dirty = 1; + ptr = ptr->next; + } + clean_caches(id); +} + +void +dirty_images(ImlibData * id, ImlibImage * im) +{ + struct image_cache *ptr; + + ptr = id->cache.image; + while (ptr) + { + if ((!strcmp(im->filename, ptr->file)) && (im == ptr->im)) + { + ptr->dirty = 1; + return; + } + ptr = ptr->next; + } + clean_caches(id); +} + +void +find_pixmap(ImlibData * id, ImlibImage * im, int width, int height, Pixmap * pmap, Pixmap * mask) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->im == im) && + (ptr->width == width) && + (ptr->height == height) && + ((!ptr->file) || ((ptr->file) && (im->filename) && + (!strcmp(im->filename, ptr->file)))) && + (!ptr->dirty)) + { + if (ptr->refnum > 0) + ptr->refnum++; + else + { + ptr->refnum++; + id->cache.num_pixmap++; + if (ptr->pmap) + id->cache.used_pixmap -= width * height * id->x.depth; + if (ptr->shape_mask) + id->cache.used_pixmap -= width * height; + if (id->cache.used_pixmap < 0) + { + id->cache.used_pixmap = 0; + fprintf(stderr, "IMLIB: uhoh.. caching problems.... meep meep\n"); + } + } + if (ptr->prev) + { + ptr->prev->next = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + ptr->next = id->cache.pixmap; + ptr->next->prev = ptr; + id->cache.pixmap = ptr; + ptr->prev = NULL; + } + *pmap = ptr->pmap; + *mask = ptr->shape_mask; + return; + } + ptr = ptr->next; + } + *pmap = 0; + *mask = 0; +} + +ImlibImage * +find_image(ImlibData * id, char *file) +{ + struct image_cache *ptr; + + ptr = id->cache.image; + while (ptr) + { + if ((!strcmp(file, ptr->file)) && (!ptr->dirty)) + { + if (ptr->refnum) + ptr->refnum++; + else + { + ptr->refnum++; + id->cache.num_image++; + id->cache.used_image -= ptr->im->rgb_width * ptr->im->rgb_height * 3; + if (id->cache.used_image < 0) + { + id->cache.used_image = 0; + fprintf(stderr, "IMLIB: uhoh.. caching problems.... meep meep\n"); + } + } + if (ptr->prev) + { + ptr->prev->next = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + ptr->next = id->cache.image; + ptr->next->prev = ptr; + id->cache.image = ptr; + ptr->prev = NULL; + } + return ptr->im; + } + ptr = ptr->next; + } + return NULL; +} + +void +free_pixmappmap(ImlibData * id, Pixmap pmap) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->pmap == pmap) || (ptr->shape_mask == pmap)) + { + if (ptr->shape_mask == pmap) + return; + if (ptr->refnum > 0) + { + ptr->refnum--; + if (ptr->refnum == 0) + { + id->cache.num_pixmap--; + if (ptr->pmap) + id->cache.used_pixmap += ptr->width * ptr->height * + id->x.depth; + if (ptr->shape_mask) + id->cache.used_pixmap += ptr->width * ptr->height; + } + } + return; + } + ptr = ptr->next; + } + XFreePixmap(id->x.disp, pmap); +} + +void +free_image(ImlibData * id, ImlibImage * im) +{ + struct image_cache *ptr; + + ptr = id->cache.image; + while (ptr) + { + if (im == ptr->im) + { + if (ptr->refnum) + { + ptr->refnum--; + if (ptr->refnum == 0) + { + id->cache.num_image--; + id->cache.used_image += ptr->im->rgb_width * ptr->im->rgb_height * 3; + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + im->shape_mask = 0; + } + } + } + return; + } + ptr = ptr->next; + } + nullify_image(id, im); +} + +void +flush_image(ImlibData * id, ImlibImage * im) +{ + if (im) + im->cache = 0; +} + +void +add_image(ImlibData * id, ImlibImage * im, char *file) +{ + struct image_cache *ptr; + struct image_cache *n; + + if ((!im) || (!file)) + return; + ptr = id->cache.image; + n = malloc(sizeof(struct image_cache)); + + if (!n) + return; + n->prev = NULL; + n->next = ptr; + n->file = malloc(strlen(file) + 1); + if (!n->file) + { + free(n); + return; + } + strcpy(n->file, file); + n->im = im; + n->refnum = 1; + n->dirty = 0; + if (n->next) + n->next->prev = n; + id->cache.image = n; + id->cache.num_image++; +} + +void +add_pixmap(ImlibData * id, ImlibImage * im, int width, int height, XImage * xim, XImage * sxim) +{ + struct pixmap_cache *ptr; + struct pixmap_cache *n; + + if (!im) + return; + ptr = id->cache.pixmap; + n = malloc(sizeof(struct pixmap_cache)); + + if (!n) + return; + n->prev = NULL; + n->next = ptr; + n->im = im; + if (im->filename) + { + n->file = malloc(strlen(im->filename) + 1); + if (n->file) + strcpy(n->file, im->filename); + } + else + n->file = NULL; + n->refnum = 1; + n->dirty = 0; + n->width = width; + n->height = height; + n->pmap = im->pixmap; + n->shape_mask = im->shape_mask; + n->xim = xim; + n->sxim = sxim; + if (n->next) + n->next->prev = n; + id->cache.pixmap = n; + id->cache.num_pixmap++; +} + +void +clean_caches(ImlibData * id) +{ + { + struct image_cache *ptr = NULL; + struct image_cache *pptr = NULL; + struct image_cache *last = NULL; + int newlast; + +#ifdef IMAGE_ACCOUNTING + int total, total2, num, num2; + + fprintf(stderr, + "--------- Image cache sise %i / %i with %i images referenced\n", + id->cache.used_image, id->cache.size_image, + id->cache.num_image); + ptr = id->cache.image; + total = 0; + total2 = 0; + num = 0; + num2 = 0; + while (ptr) + { + fprintf(stderr, + "Image for file %80s REFNUM %3i SIZE %4ix%4i\n", + ptr->file, ptr->refnum, ptr->im->rgb_width, + ptr->im->rgb_height); + if (ptr->refnum > 0) + { + total += (ptr->im->rgb_width * ptr->im->rgb_height * 3); + num++; + } + else + { + total2 += (ptr->im->rgb_width * ptr->im->height * 3); + num2++; + } + ptr = ptr->next; + } + fprintf(stderr, "Accounting Data:\n"); + fprintf(stderr, "*** total images in cache %i with %i images\n", + total, num); + fprintf(stderr, + "*** total unref images in cache %i with %i images\n\n", + total2, num2); +#endif + /* find the back of the list */ + ptr = id->cache.image; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + newlast = 0; + ptr = last; + /* remove all images that are tagged non-cachable, and have 0 */ + /* references , even if the cache has spare room. */ + while (ptr) + { + if (ptr->refnum <= 0) + { + if (!ptr->im->cache) + { + id->cache.used_image -= ptr->im->rgb_width * + ptr->im->rgb_height * 3; + nullify_image(id, ptr->im); + if (ptr->prev) + ptr->prev->next = ptr->next; + else + id->cache.image = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + if (ptr->file) + free(ptr->file); + last = ptr; + ptr = ptr->prev; + free(last); + } + else + ptr = ptr->prev; + } + else + ptr = ptr->prev; + } + /* find the back of the list */ + ptr = id->cache.image; + last = NULL; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + ptr = last; + newlast = 0; + /* while the amount of data in the cache is greater than the set */ + /* amount, delete the last entry (last used) from the unreferenced */ + /* cached 24-bit images */ + while (id->cache.used_image > id->cache.size_image) + { + if (newlast) + { + ptr = id->cache.image; + last = NULL; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + ptr = last; + newlast = 0; + } + while (ptr) + { + if (ptr->refnum <= 0) + { + id->cache.used_image -= ptr->im->rgb_width + * ptr->im->rgb_height * 3; + nullify_image(id, ptr->im); + if (ptr->prev) + ptr->prev->next = ptr->next; + else + id->cache.image = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + if (ptr->file) + free(ptr->file); + last = ptr; + ptr = ptr->prev; + free(last); + newlast = 1; + } + else + ptr = ptr->prev; + if (id->cache.used_image <= id->cache.size_image) + ptr = NULL; + } + } + } + { + struct pixmap_cache *ptr; + struct pixmap_cache *last; + int newlast; + +#ifdef PIXMAP_ACCOUNTING + int total, total2, num, num2; + + fprintf(stderr, + "--------- Pixmap cache sie %i / %i with %i pixmaps referenced\n", + id->cache.used_pixmap, id->cache.size_pixmap, + id->cache.num_pixmap); + ptr = id->cache.pixmap; + total = 0; + total2 = 0; + num = 0; + num2 = 0; + while (ptr) + { + fprintf(stderr, + "Pmap for file %80s REFNUM %3i SIZE %4ix%4i" + " PMAP %8x MASK %8x\n", + ptr->file, ptr->refnum, ptr->width, ptr->height, ptr->pmap, + ptr->shape_mask); + if (ptr->refnum > 0) + { + total += (ptr->width * ptr->height * id->x.depth); + if (ptr->shape_mask) + total += (ptr->width * ptr->height); + num++; + } + else + { + total2 += (ptr->width * ptr->height * id->x.depth); + if (ptr->shape_mask) + total2 += (ptr->width * ptr->height); + num2++; + } + ptr = ptr->next; + } + fprintf(stderr, "Accounting Data:\n"); + fprintf(stderr, "*** total pixmaps in cache %i with %i pixmaps\n", + total, num); + fprintf(stderr, + "*** total unref pixmaps in cache %i with %i pixmaps\n\n", + total2, num2); +#endif + ptr = id->cache.pixmap; + while (ptr) + { + last = ptr->next; + if ((ptr->dirty) && (ptr->refnum <= 0)) + { + if (ptr->pmap) + id->cache.used_pixmap -= ptr->width * ptr->height * id->x.depth; + if (ptr->shape_mask) + id->cache.used_pixmap -= ptr->width * ptr->height; + if (ptr->pmap) + XFreePixmap(id->x.disp, ptr->pmap); + if (ptr->shape_mask) + XFreePixmap(id->x.disp, ptr->shape_mask); + if (ptr->xim) + XDestroyImage(ptr->xim); + if (ptr->sxim) + XDestroyImage(ptr->sxim); + if (ptr->prev) + ptr->prev->next = ptr->next; + else + id->cache.pixmap = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + free(ptr->file); + free(ptr); + } + ptr = last; + } + /* find the back of the list */ + last = NULL; + ptr = id->cache.pixmap; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + ptr = last; + /* the amount of data in the cache is greater than the set */ + /* amount, delete the last entry (last used) from the unreferenced */ + /* cached pixmaps */ + while ((ptr) && (id->cache.used_pixmap > id->cache.size_pixmap)) + { + if (ptr->refnum <= 0) + { + if (ptr->pmap) + id->cache.used_pixmap -= ptr->width * ptr->height * id->x.depth; + if (ptr->shape_mask) + id->cache.used_pixmap -= ptr->width * ptr->height; + if (ptr->pmap) + XFreePixmap(id->x.disp, ptr->pmap); + if (ptr->shape_mask) + XFreePixmap(id->x.disp, ptr->shape_mask); + if (ptr->xim) + XDestroyImage(ptr->xim); + if (ptr->sxim) + XDestroyImage(ptr->sxim); + if (ptr->prev) + ptr->prev->next = ptr->next; + else + id->cache.pixmap = ptr->next; + if (ptr->next) + ptr->next->prev = ptr->prev; + if (ptr->file) + free(ptr->file); + last = ptr; + ptr = ptr->prev; + free(last); + } + else + ptr = ptr->prev; + if (id->cache.used_pixmap <= id->cache.size_pixmap) + ptr = NULL; + } + } +} + +void +nullify_image(ImlibData * id, ImlibImage * im) +{ + if (!im) + return; + if (im->rgb_data) + free(im->rgb_data); + if (im->alpha_data) + free(im->alpha_data); + if (im->pixmap) + free_pixmappmap(id, im->pixmap); + if (im->filename) + free(im->filename); + free(im); +} diff --git a/debian/imlib/imlib-1.9.15/Imlib/colors.c b/debian/imlib/imlib-1.9.15/Imlib/colors.c new file mode 100644 index 00000000..bf2e944f --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/colors.c @@ -0,0 +1,271 @@ +#define _GNU_SOURCE +#include <config.h> +#include "Imlib.h" +#include "Imlib_private.h" + +#ifndef HAVE_BASENAME +#include <string.h> +#endif + +#ifdef __EMX__ +extern const char *__XOS2RedirRoot(const char*); +#endif + +static int PaletteLUTGet(ImlibData *id); +static void PaletteLUTSet(ImlibData *id); + +static int +PaletteLUTGet(ImlibData *id) +{ + unsigned char *retval; + Atom type_ret; + unsigned long bytes_after, num_ret; + int format_ret; + long length; + Atom to_get; + + retval = NULL; + length = 0x7fffffff; + to_get = XInternAtom(id->x.disp, "_IMLIB_COLORMAP", False); + XGetWindowProperty(id->x.disp, id->x.root, to_get, 0, length, False, + XA_CARDINAL, &type_ret, &format_ret, &num_ret, + &bytes_after, &retval); + if ((retval) && (num_ret > 0) && (format_ret > 0)) + { + if (format_ret == 8) + { + int j, i, pnum; + + pnum = (int)(retval[0]); + j = 1; + if (pnum != id->num_colors) + { + XFree(retval); + return 0; + } + for (i = 0; i < id->num_colors; i++) + { + if (retval[j++] != ((unsigned char)id->palette[i].r)) + { + XFree(retval); + return 0; + } + if (retval[j++] != ((unsigned char)id->palette[i].g)) + { + XFree(retval); + return 0; + } + if (retval[j++] != ((unsigned char)id->palette[i].b)) + { + XFree(retval); + return 0; + } + if (retval[j++] != ((unsigned char)id->palette[i].pixel)) + { + XFree(retval); + return 0; + } + } + if (id->fast_rgb) + free(id->fast_rgb); + id->fast_rgb = malloc(sizeof(unsigned char) * 32 * 32 * 32); + for (i = 0; (i < (32 * 32 * 32)) && (j < num_ret); i++) + id->fast_rgb[i] = retval[j++]; + XFree(retval); + return 1; + } + else + XFree(retval); + } + return 0; +} + +static void +PaletteLUTSet(ImlibData *id) +{ + Atom to_set; + unsigned char *prop; + int i, j; + + to_set = XInternAtom(id->x.disp, "_IMLIB_COLORMAP", False); + prop = malloc((id->num_colors * 4) + 1 + (32 * 32 * 32)); + prop[0] = id->num_colors; + j = 1; + for (i = 0; i < id->num_colors; i++) + { + prop[j++] = (unsigned char)id->palette[i].r; + prop[j++] = (unsigned char)id->palette[i].g; + prop[j++] = (unsigned char)id->palette[i].b; + prop[j++] = (unsigned char)id->palette[i].pixel; + } + for (i = 0; i < (32 * 32 * 32); i++) + prop[j++] = (unsigned char)id->fast_rgb[i]; + XChangeProperty(id->x.disp, id->x.root, to_set, XA_CARDINAL, 8, + PropModeReplace, (unsigned char *)prop, j); + free(prop); +} + +void +_PaletteAlloc(ImlibData * id, int num, int *cols) +{ + XColor xcl; + int colnum, i, j; + int r, g, b; + int used[256], num_used, is_used; + + if (id->palette) + free(id->palette); + id->palette = malloc(sizeof(ImlibColor) * num); + if (id->palette_orig) + free(id->palette_orig); + id->palette_orig = malloc(sizeof(ImlibColor) * num); + num_used = 0; + colnum = 0; + for (i = 0; i < num; i++) + { + r = cols[(i * 3) + 0]; + g = cols[(i * 3) + 1]; + b = cols[(i * 3) + 2]; + xcl.red = (unsigned short)((r << 8) | (r)); + xcl.green = (unsigned short)((g << 8) | (g)); + xcl.blue = (unsigned short)((b << 8) | (b)); + xcl.flags = DoRed | DoGreen | DoBlue; + XAllocColor(id->x.disp, id->x.root_cmap, &xcl); + is_used = 0; + for (j = 0; j < num_used; j++) + { + if (xcl.pixel == used[j]) + { + is_used = 1; + j = num_used; + } + } + if (!is_used) + { + id->palette[colnum].r = xcl.red >> 8; + id->palette[colnum].g = xcl.green >> 8; + id->palette[colnum].b = xcl.blue >> 8; + id->palette[colnum].pixel = xcl.pixel; + used[num_used++] = xcl.pixel; + colnum++; + } + else + xcl.pixel = 0; + id->palette_orig[i].r = r; + id->palette_orig[i].g = g; + id->palette_orig[i].b = b; + id->palette_orig[i].pixel = xcl.pixel; + } + id->num_colors = colnum; +} + +int +Imlib_load_colors(ImlibData * id, char *file) +{ + FILE *f; + char s[1024]; + int i; + int pal[768]; + int r, g, b; + int rr, gg, bb; + +#ifndef __EMX__ + f = fopen(file, "r"); +#else + if (*file =='/') + f = fopen(__XOS2RedirRoot(file), "rt"); + else + f = fopen(file, "rt"); +#endif + +#ifndef __EMX__ + if (!f) + { + char *ctmp; + +#ifdef HAVE_BASENAME + ctmp = basename(file); +#else + char *base; + + base = strrchr(file, '/'); + if (base) + ctmp = base + 1; + else + ctmp = file; +#endif /* HAVE_BASENAME */ + + if(ctmp) { snprintf(s, sizeof(s), "%s/%s", SYSCONFDIR, ctmp); + f = fopen(s, "r"); } + } +#endif /* __EMX__ */ + + if (!f) + { + fprintf(stderr, "ImLib ERROR: Cannot find palette file %s\n", file); + return 0; + } + i = 0; + while (fgets(s, sizeof(s), f)) + { + if (s[0] == '0') + { + sscanf(s, "%x %x %x", &r, &g, &b); + if (r < 0) + r = 0; + if (r > 255) + r = 255; + if (g < 0) + g = 0; + if (g > 255) + g = 255; + if (b < 0) + b = 0; + if (b > 255) + b = 255; + pal[i++] = r; + pal[i++] = g; + pal[i++] = b; + } + if (i >= 768) + break; + } + fclose(f); + XGrabServer(id->x.disp); + _PaletteAlloc(id, (i / 3), pal); + if (!PaletteLUTGet(id)) + { + if (id->fast_rgb) + free(id->fast_rgb); + id->fast_rgb = malloc(sizeof(unsigned char) * 32 * 32 * 32); + + for (r = 0; r < 32; r++) + { + for (g = 0; g < 32; g++) + { + for (b = 0; b < 32; b++) + { + rr = (r << 3) | (r >> 2); + gg = (g << 3) | (g >> 2); + bb = (b << 3) | (b >> 2); + INDEX_RGB(r, g, b) = index_best_color_match(id, &rr, &gg, &bb); + } + } + } + PaletteLUTSet(id); + } + XUngrabServer(id->x.disp); + return 1; +} + +void +Imlib_free_colors(ImlibData * id) +{ + int i; + unsigned long pixels[256]; + + for (i = 0; i < id->num_colors; i++) + pixels[i] = id->palette[i].pixel; + XFreeColors(id->x.disp, id->x.root_cmap, pixels, id->num_colors, 0); + id->num_colors = 0; +} diff --git a/debian/imlib/imlib-1.9.15/Imlib/install-sh b/debian/imlib/imlib-1.9.15/Imlib/install-sh new file mode 100755 index 00000000..89fc9b09 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/install-sh @@ -0,0 +1,238 @@ +#! /bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. +# + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +tranformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + true +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + else + instcmd=mkdir + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f $src -o -d $src ] + then + true + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + true + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + true + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' +' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + true + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + true + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/debian/imlib/imlib-1.9.15/Imlib/load.c b/debian/imlib/imlib-1.9.15/Imlib/load.c new file mode 100644 index 00000000..8a3b17d5 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/load.c @@ -0,0 +1,2081 @@ +#define _GNU_SOURCE +#include <config.h> +#include "Imlib.h" +#include "Imlib_private.h" +#include <setjmp.h> + +/* Split the ID - damages input */ + +static char * +_SplitID(char *file) +{ +#ifndef __EMX__ + char *p = strrchr(file, ':'); +#else + char *p = strrchr(file, ';'); +#endif + + if (p == NULL) + return ""; + else + { + *p++ = 0; + return p; + } +} + +/* + * * Doesn't damage the input + */ + +char * +_GetExtension(char *file) +{ + char *p = strrchr(file, '.'); + + if (p == NULL) + return ""; + else + return p + 1; +} + +/* + * Make sure we don't wrap on our memory allocations + */ + +void * _imlib_malloc_image(unsigned int w, unsigned int h) +{ + if( w > 32767 || h > 32767) + return NULL; + return malloc(w * h * 3); +} + +#ifdef HAVE_LIBJPEG + +/** + * * This error handling is broken beyond belief, but oh well it works + * **/ + +struct ImLib_JPEG_error_mgr +{ + struct jpeg_error_mgr pub; + sigjmp_buf setjmp_buffer; +}; + +typedef struct ImLib_JPEG_error_mgr *emptr; + +void +_JPEGFatalErrorHandler(j_common_ptr cinfo) +{ + /* + * FIXME: + * We should somehow signal what error occurred to the caller so the + * caller can handle the error message + */ + emptr errmgr; + + errmgr = (emptr) cinfo->err; + cinfo->err->output_message(cinfo); + siglongjmp(errmgr->setjmp_buffer, 1); + return; +} + +unsigned char * +_LoadJPEG(ImlibData * id, FILE * f, int *w, int *h) +{ + struct jpeg_decompress_struct cinfo; + struct ImLib_JPEG_error_mgr jerr; + unsigned char *data, *line[16], *ptr; + int x, y, i; + + cinfo.err = jpeg_std_error(&(jerr.pub)); + jerr.pub.error_exit = _JPEGFatalErrorHandler; + + /* error handler to longjmp to, we want to preserve signals */ + if (sigsetjmp(jerr.setjmp_buffer, 1)) + { + /* Whoops there was a jpeg error */ + jpeg_destroy_decompress(&cinfo); + return NULL; + } + + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, f); + jpeg_read_header(&cinfo, TRUE); + cinfo.do_fancy_upsampling = FALSE; + cinfo.do_block_smoothing = FALSE; + jpeg_start_decompress(&cinfo); + *w = cinfo.output_width; + *h = cinfo.output_height; + data = _imlib_malloc_image(*w, *h); + if (!data) + { + jpeg_destroy_decompress(&cinfo); + return NULL; + } + ptr = data; + + if (cinfo.rec_outbuf_height > 16) + { + fprintf(stderr, "Imlib ERROR: JPEG uses line buffers > 16. Cannot load.\n"); + return NULL; + } + if (cinfo.output_components == 3) + { + for (y = 0; y < *h; y += cinfo.rec_outbuf_height) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + { + line[i] = ptr; + ptr += *w * 3; + } + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + } + } + else if (cinfo.output_components == 1) + { + for (i = 0; i < cinfo.rec_outbuf_height; i++) + { + if ((line[i] = malloc(*w)) == NULL) + { + int t = 0; + + for (t = 0; t < i; t++) + free(line[t]); + jpeg_destroy_decompress(&cinfo); + return NULL; + } + } + for (y = 0; y < *h; y += cinfo.rec_outbuf_height) + { + jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); + for (i = 0; i < cinfo.rec_outbuf_height; i++) + { + for (x = 0; x < *w; x++) + { + *ptr++ = line[i][x]; + *ptr++ = line[i][x]; + *ptr++ = line[i][x]; + } + } + } + for (i = 0; i < cinfo.rec_outbuf_height; i++) + free(line[i]); + } + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + return data; +} +#endif /* HAVE_LIBJPEG */ + +#ifdef HAVE_LIBPNG +unsigned char * +_LoadPNG(ImlibData * id, FILE * f, int *w, int *h, int *t) +{ + png_structp png_ptr; + png_infop info_ptr; + unsigned char *data, *ptr, **lines, *ptr2, r, g, b, a; + int i, x, y, transp, bit_depth, color_type, interlace_type; + png_uint_32 ww, hh; + + /* Init PNG Reader */ + transp = 0; + + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + return NULL; + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, NULL, NULL); + return NULL; + } + if (setjmp(png_ptr->jmpbuf)) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + png_init_io(png_ptr, f); + + /* Read Header */ + png_read_info(png_ptr, info_ptr); + png_get_IHDR(png_ptr, info_ptr, &ww, &hh, + &bit_depth, &color_type, &interlace_type, NULL, NULL); + *w = ww; + *h = hh; + + /* Setup Translators */ + if ((color_type == PNG_COLOR_TYPE_PALETTE) || + (color_type == PNG_COLOR_TYPE_GRAY)) + png_set_expand(png_ptr); + png_set_strip_16(png_ptr); + png_set_packing(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_expand(png_ptr); + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + data = _imlib_malloc_image(*w, *h); + if (!data) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + /* This malloc is fine, _imlib_malloc_image will fail first */ + lines = (unsigned char **)malloc(*h * sizeof(unsigned char *)); + + if (lines == NULL) + { + free(data); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + + for (i = 0; i < *h; i++) + { + /* Safe as well for the same reason as above */ + if ((lines[i] = malloc(*w * (sizeof(unsigned char) * 4))) == NULL) + { + int n; + + free(data); + for (n = 0; n < i; n++) + free(lines[n]); + free(lines); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + } + + png_read_image(png_ptr, lines); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + ptr = data; + if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + r = *ptr2++; + a = *ptr2++; + if (a < 128) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + transp = 1; + } + else + { + *ptr++ = r; + *ptr++ = r; + *ptr++ = r; + } + } + } + } + else if (color_type == PNG_COLOR_TYPE_GRAY) + { + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + r = *ptr2++; + ptr2++; + *ptr++ = r; + *ptr++ = r; + *ptr++ = r; + } + } + } + else + { + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + r = *ptr2++; + g = *ptr2++; + b = *ptr2++; + a = *ptr2++; + if (a < 128) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + transp = 1; + } + else + { + if ((r == 255) && (g == 0) && (b == 255)) + r = 254; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + } + for (i = 0; i < *h; i++) + free(lines[i]); + free(lines); + *t = transp; + return data; +} +#endif /* HAVE_LIBPNG */ + +#ifdef HAVE_LIBTIFF +unsigned char * +_LoadTIFF(ImlibData * id, FILE *f, char *file, int *w, int *h, int *t) +{ + TIFF *tif; + unsigned char *data, *ptr, r, g, b, a; + int x, y; + uint32 ww, hh, *rast, *tptr; + size_t npix; + int istransp; + int fd; + + istransp = 0; + if (!f) + return NULL; + + fd = fileno(f); + /* Apparently rewind(f) isn't sufficient */ + lseek(fd, (long) 0, 0); + /* So why does libtif need a filename here ??? */ + tif = TIFFFdOpen(fd, file, "r"); + + if (!tif) + return NULL; + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &ww); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &hh); + npix = ww * hh; + *w = (int)ww; + *h = (int)hh; + if(ww > 32767 || hh > 32767) + { + TIFFClose(tif); + return NULL; + } + rast = (uint32 *) _TIFFmalloc(npix * sizeof(uint32)); + if (!rast) + { + TIFFClose(tif); + return NULL; + } + data = NULL; + if (TIFFReadRGBAImage(tif, ww, hh, rast, 0)) + { + data = (unsigned char *)malloc(*w ** h * 3); + if (!data) + { + _TIFFfree(rast); + TIFFClose(tif); + return NULL; + } + ptr = data; + for (y = 0; y < *h; y++) + { + tptr = rast; + tptr += ((*h - y - 1) ** w); + for (x = 0; x < *w; x++) + { + a = TIFFGetA(*tptr); + b = TIFFGetB(*tptr); + g = TIFFGetG(*tptr); + r = TIFFGetR(*tptr); + tptr++; + if (a < 128) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + istransp = 1; + } + else + { + if ((r == 255) && (g == 0) && (b == 255)) + r = 254; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + } + _TIFFfree(rast); + TIFFClose(tif); + *t = istransp; + return data; +} + +#endif /* HAVE_LIBTIFF */ + +#ifdef HAVE_LIBGIF +unsigned char * +_LoadGIF(ImlibData * id, FILE *f, int *w, int *h, int *t) +{ + unsigned char *data, *ptr; + GifFileType *gif; + GifRowType *rows; + GifRecordType rec; + ColorMapObject *cmap; + int i, j, done, bg, csize, r, g, b; + int intoffset[] = {0, 4, 2, 1}; + int intjump[] = {8, 8, 4, 2}; + int istransp, transp; + int fd; + + done = 0; + istransp = 0; + data = NULL; + rows = NULL; + transp = -1; + + fd = fileno(f); + /* Apparently rewind(f) isn't sufficient */ + lseek(fd, (long) 0, 0); + gif = DGifOpenFileHandle(fd); + + if (!gif) + return NULL; + do + { + if (DGifGetRecordType(gif, &rec) == GIF_ERROR) + { + PrintGifError(); + rec = TERMINATE_RECORD_TYPE; + } + if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done)) + { + if (DGifGetImageDesc(gif) == GIF_ERROR) + { + PrintGifError(); + rec = TERMINATE_RECORD_TYPE; + } + *w = gif->Image.Width; + *h = gif->Image.Height; + if (*h > 32767 || *w > 32767) + { + return NULL; + } + rows = malloc(*h * sizeof(GifRowType *)); + if (!rows) + { + DGifCloseFile(gif); + return NULL; + } + data = _imlib_malloc_image(*w, *h); + if (!data) + { + DGifCloseFile(gif); + free(rows); + return NULL; + } + for (i = 0; i < *h; i++) + rows[i] = NULL; + for (i = 0; i < *h; i++) + { + rows[i] = malloc(*w * sizeof(GifPixelType)); + if (!rows[i]) + { + DGifCloseFile(gif); + for (i = 0; i < *h; i++) + if (rows[i]) + free(rows[i]); + free(rows); + free(data); + return NULL; + } + } + if (gif->Image.Interlace) + { + for (i = 0; i < 4; i++) + { + for (j = intoffset[i]; j < *h; j += intjump[i]) + DGifGetLine(gif, rows[j], *w); + } + } + else + { + for (i = 0; i < *h; i++) + DGifGetLine(gif, rows[i], *w); + } + done = 1; + } + else if (rec == EXTENSION_RECORD_TYPE) + { + int ext_code; + GifByteType *ext; + + ext = NULL; + DGifGetExtension(gif, &ext_code, &ext); + while (ext) + { + if ((ext_code == 0xf9) && (ext[1] & 1) && (transp < 0)) + { + istransp = 1; + transp = (int)ext[4]; + } + ext = NULL; + DGifGetExtensionNext(gif, &ext); + } + } + } + while (rec != TERMINATE_RECORD_TYPE); + bg = gif->SBackGroundColor; + cmap = (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap); + csize = cmap->ColorCount; + ptr = data; + if (!istransp) + { + for (i = 0; i < *h; i++) + { + for (j = 0; j < *w; j++) + { + r = cmap->Colors[rows[i][j]].Red; + g = cmap->Colors[rows[i][j]].Green; + b = cmap->Colors[rows[i][j]].Blue; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + else + { + for (i = 0; i < *h; i++) + { + for (j = 0; j < *w; j++) + { + if (rows[i][j] == transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + r = cmap->Colors[rows[i][j]].Red; + g = cmap->Colors[rows[i][j]].Green; + b = cmap->Colors[rows[i][j]].Blue; + if ((r == 255) && (g == 0) && (b == 255)) + r = 254; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + } + DGifCloseFile(gif); + for (i = 0; i < *h; i++) + free(rows[i]); + free(rows); + *t = istransp; + return data; +} + +#endif /* HAVE_LIBGIF */ + +unsigned char * +_LoadBMP(ImlibData * id, FILE *file, int *w, int *h, int *t) +{ + unsigned char *data, *ptr; + int done, i, bpp, planes, comp, ncolors, line, column, + linesize, linepos, rshift, gshift, bshift, size; + unsigned char byte; + short int word; + long int dbuf[4], dword, rmask, gmask, bmask, offset; + signed char bbuf[4]; + struct _cmap + { + unsigned char r, g, b; + } + *cmap; + +#define BI_RGB 0 +#define BI_RLE8 1 +#define BI_RLE4 2 +#define BI_BITFIELDS 3 + + rshift = 0; + gshift = 0; + bshift = 0; + rmask = 0xff; + gmask = 0xff; + bmask = 0xff; + if (!file) + return NULL; + + done = 0; + /* + * reading the bmp header + */ + + fread(bbuf, 1, 2, file); + + fread(dbuf, 4, 4, file); + + size = dbuf[0]; + offset = dbuf[2]; + + fread(dbuf, 4, 2, file); + *w = (int)dbuf[0]; + *h = (int)dbuf[1]; + if ((*w > 32767) || (*w < 0)) + { + fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n"); + return NULL; + } + if ((*h > 32767) || (*h < 0)) + { + fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n"); + return NULL; + } + fread(&word, 2, 1, file); + planes = (int)word; + fread(&word, 2, 1, file); + bpp = (int)word; + if (bpp != 1 && bpp != 4 && bpp != 8 && bpp && 16 && bpp != 24 && bpp != 32) + { + fprintf(stderr, "IMLIB ERROR: unknown bitdepth in file\n"); + return NULL; + } + fread(dbuf, 4, 4, file); + comp = (int)dbuf[0]; + if (comp != BI_RGB && comp != BI_RLE4 && comp != BI_RLE8 && comp != BI_BITFIELDS) + { + fprintf(stderr, "IMLIB ERROR: unknown encoding in Windows BMP file\n"); + return NULL; + } + fread(dbuf, 4, 2, file); + ncolors = (int)dbuf[0]; + if ((ncolors > (1 << bpp)) || (ncolors < 0)) + ncolors = 1 << bpp; + if ((ncolors < 0) || (ncolors > (1 << bpp))) + ncolors = 1 << bpp; + + /* some more sanity checks */ + if (((comp == BI_RLE4) && (bpp != 4)) || ((comp == BI_RLE8) && (bpp != 8)) || ((comp == BI_BITFIELDS) && (bpp != 16 && bpp != 32))) + { + fprintf(stderr, "IMLIB ERROR: encoding of BMP doesn't match bitdepth\n"); + return NULL; + } + if (bpp < 16) + { + cmap = (struct _cmap *)malloc(sizeof(struct _cmap) * ncolors); + + if (!cmap) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for color map in BMP file\n"); + return NULL; + } + } + else + cmap = NULL; + ptr = (unsigned char *)_imlib_malloc_image(*w, *h); + if (!ptr) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for RGB data in file\n"); + if (cmap) + free(cmap); + return NULL; + } + + /* + * Reading the palette, if it exists. + */ + if (bpp < 16 && ncolors != 0) + { + for (i = 0; i < ncolors; i++) + { + fread(bbuf, 1, 4, file); + cmap[i].b = bbuf[0]; + cmap[i].g = bbuf[1]; + cmap[i].r = bbuf[2]; + } + } + else if (bpp == 16 || bpp == 32) + { + if (comp == BI_BITFIELDS) + { + int bit = 0; + + fread(dbuf, 4, 3, file); + bmask = dbuf[0]; + gmask = dbuf[1]; + rmask = dbuf[2]; + /* find shift amount.. ugly, but i can't think of a better way */ + for (bit = 0; bit < bpp; bit++) + { + if (bmask & (1 << bit)) + bshift = bit; + if (gmask & (1 << bit)) + gshift = bit; + if (rmask & (1 << bit)) + rshift = bit; + } + } + else if (bpp == 16) + { + rmask = 0x7C00; + gmask = 0x03E0; + bmask = 0x001F; + rshift = 10; + gshift = 5; + bshift = 0; + } + else if (bpp == 32) + { + rmask = 0x00FF0000; + gmask = 0x0000FF00; + bmask = 0x000000FF; + rshift = 16; + gshift = 8; + bshift = 0; + } + } + + /* + * Reading the image data + */ + fseek(file, offset, SEEK_SET); + data = ptr; + + /* set the whole image to the background color */ + if (bpp < 16 && (comp == BI_RLE4 || comp == BI_RLE8)) + { + for (i = 0; i < *w * *h; i++) + { + *ptr++ = cmap[0].r; + *ptr++ = cmap[0].g; + *ptr++ = cmap[0].b; + } + ptr = data; + } + line = 0; + column = 0; +#define poffset (line * *w * 3 + column * 3) + + /* + * BMPs are stored upside down... hmmmmmmmmmm.... + */ + + linesize = ((*w * bpp + 31) / 32) * 4; + for (line = (*h - 1); line >= 0; line--) + { + linepos = 0; + for (column = 0; column < *w;) + { + if (bpp < 16) + { + int index; + + linepos++; + byte = getc(file); + if (bpp == 1) + { + int bit = 0; + + for (bit = 0; bit < 8; bit++) + { + index = ((byte & (0x80 >> bit)) ? 1 : 0); + /* possibly corrupted file? */ + if (index < ncolors && poffset < *w * *h * 3) + { + ptr[poffset] = cmap[index].r; + ptr[poffset + 1] = cmap[index].g; + ptr[poffset + 2] = cmap[index].b; + } + column++; + } + } + else if (bpp == 4) + { + if (comp == BI_RLE4) + { + fprintf(stderr, "can't deal with 4bit encoded yet.\n"); + free(data); + free(cmap); + return NULL; + } + else + { + int nibble = 0; + + for (nibble = 0; nibble < 2; nibble++) + { + index = ((byte & (0xF0 >> nibble * 4)) >> (!nibble * 4)); + if (index >= 16) + index = 15; + /* possibly corrupted file? */ + if (index < ncolors && poffset < *w * *h * 3) + { + ptr[poffset] = cmap[index].r; + ptr[poffset + 1] = cmap[index].g; + ptr[poffset + 2] = cmap[index].b; + } + column++; + } + } + } + else if (bpp == 8) + { + if (comp == BI_RLE8) + { + unsigned char first = byte; + + byte = getc(file); + if (first == 0) + { + if (byte == 0) + { + /* column = *w; */ + } + else if (byte == 1) + { + column = *w; + line = -1; + } + else if (byte == 2) + { + byte = getc(file); + column += byte; + linepos = column * bpp / 8; + byte = getc(file); + line += byte; + } + else + { + int absolute = byte; + + for (i = 0; i < absolute; i++) + { + linepos++; + byte = getc(file); + /* possibly corrupted file? */ + if (byte < ncolors && poffset < *w * *h * 3) + { + ptr[poffset] = cmap[byte].r; + ptr[poffset + 1] = cmap[byte].g; + ptr[poffset + 2] = cmap[byte].b; + } + column++; + } + if (absolute & 0x01) + byte = getc(file); + } + } + else + { + for (i = 0; i < first; i++) + { + /* possibly corrupted file? */ + if (byte < ncolors && poffset < *w * *h * 3) + { + ptr[poffset] = cmap[byte].r; + ptr[poffset + 1] = cmap[byte].g; + ptr[poffset + 2] = cmap[byte].b; + } + column++; + linepos++; + } + } + } + else + { + /* possibly corrupted file? */ + if (byte < ncolors && poffset < *w * *h * 3) + { + ptr[poffset] = cmap[byte].r; + ptr[poffset + 1] = cmap[byte].g; + ptr[poffset + 2] = cmap[byte].b; + } + column++; + } + } + } + else if (bpp == 24) + { + linepos += fread(bbuf, 1, 3, file); + /* possibly corrupted file? */ + if (poffset < *w * *h * 3) + { + ptr[poffset] = (unsigned char)bbuf[2]; + ptr[poffset + 1] = (unsigned char)bbuf[1]; + ptr[poffset + 2] = (unsigned char)bbuf[0]; + } + column++; + } + else if (bpp == 16) + { + unsigned char temp; + + linepos += fread(&word, 2, 1, file); + /* possibly corrupted file? */ + if (poffset < *w * *h * 3) + { + temp = (word & rmask) >> rshift; + ptr[poffset] = temp; + temp = (word & gmask) >> gshift; + ptr[poffset + 1] = temp; + temp = (word & bmask) >> gshift; + ptr[poffset + 2] = temp; + } + column++; + } + else + { + unsigned char temp; + + linepos += fread(&dword, 4, 1, file); + /* possibly corrupted file? */ + if (poffset < *w * *h * 3) + { + temp = (dword & rmask) >> rshift; + ptr[poffset] = temp; + temp = (dword & gmask) >> gshift; + ptr[poffset + 1] = temp; + temp = (dword & bmask) >> bshift; + ptr[poffset + 2] = temp; + } + column++; + } + } + while ((linepos < linesize) && (comp != 1) && (comp != 2)) + { + int temp = fread(&byte, 1, 1, file); + + linepos += temp; + if (!temp) + break; + } + } + if (cmap) + free(cmap); + *t = 0; + return data; +} + +unsigned char * +_LoadXPM(ImlibData * id, FILE *file, int *w, int *h, int *t) +{ + unsigned char *data, *ptr, *end; + int pc, c, i, j, k, ncolors, cpp, comment, transp, quote, + context, len, done; + char *line, s[256], tok[128], col[256]; + XColor xcol; + int lsz = 256; + struct _cmap + { + unsigned char str[6]; + unsigned char transp; + short r, g, b; + } + *cmap; + short lookup[128 - 32][128 - 32]; + + transp = 0; + done = 0; + if (!file) + return NULL; + i = 0; + j = 0; + cmap = NULL; + *w = 10; + *h = 10; + ptr = NULL; + data = NULL; + end = NULL; + c = ' '; + comment = 0; + quote = 0; + context = 0; + line = malloc(lsz); + while (!done) + { + pc = c; + c = fgetc(file); + if (c == EOF) + break; + if (!quote) + { + if ((pc == '/') && (c == '*')) + comment = 1; + else if ((pc == '*') && (c == '/') && (comment)) + comment = 0; + } + if (!comment) + { + if ((!quote) && (c == '"')) + { + quote = 1; + i = 0; + } + else if ((quote) && (c == '"')) + { + line[i] = 0; + quote = 0; + if (context == 0) + { + /* Header */ + sscanf(line, "%i %i %i %i", w, h, &ncolors, &cpp); + if (ncolors > 32766) + { + fprintf(stderr, "IMLIB ERROR: XPM files wth colors > 32766 not supported\n"); + free(line); + return NULL; + } + if (cpp > 5) + { + fprintf(stderr, "IMLIB ERROR: XPM files with characters per pixel > 5 not supported\n"); + free(line); + return NULL; + } + if (*w > 32767) + { + fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n"); + free(line); + return NULL; + } + if (*h > 32767) + { + fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n"); + free(line); + return NULL; + } + cmap = malloc(sizeof(struct _cmap) * ncolors); + + if (!cmap) + { + free(line); + return NULL; + } + /* SAFE -- Check for w,h in earlier code */ + data = malloc(*w ** h * 3); + if (!data) + { + free(cmap); + free(line); + return NULL; + } + ptr = data; + end = ptr + (*w ** h * 3); + j = 0; + context++; + } + else if (context == 1) + { + /* Color Table */ + if (j < ncolors) + { + int slen; + int hascolor, iscolor; + + iscolor = 0; + hascolor = 0; + tok[0] = 0; + col[0] = 0; + s[0] = 0; + len = strlen(line); + strncpy(cmap[j].str, line, cpp); + cmap[j].str[cpp] = 0; + cmap[j].r = -1; + cmap[j].transp = 0; + for (k = cpp; k < len; k++) + { + if (line[k] != ' ') + { + s[0] = 0; + sscanf(&line[k], "%256s", s); + slen = strlen(s); + k += slen; + if (!strcmp(s, "c")) + iscolor = 1; + if ((!strcmp(s, "m")) || (!strcmp(s, "s")) || + (!strcmp(s, "g4")) || (!strcmp(s, "g")) || + (!strcmp(s, "c")) || (k >= len)) + { + if (k >= len) + { + if (col[0]) + strcat(col, " "); + if (strlen(col) + strlen(s) < sizeof(col)) + strcat(col, s); + } + if (col[0]) + { + if (!strcasecmp(col, "none")) + { + transp = 1; + cmap[j].transp = 1; + } + else + { + if ((((cmap[j].r < 0) || + (!strcmp(tok, "c"))) && + (!hascolor))) + { + XParseColor(id->x.disp, + id->x.root_cmap, + col, &xcol); + cmap[j].r = xcol.red >> 8; + cmap[j].g = xcol.green >> 8; + cmap[j].b = xcol.blue >> 8; + if ((cmap[j].r == 255) && + (cmap[j].g == 0) && + (cmap[j].b == 255)) + cmap[j].r = 254; + if (iscolor) + hascolor = 1; + } + } + } + strcpy(tok, s); + col[0] = 0; + } + else + { + if (col[0]) + strcat(col, " "); + strcat(col, s); + } + } + } + } + j++; + if (j >= ncolors) + { + if (cpp == 1) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0] - 32][0] = i; + if (cpp == 2) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0] - 32][(int)cmap[i].str[1] - 32] = i; + context++; + } + } + else + { + /* Image Data */ + i = 0; + if (cpp == 0) + { + /* Chars per pixel = 0? well u never know */ + } + if (cpp == 1) + { + if (transp) + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i]; + if (cmap[lookup[(int)col[0] - 32][0]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; + } + } + } + else if (cpp == 2) + { + if (transp) + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + if (cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].b; + } + } + } + else + { + if (transp) + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + if (cmap[j].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + } + j = ncolors; + } + } + } + } + else + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + j = ncolors; + } + } + } + } + } + } + } + } + /* Scan in line from XPM file */ + if ((!comment) && (quote) && (c != '"')) + { + if (c < 32) + c = 32; + else if (c > 127) + c = 127; + line[i++] = c; + } + if (i >= lsz) + { + lsz += 256; + line = realloc(line, lsz); + if(line == NULL) + { + free(cmap); + return NULL; + } + } + if ((ptr) && ((ptr - data) >= *w ** h * 3)) + done = 1; + } + if (transp) + *t = 1; + else + *t = 0; + free(cmap); + free(line); + return data; +} + +unsigned char * +_LoadPPM(ImlibData * id, FILE * f, int *w, int *h) +{ + int done; + unsigned char *ptr; + unsigned char chr; + char s[256]; + int a, b, i, j; + int color, scale, ascii, bw; + + a = b = scale = ascii = bw = color = 0; + fgets(s, 256, f); + s[2] = 0; + if (!strcmp(s, "P6")) + color = 1; + else if (!strcmp(s, "P5")) + color = 0; + else if (!strcmp(s, "P4")) + bw = 1; + else if (!strcmp(s, "P3")) + { + color = 1; + ascii = 1; + } + else if (!strcmp(s, "P2")) + { + ascii = 1; + } + else if (!strcmp(s, "P1")) + { + ascii = 1; + bw = 1; + } + else + return NULL; + done = 1; + ptr = NULL; + while (done) + { + if (fgets(s, 256, f) == NULL) + break; + + if (s[0] != '#') + { + done = 0; + sscanf(s, "%i %i", w, h); + a = *w; + b = *h; + if (a > 32767) + { + fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n"); + return NULL; + } + if (b > 32767) + { + fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n"); + return NULL; + } + if (!bw) + { + fgets(s, 256, f); + sscanf(s, "%i", &scale); + } + else + scale = 99999; + ptr = (unsigned char *)_imlib_malloc_image(a, b); + if (!ptr) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for RGB data in file"); + return ptr; + } + if ((color) && (!ascii) && (!bw)) + { + fread(ptr, a * b * 3, 1, f); + } + else if ((!color) && (!ascii) && (!bw)) + { + b = (a * b * 3); + a = 0; + while ((fread(&chr, 1, 1, f)) && (a < b)) + { + ptr[a++] = chr; + ptr[a++] = chr; + ptr[a++] = chr; + } + } + else if ((!color) && (!ascii) && (bw)) + { + b = (a * b * 3); + a = 0; + j = 0; + while ((fread(&chr, 1, 1, f)) && (a < b)) + { + for (i = 7; i >= 0; i--) + { + j++; + if (j <= *w) + { + if (chr & (1 << i)) + { + ptr[a++] = 0; + ptr[a++] = 0; + ptr[a++] = 0; + } + else + { + ptr[a++] = 255; + ptr[a++] = 255; + ptr[a++] = 255; + } + } + } + if (j >= *w) + j = 0; + } + } + else if ((color) && (ascii) && (!bw)) + { + b = (a * b * 3); + a = 0; + i = 0; + if (scale != 255) + { + while ((fread(&chr, 1, 1, f)) && (a < b)) + { + s[i++] = chr; + if (!isdigit(chr)) + { + s[i - 1] = 0; + if ((i > 1) && (isdigit(s[i - 2]))) + { + ptr[a++] = ((atoi(s)) * 255) / scale; + } + i = 0; + } + } + } + else + { + while ((fread(&chr, 1, 1, f)) && (a < b)) + { + s[i++] = chr; + if (!isdigit(chr)) + { + s[i - 1] = 0; + if ((i > 1) && (isdigit(s[i - 2]))) + { + ptr[a++] = atoi(s); + } + i = 0; + } + } + } + + } + else if ((!color) && (ascii) && (!bw)) + { + b = (a * b * 3); + a = 0; + i = 0; + if (scale != 255) + { + while ((fread(&chr, 1, 1, f)) && (a < b)) + { + s[i++] = chr; + if (!isdigit(chr)) + { + s[i - 1] = 0; + if ((i > 1) && (isdigit(s[i - 2]))) + { + ptr[a++] = ((atoi(s)) * 255) / scale; + ptr[a++] = ptr[a - 1]; + ptr[a++] = ptr[a - 1]; + } + i = 0; + } + } + } + else + { + while ((fread(&chr, 1, 1, f)) && (a < b)) + { + s[i++] = chr; + if (!isdigit(chr)) + { + s[i - 1] = 0; + if ((i > 1) && (isdigit(s[i - 2]))) + { + ptr[a++] = atoi(s); + ptr[a++] = ptr[a - 1]; + ptr[a++] = ptr[a - 1]; + } + i = 0; + } + } + } + } + else if ((!color) && (ascii) && (bw)) + { + } + } + } + if (!ptr) + return NULL; + if (scale == 0) + { + free(ptr); + return NULL; + } + if ((scale < 255) && (!ascii)) + { + int rot; + unsigned char *po; + + if (scale <= 1) + rot = 7; + else if (scale <= 3) + rot = 6; + else if (scale <= 7) + rot = 5; + else if (scale <= 15) + rot = 4; + else if (scale <= 31) + rot = 3; + else if (scale <= 63) + rot = 2; + else + rot = 1; + + if (rot > 0) + { + po = ptr; + while (po < (ptr + (*w ** h * 3))) + { + *po++ <<= rot; + *po++ <<= rot; + *po++ <<= rot; + } + } + } + return ptr; +} + +int +ispnm(FILE *f) +{ + char buf[8]; + + if (!f) + return 0; + fgets(buf, 8, f); + rewind(f); + if (!strcmp("P6", buf)) + return 1; + if (!strcmp("P5", buf)) + return 1; + if (!strcmp("P4", buf)) + return 1; + if (!strcmp("P3", buf)) + return 1; + if (!strcmp("P2", buf)) + return 1; + if (!strcmp("P1", buf)) + return 1; + return 0; +} + +int +isjpeg(FILE *f) +{ + unsigned char buf[8]; + + if (!f) + return 0; + fread(buf, 1, 2, f); + rewind(f); + if ((buf[0] == 0xff) && (buf[1] == 0xd8)) + return 1; + return 0; +} + +int +ispng(FILE *f) +{ +#ifdef HAVE_LIBPNG + unsigned char buf[8]; + + if (!f) + return 0; + fread(buf, 1, 8, f); + rewind(f); + return (int)png_check_sig(buf, 8); +#else + return 0; +#endif +} + +int +istiff(FILE *f) +{ + char buf[8]; + + if (!f) + return 0; + fgets(buf, 5, f); + rewind(f); + if ((buf[0] == 'M') && (buf[1] == 'M') && (buf[2] == 0x00) && (buf[3] == 0x2a)) + return 1; + if ((buf[0] == 'I') && (buf[1] == 'I') && (buf[2] == 0x2a) && (buf[3] == 0x00)) + return 1; + return 0; +} + +int +iseim(FILE *f) +{ + char buf[8]; + + if (!f) + return 0; + fread(buf, 1, 4, f); + rewind(f); + buf[4] = 0; + if (!strncmp("EIM ", buf, 4)) + return 1; + return 0; +} + +int +isgif(FILE *f) +{ + char buf[8]; + + if (!f) + return 0; + fread(buf, 1, 4, f); + rewind(f); + buf[4] = 0; + if (!strcmp("GIF8", buf)) + return 1; + return 0; +} + +int +isxpm(FILE *f) +{ + char buf[11]; + + if (!f) + return 0; + fread(buf, 1, 9, f); + rewind(f); + buf[9] = 0; + if (!strcmp("/* XPM */", buf)) + return 1; + return 0; +} + +int +isbmp(FILE *f) +{ + char buf[3]; + + if (!f) + return 0; + fread(buf, 1, 2, f); + rewind(f); + buf[2] = 0; + if (!strcmp("BM", buf)) + return 1; + return 0; +} + +ImlibImage * +Imlib_load_image(ImlibData * id, char *file) +{ + int w, h; + unsigned char *data; + ImlibImage *im; + char s[4096]; + char fil[4096]; + char *iden; + char *e; + char cmd[4096]; + FILE *p; + int eim; + int fmt; + int trans; + + eim = 0; + fmt = 0; + data = NULL; + + if (!file) + return NULL; + if (id->cache.on_image) + if ((im = find_image(id, file))) + { + if (im->rgb_width == 0 || im->rgb_height == 0) + { + Imlib_destroy_image(id, im); + return NULL; + } + else + return im; + } + if (!strcmp(file,"-")) { + p = stdin; + } + else { + p = fopen(file, "rb"); + } + if (!p) + return NULL; + strncpy(fil, file, sizeof(fil)); + iden = _SplitID(fil); + e = _GetExtension(fil); + + if (ispnm(p)) + { + fmt = 0; + } + else if (isjpeg(p)) + { + fmt = 2; + } + else if (istiff(p)) + { + fmt = 3; + } + else if (iseim(p)) + { + eim = 1; + fmt = 9999; + } + else if (isxpm(p)) + { + fmt = 5; + } + else if (ispng(p)) + { + fmt = 1; + } + else if (isgif(p)) + { + fmt = 4; + } + else if (isbmp(p)) + { + fmt = 6; + } + + trans = 0; + if ((!eim) && (!data)) + { + switch (fmt) + { + case 6: + data = _LoadBMP(id, p, &w, &h, &trans); + break; + case 5: + data = _LoadXPM(id, p, &w, &h, &trans); + break; +#ifdef HAVE_LIBGIF + case 4: + data = _LoadGIF(id, p, &w, &h, &trans); + break; +#endif +#ifdef HAVE_LIBTIFF + case 3: + data = _LoadTIFF(id, p, file, &w, &h, &trans); + break; +#endif +#ifdef HAVE_LIBJPEG + case 2: + data = _LoadJPEG(id, p, &w, &h); + break; +#endif +#ifdef HAVE_LIBPNG + case 1: + data = _LoadPNG(id, p, &w, &h, &trans); + break; +#endif + default: + data = _LoadPPM(id, p, &w, &h); + break; + } + } + + if (p != stdin) + fclose(p); + + if ((!eim) && (!data)) + { + fprintf(stderr, "IMLIB ERROR: Cannot load image: %s\n" + "All fallbacks failed.\n", fil); + return NULL; + } + + if (!w || !h) + { + fprintf(stderr, "IMLIB ERROR: zero image\n" ); + if(data) + free(data); + return NULL; + } + + im = (ImlibImage *) malloc(sizeof(ImlibImage)); + if (!im) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for image structure\n"); + if (data) + free(data); + return NULL; + } + im->alpha_data = NULL; + if (trans) + { + im->shape_color.r = 255; + im->shape_color.g = 0; + im->shape_color.b = 255; + } + else + { + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + } + im->border.left = 0; + im->border.right = 0; + im->border.top = 0; + im->border.bottom = 0; + im->cache = 1; + im->rgb_data = data; + im->rgb_width = w; + im->rgb_height = h; + im->pixmap = 0; + im->shape_mask = 0; + if (eim) + { + char s1[256], s2[256]; + int num, size; + int r, g, b; + int br, bl, bt, bb; + + /* Load Native-as-can-be EIM format (Enlightenment IMlib format) */ + if (!strcmp(file,"-")) + p = stdin; + else { +#ifndef __EMX__ + p = fopen(file, "r"); +#else + p = fopen(file, "rt"); +#endif + } + + if (!p) + { + free(im); + return NULL; + } + fgets(s, 4096, p); + if ((s[0] != 'E') && (s[1] != 'I') && (s[2] != 'M') && (s[3] != ' ')) + { + fclose(p); + free(im); + return NULL; + } + sscanf(s, "%256s %i", s1, &num); + if (num <= 0) + { + fclose(p); + free(im); + return NULL; + } + while (fgets(s, 4096, p)) + { + sscanf(s, "%256s", s1); + if (!strcmp("IMAGE", s1)) + { + sscanf(s, "%256s %i %256s %i %i %i %i %i %i %i %i %i", s1, &size, + s2, &w, &h, &r, &g, &b, &bl, &br, &bt, &bb); + if (!iden[0]) + break; + else if (!strcmp(iden, s2)) + break; + if (size > 0) + fseek(p, size, SEEK_CUR); + } + } + im->rgb_data = _imlib_malloc_image(w, h); + if (!im->rgb_data) + { + fclose(p); + free(im); + return NULL; + } + im->shape_color.r = r; + im->shape_color.g = g; + im->shape_color.b = b; + im->rgb_width = w; + im->rgb_height = h; + im->border.left = bl; + im->border.right = br; + im->border.top = bt; + im->border.bottom = bb; + fread(im->rgb_data, 1, w * h * 3, p); + fclose(p); + if (iden[0]) + { +#ifndef __EMX__ + strncat(fil, ":", sizeof(fil) - strlen(fil)); +#else + strncat(fil, ";", sizeof(fil) - strlen(fil)); +#endif + strncat(fil, iden, sizeof(fil) - strlen(fil)); + } + } + im->mod.gamma = id->mod.gamma; + im->mod.brightness = id->mod.brightness; + im->mod.contrast = id->mod.contrast; + im->rmod.gamma = id->rmod.gamma; + im->rmod.brightness = id->rmod.brightness; + im->rmod.contrast = id->rmod.contrast; + im->gmod.gamma = id->gmod.gamma; + im->gmod.brightness = id->gmod.brightness; + im->gmod.contrast = id->gmod.contrast; + im->bmod.gamma = id->bmod.gamma; + im->bmod.brightness = id->bmod.brightness; + im->bmod.contrast = id->bmod.contrast; + im->filename = malloc(strlen(file) + 1); + if (im->filename) + strcpy(im->filename, file); + if ((id->cache.on_image) && (im)) + add_image(id, im, fil); + calc_map_tables(id, im); + return im; +} + +int +Imlib_save_image_to_eim(ImlibData * id, ImlibImage * im, char *file) +{ + char fil[4096]; + char *iden; + FILE *f; + int size; + + if ((!id) || (!im) || (!file)) + return 0; + strncpy(fil, file, sizeof(fil)); + iden = _SplitID(fil); + if (!iden[0]) + iden = "default"; + f = fopen(fil, "w"); + if (!f) + return 0; + + size = im->rgb_width * im->rgb_height * 3; + fprintf(f, "EIM 1\n"); + fprintf(f, "IMAGE %i %s %i %i %i %i %i %i %i %i %i\n", + size, + iden, + im->rgb_width, + im->rgb_height, + im->shape_color.r, + im->shape_color.g, + im->shape_color.b, + im->border.left, + im->border.right, + im->border.top, + im->border.bottom); + if (fwrite(im->rgb_data, size, 1, f) != 1) + { + fclose(f); + return 0; + } + fclose(f); + return 1; +} + +int +Imlib_add_image_to_eim(ImlibData * id, ImlibImage * im, char *file) +{ + char fil[4096]; + char *iden; + FILE *f; + int size; + + if ((!id) || (!im) || (!file)) + return 0; + strncpy(fil, file, sizeof(fil)); + + iden = _SplitID(file); + if (!iden[0]) + strcpy(iden, "default"); + + f = fopen(fil, "a"); + if (!f) + return 0; + + size = im->rgb_width * im->rgb_height * 3; + fprintf(f, "IMAGE %i %s %i %i %i %i %i %i %i %i %i\n", + size, + iden, + im->rgb_width, + im->rgb_height, + im->shape_color.r, + im->shape_color.g, + im->shape_color.b, + im->border.left, + im->border.right, + im->border.top, + im->border.bottom); + + if (fwrite(im->rgb_data, size, 1, f) != 1) + { + fclose(f); + return 0; + } + fclose(f); + return 1; +} + +int +Imlib_save_image_to_ppm(ImlibData * id, ImlibImage * im, char *file) +{ + FILE *f; + + if ((!id) || (!im) || (!file)) + return 0; +#ifndef __EMX__ + f = fopen(file, "w"); +#else + f = fopen(file, "wb"); +#endif + + if (!f) + return 0; + + fprintf(f, "P6\n"); + fprintf(f, "%i %i\n255\n", + im->rgb_width, + im->rgb_height); + if (fwrite(im->rgb_data, im->rgb_width * im->rgb_height * 3, 1, f) != 1) + { + fclose(f); + return 0; + } + fclose(f); + return 1; +} diff --git a/debian/imlib/imlib-1.9.15/Imlib/misc.c b/debian/imlib/imlib-1.9.15/Imlib/misc.c new file mode 100644 index 00000000..aeba74e0 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/misc.c @@ -0,0 +1,1430 @@ +#define _GNU_SOURCE +#include <config.h> +#include "Imlib.h" +#include "Imlib_private.h" +#include <locale.h> + +#ifdef __EMX__ +extern const char *__XOS2RedirRoot(const char *); +#endif + +#ifndef HAVE_SNPRINTF +#define snprintf my_snprintf +#ifdef HAVE_STDARGS +int my_snprintf(char *str, size_t count, const char *fmt,...); + +#else +int my_snprintf(va_alist); + +#endif +#endif + +static char x_error; + +static void +HandleXError(Display * d, XErrorEvent * ev) +{ + x_error = 1; +} + +int +Imlib_get_render_type(ImlibData * id) +{ + if (id) + return id->render_type; + else + { + fprintf(stderr, "IMLIB ERROR: Imlib not initialised\n"); + return -1; + } +} + +void +Imlib_set_render_type(ImlibData * id, int rend_type) +{ + if (id) + { + if (id->x.depth > 8) + id->render_type = rend_type; + else + { + if ((rend_type == RT_PLAIN_TRUECOL) || + (rend_type == RT_DITHER_TRUECOL)) + id->render_type = RT_DITHER_PALETTE_FAST; + else + id->render_type = rend_type; + } + return; + } + else + { + fprintf(stderr, "IMLIB ERROR: Imlib not initialised\n"); + return; + } +} + +#ifdef HAVE_SHM +int + XShmGetEventBase(Display * disp); + +#endif + +ImlibData * +Imlib_init(Display * disp) +{ + ImlibData *id; + XWindowAttributes xwa; + XVisualInfo xvi, *xvir; + char *homedir; + char s[4096], *s1, *s2; + FILE *f; + int override = 0; + int dither = 0; + int remap = 1; + int num; + int i, max, maxn; + int clas; + char *palfile; + int loadpal; + int vis; + int newcm; + char *old_locale; + + /* fprintf(stderr, "Imlib Init\n"); + fflush(stderr); */ + + palfile = NULL; + if (!disp) + { + fprintf(stderr, "IMLIB ERROR: no display\n"); + return NULL; + } + vis = -1; + loadpal = 0; + id = (ImlibData *) malloc(sizeof(ImlibData)); + if (!id) + { + fprintf(stderr, "IMLIB ERROR: Cannot alloc RAM for Initial data struct\n"); + return NULL; + } + id->palette = NULL; + id->palette_orig = NULL; + id->fast_rgb = NULL; + id->fast_err = NULL; + id->fast_erg = NULL; + id->fast_erb = NULL; + id->x.disp = disp; + id->x.screen = DefaultScreen(disp); /* the screen number */ + id->x.root = DefaultRootWindow(disp); /* the root window id */ + id->x.visual = DefaultVisual(disp, id->x.screen); /* the visual type */ + id->x.depth = DefaultDepth(disp, id->x.screen); /* the depth of the screen in bpp */ + + id->x.shm = 0; + id->x.shmp = 0; + id->max_shm = 0; +#ifdef HAVE_SHM + if (XShmQueryExtension(id->x.disp)) + { + int maj, min, dum; + Bool pm; + + if (XQueryExtension(id->x.disp, "MIT-SHM", &dum, &dum, &dum)) + { + if (XShmQueryVersion(id->x.disp, &maj, &min, &pm) == True) + { + id->x.shm = 1; + id->x.shm_event = XShmGetEventBase(id->x.disp) + ShmCompletion; + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + id->max_shm = 0x7fffffff; + if ((XShmPixmapFormat(id->x.disp) == ZPixmap) && + (pm == True)) + id->x.shmp = 1; + } + } + } +#endif + id->cache.on_image = 0; + id->cache.size_image = 0; + id->cache.num_image = 0; + id->cache.used_image = 0; + id->cache.image = NULL; + id->cache.on_pixmap = 0; + id->cache.size_pixmap = 0; + id->cache.num_pixmap = 0; + id->cache.used_pixmap = 0; + id->cache.pixmap = NULL; + id->byte_order = 0; + id->fastrend = 0; + id->hiq = 0; + id->fallback = 1; + id->mod.gamma = 256; + id->mod.brightness = 256; + id->mod.contrast = 256; + id->rmod.gamma = 256; + id->rmod.brightness = 256; + id->rmod.contrast = 256; + id->gmod.gamma = 256; + id->gmod.brightness = 256; + id->gmod.contrast = 256; + id->bmod.gamma = 256; + id->bmod.brightness = 256; + id->bmod.contrast = 256; + id->ordered_dither = 1; + + if (XGetWindowAttributes(disp, id->x.root, &xwa)) + { + if (xwa.colormap) + id->x.root_cmap = xwa.colormap; + else + id->x.root_cmap = 0; + } + else + id->x.root_cmap = 0; + id->num_colors = 0; + homedir = getenv("HOME"); + snprintf(s, sizeof(s), "%s/.imrc", homedir); + + old_locale = strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + +#ifndef __EMX__ + f = fopen(s, "r"); +#else + f = fopen(s, "rt"); +#endif + + if (!f) + { +#ifndef __EMX__ + f = fopen(SYSTEM_IMRC, "r"); +#else + f = fopen(__XOS2RedirRoot(SYSTEM_IMRC), "rt"); +#endif + } + + if (f) + { + while (fgets(s, 4096, f)) + { + if (s[0] == '#') + continue; + + s1 = strtok(s, " \t\n"); + + /* Blank line ? */ + + if (s1 == NULL) + continue; + + s2 = strtok(NULL, " \t\n"); + if (s2 == NULL) + s2 = ""; /* NULL argument */ + + if (!strcasecmp("PaletteFile", s1)) + { + palfile = strdup(s2); + } + else if (!strcasecmp("PaletteOverride", s1)) + { + if (!strcasecmp("yes", s2)) + override = 1; + else + override = 0; + } + else if (!strcasecmp("Dither", s1)) + { + if (!strcasecmp("yes", s2)) + dither = 1; + else + dither = 0; + } + else if (!strcasecmp("Remap", s1)) + { + if (!strcasecmp("fast", s2)) + remap = 1; + else + remap = 0; + } + else if (!strcasecmp("Mit-Shm", s1)) + { +#ifdef HAVE_SHM + if (!strcasecmp("off", s2)) +#endif + { + id->x.shm = 0; + id->x.shmp = 0; + } + } + else if (!strcasecmp("SharedPixmaps", s1)) + { +#ifdef HAVE_SHM + if (!strcasecmp("off", s2)) +#endif + id->x.shmp = 0; + } + else if (!strcasecmp("FastRender", s1)) + { + if (!strcasecmp("on", s2)) + id->fastrend = 1; + } + else if (!strcasecmp("HighQuality", s1)) + { + if (!strcasecmp("on", s2)) + id->hiq = 1; + } + else if (!strcasecmp("Shm_Max_Size", s1)) + { + num = atoi(s2); + id->max_shm = num; + } + else if (!strcasecmp("Image_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_image = num; + } + else if (!strcasecmp("Pixmap_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_pixmap = num; + } + else if (!strcasecmp("Image_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_image = 1; + } + else if (!strcasecmp("Pixmap_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_pixmap = 1; + } + else if (!strcasecmp("ForceVisualID", s1)) + { + sscanf(s, "%1024s %x", s1, &num); + vis = num; + } + else if (!strcasecmp("Fallback", s1)) + { + if (!strcasecmp("off", s2)) + id->fallback = 0; + else + id->fallback = 1; + } + else if (!strcasecmp("Gamma", s1)) + { + id->mod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Brightness", s1)) + { + id->mod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Contrast", s1)) + { + id->mod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Gamma", s1)) + { + id->rmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Brightness", s1)) + { + id->rmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Contrast", s1)) + { + id->rmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Gamma", s1)) + { + id->gmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Brightness", s1)) + { + id->gmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Contrast", s1)) + { + id->gmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Gamma", s1)) + { + id->bmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Brightness", s1)) + { + id->bmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Contrast", s1)) + { + id->bmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Ordered_Dither", s1)) + { + if (!strcasecmp("off", s2)) + id->ordered_dither = 0; + else + id->ordered_dither = 1; + } + } + fclose(f); + } + setlocale(LC_NUMERIC, old_locale); + if (old_locale) + free(old_locale); + + /* list all visuals for the default screen */ + xvi.screen = id->x.screen; + xvir = XGetVisualInfo(disp, VisualScreenMask, &xvi, &num); + if (vis >= 0) + { + /* use the forced visual id */ + maxn = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].visualid == (VisualID) vis) + maxn = i; + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.depth = xvir[maxn].depth; + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + else + fprintf(stderr, "IMLIB ERROR: Visual Id no 0x%x specified in the imrc file is invalid on this display.\nUsing Default Visual.\n", vis); + } + else + { + if (xvir) + { + /* find the highest bit-depth supported by visuals */ + max = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].depth > max) + max = xvir[i].depth; + } + if (max > 8) + { + id->x.depth = max; + clas = -1; + maxn = -1; + for (i = 0; i < num; i++) + { + if (xvir[i].depth == id->x.depth) + { + if ((xvir[i].class > clas) && + (xvir[i].class != DirectColor)) + { + maxn = i; + clas = xvir[i].class; + } + } + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + } + } + } + id->x.render_depth = id->x.depth; + XFree(xvir); + if (id->x.depth == 16) + { + xvi.visual = id->x.visual; + xvi.visualid = XVisualIDFromVisual(id->x.visual); + xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num); + if (xvir) + { + if (xvir->red_mask != 0xf800) + id->x.render_depth = 15; + XFree(xvir); + } + } + if (id->x.depth < 8) + id->x.shmp = 0; + if ((id->x.depth <= 8) || (override == 1)) + loadpal = 1; + if (loadpal) + { + if (dither == 1) + { + if (remap == 1) + id->render_type = RT_DITHER_PALETTE_FAST; + else + id->render_type = RT_DITHER_PALETTE; + } + else + { + if (remap == 1) + id->render_type = RT_PLAIN_PALETTE_FAST; + else + id->render_type = RT_PLAIN_PALETTE; + } + if (palfile != NULL) + Imlib_load_colors(id, palfile); + if (id->num_colors == 0) + { + fprintf(stderr, "IMLIB ERROR: Cannot Find Palette. A Palette is required for this mode\n"); + free(id); + if (palfile) + free(palfile); + return NULL; + } + } + else + { + if (id->hiq == 1) + id->render_type = RT_DITHER_TRUECOL; + else + id->render_type = RT_PLAIN_TRUECOL; + } + { + XSetWindowAttributes at; + unsigned long mask; + + at.border_pixel = 0; + at.backing_store = NotUseful; + at.background_pixel = 0; + at.save_under = False; + at.override_redirect = True; + mask = CWOverrideRedirect | CWBackPixel | CWBorderPixel | + CWBackingStore | CWSaveUnder; + newcm = 0; + if (id->x.visual != DefaultVisual(disp, id->x.screen)) + { + Colormap cm; + + cm = XCreateColormap(id->x.disp, id->x.root, + id->x.visual, AllocNone); + if (cm) + { + mask |= CWColormap; + id->x.root_cmap = cm; + at.colormap = cm; + newcm = 1; + } + } + id->x.base_window = XCreateWindow(id->x.disp, id->x.root, + -100, -100, 10, 10, 0, + id->x.depth, InputOutput, + id->x.visual, mask, &at); + } + { + /* Turn off fastrender if there is an endianess diff between */ + /* client and Xserver */ + int byt, bit; + + byt = ImageByteOrder(id->x.disp); /* LSBFirst | MSBFirst */ + bit = BitmapBitOrder(id->x.disp); /* LSBFirst | MSBFirst */ + id->x.byte_order = byt; + id->x.bit_order = bit; + /* if little endian && server big */ + if ((htonl(1) != 1) && (byt == MSBFirst)) + id->fastrend = 0; + /* if big endian && server little */ + if ((htonl(1) == 1) && (byt == LSBFirst)) + id->fastrend = 0; + } + if (palfile) + free(palfile); + +#ifdef HAVE_SHM + if (id->x.shm) + { + XImage *xim; + + xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, + ZPixmap, NULL, &id->x.last_shminfo, 10, 10); + if (!xim) + { + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.last_shminfo.shmid = + shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, + IPC_CREAT | 0777); + if (id->x.last_shminfo.shmid < 0) + { + XDestroyImage(xim); + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.last_shminfo.shmaddr = xim->data = + shmat(id->x.last_shminfo.shmid, 0, 0); + if (id->x.last_shminfo.shmaddr == (char *)-1) + { + XDestroyImage(xim); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.last_shminfo.readOnly = False; + XSetErrorHandler((XErrorHandler) HandleXError); + x_error = 0; + XShmAttach(id->x.disp, &id->x.last_shminfo); + XSync(disp, False); + if (x_error) + { + id->x.shm = 0; + id->x.shmp = 0; + } + else + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + } + } + } + } +#endif + + return id; +} + +ImlibData * +Imlib_init_with_params(Display * disp, ImlibInitParams * p) +{ + ImlibData *id; + XWindowAttributes xwa; + XVisualInfo xvi, *xvir; + char *homedir; + char s[4096], *s1, *s2; + FILE *f; + int override = 0; + int dither = 0; + int remap = 1; + int num; + int i, max, maxn; + int clas; + char *palfile; + int loadpal; + int vis; + int newcm = 0; + char *old_locale; + + palfile = NULL; + if (!disp) + { + fprintf(stderr, "IMLIB ERROR: no display\n"); + return NULL; + } + vis = -1; + loadpal = 0; + id = (ImlibData *) malloc(sizeof(ImlibData)); + if (!id) + { + fprintf(stderr, "IMLIB ERROR: Cannot alloc RAM for Initial data struct\n"); + return NULL; + } + id->palette = NULL; + id->palette_orig = NULL; + id->fast_rgb = NULL; + id->fast_err = NULL; + id->fast_erg = NULL; + id->fast_erb = NULL; + id->x.disp = disp; + id->x.screen = DefaultScreen(disp); /* the screen number */ + id->x.root = DefaultRootWindow(disp); /* the root window id */ + id->x.visual = DefaultVisual(disp, id->x.screen); /* the visual type */ + id->x.depth = DefaultDepth(disp, id->x.screen); /* the depth of the screen in bpp */ +#ifdef HAVE_SHM + if (XShmQueryExtension(id->x.disp)) + { + int maj, min, dum; + Bool pm; + + if (XQueryExtension(id->x.disp, "MIT-SHM", &dum, &dum, &dum)) + { + if (XShmQueryVersion(id->x.disp, &maj, &min, &pm) == True) + { + id->x.shm = 1; + id->x.shm_event = XShmGetEventBase(id->x.disp) + ShmCompletion; + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + id->max_shm = 0x7fffffff; + if (XShmPixmapFormat(id->x.disp) == ZPixmap) + id->x.shmp = 1; + } + } + } + else +#endif + { + id->x.shm = 0; + id->x.shmp = 0; + } + id->cache.on_image = 0; + id->cache.size_image = 0; + id->cache.num_image = 0; + id->cache.used_image = 0; + id->cache.image = NULL; + id->cache.on_pixmap = 0; + id->cache.size_pixmap = 0; + id->cache.num_pixmap = 0; + id->cache.used_pixmap = 0; + id->cache.pixmap = NULL; + id->byte_order = 0; + id->fastrend = 0; + id->hiq = 0; + id->fallback = 1; + id->mod.gamma = 256; + id->mod.brightness = 256; + id->mod.contrast = 256; + id->rmod.gamma = 256; + id->rmod.brightness = 256; + id->rmod.contrast = 256; + id->gmod.gamma = 256; + id->gmod.brightness = 256; + id->gmod.contrast = 256; + id->bmod.gamma = 256; + id->bmod.brightness = 256; + id->bmod.contrast = 256; + id->ordered_dither = 1; + + if (XGetWindowAttributes(disp, id->x.root, &xwa)) + { + if (xwa.colormap) + id->x.root_cmap = xwa.colormap; + else + id->x.root_cmap = 0; + } + else + id->x.root_cmap = 0; + id->num_colors = 0; + homedir = getenv("HOME"); + snprintf(s, sizeof(s), "%s/.imrc", homedir); + old_locale = strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + +#ifndef __EMX__ + f = fopen(s, "r"); +#else + f = fopen(s, "rt"); +#endif + + if (!f) + { +#ifndef __EMX__ + f = fopen(SYSTEM_IMRC, "r"); +#else + f = fopen(__XOS2RedirRoot(SYSTEM_IMRC), "rt"); +#endif + } + + if (f) + { + while (fgets(s, 4096, f)) + { + if (s[0] == '#') + continue; + + s1 = strtok(s, " \t\n"); + + /* Blank line ? */ + + if (s1 == NULL) + continue; + + s2 = strtok(NULL, " \t\n"); + if (s2 == NULL) + s2 = ""; /* NULL argument */ + + if (!strcasecmp("PaletteFile", s1)) + { + palfile = strdup(s2); + } + else if (!strcasecmp("PaletteOverride", s1)) + { + if (!strcasecmp("yes", s2)) + override = 1; + else + override = 0; + } + else if (!strcasecmp("Dither", s1)) + { + if (!strcasecmp("yes", s2)) + dither = 1; + else + dither = 0; + } + else if (!strcasecmp("Remap", s1)) + { + if (!strcasecmp("fast", s2)) + remap = 1; + else + remap = 0; + } + else if (!strcasecmp("Mit-Shm", s1)) + { +#ifdef HAVE_SHM + if (!strcasecmp("off", s2)) +#endif + { + id->x.shm = 0; + id->x.shmp = 0; + } + } + else if (!strcasecmp("SharedPixmaps", s1)) + { +#ifdef HAVE_SHM + if (!strcasecmp("off", s2)) +#endif + id->x.shmp = 0; + } + else if (!strcasecmp("FastRender", s1)) + { + if (!strcasecmp("on", s2)) + id->fastrend = 1; + } + else if (!strcasecmp("HighQuality", s1)) + { + if (!strcasecmp("on", s2)) + id->hiq = 1; + } + else if (!strcasecmp("Shm_Max_Size", s1)) + { + num = atoi(s2); + id->max_shm = num; + } + else if (!strcasecmp("Image_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_image = num; + } + else if (!strcasecmp("Pixmap_Cache_Size", s1)) + { + num = atoi(s2); + id->cache.size_pixmap = num; + } + else if (!strcasecmp("Image_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_image = 1; + } + else if (!strcasecmp("Pixmap_Cache", s1)) + { + if (!strcasecmp("on", s2)) + id->cache.on_pixmap = 1; + } + else if (!strcasecmp("ForceVisualID", s1)) + { + sscanf(s, "%1024s %x", s1, &num); + vis = num; + } + else if (!strcasecmp("Fallback", s1)) + { + if (!strcasecmp("off", s2)) + id->fallback = 0; + else + id->fallback = 1; + } + else if (!strcasecmp("Gamma", s1)) + { + id->mod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Brightness", s1)) + { + id->mod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Contrast", s1)) + { + id->mod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Gamma", s1)) + { + id->rmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Brightness", s1)) + { + id->rmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Red_Contrast", s1)) + { + id->rmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Gamma", s1)) + { + id->gmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Brightness", s1)) + { + id->gmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Green_Contrast", s1)) + { + id->gmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Gamma", s1)) + { + id->bmod.gamma = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Brightness", s1)) + { + id->bmod.brightness = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Blue_Contrast", s1)) + { + id->bmod.contrast = (int)(256.0 * atof(s2)); + } + else if (!strcasecmp("Ordered_Dither", s1)) + { + if (!strcasecmp("off", s2)) + id->ordered_dither = 0; + else + id->ordered_dither = 1; + } + } + fclose(f); + } + setlocale(LC_NUMERIC, old_locale); + if (old_locale) + free(old_locale); + + if (p) + { + if (p->flags & PARAMS_VISUALID) + vis = p->visualid; + if (p->flags & PARAMS_PALETTEFILE) { + if (palfile) + free(palfile); + palfile = strdup(p->palettefile); + } + if (p->flags & PARAMS_SHAREDMEM) + { + if (!p->sharedmem) + { + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.shm = 1; + id->x.shmp = 0; + } + } + if (p->flags & PARAMS_SHAREDPIXMAPS) + { + if (id->x.shm) + id->x.shmp = p->sharedpixmaps; + } + if (p->flags & PARAMS_PALETTEOVERRIDE) + override = p->paletteoverride; + if (p->flags & PARAMS_REMAP) + remap = p->remap; + if (p->flags & PARAMS_FASTRENDER) + id->fastrend = p->fastrender; + if (p->flags & PARAMS_HIQUALITY) + id->hiq = p->hiquality; + if (p->flags & PARAMS_DITHER) + dither = p->dither; + if (p->flags & PARAMS_IMAGECACHESIZE) + id->cache.size_image = p->imagecachesize; + if (p->flags & PARAMS_PIXMAPCACHESIZE) + id->cache.size_pixmap = p->pixmapcachesize; + if (p->flags & PARAMS_COLORMAP) + { + id->x.root_cmap = p->cmap; + newcm = 1; + } + } + /* list all visuals for the default screen */ + xvi.screen = id->x.screen; + xvir = XGetVisualInfo(disp, VisualScreenMask, &xvi, &num); + if (vis >= 0) + { + /* use the forced visual id */ + maxn = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].visualid == (VisualID) vis) + maxn = i; + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.depth = xvir[maxn].depth; + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + else + fprintf(stderr, "IMLIB ERROR: Visual Id no 0x%x specified in the imrc file is invalid on this display.\nUsing Default Visual.\n", vis); + } + else + { + if (xvir) + { + /* find the highest bit-depth supported by visuals */ + max = 0; + for (i = 0; i < num; i++) + { + if (xvir[i].depth > max) + max = xvir[i].depth; + } + if (max > 8) + { + id->x.depth = max; + clas = -1; + maxn = -1; + for (i = 0; i < num; i++) + { + if (xvir[i].depth == id->x.depth) + { + if ((xvir[i].class > clas) && (xvir[i].class != DirectColor)) + { + maxn = i; + clas = xvir[i].class; + } + } + } + if (maxn >= 0) + { + unsigned long rmsk, gmsk, bmsk; + + id->x.visual = xvir[maxn].visual; + rmsk = xvir[maxn].red_mask; + gmsk = xvir[maxn].green_mask; + bmsk = xvir[maxn].blue_mask; + + if ((rmsk > gmsk) && (gmsk > bmsk)) + id->byte_order = BYTE_ORD_24_RGB; + else if ((rmsk > bmsk) && (bmsk > gmsk)) + id->byte_order = BYTE_ORD_24_RBG; + else if ((bmsk > rmsk) && (rmsk > gmsk)) + id->byte_order = BYTE_ORD_24_BRG; + else if ((bmsk > gmsk) && (gmsk > rmsk)) + id->byte_order = BYTE_ORD_24_BGR; + else if ((gmsk > rmsk) && (rmsk > bmsk)) + id->byte_order = BYTE_ORD_24_GRB; + else if ((gmsk > bmsk) && (bmsk > rmsk)) + id->byte_order = BYTE_ORD_24_GBR; + else + id->byte_order = 0; + } + } + } + } + id->x.render_depth = id->x.depth; + XFree(xvir); + if (id->x.depth == 16) + { + xvi.visual = id->x.visual; + xvi.visualid = XVisualIDFromVisual(id->x.visual); + xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num); + if (xvir) + { + if (xvir->red_mask != 0xf800) + id->x.render_depth = 15; + XFree(xvir); + } + } + if (id->x.depth < 8) + id->x.shmp = 0; + if ((id->x.depth <= 8) || (override == 1)) + loadpal = 1; + if (loadpal) + { + if (dither == 1) + { + if (remap == 1) + id->render_type = RT_DITHER_PALETTE_FAST; + else + id->render_type = RT_DITHER_PALETTE; + } + else + { + if (remap == 1) + id->render_type = RT_PLAIN_PALETTE_FAST; + else + id->render_type = RT_PLAIN_PALETTE; + } + if (palfile != NULL) + Imlib_load_colors(id, palfile); + if (id->num_colors == 0) + { + fprintf(stderr, "IMLIB ERROR: Cannot Find Palette. A Palette is required for this mode\n"); + free(id); + if (palfile) + free(palfile); + return NULL; + } + } + else + { + if (id->hiq == 1) + id->render_type = RT_DITHER_TRUECOL; + else + id->render_type = RT_PLAIN_TRUECOL; + } + { + XSetWindowAttributes at; + unsigned long mask; + + at.border_pixel = 0; + at.backing_store = NotUseful; + at.background_pixel = 0; + at.save_under = False; + at.override_redirect = True; + mask = CWOverrideRedirect | CWBackPixel | CWBorderPixel | + CWBackingStore | CWSaveUnder; + if (id->x.visual != DefaultVisual(disp, id->x.screen)) + { + Colormap cm; + + cm = XCreateColormap(id->x.disp, id->x.root, + id->x.visual, AllocNone); + if (cm) + { + mask |= CWColormap; + id->x.root_cmap = cm; + at.colormap = cm; + newcm = 1; + } + } + else if (newcm) + { + mask |= CWColormap; + at.colormap = id->x.root_cmap; + } + id->x.base_window = XCreateWindow(id->x.disp, id->x.root, + -100, -100, 10, 10, 0, + id->x.depth, InputOutput, + id->x.visual, mask, &at); + } + { + /* Turn off fastrender if there is an endianess diff between */ + /* client and Xserver */ + int byt, bit; + + byt = ImageByteOrder(id->x.disp); /* LSBFirst | MSBFirst */ + bit = BitmapBitOrder(id->x.disp); /* LSBFirst | MSBFirst */ + /* if little endian && server big */ + if ((htonl(1) != 1) && (byt == MSBFirst)) + id->fastrend = 0; + /* if big endian && server little */ + if ((htonl(1) == 1) && (byt == LSBFirst)) + id->fastrend = 0; + } + if (palfile) + free(palfile); +#ifdef HAVE_SHM + if (id->x.shm) + { + XImage *xim; + + xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, + ZPixmap, NULL, &id->x.last_shminfo, 10, 10); + if (!xim) + { + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.last_shminfo.shmid = + shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, + IPC_CREAT | 0777); + if (id->x.last_shminfo.shmid < 0) + { + XDestroyImage(xim); + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.last_shminfo.shmaddr = xim->data = + shmat(id->x.last_shminfo.shmid, 0, 0); + if (id->x.last_shminfo.shmaddr == (char *)-1) + { + XDestroyImage(xim); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + id->x.shm = 0; + id->x.shmp = 0; + } + else + { + id->x.last_shminfo.readOnly = False; + XSetErrorHandler((XErrorHandler) HandleXError); + x_error = 0; + XShmAttach(id->x.disp, &id->x.last_shminfo); + XSync(disp, False); + if (x_error) + { + id->x.shm = 0; + id->x.shmp = 0; + } + else + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + } + } + } + } +#endif + return id; +} + +Pixmap +Imlib_copy_image(ImlibData * id, ImlibImage * im) +{ + Pixmap p; + GC tgc; + XGCValues gcv; + + if (!im || !im->pixmap) + return 0; + p = XCreatePixmap(id->x.disp, id->x.base_window, im->width, im->height, id->x.depth); + gcv.graphics_exposures = False; + tgc = XCreateGC(id->x.disp, p, GCGraphicsExposures, &gcv); + XCopyArea(id->x.disp, im->pixmap, p, tgc, 0, 0, im->width, im->height, 0, 0); + XFreeGC(id->x.disp, tgc); + return p; +} + +Pixmap +Imlib_move_image(ImlibData * id, ImlibImage * im) +{ + Pixmap p; + + if (!im) + return 0; + p = im->pixmap; + im->pixmap = 0; + return p; +} + +Pixmap +Imlib_copy_mask(ImlibData * id, ImlibImage * im) +{ + Pixmap p; + GC tgc; + XGCValues gcv; + + if (!im || !im->shape_mask) + return 0; + p = XCreatePixmap(id->x.disp, id->x.base_window, im->width, im->height, 1); + gcv.graphics_exposures = False; + tgc = XCreateGC(id->x.disp, p, GCGraphicsExposures, &gcv); + XCopyArea(id->x.disp, im->shape_mask, p, tgc, 0, 0, im->width, im->height, 0, 0); + XFreeGC(id->x.disp, tgc); + return p; +} + +Pixmap +Imlib_move_mask(ImlibData * id, ImlibImage * im) +{ + Pixmap p; + + if (!im) + return 0; + p = im->shape_mask; + im->shape_mask = 0; + return p; +} + +void +Imlib_destroy_image(ImlibData * id, ImlibImage * im) +{ + if (im) + { + if (id->cache.on_image) + { + free_image(id, im); + clean_caches(id); + } + else + nullify_image(id, im); + } +} + +void +Imlib_kill_image(ImlibData * id, ImlibImage * im) +{ + if (im) + { + if (id->cache.on_image) + { + free_image(id, im); + flush_image(id, im); + clean_caches(id); + } + else + nullify_image(id, im); + } +} + +void +Imlib_free_pixmap(ImlibData * id, Pixmap pmap) +{ + if (pmap) + { + free_pixmappmap(id, pmap); + clean_caches(id); + } +} + +void +Imlib_set_image_border(ImlibData * id, ImlibImage * im, ImlibBorder * border) +{ + if ((im) && (border)) + { + if ((im->border.left != border->left) || + (im->border.right != border->right) || + (im->border.top != border->top) || + (im->border.bottom != border->bottom)) + { + dirty_pixmaps(id, im); + + im->border.left = border->left; + im->border.right = border->right; + im->border.top = border->top; + im->border.bottom = border->bottom; + } + } +} + +void +Imlib_get_image_border(ImlibData * id, ImlibImage * im, ImlibBorder * border) +{ + if ((im) && (border)) + { + border->left = im->border.left; + border->right = im->border.right; + border->top = im->border.top; + border->bottom = im->border.bottom; + } +} + +void +Imlib_get_image_shape(ImlibData * id, ImlibImage * im, ImlibColor * color) +{ + if ((!im) || (!color)) + return; + + color->r = im->shape_color.r; + color->g = im->shape_color.g; + color->b = im->shape_color.b; +} + +void +Imlib_set_image_shape(ImlibData * id, ImlibImage * im, ImlibColor * color) +{ + if ((!im) || (!color)) + return; + if ((im->shape_color.r != color->r) || (im->shape_color.g != color->g) || (im->shape_color.b != color->b)) + { + im->shape_color.r = color->r; + im->shape_color.g = color->g; + im->shape_color.b = color->b; + dirty_pixmaps(id, im); + } +} + +int +Imlib_get_fallback(ImlibData * id) +{ + if (!id) + return 0; + return id->fallback; +} + +void +Imlib_set_fallback(ImlibData * id, int fallback) +{ + if (!id) + return; + id->fallback = fallback; +} + +Visual * +Imlib_get_visual(ImlibData * id) +{ + if (!id) + return NULL; + return id->x.visual; +} + +Colormap +Imlib_get_colormap(ImlibData * id) +{ + if (!id) + return 0; + return id->x.root_cmap; +} + +char * +Imlib_get_sysconfig(ImlibData * id) +{ +#ifndef __EMX__ + return strdup(SYSTEM_IMRC); +#else + return strdup(__XOS2RedirRoot(SYSTEM_IMRC)); +#endif +} diff --git a/debian/imlib/imlib-1.9.15/Imlib/mkinstalldirs b/debian/imlib/imlib-1.9.15/Imlib/mkinstalldirs new file mode 100755 index 00000000..91f6d04e --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/mkinstalldirs @@ -0,0 +1,32 @@ +#!/bin/sh +# mkinstalldirs --- make directory hierarchy +# Author: Noah Friedman <[email protected]> +# Created: 1993-05-16 +# Last modified: 1994-03-25 +# Public domain + +errstatus=0 + +for file in ${1+"$@"} ; do + set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` + shift + + pathcomp= + for d in ${1+"$@"} ; do + pathcomp="$pathcomp$d" + case "$pathcomp" in + -* ) pathcomp=./$pathcomp ;; + esac + + if test ! -d "$pathcomp"; then + echo "mkdir $pathcomp" 1>&2 + mkdir "$pathcomp" || errstatus=$? + fi + + pathcomp="$pathcomp/" + done +done + +exit $errstatus + +# mkinstalldirs ends here diff --git a/debian/imlib/imlib-1.9.15/Imlib/rend.c b/debian/imlib/imlib-1.9.15/Imlib/rend.c new file mode 100644 index 00000000..df459ba4 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/rend.c @@ -0,0 +1,6906 @@ +#define _GNU_SOURCE +#include <config.h> +#include "Imlib.h" +#include "Imlib_private.h" + +int +Imlib_best_color_match(ImlibData * id, int *r, int *g, int *b) +{ + int i; + int dif; + int dr, dg, db; + int col; + int mindif = 0x7fffffff; + + col = 0; + if (!id) + { + fprintf(stderr, "ImLib ERROR: No ImlibData initialised\n"); + return -1; + } + if ((id->render_type == RT_PLAIN_TRUECOL) || + (id->render_type == RT_DITHER_TRUECOL)) + { + dr = *r; + dg = *g; + db = *b; + switch (id->x.depth) + { + case 15: + *r = dr - (dr & 0xf8); + *g = dg - (dg & 0xf8); + *b = db - (db & 0xf8); + return ((dr & 0xf8) << 7) | ((dg & 0xf8) << 2) | ((db & 0xf8) >> 3); + break; + case 16: + *r = dr - (dr & 0xf8); + *g = dg - (dg & 0xfc); + *b = db - (db & 0xf8); + return ((dr & 0xf8) << 8) | ((dg & 0xfc) << 3) | ((db & 0xf8) >> 3); + break; + case 24: + case 32: + *r = 0; + *g = 0; + *b = 0; + switch (id->byte_order) + { + case BYTE_ORD_24_RGB: + return ((dr & 0xff) << 16) | ((dg & 0xff) << 8) | (db & 0xff); + break; + case BYTE_ORD_24_RBG: + return ((dr & 0xff) << 16) | ((db & 0xff) << 8) | (dg & 0xff); + break; + case BYTE_ORD_24_BRG: + return ((db & 0xff) << 16) | ((dr & 0xff) << 8) | (dg & 0xff); + break; + case BYTE_ORD_24_BGR: + return ((db & 0xff) << 16) | ((dg & 0xff) << 8) | (dr & 0xff); + break; + case BYTE_ORD_24_GRB: + return ((dg & 0xff) << 16) | ((dr & 0xff) << 8) | (db & 0xff); + break; + case BYTE_ORD_24_GBR: + return ((dg & 0xff) << 16) | ((db & 0xff) << 8) | (dr & 0xff); + break; + default: + return 0; + break; + } + break; + default: + return 0; + break; + } + return 0; + } + for (i = 0; i < id->num_colors; i++) + { + dr = *r - id->palette[i].r; + if (dr < 0) + dr = -dr; + dg = *g - id->palette[i].g; + if (dg < 0) + dg = -dg; + db = *b - id->palette[i].b; + if (db < 0) + db = -db; + dif = dr + dg + db; + if (dif < mindif) + { + mindif = dif; + col = i; + } + } + *r -= id->palette[col].r; + *g -= id->palette[col].g; + *b -= id->palette[col].b; + col = id->palette[col].pixel; + return col; +} + +int +index_best_color_match(ImlibData * id, int *r, int *g, int *b) +{ + int i; + int dif; + int dr, dg, db; + int col; + int mindif = 0x7fffffff; + + col = 0; + if (!id) + { + fprintf(stderr, "ImLib ERROR: No ImlibData initialised\n"); + return -1; + } + if ((id->render_type == RT_PLAIN_TRUECOL) || + (id->render_type == RT_DITHER_TRUECOL)) + { + dr = *r; + dg = *g; + db = *b; + switch (id->x.depth) + { + case 15: + *r = dr - (dr & 0xf8); + *g = dg - (dg & 0xf8); + *b = db - (db & 0xf8); + return ((dr & 0xf8) << 7) | ((dg & 0xf8) << 2) | ((db & 0xf8) >> 3); + break; + case 16: + *r = dr - (dr & 0xf8); + *g = dg - (dg & 0xfc); + *b = db - (db & 0xf8); + return ((dr & 0xf8) << 8) | ((dg & 0xfc) << 3) | ((db & 0xf8) >> 3); + break; + case 24: + case 32: + *r = 0; + *g = 0; + *b = 0; + switch (id->byte_order) + { + case BYTE_ORD_24_RGB: + return ((dr & 0xff) << 16) | ((dg & 0xff) << 8) | (db & 0xff); + break; + case BYTE_ORD_24_RBG: + return ((dr & 0xff) << 16) | ((db & 0xff) << 8) | (dg & 0xff); + break; + case BYTE_ORD_24_BRG: + return ((db & 0xff) << 16) | ((dr & 0xff) << 8) | (dg & 0xff); + break; + case BYTE_ORD_24_BGR: + return ((db & 0xff) << 16) | ((dg & 0xff) << 8) | (dr & 0xff); + break; + case BYTE_ORD_24_GRB: + return ((dg & 0xff) << 16) | ((dr & 0xff) << 8) | (db & 0xff); + break; + case BYTE_ORD_24_GBR: + return ((dg & 0xff) << 16) | ((db & 0xff) << 8) | (dr & 0xff); + break; + default: + return 0; + break; + } + break; + default: + return 0; + break; + } + return 0; + } + for (i = 0; i < id->num_colors; i++) + { + dr = *r - id->palette[i].r; + if (dr < 0) + dr = -dr; + dg = *g - id->palette[i].g; + if (dg < 0) + dg = -dg; + db = *b - id->palette[i].b; + if (db < 0) + db = -db; + dif = dr + dg + db; + if (dif < mindif) + { + mindif = dif; + col = i; + } + } + *r -= id->palette[col].r; + *g -= id->palette[col].g; + *b -= id->palette[col].b; + return col; +} + +void +render_shaped_15_fast_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_shaped_15_fast_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 1, 5}, + {6, 2, 7, 3}, + {1, 5, 0, 4}, + {7, 3, 6, 2} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_15_fast_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +render_15_fast_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 1, 5}, + {6, 2, 7, 3}, + {1, 5, 0, 4}, + {7, 3, 6, 2} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_16_fast_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_shaped_16_fast_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 1, 5}, + {6, 2, 7, 3}, + {1, 5, 0, 4}, + {7, 3, 6, 2} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_16_fast_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +render_16_fast_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 1, 5}, + {6, 2, 7, 3}, + {1, 5, 0, 4}, + {7, 3, 6, 2} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_15_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_shaped_15_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_15_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_15_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_16_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_shaped_16_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_16_dither(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_16_dither_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_15_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_15_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_16_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_16_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_24_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * 3; + img = (unsigned char *)xim->data; + + if (id->x.byte_order == MSBFirst) + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = r; + *img++ = g; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = r; + *img++ = b; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = b; + *img++ = r; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = b; + *img++ = g; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = r; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = b; + *img++ = r; + } + } + img += jmp; + } + } + } + else + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = b; + *img++ = g; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = b; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = r; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = r; + *img++ = g; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = b; + *img++ = r; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = r; + *img++ = b; + *img++ = g; + } + } + img += jmp; + } + } + } +} + +void +render_24_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * 3; + img = (unsigned char *)xim->data; + if (id->x.byte_order == MSBFirst) + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = r; + *img++ = g; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = r; + *img++ = b; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = b; + *img++ = r; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = b; + *img++ = g; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = g; + *img++ = r; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = g; + *img++ = b; + *img++ = r; + } + img += jmp; + } + } + } + else + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = b; + *img++ = g; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = g; + *img++ = b; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = g; + *img++ = r; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = r; + *img++ = g; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = b; + *img++ = r; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + *img++ = r; + *img++ = b; + *img++ = g; + } + img += jmp; + } + } + } +} + +void +render_shaped_32_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } +} + +void +render_32_fast(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + img += jmp; + } + } +} + +void +render_shaped_15(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_15(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_16(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_16(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_24(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } +} + +void +render_24(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_shaped(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * (bpp >> 3); + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = Imlib_best_color_match(id, &r, &g, &b); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = Imlib_best_color_match(id, &r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + render_shaped_15_fast_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_15_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + render_shaped_16_fast_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_16_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + render_shaped_24_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_32_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + render_shaped_15_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_15(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + render_shaped_16_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_16(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + render_shaped_24(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + case 32: + render_shaped_24(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + break; + } +} + +void +render(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * (bpp >> 3); + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = Imlib_best_color_match(id, &r, &g, &b); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = Imlib_best_color_match(id, &r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_15_fast_dither_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_15_fast_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_15_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_16_fast_dither_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_16_fast_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_16_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + render_24_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_32_fast(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_15_dither_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_15_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_15(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_16_dither_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_16_dither(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_16(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + render_24(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 32: + render_24(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + break; + } + } +} + +void +render_shaped_15_fast_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_shaped_15_fast_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_15_fast_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +render_15_fast_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_16_fast_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_shaped_16_fast_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_16_fast_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } +} + +void +render_16_fast_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_15_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_15_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < eg) && (g < (256 - 8))) + g += 8; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_16_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + } + else + { + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + XPutPixel(sxim, x, y, 1); + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_16_dither_mod_ordered(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, er, eg, eb; + unsigned char *ptr2; + + unsigned char dither[4][4] = + { + {0, 4, 6, 5}, + {6, 2, 7, 3}, + {2, 6, 1, 5}, + {7, 4, 7, 3} + }; + int dithy, dithx; + + for (y = 0; y < h; y++) + { + dithy = y & 0x3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r & 0x07; + eg = g & 0x03; + eb = b & 0x07; + dithx = x & 0x3; + if ((dither[dithy][dithx] < er) && (r < (256 - 8))) + r += 8; + if ((dither[dithy][dithx] < (eg << 1)) && (g < (256 - 4))) + g += 4; + if ((dither[dithy][dithx] < eb) && (b < (256 - 8))) + b += 8; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_15_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + er = r & 0x07; + eg = g & 0x07; + eb = b & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_15_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 7) | ((eg & 0xf8) << 2) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x07; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_16_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_16_dither_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + if (eg > 255) + eg = 255; + if (eb > 255) + eb = 255; + val = ((er & 0xf8) << 8) | ((eg & 0xfc) << 3) | ((eb & 0xf8) >> 3); + er = er & 0x07; + eg = eg & 0x03; + eb = eb & 0x07; + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_15_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_15_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_16_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +void +render_16_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + unsigned short *img; + int jmp; + + jmp = (xim->bytes_per_line >> 1) - w; + img = (unsigned short *)xim->data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +void +render_shaped_24_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * 3; + img = (unsigned char *)xim->data; + + if (id->x.byte_order == MSBFirst) + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = g; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = b; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = r; + *img++ = g; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = g; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = r; + *img++ = b; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = g; + *img++ = b; + *img++ = r; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + } + } + img += jmp; + } + } + } + else + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = g; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = b; + *img++ = r; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = r; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = g; + *img++ = b; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = b; + *img++ = r; + *img++ = g; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + *img++ = r; + *img++ = b; + *img++ = g; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + } + } + img += jmp; + } + } + } +} + +void +render_24_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, r, g, b; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * 3; + img = (unsigned char *)xim->data; + + if (id->x.byte_order == MSBFirst) + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = g; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = b; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = r; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = g; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = r; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = b; + *img++ = r; + } + img += jmp; + } + } + } + else + { + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = g; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = b; + *img++ = r; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = g; + *img++ = r; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = g; + *img++ = b; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = b; + *img++ = r; + *img++ = g; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + *img++ = r; + *img++ = b; + *img++ = g; + } + img += jmp; + } + } + } +} + +void +render_shaped_32_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } +} + +void +render_32_fast_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + unsigned int *img; + int jmp; + + jmp = (xim->bytes_per_line >> 2) - w; + img = (unsigned int *)xim->data; + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + *img++ = val; + } + img += jmp; + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + img += jmp; + } + } +} + +void +render_shaped_15_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_15_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_16_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_16_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +void +render_shaped_24_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } +} + +void +render_24_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray) +{ + int x, y, val, r, g, b; + unsigned char *ptr2; + + if (id->byte_order == BYTE_ORD_24_RGB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (g << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_RBG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (r << 16) | (b << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BRG) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (r << 8) | g; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_BGR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (b << 16) | (g << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GRB) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (r << 8) | b; + XPutPixel(xim, x, y, val); + } + } + } + else if (id->byte_order == BYTE_ORD_24_GBR) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } +} + +void +render_shaped_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * (bpp >> 3); + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = Imlib_best_color_match(id, &r, &g, &b); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = Imlib_best_color_match(id, &r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + img++; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + XPutPixel(sxim, x, y, 0); + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + { + XPutPixel(sxim, x, y, 0); + img++; + } + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + if ((r == im->shape_color.r) && + (g == im->shape_color.g) && + (b == im->shape_color.b)) + { + XPutPixel(sxim, x, y, 0); + ex += 3; + } + else + { + XPutPixel(sxim, x, y, 1); + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_shaped_15_fast_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_15_fast_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_shaped_15_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_shaped_16_fast_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_16_fast_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_shaped_16_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + render_shaped_24_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_32_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_shaped_15_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_15_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_shaped_15_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_shaped_16_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_shaped_16_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_shaped_16_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + render_shaped_24_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + case 32: + render_shaped_24_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + break; + } +} + +void +render_mod(ImlibData * id, ImlibImage * im, int w, int h, XImage * xim, + XImage * sxim, int *er1, int *er2, int *xarray, + unsigned char **yarray, int bpp) +{ + int x, y, val, r, g, b, *ter, ex, er, eg, eb; + unsigned char *ptr2; + unsigned char *img; + int jmp; + + jmp = (xim->bytes_per_line) - w * (bpp >> 3); + img = (unsigned char *)xim->data; + switch (id->render_type) + { + case RT_PLAIN_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = Imlib_best_color_match(id, &r, &g, &b); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = Imlib_best_color_match(id, &r, &g, &b); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_PLAIN_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + val = COLOR_RGB(r >> 3, g >> 3, b >> 3); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = val; + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = Imlib_best_color_match(id, &er, &eg, &eb); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, val); + } + } + } + break; + case RT_DITHER_PALETTE_FAST: + if ((id->fastrend) && (xim->bits_per_pixel == 8)) + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + *img++ = COLOR_INDEX(val); + } + img += jmp; + } + } + else + { + for (y = 0; y < h; y++) + { + ter = er1; + er1 = er2; + er2 = ter; + for (ex = 0; ex < (w + 2) * 3; ex++) + er2[ex] = 0; + ex = 3; + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + r = (int)*ptr2++; + g = (int)*ptr2++; + b = (int)*ptr2; + r = im->rmap[r]; + g = im->gmap[g]; + b = im->bmap[b]; + er = r + er1[ex++]; + eg = g + er1[ex++]; + eb = b + er1[ex++]; + if (er > 255) + er = 255; + else if (er < 0) + er = 0; + if (eg > 255) + eg = 255; + else if (eg < 0) + eg = 0; + if (eb > 255) + eb = 255; + else if (eb < 0) + eb = 0; + val = INDEX_RGB(er >> 3, eg >> 3, eb >> 3); + er = ERROR_RED(er, val); + eg = ERROR_GRN(eg, val); + eb = ERROR_BLU(eb, val); + DITHER_ERROR(er1, er2, ex, er, eg, eb); + XPutPixel(xim, x, y, COLOR_INDEX(val)); + } + } + } + break; + default: + if (id->fastrend) + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_15_fast_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_15_fast_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_15_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_16_fast_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_16_fast_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_16_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + render_24_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_32_fast_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_15_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_15_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_15_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + render_16_dither_mod_ordered(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + render_16_dither_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + render_16_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + render_24_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 32: + render_24_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + break; + } + } +} + +int +Imlib_render(ImlibData * id, ImlibImage * im, int w, int h) +{ + XImage *xim, *sxim; + static Display *pd = NULL; + static GC tgc = 0, stgc = 0; + XGCValues gcv; + unsigned char *tmp, *stmp, **yarray, *ptr22; + int w3, x, inc, pos, *error, *er1, *er2, *xarray, ex, bpp, + huge; + Pixmap pmap, mask; + int shared_pixmap, shared_image, ok; + + if (!pd) + pd = id->x.disp; + if (tgc) + { + if (id->x.disp != pd) + { + XFreeGC(pd, tgc); + tgc = 0; + } + } + if (stgc) + { + if (id->x.disp != pd) + { + XFreeGC(pd, stgc); + stgc = 0; + } + } + pd = id->x.disp; + + sxim = NULL; + xim = NULL; + tmp = NULL; + stmp = NULL; + pmap = 0; + mask = 0; + inc = 0; + if (!im) + return 0; + if (w <= 0) + return 0; + if (h <= 0) + return 0; + gcv.graphics_exposures = False; + +/* look for the pixmap in cache first */ + if (id->cache.on_pixmap) + { + pmap = 0; + find_pixmap(id, im, w, h, &pmap, &mask); + if (pmap) + { + im->width = w; + im->height = h; + im->pixmap = pmap; + if (mask) + im->shape_mask = mask; + else + im->shape_mask = 0; + return 1; + } + } + if (im->pixmap) + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + im->shape_mask = 0; +/* setup stuff */ + huge = 0; + if (id->x.depth <= 8) + bpp = 1; + else if (id->x.depth <= 16) + bpp = 2; + else if (id->x.depth <= 24) + bpp = 3; + else + bpp = 4; + + if ((id->max_shm) && ((bpp * w * h) > id->max_shm)) + huge = 1; + im->width = w; + im->height = h; + +/* dithering array */ + error = (int *)malloc(sizeof(int) * (w + 2) * 2 * 3); + + if (!error) + { + fprintf(stderr, "ERROR: Cannot allocate RAM for image dither buffer\n"); + return 0; + } + +/* setup pointers to point right */ + er1 = error; + er2 = error + ((w + 2) * 3); + w3 = im->rgb_width * 3; + ptr22 = im->rgb_data; + +/* setup coord-mapping array (specially for border scaling) */ + xarray = malloc(sizeof(int) * w); + + if (!xarray) + { + fprintf(stderr, "ERROR: Cannot allocate X co-ord buffer\n"); + free(error); + return 0; + } + yarray = malloc(sizeof(unsigned char *) * h); + + if (!yarray) + { + fprintf(stderr, "ERROR: Cannot allocate Y co-ord buffer\n"); + free(xarray); + free(error); + return 0; + } + for (ex = 0; ex < ((w + 2) * 3 * 2); ex++) + error[ex] = 0; + { + int l, r, m; + + if (w < im->border.left + im->border.right) + { + l = w >> 1; + r = w - l; + m = 0; + } + else + { + l = im->border.left; + r = im->border.right; + m = w - l - r; + } + if (m > 0) + inc = ((im->rgb_width - im->border.left - im->border.right) << 16) / m; + pos = 0; + if (l) + for (x = 0; x < l; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + if (m) + { + for (x = l; x < l + m; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += inc; + } + } + pos = (im->rgb_width - r) << 16; + for (x = w - r; x < w; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + + if (h < im->border.top + im->border.bottom) + { + l = h >> 1; + r = h - l; + m = 0; + } + else + { + l = im->border.top; + r = im->border.bottom; + m = h - l - r; + } + if (m > 0) + inc = ((im->rgb_height - im->border.top - im->border.bottom) << 16) / m; + pos = 0; + for (x = 0; x < l; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + if (m) + { + for (x = l; x < l + m; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += inc; + } + } + pos = (im->rgb_height - r) << 16; + for (x = h - r; x < h; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + } + +/* work out if we should use shared pixmap. images etc */ + shared_pixmap = 0; + shared_image = 0; + if ((id->x.shmp) && (id->x.shm) && (!huge)) + { +#if defined(__alpha__) + shared_pixmap = 0; + shared_image = 1; +#else + shared_pixmap = 1; + shared_image = 0; +#endif + } + else if ((id->x.shm) && (!huge)) + { + shared_pixmap = 0; + shared_image = 1; + } + else + { + shared_pixmap = 0; + shared_image = 0; + } + +/* init images and pixmaps */ + ok = 1; +#ifdef HAVE_SHM + if (shared_pixmap) + { + xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, NULL, &id->x.last_shminfo, w, h); + if (!xim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create XImage for Shared Pixmap Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, IPC_CREAT | 0777); + if (id->x.last_shminfo.shmid == -1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared Pixmap Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XDestroyImage(xim); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.shmaddr = xim->data = shmat(id->x.last_shminfo.shmid, 0, 0); + if (xim->data == (char *)-1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't attach SHM Segment for Shared Pixmap Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XDestroyImage(xim); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_shminfo); + tmp = (unsigned char *)xim->data; + id->x.last_xim = xim; + pmap = XShmCreatePixmap(id->x.disp, id->x.base_window, + id->x.last_shminfo.shmaddr, + &id->x.last_shminfo, w, h, id->x.depth); + if (!tgc) + tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + sxim = XShmCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, NULL, &id->x.last_sshminfo, w, h); + if (!sxim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create XImage for Shared Pixmap mask Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.shmid = shmget(IPC_PRIVATE, sxim->bytes_per_line * sxim->height, IPC_CREAT | 0777); + if (id->x.last_sshminfo.shmid == -1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared Pixmap mask Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(xim->data); + /* missing shmctl(RMID) */ + XDestroyImage(sxim); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.shmaddr = sxim->data = shmat(id->x.last_sshminfo.shmid, 0, 0); + if (sxim->data == (char *)-1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't attach SHM Segment for Shared Pixmap mask Wrapper\n"); + fprintf(stderr, " Falling back on Shared XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(xim->data); + /* missing shmctl(RMID) */ + XDestroyImage(sxim); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + shared_pixmap = 0; + shared_image = 1; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_sshminfo); + stmp = (unsigned char *)sxim->data; + id->x.last_sxim = sxim; + mask = XShmCreatePixmap(id->x.disp, id->x.base_window, + id->x.last_sshminfo.shmaddr, + &id->x.last_sshminfo, w, h, 1); + if (!stgc) + stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); + } + } + } + } + } + } + } + } + ok = 1; + if (shared_image) + { + xim = XShmCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, NULL, &id->x.last_shminfo, w, h); + if (!xim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create Shared XImage\n"); + fprintf(stderr, " Falling back on XImages\n"); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, IPC_CREAT | 0777); + if (id->x.last_shminfo.shmid == -1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't get SHM Identifier for Shared XImage\n"); + fprintf(stderr, " Falling back on XImages\n"); + XDestroyImage(xim); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.shmaddr = xim->data = shmat(id->x.last_shminfo.shmid, 0, 0); + + if (xim->data == (char *)-1) + { + fprintf(stderr, "IMLIB ERROR: SHM can't attach SHM Segment for Shared XImage\n"); + fprintf(stderr, " Falling back on XImages\n"); + XDestroyImage(xim); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_shminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_shminfo); + tmp = (unsigned char *)xim->data; + id->x.last_xim = xim; + pmap = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + if (!tgc) + tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); + im->pixmap = pmap; + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + sxim = XShmCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, NULL, &id->x.last_sshminfo, w, h); + if (!sxim) + { + fprintf(stderr, "IMLIB ERROR: Mit-SHM can't create Shared XImage mask\n"); + fprintf(stderr, " Falling back on XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.shmid = shmget(IPC_PRIVATE, sxim->bytes_per_line * sxim->height, IPC_CREAT | 0777); + if (id->x.last_sshminfo.shmid == -1) + { + fprintf(stderr, "Imlib ERROR: SHM can't get SHM Identifier for Shared XImage mask\n"); + fprintf(stderr, " Falling back on XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(xim->data); + /* missing shmctl(RMID) */ + XDestroyImage(sxim); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + if (ok) + { + id->x.last_sshminfo.shmaddr = sxim->data = shmat(id->x.last_sshminfo.shmid, 0, 0); + if (sxim->data == (char *)-1) + { + fprintf(stderr, "Imlib ERROR: SHM can't attach SHM Segment for Shared XImage mask\n"); + fprintf(stderr, " Falling back on XImages\n"); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(xim->data); + /* missing shmctl(RMID) */ + XDestroyImage(sxim); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + shared_pixmap = 0; + shared_image = 0; + ok = 0; + } + + if (ok) + { + id->x.last_sshminfo.readOnly = False; + XShmAttach(id->x.disp, &id->x.last_sshminfo); + stmp = (unsigned char *)sxim->data; + id->x.last_sxim = sxim; + mask = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); + if (!stgc) + stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); + im->shape_mask = mask; + } + } + } + } + } + } + } + } + ok = 1; + if ((!shared_pixmap) && (!shared_image)) +#endif /* HAVE_SHM */ + { + tmp = (unsigned char *)malloc(w * h * bpp); + if (!tmp) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for XImage data\n"); + free(xarray); + free(yarray); + free(error); + return 0; + } + xim = XCreateImage(id->x.disp, id->x.visual, id->x.depth, ZPixmap, 0, (char *)tmp, w, h, 8, 0); + if (!xim) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate XImage buffer\n"); + free(xarray); + free(yarray); + free(error); + free(tmp); + return 0; + } + if (xim->bits_per_pixel != bpp) + xim->data = realloc(xim->data, xim->bytes_per_line * xim->height); + pmap = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + if (!pmap) + { + fprintf(stderr, "IMLIB ERROR: Cannot create pixmap\n"); + free(xarray); + free(yarray); + free(error); + XDestroyImage(xim); + return 0; + } + im->pixmap = pmap; + if (!tgc) + tgc = XCreateGC(id->x.disp, pmap, GCGraphicsExposures, &gcv); + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + stmp = (unsigned char *)malloc(((w >> 3) + 8) * h); + if (!stmp) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate RAM for shape XImage data\n"); + free(xarray); + free(yarray); + free(error); + XDestroyImage(xim); + return 0; + } + sxim = XCreateImage(id->x.disp, id->x.visual, 1, ZPixmap, 0, (char *)stmp, w, h, 8, 0); + if (!sxim) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate XImage shape buffer\n"); + free(xarray); + free(yarray); + free(error); + free(stmp); + XDestroyImage(xim); + return 0; + } + mask = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); + if (!mask) + { + fprintf(stderr, "IMLIB ERROR: Cannot create shape pixmap\n"); + free(xarray); + free(yarray); + free(error); + XDestroyImage(sxim); + XDestroyImage(xim); + return 0; + } + im->shape_mask = mask; + if (!stgc) + stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); + } + } +/* copy XImage to the pixmap, if not a shared pixmap */ + if ((im->shape_color.r >= 0) && (im->shape_color.g >= 0) && (im->shape_color.b >= 0)) + { + if ((im->mod.gamma == 256) && (im->mod.brightness == 256) && (im->mod.contrast == 256) && + (im->rmod.gamma == 256) && (im->rmod.brightness == 256) && (im->rmod.contrast == 256) && + (im->gmod.gamma == 256) && (im->gmod.brightness == 256) && (im->gmod.contrast == 256) && + (im->bmod.gamma == 256) && (im->bmod.brightness == 256) && (im->bmod.contrast == 256)) + { + if (id->x.depth <= 8) + render_shaped(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + render_shaped(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + else + { + if (id->x.depth <= 8) + render_shaped_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + render_shaped_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } +#ifdef HAVE_SHM + if (shared_image) + { + XShmPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h, False); + XShmPutImage(id->x.disp, mask, stgc, sxim, 0, 0, 0, 0, w, h, False); + XSync(id->x.disp, False); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + XShmDetach(id->x.disp, &id->x.last_sshminfo); + XDestroyImage(sxim); + shmdt(id->x.last_sshminfo.shmaddr); + shmctl(id->x.last_sshminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + xim = NULL; + sxim = NULL; +/* XFreeGC(id->x.disp, tgc);*/ +/* XFreeGC(id->x.disp, stgc);*/ + } + else if (shared_pixmap) + { + Pixmap p2, m2; + + p2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + m2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, 1); + XCopyArea(id->x.disp, pmap, p2, tgc, 0, 0, w, h, 0, 0); + XCopyArea(id->x.disp, mask, m2, stgc, 0, 0, w, h, 0, 0); + im->pixmap = p2; + im->shape_mask = m2; +/* XFreeGC(id->x.disp, tgc);*/ +/* XFreeGC(id->x.disp, stgc);*/ + XFreePixmap(id->x.disp, pmap); + XFreePixmap(id->x.disp, mask); + XSync(id->x.disp, False); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + XShmDetach(id->x.disp, &id->x.last_sshminfo); + XDestroyImage(sxim); + shmdt(id->x.last_sshminfo.shmaddr); + shmctl(id->x.last_sshminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + id->x.last_sxim = NULL; + xim = NULL; + sxim = NULL; + } + else +#endif /* HAVE_SHM */ + { + XPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h); + XPutImage(id->x.disp, mask, stgc, sxim, 0, 0, 0, 0, w, h); + XDestroyImage(xim); + XDestroyImage(sxim); + xim = NULL; + sxim = NULL; +/* XFreeGC(id->x.disp, tgc);*/ +/* XFreeGC(id->x.disp, stgc);*/ + } + } + else + { + if ((im->mod.gamma == 256) && (im->mod.brightness == 256) && (im->mod.contrast == 256) && + (im->rmod.gamma == 256) && (im->rmod.brightness == 256) && (im->rmod.contrast == 256) && + (im->gmod.gamma == 256) && (im->gmod.brightness == 256) && (im->gmod.contrast == 256) && + (im->bmod.gamma == 256) && (im->bmod.brightness == 256) && (im->bmod.contrast == 256)) + { + if (id->x.depth <= 8) + render(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + render(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + else + { + if (id->x.depth <= 8) + render_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + render_mod(id, im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } +#ifdef HAVE_SHM + if (shared_image) + { + XShmPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h, False); + XSync(id->x.disp, False); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + xim = NULL; + sxim = NULL; +/* XFreeGC(id->x.disp, tgc);*/ + } + else if (shared_pixmap) + { + Pixmap p2; + + p2 = XCreatePixmap(id->x.disp, id->x.base_window, w, h, id->x.depth); + XCopyArea(id->x.disp, pmap, p2, tgc, 0, 0, w, h, 0, 0); + im->pixmap = p2; +/* XFreeGC(id->x.disp, tgc);*/ + XFreePixmap(id->x.disp, pmap); + XSync(id->x.disp, False); + XShmDetach(id->x.disp, &id->x.last_shminfo); + XDestroyImage(xim); + shmdt(id->x.last_shminfo.shmaddr); + shmctl(id->x.last_shminfo.shmid, IPC_RMID, 0); + id->x.last_xim = NULL; + xim = NULL; + sxim = NULL; + } + else +#endif /* HAVE_SHM */ + { + XPutImage(id->x.disp, pmap, tgc, xim, 0, 0, 0, 0, w, h); + XDestroyImage(xim); + xim = NULL; + sxim = NULL; +/* XFreeGC(id->x.disp, tgc);*/ + } + } + +/* cleanup */ +/* XSync(id->x.disp, False);*/ + free(error); + free(xarray); + free(yarray); + +/* add this pixmap to the cache */ + add_pixmap(id, im, w, h, xim, sxim); + return 1; +} diff --git a/debian/imlib/imlib-1.9.15/Imlib/save.c b/debian/imlib/imlib-1.9.15/Imlib/save.c new file mode 100644 index 00000000..f187e507 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/save.c @@ -0,0 +1,555 @@ +#define _GNU_SOURCE +#include <config.h> +#include "Imlib.h" +#include "Imlib_private.h" + +#ifndef HAVE_SNPRINTF +#define snprintf my_snprintf +#ifdef HAVE_STDARGS +int my_snprintf(char *str, size_t count, const char *fmt,...); + +#else +int my_snprintf(va_alist); + +#endif +#endif + +int +Imlib_save_image(ImlibData * id, ImlibImage * im, char *file, ImlibSaveInfo * info) +{ + char *ext; + char cmd[10240]; + FILE *f; + ImlibSaveInfo defaults; + + if (!im || !file) + return 0; + + defaults.quality = 208; + defaults.scaling = 1024; + defaults.xjustification = 512; + defaults.yjustification = 512; + defaults.page_size = PAGE_SIZE_LETTER; + defaults.color = 1; + + if (!info) + info = &defaults; + ext = _GetExtension(file); + + if ((!strcasecmp(ext, "ppm")) || (!strcasecmp(ext, "pnm"))) + { + f = fopen(file, "wb"); + if (f) + { + if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + fclose(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + fclose(f); + return 0; + } + fclose(f); + return 1; + } + } + else if (!strcasecmp(ext, "pgm")) + { + int x, y; + unsigned char *ptr, val; + int v; + + f = fopen(file, "wb"); + if (f) + { + if (!fprintf(f, "P5\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + fclose(f); + return 0; + } + ptr = im->rgb_data; + for (y = 0; y < im->rgb_height; y++) + { + for (x = 0; x < im->rgb_width; x++) + { + v = (int)(*ptr++); + v += (int)(*ptr++); + v += (int)(*ptr++); + val = (unsigned char)(v / 3); + if (!fwrite(&val, 1, 1, f)) + { + fclose(f); + return 0; + } + } + } + fclose(f); + return 1; + } + } + else if (!strcasecmp(ext, "ps")) + { + int bx, by, bxx, byy; + int w, h; + int sx, sy; + int tx = 35, ty = 35; + int x, y; + unsigned char *ptr; + int v; + + sx = 0; + sy = 0; + f = fopen(file, "wb"); + + if (f == NULL) + return 0; + + w = im->rgb_width; + h = im->rgb_height; + + switch (info->page_size) + { + case PAGE_SIZE_EXECUTIVE: + sx = 540; + sy = 720; + break; + case PAGE_SIZE_LETTER: + sx = 612; + sy = 792; + break; + case PAGE_SIZE_LEGAL: + sx = 612; + sy = 1008; + break; + case PAGE_SIZE_A4: + sx = 595; + sy = 842; + break; + case PAGE_SIZE_A3: + sx = 842; + sy = 1190; + break; + case PAGE_SIZE_A5: + sx = 420; + sy = 595; + break; + case PAGE_SIZE_FOLIO: + sx = 612; + sy = 936; + break; + } + bxx = ((sx - (tx * 2)) * info->scaling) >> 10; + byy = (int)(((float)h / (float)w) * (float)bxx); + if ((((sy - (ty * 2)) * info->scaling) >> 10) < byy) + { + byy = ((sy - (ty * 2)) * info->scaling) >> 10; + bxx = (int)(((float)w / (float)h) * (float)byy); + } + bx = tx + ((((sx - (tx * 2)) - bxx) * info->xjustification) >> 10); + by = ty + ((((sy - (ty * 2)) - byy) * info->yjustification) >> 10); + if (f) + { + fprintf(f, "%%!PS-Adobe-2.0 EPSF-2.0\n"); + fprintf(f, "%%%%Title: %s\n", file); + fprintf(f, "%%%%Creator: Imlib by The Rasterman\n"); + fprintf(f, "%%%%BoundingBox: %i %i %i %i\n", bx, by, bxx, byy); + fprintf(f, "%%%%Pages: 1\n"); + fprintf(f, "%%%%DocumentFonts:\n"); + fprintf(f, "%%%%EndComments\n"); + fprintf(f, "%%%%EndProlog\n"); + fprintf(f, "%%%%Page: 1 1\n"); + fprintf(f, "/origstate save def\n"); + fprintf(f, "20 dict begin\n"); + if (info->color) + { + fprintf(f, "/pix %i string def\n", w * 3); + fprintf(f, "/grays %i string def\n", w); + fprintf(f, "/npixls 0 def\n"); + fprintf(f, "/rgbindx 0 def\n"); + fprintf(f, "%i %i translate\n", bx, by); + fprintf(f, "%i %i scale\n", bxx, byy); + fprintf(f, + "/colorimage where\n" + "{ pop }\n" + "{\n" + "/colortogray {\n" + "/rgbdata exch store\n" + "rgbdata length 3 idiv\n" + "/npixls exch store\n" + "/rgbindx 0 store\n" + "0 1 npixls 1 sub {\n" + "grays exch\n" + "rgbdata rgbindx get 20 mul\n" + "rgbdata rgbindx 1 add get 32 mul\n" + "rgbdata rgbindx 2 add get 12 mul\n" + "add add 64 idiv\n" + "put\n" + "/rgbindx rgbindx 3 add store\n" + "} for\n" + "grays 0 npixls getinterval\n" + "} bind def\n" + "/mergeprocs {\n" + "dup length\n" + "3 -1 roll\n" + "dup\n" + "length\n" + "dup\n" + "5 1 roll\n" + "3 -1 roll\n" + "add\n" + "array cvx\n" + "dup\n" + "3 -1 roll\n" + "0 exch\n" + "putinterval\n" + "dup\n" + "4 2 roll\n" + "putinterval\n" + "} bind def\n" + "/colorimage {\n" + "pop pop\n" + "{colortogray} mergeprocs\n" + "image\n" + "} bind def\n" + "} ifelse\n"); + fprintf(f, "%i %i 8\n", w, h); + fprintf(f, "[%i 0 0 -%i 0 %i]\n", w, h, h); + fprintf(f, "{currentfile pix readhexstring pop}\n"); + fprintf(f, "false 3 colorimage\n"); + fprintf(f, "\n"); + ptr = im->rgb_data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + v = (int)(*ptr++); + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + v = (int)(*ptr++); + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + v = (int)(*ptr++); + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + } + fprintf(f, "\n"); + } + } + else + { + fprintf(f, "/pix %i string def\n", w); + fprintf(f, "/grays %i string def\n", w); + fprintf(f, "/npixls 0 def\n"); + fprintf(f, "/rgbindx 0 def\n"); + fprintf(f, "%i %i translate\n", bx, by); + fprintf(f, "%i %i scale\n", bxx, byy); + fprintf(f, "%i %i 8\n", w, h); + fprintf(f, "[%i 0 0 -%i 0 %i]\n", w, h, h); + fprintf(f, "{currentfile pix readhexstring pop}\n"); + fprintf(f, "image\n"); + fprintf(f, "\n"); + ptr = im->rgb_data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + v = (int)(*ptr++); + v += (int)(*ptr++); + v += (int)(*ptr++); + v /= 3; + if (v < 0x10) + fprintf(f, "0%x", v); + else + fprintf(f, "%x", v); + } + fprintf(f, "\n"); + } + } + fprintf(f, "\n"); + fprintf(f, "showpage\n"); + fprintf(f, "end\n"); + fprintf(f, "origstate restore\n"); + fprintf(f, "%%%%Trailer\n"); + fclose(f); + return 1; + } + } + else if ((!strcasecmp(ext, "jpeg")) || (!strcasecmp(ext, "jpg"))) + { +#ifdef HAVE_LIBJPEG + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPROW row_pointer[1]; + int row_stride; + + f = fopen(file, "wb"); + if (f) + { + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + jpeg_stdio_dest(&cinfo, f); + cinfo.image_width = im->rgb_width; + cinfo.image_height = im->rgb_height; + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + jpeg_set_defaults(&cinfo); + jpeg_set_quality(&cinfo, (100 * info->quality) >> 8, TRUE); + jpeg_start_compress(&cinfo, TRUE); + row_stride = cinfo.image_width * 3; + while (cinfo.next_scanline < cinfo.image_height) + { + row_pointer[0] = im->rgb_data + (cinfo.next_scanline * row_stride); + jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + jpeg_finish_compress(&cinfo); + fclose(f); + return 1; + } +#endif + } + else if (!strcasecmp(ext, "png")) + { +#ifdef HAVE_LIBPNG + png_structp png_ptr; + png_infop info_ptr; + unsigned char *data, *ptr; + int x, y; + png_bytep row_ptr; + png_color_8 sig_bit; + + f = fopen(file, "wb"); + if (f) + { + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + if (!png_ptr) + { + fclose(f); + return 0; + } + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return 0; + } + if (setjmp(png_ptr->jmpbuf)) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return 0; + } + png_init_io(png_ptr, f); + png_set_IHDR(png_ptr, info_ptr, im->rgb_width, im->rgb_height, 8, + PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + sig_bit.red = 8; + sig_bit.green = 8; + sig_bit.blue = 8; + sig_bit.alpha = 8; + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + png_write_info(png_ptr, info_ptr); + png_set_shift(png_ptr, &sig_bit); + png_set_packing(png_ptr); + data = malloc(im->rgb_width * 4); + if (!data) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return 0; + } + for (y = 0; y < im->rgb_height; y++) + { + ptr = im->rgb_data + (y * im->rgb_width * 3); + for (x = 0; x < im->rgb_width; x++) + { + data[(x << 2) + 0] = *ptr++; + data[(x << 2) + 1] = *ptr++; + data[(x << 2) + 2] = *ptr++; + if ((data[(x << 2) + 0] == im->shape_color.r) && + (data[(x << 2) + 1] == im->shape_color.g) && + (data[(x << 2) + 2] == im->shape_color.b)) + data[(x << 2) + 3] = 0; + else + data[(x << 2) + 3] = 255; + } + row_ptr = data; + png_write_rows(png_ptr, &row_ptr, 1); + } + free(data); + png_write_end(png_ptr, info_ptr); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + + fclose(f); + return 1; + } +#endif + } + else if ((!strcasecmp(ext, "tiff")) || (!strcasecmp(ext, "tif"))) + { +#ifdef HAVE_LIBTIFF + TIFF *tif; + unsigned char *data; + int y; + int w; + + tif = TIFFOpen(file, "w"); + if (tif) + { + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, im->rgb_width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, im->rgb_height); + TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_LZW); + { + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + w = TIFFScanlineSize(tif); + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, + TIFFDefaultStripSize(tif, -1)); + for (y = 0; y < im->rgb_height; y++) + { + data = im->rgb_data + (y * im->rgb_width * 3); + TIFFWriteScanline(tif, data, y, 0); + } + } + TIFFClose(tif); + return 1; + } +#endif + } +#if 0 + /* Once again, no shell fallbacks. This is just asking for it */ + if (id->fallback) + { + f = open_helper("%C/convert pnm:- '%s'", file, "wb"); + if (f) + { + if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + close_helper(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + close_helper(f); + return 0; + } + if (close_helper(f)) + return 0; + return 1; + } + + if (!strcasecmp(ext, "jpeg")) + snprintf(cmd, sizeof(cmd), "%%H -quality %i -progressive -outfile %%s", 100 * info->quality / 256); + else if (!strcasecmp(ext, "jpg")) + snprintf(cmd, sizeof(cmd), "%%H -quality %i -progressive -outfile %%s", 100 * info->quality / 256); + else if (!strcasecmp(ext, "bmp")) + strcpy(cmd, "%Q %N/ppmtobmp > %s"); + else if (!strcasecmp(ext, "gif")) + strcpy(cmd, "%Q %N/ppmtogif -interlace > %s"); + else if (!strcasecmp(ext, "ilbm")) + strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress > %s"); + else if (!strcasecmp(ext, "ilb")) + strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress > %s"); + else if (!strcasecmp(ext, "iff")) + strcpy(cmd, "%N/ppmtoilbm -24if -hires -lace -compress > %s"); + else if (!strcasecmp(ext, "icr")) + strcpy(cmd, "%N/ppmtoicr > %s"); + else if (!strcasecmp(ext, "map")) + strcpy(cmd, "%N/ppmtomap > %s"); + else if (!strcasecmp(ext, "mit")) + strcpy(cmd, "%N/ppmtomitsu -sharpness 4 > %s"); + else if (!strcasecmp(ext, "mitsu")) + strcpy(cmd, "%N/ppmtomitsu -sharpness 4 > %s"); + else if (!strcasecmp(ext, "pcx")) + strcpy(cmd, "%N/ppmtopcx -24bit -packed > %s"); + else if (!strcasecmp(ext, "pgm")) + strcpy(cmd, "%N/ppmtopgm > %s"); + else if (!strcasecmp(ext, "pi1")) + strcpy(cmd, "%N/ppmtopi1 > %s"); + else if (!strcasecmp(ext, "pic")) + strcpy(cmd, "%Q %N/ppmtopict > %s"); + else if (!strcasecmp(ext, "pict")) + strcpy(cmd, "%Q %N/ppmtopict > %s"); + else if (!strcasecmp(ext, "pj")) + strcpy(cmd, "%N/ppmtopj > %s"); + else if (!strcasecmp(ext, "pjxl")) + strcpy(cmd, "%N/ppmtopjxl > %s"); + else if (!strcasecmp(ext, "puz")) + strcpy(cmd, "%N/ppmtopuzz > %s"); + else if (!strcasecmp(ext, "puzz")) + strcpy(cmd, "%N/ppmtopuzz > %s"); + else if (!strcasecmp(ext, "rgb3")) + strcpy(cmd, "%N/ppmtorgb3 > %s"); + else if (!strcasecmp(ext, "six")) + strcpy(cmd, "%N/ppmtosixel > %s"); + else if (!strcasecmp(ext, "sixel")) + strcpy(cmd, "%N/ppmtosizel > %s"); + else if (!strcasecmp(ext, "tga")) + strcpy(cmd, "%N/ppmtotga -rgb > %s"); + else if (!strcasecmp(ext, "targa")) + strcpy(cmd, "%N/ppmtotga -rgb > %s"); + else if (!strcasecmp(ext, "uil")) + strcpy(cmd, "%N/ppmtouil > %s"); + else if (!strcasecmp(ext, "xpm")) + strcpy(cmd, "%Q %N/ppmtoxpm > %s"); + else if (!strcasecmp(ext, "yuv")) + strcpy(cmd, "%N/ppmtoyuv > %s"); + else if (!strcasecmp(ext, "png")) + strcpy(cmd, "%N/pnmtopng > %s"); + else if (!strcasecmp(ext, "ps")) + strcpy(cmd, "%N/pnmtops -center -scale 100 > %s"); + else if (!strcasecmp(ext, "rast")) + strcpy(cmd, "%N/pnmtorast -rle > %s"); + else if (!strcasecmp(ext, "ras")) + strcpy(cmd, "%N/pnmtorast -rle > %s"); + else if (!strcasecmp(ext, "sgi")) + strcpy(cmd, "%N/pnmtosgi > %s"); + else if (!strcasecmp(ext, "sir")) + strcpy(cmd, "%N/pnmtosir > %s"); + else if (!strcasecmp(ext, "tif")) + strcpy(cmd, "%N/pnmtotiff -lzw > %s"); + else if (!strcasecmp(ext, "tiff")) + strcpy(cmd, "%N/pnmtotiff -lzw > %s"); + else if (!strcasecmp(ext, "xwd")) + strcpy(cmd, "%N/pnmtoxwd > %s"); + else + ext = ""; + if (ext[0]) + { + f = open_helper(cmd, file, "wb"); + if (f) + { + if (!fprintf(f, "P6\n# Created by Imlib\n%i %i\n255\n", im->rgb_width, im->rgb_height)) + { + close_helper(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + close_helper(f); + return 0; + } + if (close_helper(f)) + return 0; + return 1; + } + } + } +#endif + fprintf(stderr, "IMLIB ERROR: Cannot save image: %s\n", file); + fprintf(stderr, "All fallbacks failed.\n"); + + return 0; +} diff --git a/debian/imlib/imlib-1.9.15/Imlib/snprintf.c b/debian/imlib/imlib-1.9.15/Imlib/snprintf.c new file mode 100644 index 00000000..445e861d --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/snprintf.c @@ -0,0 +1,561 @@ +#include "config.h" + +#ifndef HAVE_SNPRINTF +#include <stdlib.h> +#include <unistd.h> +#include <stdarg.h> +#include <errno.h> + +/* + * Shamelessly snarfed from sane... + * which shamelessly snarfed from LPR + * which probably shamelessly snarfed from.... + * + * Moved comments to end so I can actually read the code.. cleaned out useless + * junk.... + */ + +#define VA_LOCAL_DECL va_list ap +#define VA_START(f) va_start(ap, f) +#define VA_SHIFT(v,t) ; /* no-op for ANSI */ +#define VA_END va_end(ap) + +/* + * dopr(): poor man's version of doprintf + */ + +static void dopr(char *buffer, const char *format, va_list args); +static void fmtstr(char *value, int ljust, int len, int zpad, int precision); +static void fmtnum(long value, int base, int dosign, + int ljust, int len, int zpad, int precision); +static void fmtdouble(int fmt, double value, + int ljust, int len, int zpad, int precision); +static void dostr(char *); +static char *output; +static void dopr_outch(int c); +static char *end; +int visible_control = 1; + +static int +my_vsnprintf(char *str, size_t count, const char *fmt, va_list args) +{ + str[0] = 0; + end = str + count - 1; + dopr(str, fmt, args); + if (count > 0) + { + end[0] = 0; + } + return (strlen(str)); +} + +#ifdef HAVE_STDARGS +int +my_snprintf(char *str, size_t count, const char *fmt,...) +#else +int +my_snprintf(va_alist) + va_dcl + +#endif +{ +#ifndef HAVE_STDARGS + char *str; + size_t count; + char *fmt; + +#endif + VA_LOCAL_DECL; + + VA_START(fmt); + VA_SHIFT(str, char *); + + VA_SHIFT(count, size_t); + VA_SHIFT(fmt, char *); + + (void)my_vsnprintf(str, count, fmt, ap); + VA_END; + return (strlen(str)); +} + +static void +dopr(char *buffer, const char *format, va_list args) +{ + int ch; + long value; + int longflag = 0; + char *strvalue; + int ljust; + int len; + int zpad; + int precision; + int set_precision; + double dval; + + output = buffer; + while ((ch = *format++)) + { + switch (ch) + { + case '%': + ljust = len = zpad = 0; + precision = -1; + set_precision = 0; + nextch: + ch = *format++; + switch (ch) + { + case 0: + dostr("**end of format**"); + return; + case '-': + ljust = 1; + goto nextch; + case '.': + set_precision = 1; + precision = 0; + goto nextch; + case '*': + len = va_arg(args, int); + + goto nextch; + case '0': /* set zero padding if len not set */ + if (len == 0 && set_precision == 0) + zpad = '0'; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (set_precision) + { + precision = precision * 10 + ch - '0'; + } + else + { + len = len * 10 + ch - '0'; + } + goto nextch; + case 'l': + longflag = 1; + goto nextch; + case 'u': + case 'U': + /*fmtnum(value,base,dosign,ljust,len, zpad, precision) */ + if (longflag) + { + value = va_arg(args, long); + } + else + { + value = va_arg(args, int); + } + fmtnum(value, 10, 0, ljust, len, zpad, precision); + break; + case 'o': + case 'O': + /*fmtnum(value,base,dosign,ljust,len, zpad, precision) */ + if (longflag) + { + value = va_arg(args, long); + } + else + { + value = va_arg(args, int); + } + fmtnum(value, 8, 0, ljust, len, zpad, precision); + break; + case 'd': + case 'i': + case 'D': + if (longflag) + { + value = va_arg(args, long); + } + else + { + value = va_arg(args, int); + } + fmtnum(value, 10, 1, ljust, len, zpad, precision); + break; + case 'x': + if (longflag) + { + value = va_arg(args, long); + } + else + { + value = va_arg(args, int); + } + fmtnum(value, 16, 0, ljust, len, zpad, precision); + break; + case 'X': + if (longflag) + { + value = va_arg(args, long); + } + else + { + value = va_arg(args, int); + } + fmtnum(value, -16, 0, ljust, len, zpad, precision); + break; + case 's': + strvalue = va_arg(args, char *); + + fmtstr(strvalue, ljust, len, zpad, precision); + break; + case 'c': + ch = va_arg(args, int); + + { + char b[2]; + int vsb = visible_control; + + b[0] = ch; + b[1] = 0; + visible_control = 0; + fmtstr(b, ljust, len, zpad, precision); + visible_control = vsb; + } + break; + case 'f': + case 'g': + dval = va_arg(args, double); + + fmtdouble(ch, dval, ljust, len, zpad, precision); + break; + case '%': + dopr_outch(ch); + continue; + default: + dostr("???????"); + } + longflag = 0; + break; + default: + dopr_outch(ch); + break; + } + } + *output = 0; +} + +/* + * Format '%[-]len[.precision]s' + * - = left justify (ljust) + * len = minimum length + * precision = numbers of chars in string to use + */ +static void +fmtstr(char *value, int ljust, int len, int zpad, int precision) +{ + int padlen, strlen, i, c; /* amount to pad */ + + zpad = 0; + if (value == 0) + { + value = "<NULL>"; + } + if (precision > 0) + { + strlen = precision; + } + else + { + /* cheap strlen so you do not have library call */ + for (strlen = 0; (c = value[strlen]); ++strlen) + { + if (visible_control && iscntrl(c) && !isspace(c)) + { + ++strlen; + } + } + } + padlen = len - strlen; + if (padlen < 0) + padlen = 0; + if (ljust) + padlen = -padlen; + while (padlen > 0) + { + dopr_outch(' '); + --padlen; + } + /* output characters */ + for (i = 0; (c = value[i]); ++i) + { + if (visible_control && iscntrl(c) && !isspace(c)) + { + dopr_outch('^'); + c = ('@' | (c & 0x1F)); + } + dopr_outch(c); + } + while (padlen < 0) + { + dopr_outch(' '); + ++padlen; + } +} + +static void +fmtnum(long value, int base, int dosign, int ljust, + int len, int zpad, int precision) +{ + int signvalue = 0; + unsigned long uvalue; + char convert[20]; + int place = 0; + int padlen = 0; /* amount to pad */ + int caps = 0; + + precision = 0; + /* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n", + * value, base, dosign, ljust, len, zpad )); */ + uvalue = value; + if (dosign) + { + if (value < 0) + { + signvalue = '-'; + uvalue = -value; + } + } + if (base < 0) + { + caps = 1; + base = -base; + } + do + { + convert[place++] = + (caps ? "0123456789ABCDEF" : "0123456789abcdef") + [uvalue % (unsigned)base]; + uvalue = (uvalue / (unsigned)base); + } + while (uvalue); + convert[place] = 0; + padlen = len - place; + if (padlen < 0) + padlen = 0; + if (ljust) + padlen = -padlen; + /* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n", + * convert,place,signvalue,padlen)); */ + if (zpad && padlen > 0) + { + if (signvalue) + { + dopr_outch(signvalue); + --padlen; + signvalue = 0; + } + while (padlen > 0) + { + dopr_outch(zpad); + --padlen; + } + } + while (padlen > 0) + { + dopr_outch(' '); + --padlen; + } + if (signvalue) + dopr_outch(signvalue); + while (place > 0) + dopr_outch(convert[--place]); + while (padlen < 0) + { + dopr_outch(' '); + ++padlen; + } +} + +static void +fmtdouble(int fmt, double value, int ljust, int len, int zpad, int precision) +{ + char convert[128]; + char fmtstr[128]; + int l; + + zpad = 0; + if (len == 0) + len = 10; + if (len > (int)sizeof(convert) - 10) + { + len = (int)sizeof(convert) - 10; + } + if (precision > (int)sizeof(convert) - 10) + { + precision = (int)sizeof(convert) - 10; + } + if (precision > len) + precision = len; + strcpy(fmtstr, "%"); + if (ljust) + strcat(fmtstr, "-"); + if (len) + { + sprintf(fmtstr + strlen(fmtstr), "%d", len); + } + if (precision > 0) + { + sprintf(fmtstr + strlen(fmtstr), ".%d", precision); + } + l = strlen(fmtstr); + fmtstr[l] = fmt; + fmtstr[l + 1] = 0; + sprintf(convert, fmtstr, value); + dostr(convert); +} + +static void +dostr(char *str) +{ + while (*str) + dopr_outch(*str++); +} + +static void +dopr_outch(int c) +{ + if (end == 0 || output < end) + { + *output++ = c; + } +} + +/************************************************************** + * Original: + * Patrick Powell Tue Apr 11 09:48:21 PDT 1995 + * A bombproof version of doprnt (dopr) included. + * Sigh. This sort of thing is always nasty do deal with. Note that + * the version here does not include floating point... + * + * plp_snprintf() is used instead of sprintf() as it does limit checks + * for string length. This covers a nasty loophole. + * + * The other functions are there to prevent NULL pointers from + * causing nast effects. + **************************************************************/ + +/*************************************************************************** + * LPRng - An Extended Print Spooler System + * + * Copyright 1988-1997, Patrick Powell, San Diego, CA + * See below for conditions of use. + * + *************************************************************************** + * MODULE: snprintf.c + * PURPOSE: LPRng version of printf - absolutely bombproof (hopefully!) + **************************************************************************/ + +/* + * The "Artistic License" + * + * Preamble + * + * The intent of this document is to state the conditions under which a + * Package may be copied, such that the Copyright Holder maintains some + * semblance of artistic control over the development of the package, + * while giving the users of the package the right to use and distribute + * the Package in a more-or-less customary fashion, plus the right to make + * reasonable modifications. + * + * Definitions: + * + * "Package" refers to the collection of files distributed by the + * Copyright Holder, and derivatives of that collection of files + * created through textual modification. + * + * "Standard Version" refers to such a Package if it has not been + * modified, or has been modified in accordance with the wishes + * of the Copyright Holder as specified below. + * + * "Copyright Holder" is whoever is named in the copyright or + * copyrights for the package. + * + * "You" is you, if you are thinking about copying or distributing + * this Package. + * + * "Reasonable copying fee" is whatever you can justify on the + * basis of media cost, duplication charges, time of people involved, + * and so on. (You will not be required to justify it to the + * Copyright Holder, but only to the computing community at large + * as a market that must bear the fee.) + * + * "Freely Available" means that no fee is charged for the item + * itself, though there may be fees involved in handling the item. + * It also means that recipients of the item may redistribute it + * under the same conditions they received it. + * + * 1. You may make and give away verbatim copies of the source form of the + * Standard Version of this Package without restriction, provided that you + * duplicate all of the original copyright notices and associated disclaimers. + * + * 2. You may apply bug fixes, portability fixes and other modifications + * derived from the Public Domain or from the Copyright Holder. A Package + * modified in such a way shall still be considered the Standard Version. + * + * 3. You may otherwise modify your copy of this Package in any way, provided + * that you insert a prominent notice in each changed file stating how and + * when you changed that file, and provided that you do at least ONE of the + * following: + * + * a) place your modifications in the Public Domain or otherwise make them + * Freely Available, such as by posting said modifications to Usenet or + * an equivalent medium, or placing the modifications on a major archive + * site such as uunet.uu.net, or by allowing the Copyright Holder to include + * your modifications in the Standard Version of the Package. + * + * b) use the modified Package only within your corporation or organization. + * + * c) rename any non-standard executables so the names do not conflict + * with standard executables, which must also be provided, and provide + * a separate manual page for each non-standard executable that clearly + * documents how it differs from the Standard Version. + * + * d) make other distribution arrangements with the Copyright Holder. + * + * 4. You may distribute the programs of this Package in object code or + * executable form, provided that you do at least ONE of the following: + * + * a) distribute a Standard Version of the executables and library files, + * together with instructions (in the manual page or equivalent) on where + * to get the Standard Version. + * + * b) accompany the distribution with the machine-readable source of + * the Package with your modifications. + * + * c) give non-standard executables non-standard names, and clearly + * document the differences in manual pages (or equivalent), together + * with instructions on where to get the Standard Version. + * + * d) make other distribution arrangements with the Copyright Holder. + * + * 5. You may charge a reasonable copying fee for any distribution of this + * Package. You may charge any fee you choose for support of this + * Package. You may not charge a fee for this Package itself. However, + * you may distribute this Package in aggregate with other (possibly + * commercial) programs as part of a larger (possibly commercial) software + * distribution provided that you do not advertise this Package as a + * product of your own. + * + * 6. The name of the Copyright Holder may not be used to endorse or promote + * products derived from this software without specific prior written permission. + * + * 7. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * The End + */ + +#endif diff --git a/debian/imlib/imlib-1.9.15/Imlib/t-load.c b/debian/imlib/imlib-1.9.15/Imlib/t-load.c new file mode 100644 index 00000000..c8669476 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/t-load.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include "Imlib.h" + + +int +main( int ac, char* av[] ) +{ + Display *disp; + ImlibData *id; + XSetWindowAttributes attr; + Window win; + ImlibImage *img; + Pixmap p,m; + int w,h; + + /* Be nice and tell the user if they don't, to provide a file as an arg */ + if (ac != 2) { + fprintf( stderr, "usage: %s filename\n", av[0] ); + return 33; + } + + /* Connect to the default Xserver */ + disp = XOpenDisplay(NULL); + + /* Immediately afterwards Intitialise Imlib */ + id = Imlib_init(disp); + + /* Load the image specified as the first argument */ + img = Imlib_load_image(id,av[1]); + + + if ( img == NULL ) { + fprintf( stderr, "failed to load file '%s'.\n", av[1] ); + return 1; + } + + return 0; +} diff --git a/debian/imlib/imlib-1.9.15/Imlib/utils.c b/debian/imlib/imlib-1.9.15/Imlib/utils.c new file mode 100644 index 00000000..d1b81898 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/Imlib/utils.c @@ -0,0 +1,2499 @@ +#define _GNU_SOURCE +#include <config.h> +#include "Imlib.h" +#include "Imlib_private.h" + +#ifdef __EMX__ +#include <io.h> +#include <process.h> +#endif + +#ifndef HAVE_SNPRINTF +#define snprintf my_snprintf +#ifdef HAVE_STDARGS +int my_snprintf(char *str, size_t count, const char *fmt,...); + +#else +int my_snprintf(va_alist); + +#endif +#endif + +void +calc_map_tables(ImlibData * id, ImlibImage * im) +{ + int i; + double g, b, c, ii, v; + + if (!im) + return; + + g = ((double)im->mod.gamma) / 256; + b = ((double)im->mod.brightness) / 256; + c = ((double)im->mod.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; + im->rmap[i] = (unsigned char)v; + im->gmap[i] = (unsigned char)v; + im->bmap[i] = (unsigned char)v; + } + g = ((double)im->rmod.gamma) / 256; + b = ((double)im->rmod.brightness) / 256; + c = ((double)im->rmod.contrast) / 256; + if (g < 0.01) + g = 0.01; + + for (i = 0; i < 256; i++) + { + ii = ((double)im->rmap[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; + im->rmap[i] = (unsigned char)v; + } + g = ((double)im->gmod.gamma) / 256; + b = ((double)im->gmod.brightness) / 256; + c = ((double)im->gmod.contrast) / 256; + if (g < 0.01) + g = 0.01; + + for (i = 0; i < 256; i++) + { + ii = ((double)im->gmap[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; + im->gmap[i] = (unsigned char)v; + } + g = ((double)im->bmod.gamma) / 256; + b = ((double)im->bmod.brightness) / 256; + c = ((double)im->bmod.contrast) / 256; + if (g < 0.01) + g = 0.01; + for (i = 0; i < 256; i++) + { + ii = ((double)im->bmap[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; + im->bmap[i] = (unsigned char)v; + } + dirty_pixmaps(id, im); +} + +int +Imlib_load_file_to_pixmap(ImlibData * id, char *filename, Pixmap * pmap, Pixmap * mask) +{ + ImlibImage *im; + + im = Imlib_load_image(id, filename); + if (!im) + { + if (pmap) + *pmap = 0; + if (mask) + *mask = 0; + return 0; + } + if (!Imlib_render(id, im, im->rgb_width, im->rgb_height)) + { + Imlib_destroy_image(id, im); + if (pmap) + *pmap = 0; + if (mask) + *mask = 0; + return 0; + } + if (pmap) + *pmap = Imlib_move_image(id, im); + if (mask) + *mask = Imlib_move_mask(id, im); + Imlib_destroy_image(id, im); + return 1; +} + +void +Imlib_set_image_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + if ((im->mod.gamma != mod->gamma) || (im->mod.brightness != mod->brightness) || (im->mod.contrast != mod->contrast)) + { + im->mod.gamma = mod->gamma; + im->mod.brightness = mod->brightness; + im->mod.contrast = mod->contrast; + calc_map_tables(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + } +} + +void +Imlib_set_image_red_modifier(ImlibData * id, ImlibImage * im, + ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + if ((im->rmod.gamma != mod->gamma) || + (im->rmod.brightness != mod->brightness) || + (im->rmod.contrast != mod->contrast)) + { + im->rmod.gamma = mod->gamma; + im->rmod.brightness = mod->brightness; + im->rmod.contrast = mod->contrast; + calc_map_tables(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + } +} + +void +Imlib_set_image_green_modifier(ImlibData * id, ImlibImage * im, + ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + if ((im->gmod.gamma != mod->gamma) || + (im->gmod.brightness != mod->brightness) || + (im->gmod.contrast != mod->contrast)) + { + im->gmod.gamma = mod->gamma; + im->gmod.brightness = mod->brightness; + im->gmod.contrast = mod->contrast; + calc_map_tables(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + } +} + +void +Imlib_set_image_blue_modifier(ImlibData * id, ImlibImage * im, + ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + if ((im->bmod.gamma != mod->gamma) || + (im->bmod.brightness != mod->brightness) || + (im->bmod.contrast != mod->contrast)) + { + im->bmod.gamma = mod->gamma; + im->bmod.brightness = mod->brightness; + im->bmod.contrast = mod->contrast; + calc_map_tables(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + } +} + +void +Imlib_get_image_modifier(ImlibData * id, ImlibImage * im, + ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + mod->gamma = im->mod.gamma; + mod->brightness = im->mod.brightness; + mod->contrast = im->mod.contrast; + calc_map_tables(id, im); +} + +void +Imlib_get_image_red_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + mod->gamma = im->rmod.gamma; + mod->brightness = im->rmod.brightness; + mod->contrast = im->rmod.contrast; +} + +void +Imlib_get_image_green_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + mod->gamma = im->gmod.gamma; + mod->brightness = im->gmod.brightness; + mod->contrast = im->gmod.contrast; +} + +void +Imlib_get_image_blue_modifier(ImlibData * id, ImlibImage * im, ImlibColorModifier * mod) +{ + if ((!im) | (!mod)) + return; + mod->gamma = im->bmod.gamma; + mod->brightness = im->bmod.brightness; + mod->contrast = im->bmod.contrast; +} + +void +Imlib_set_image_red_curve(ImlibData * id, ImlibImage * im, unsigned char *mod) +{ + int i; + char same = 1; + + if ((!im) || (!mod)) + return; + + for (i = 0; i < 256; i++) + { + if (im->rmap[i] != mod[i]) + { + same = 0; + break; + } + } + if (same) + return; + + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + + for (i = 0; i < 256; i++) + im->rmap[i] = mod[i]; + + im->mod.contrast = 257; +} + +void +Imlib_set_image_green_curve(ImlibData * id, ImlibImage * im, unsigned char *mod) +{ + int i; + char same = 1; + + if ((!im) || (!mod)) + return; + + for (i = 0; i < 256; i++) + { + if (im->gmap[i] != mod[i]) + { + same = 0; + break; + } + } + if (same) + return; + + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + for (i = 0; i < 256; i++) + im->gmap[i] = mod[i]; + + im->mod.contrast = 257; +} + +void +Imlib_set_image_blue_curve(ImlibData * id, ImlibImage * im, unsigned char *mod) +{ + int i; + char same = 1; + + if ((!im) || (!mod)) + return; + + for (i = 0; i < 256; i++) + { + if (im->bmap[i] != mod[i]) + { + same = 0; + break; + } + } + if (same) + return; + + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + for (i = 0; i < 256; i++) + im->bmap[i] = mod[i]; + + im->mod.contrast = 257; +} + +void +Imlib_get_image_red_curve(ImlibData * id, ImlibImage * im, unsigned char *mod) +{ + int i; + + if ((!im) || (!mod)) + return; + for (i = 0; i < 256; i++) + mod[i] = im->rmap[i]; +} + +void +Imlib_get_image_green_curve(ImlibData * id, ImlibImage * im, unsigned char *mod) +{ + int i; + + if ((!im) || (!mod)) + return; + for (i = 0; i < 256; i++) + mod[i] = im->gmap[i]; +} + +void +Imlib_get_image_blue_curve(ImlibData * id, ImlibImage * im, unsigned char *mod) +{ + int i; + + if ((!im) || (!mod)) + return; + for (i = 0; i < 256; i++) + mod[i] = im->bmap[i]; +} + +void +Imlib_apply_modifiers_to_rgb(ImlibData * id, ImlibImage * im) +{ + int x, y; + unsigned char *ptr; + + if (!im) + return; + ptr = im->rgb_data; + for (y = 0; y < im->rgb_height; y++) + { + for (x = 0; x < im->rgb_width; x++) + { + *ptr = im->rmap[*ptr]; + ptr++; + *ptr = im->gmap[*ptr]; + ptr++; + *ptr = im->bmap[*ptr]; + ptr++; + } + } + im->mod.gamma = 256; + im->mod.brightness = 256; + im->mod.contrast = 256; + im->rmod.gamma = 256; + im->rmod.brightness = 256; + im->rmod.contrast = 256; + im->gmod.gamma = 256; + im->gmod.brightness = 256; + im->gmod.contrast = 256; + im->bmod.gamma = 256; + im->bmod.brightness = 256; + im->bmod.contrast = 256; + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); + calc_map_tables(id, im); + dirty_images(id, im); +} + +#define SHADE_PIXEL(pixel, dir, tmp) do {(tmp) = ((((double)pixel)/256.0) +\ + ((dir) ? 0.2 : -0.2)) * 256.0; \ + if ((tmp) > 255) (tmp) = 255; else if ((tmp) < 0) (tmp) = 0;} while (0) + +void +Imlib_bevel_image(ImlibData *id, ImlibImage *im, ImlibBorder *bord, + unsigned char up) +{ + register unsigned char *ptr; + double v; + int x, y, xbound, ybound; + + if ((!im) || (!bord)) + return; + + /* Left edge */ + ptr = im->rgb_data + 3 * im->rgb_width * bord->top; + for (y = bord->top; y < im->rgb_height; y++) + { + xbound = im->rgb_height - y; + if (xbound > bord->left) + xbound = bord->left; + for (x = 0; x < xbound; x++) + { + SHADE_PIXEL(*ptr, up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, up, v); + *ptr++ = (unsigned char) v; + } + ptr += 3 * (im->rgb_width - xbound); + } + + /* Right edge */ + ybound = im->rgb_height - bord->bottom; + for (ptr = im->rgb_data, y = 0; y < ybound; y++) + { + xbound = bord->right - y; + if (xbound < 0) + xbound = 0; + ptr += 3 * (im->rgb_width - bord->right + xbound); + for (x = xbound; x < bord->right; x++) + { + SHADE_PIXEL(*ptr, !up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, !up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, !up, v); + *ptr++ = (unsigned char) v; + } + } + + /* Top edge */ + ptr = im->rgb_data; + for (y = 0; y < bord->top; y++) + { + xbound = im->rgb_width - y; + for (x = 0; x < xbound; x++) + { + SHADE_PIXEL(*ptr, up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, up, v); + *ptr++ = (unsigned char) v; + } + ptr += y * 3; + } + + /* Bottom edge */ + ptr = im->rgb_data + ((im->rgb_height - bord->bottom) * im->rgb_width * 3); + for (y = bord->bottom - 1; y >= 0; y--) + { + ptr += y * 3; + for (x = y; x < im->rgb_width; x++) + { + SHADE_PIXEL(*ptr, !up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, !up, v); + *ptr++ = (unsigned char) v; + SHADE_PIXEL(*ptr, !up, v); + *ptr++ = (unsigned char) v; + } + } +} + +#undef SHADE_PIXEL +#define SHADE_PIXEL(pixel, dir, tmp) do {(tmp) = ((((double)pixel)/depth_factor) + ((dir) ? 0.2 : -0.2)) * depth_factor; \ + if ((tmp) > (depth_factor-1)) (tmp) = depth_factor - 1; else if ((tmp) < 0) (tmp) = 0;} while (0) +#define MOD_PIXEL_LOW(x, y, up) do {v = XGetPixel(ximg, (x), (y)); r = (int) ctab[v & 0xff].r; g = (int) ctab[v & 0xff].g; b = (int) ctab[v & 0xff].b; \ + SHADE_PIXEL(r, (up), dv); r = (int) dv; SHADE_PIXEL(g, (up), dv); g = (int) dv; SHADE_PIXEL(b, (up), dv); b = (int) dv; \ + v = Imlib_best_color_match(id, &r, &g, &b); XPutPixel(ximg, (x), (y), v);} while (0) +#define MOD_PIXEL_HIGH(x, y, up) do {v = XGetPixel(ximg, (x), (y)); r = (int) ((v >> br) & mr); g = (int) ((v >> bg) & mg); b = (int) ((v << bb) & mb); \ + SHADE_PIXEL(r, (up), dv); r = (int) dv; SHADE_PIXEL(g, (up), dv); g = (int) dv; SHADE_PIXEL(b, (up), dv); b = (int) dv; \ + v = ((r & mr) << br) | ((g & mg) << bg) | ((b & mb) >> bb); XPutPixel(ximg, (x), (y), v);} while (0) + +void +Imlib_bevel_pixmap(ImlibData *id, Pixmap p, int w, int h, ImlibBorder *bord, unsigned char up) +{ + + XImage *ximg; + register unsigned long i, v; + double dv; + short x, y, xbound, ybound; + unsigned int r, g, b; + ImlibColor ctab[256]; + int real_depth = 0, depth_factor; + register int br, bg, bb; /* Bitshifts */ + register unsigned int mr, mg, mb; /* Bitmasks */ + XGCValues gcv; + GC gc; + + if ((!id) || (!bord)) + return; + + depth_factor = 1 << id->x.depth; + if (id->x.depth <= 8) { + + XColor cols[256]; + + for (i = 0; i < depth_factor; i++) { + cols[i].pixel = i; + cols[i].flags = DoRed | DoGreen | DoBlue; + } + XQueryColors(id->x.disp, id->x.root_cmap, cols, depth_factor); + for (i = 0; i < depth_factor; i++) { + ctab[i].r = cols[i].red >> 8; + ctab[i].g = cols[i].green >> 8; + ctab[i].b = cols[i].blue >> 8; + ctab[i].pixel = cols[i].pixel; + } + } else if (id->x.depth == 16) { + + XWindowAttributes xattr; + + XGetWindowAttributes(id->x.disp, id->x.root, &xattr); + if ((xattr.visual->red_mask == 0x7c00) && (xattr.visual->green_mask == 0x3e0) && (xattr.visual->blue_mask == 0x1f)) { + real_depth = 15; + depth_factor = 1 << 15; + } + } + if (!real_depth) { + real_depth = id->x.depth; + } + ximg = XGetImage(id->x.disp, p, 0, 0, w, h, -1, ZPixmap); + if (ximg == NULL) { + return; + } + if (id->x.depth <= 8) { + /* Left edge */ + for (y = bord->top; y < h; y++) + { + xbound = h - y; + if (xbound > bord->left) + xbound = bord->left; + for (x = 0; x < xbound; x++) + { + MOD_PIXEL_LOW(x, y, up); + } + } + + /* Right edge */ + ybound = h - bord->bottom; + for (y = 0; y < ybound; y++) + { + xbound = bord->right - y; + if (xbound < 0) + xbound = 0; + for (x = xbound; x < bord->right; x++) + { + MOD_PIXEL_LOW(x + (w - bord->right), y, !up); + } + } + + /* Top edge */ + for (y = 0; y < bord->top; y++) + { + xbound = w - y; + for (x = 0; x < xbound; x++) + { + MOD_PIXEL_LOW(x, y, up); + } + } + + /* Bottom edge */ + for (y = h - bord->bottom; y < h; y++) + { + for (x = h - y - 1; x < w; x++) + { + MOD_PIXEL_LOW(x, y, !up); + } + } + } else { + /* Determine bitshift and bitmask values */ + switch (real_depth) { + case 15: + br = 7; + bg = 2; + bb = 3; + mr = mg = mb = 0xf8; + break; + case 16: + br = 8; + bg = bb = 3; + mr = mb = 0xf8; + mg = 0xfc; + break; + case 24: + case 32: + br = 16; + bg = 8; + bb = 0; + mr = mg = mb = 0xff; + break; + default: + return; + } + + /* Left edge */ + for (y = bord->top; y < h; y++) + { + xbound = h - y; + if (xbound > bord->left) + xbound = bord->left; + for (x = 0; x < xbound; x++) + { + MOD_PIXEL_HIGH(x, y, up); + } + } + + /* Right edge */ + ybound = h - bord->bottom; + for (y = 0; y < ybound; y++) + { + xbound = bord->right - y; + if (xbound < 0) + xbound = 0; + for (x = xbound; x < bord->right; x++) + { + MOD_PIXEL_HIGH(x + (w - bord->right), y, !up); + } + } + + /* Top edge */ + for (y = 0; y < bord->top; y++) + { + xbound = w - y; + for (x = 0; x < xbound; x++) + { + MOD_PIXEL_HIGH(x, y, up); + } + } + + /* Bottom edge */ + for (y = h - bord->bottom; y < h; y++) + { + for (x = h - y - 1; x < w; x++) + { + MOD_PIXEL_HIGH(x, y, !up); + } + } + } + gc = XCreateGC(id->x.disp, p, 0, &gcv); + XPutImage(id->x.disp, p, gc, ximg, 0, 0, 0, 0, w, h); + XFreeGC(id->x.disp, gc); + XDestroyImage(ximg); +} + +void +Imlib_crop_image(ImlibData * id, ImlibImage * im, int x, int y, int w, int h) +{ + unsigned char *data; + int xx, yy, w3, w4; + unsigned char *ptr1, *ptr2; + + if (!im) + return; + if (x < 0) + { + w += x; + x = 0; + } + if (y < 0) + { + h += y; + y = 0; + } + if (x >= im->rgb_width) + return; + if (y >= im->rgb_height) + return; + if (w <= 0) + return; + if (h <= 0) + return; + if (x + w > im->rgb_width) + w = im->rgb_width - x; + if (y + h > im->rgb_height) + h = im->rgb_height - y; + if (w <= 0) + return; + if (h <= 0) + return; + + w3 = im->rgb_width * 3; + w4 = (im->rgb_width - w) * 3; + data = _imlib_malloc_image(w, h); + if (data == NULL) + return; + ptr1 = im->rgb_data + (y * w3) + (x * 3); + ptr2 = data; + for (yy = 0; yy < h; yy++) + { + for (xx = 0; xx < w; xx++) + { + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + } + ptr1 += w4; + } + free(im->rgb_data); + im->rgb_data = data; + if (im->border.left > x) + im->border.left = im->border.left - x; + else + im->border.left = 0; + if (im->border.top > y) + im->border.top = im->border.top - y; + else + im->border.top = 0; + if (im->rgb_width - im->border.right < x + w) + im->border.right = im->border.right - (im->rgb_width - (x + w)); + else + im->border.right = 0; + if (im->rgb_height - im->border.bottom < y + h) + im->border.bottom = im->border.bottom - (im->rgb_height - (y + h)); + else + im->border.bottom = 0; + im->rgb_width = w; + im->rgb_height = h; + dirty_images(id, im); + dirty_pixmaps(id, im); +} + +ImlibImage * +Imlib_crop_and_clone_image(ImlibData * id, ImlibImage * im, int x, int y, int w, int h) +{ + unsigned char *data; + int xx, yy, w3, w4; + unsigned char *ptr1, *ptr2; + ImlibImage *im2; + char *s; + + if (!im) + return NULL; + im2 = malloc(sizeof(ImlibImage)); + if (!im2) + return NULL; + + if (x < 0) + { + w += x; + x = 0; + } + if (y < 0) + { + h += y; + y = 0; + } + if (x >= im->rgb_width) + return NULL; + if (y >= im->rgb_height) + return NULL; + if (w <= 0) + return NULL; + if (h <= 0) + return NULL; + if (x + w > im->rgb_width) + w = im->rgb_width - x; + if (y + h > im->rgb_height) + h = im->rgb_height - y; + if (w <= 0) + return NULL; + if (h <= 0) + return NULL; + + w3 = im->rgb_width * 3; + w4 = (im->rgb_width - w) * 3; + data = _imlib_malloc_image(w, h); + if (data == NULL) + return NULL; + ptr1 = im->rgb_data + (y * w3) + (x * 3); + ptr2 = data; + for (yy = 0; yy < h; yy++) + { + for (xx = 0; xx < w; xx++) + { + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + } + ptr1 += w4; + } + if (im->border.left > x) + im2->border.left = im->border.left - x; + else + im2->border.left = 0; + if (im->border.top > y) + im2->border.top = im->border.top - y; + else + im2->border.top = 0; + if (im->rgb_width - im->border.right < x + w) + im2->border.right = im->border.right - (im->rgb_width - (x + w)); + else + im2->border.right = 0; + if (im->rgb_height - im->border.bottom < y + h) + im2->border.bottom = im->border.bottom - (im->rgb_height - (y + h)); + else + im2->border.bottom = 0; + im2->rgb_data = data; + im2->rgb_width = w; + im2->rgb_height = h; + im2->alpha_data = NULL; + s = malloc(strlen(im->filename) + 320); + if (s) + { + snprintf(s, sizeof(s), "%s_%x_%x", im->filename, (int)time(NULL), (int)rand()); + im2->filename = malloc(strlen(s) + 1); + if (im2->filename) + strcpy(im2->filename, s); + free(s); + } + else + im2->filename = NULL; + im2->width = 0; + im2->height = 0; + im2->shape_color.r = im->shape_color.r; + im2->shape_color.g = im->shape_color.g; + im2->shape_color.b = im->shape_color.b; + im2->pixmap = 0; + im2->shape_mask = 0; + im2->cache = 1; + im2->mod.gamma = im->mod.gamma; + im2->mod.brightness = im->mod.brightness; + im2->mod.contrast = im->mod.contrast; + im2->rmod.gamma = im->rmod.gamma; + im2->rmod.brightness = im->rmod.brightness; + im2->rmod.contrast = im->rmod.contrast; + im2->gmod.gamma = im->gmod.gamma; + im2->gmod.brightness = im->gmod.brightness; + im2->gmod.contrast = im->gmod.contrast; + im2->bmod.gamma = im->bmod.gamma; + im2->bmod.brightness = im->bmod.brightness; + im2->bmod.contrast = im->bmod.contrast; + calc_map_tables(id, im2); + if (id->cache.on_image) + add_image(id, im2, im2->filename); + return im2; +} + +void +Imlib_changed_image(ImlibData * id, ImlibImage * im) +{ + if (!im) + return; + dirty_images(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); +} + +void +Imlib_apply_image(ImlibData * id, ImlibImage * im, Window p) +{ + Pixmap pp, mm; + int x, y; + unsigned int w, h, bd, d; + Window ww; + + if ((!im) || (!p)) + return; + XGetGeometry(id->x.disp, p, &ww, &x, &y, &w, &h, &bd, &d); + if ((w <= 0) || (h <= 0)) + return; + Imlib_render(id, im, w, h); + pp = Imlib_move_image(id, im); + mm = Imlib_move_mask(id, im); + XSetWindowBackgroundPixmap(id->x.disp, p, pp); + if (mm) + XShapeCombineMask(id->x.disp, p, ShapeBounding, 0, 0, mm, ShapeSet); + else + XShapeCombineMask(id->x.disp, p, ShapeBounding, 0, 0, 0, ShapeSet); + XClearWindow(id->x.disp, p); + Imlib_free_pixmap(id, pp); +} + +void +Imlib_paste_image(ImlibData * id, ImlibImage * im, Window p, int x, int y, int w, int h) +{ + GC gc; + XGCValues gcv; + Pixmap pp, mm; + + if ((!im) || (!p)) + return; + if ((w <= 0) || (h <= 0)) + return; + gc = XCreateGC(id->x.disp, p, 0, &gcv); + Imlib_render(id, im, w, h); + pp = Imlib_move_image(id, im); + mm = Imlib_move_mask(id, im); + if (mm) + { + XSetClipMask(id->x.disp, gc, mm); + XSetClipOrigin(id->x.disp, gc, x, y); + } + XCopyArea(id->x.disp, pp, p, gc, 0, 0, w, h, x, y); + Imlib_free_pixmap(id, pp); + XFreeGC(id->x.disp, gc); +} + +void +Imlib_paste_image_border(ImlibData * id, ImlibImage * im, Window p, int x, int y, int w, int h) +{ + GC gc; + XGCValues gcv; + Pixmap pp, mm; + + if (!im) + return; + if ((w <= 0) || (h <= 0)) + return; + gc = XCreateGC(id->x.disp, p, 0, &gcv); + Imlib_render(id, im, w, h); + pp = Imlib_move_image(id, im); + mm = Imlib_move_mask(id, im); + if (mm) + { + XSetClipMask(id->x.disp, gc, mm); + XSetClipOrigin(id->x.disp, gc, x, y); + } + if ((w <= (im->border.left + im->border.right)) || + (h <= (im->border.top + im->border.bottom))) + XCopyArea(id->x.disp, pp, p, gc, 0, 0, w, h, x, y); + else + { + XCopyArea(id->x.disp, pp, p, gc, + 0, 0, + x, y, + w, im->border.top); + XCopyArea(id->x.disp, pp, p, gc, + 0, h - im->border.bottom, + x, y + (h - im->border.bottom), + w, im->border.bottom); + XCopyArea(id->x.disp, pp, p, gc, + 0, im->border.top, + x, y + im->border.top, + im->border.left, h - (im->border.top + im->border.bottom)); + XCopyArea(id->x.disp, pp, p, gc, + w - im->border.right, im->border.top, + x + (w - im->border.right), y + im->border.top, + im->border.right, h - (im->border.top + im->border.bottom)); + } + Imlib_free_pixmap(id, pp); + XFreeGC(id->x.disp, gc); +} + +void +Imlib_flip_image_horizontal(ImlibData * id, ImlibImage * im) +{ + unsigned char *ptr1, *ptr2, r, rr; + int x, y; + int w3; + + if (!im) + return; + w3 = im->rgb_width * 3; + for (y = 0; y < im->rgb_height; y++) + { + ptr1 = im->rgb_data + (y * w3); + ptr2 = im->rgb_data + (y * w3) + w3 - 3; + for (x = 0; x < im->rgb_width >> 1; x++) + { + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + r = *ptr1; + rr = *ptr2; + *ptr2 = r; + *ptr1++ = rr; + ptr2 -= 5; + } + } + w3 = im->border.left; + im->border.left = im->border.right; + im->border.right = w3; + dirty_images(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); +} + +void +Imlib_flip_image_vertical(ImlibData * id, ImlibImage * im) +{ + unsigned char *ptr1, *ptr2, r, rr; + int x, y, yy; + int w3; + + if (!im) + return; + w3 = im->rgb_width * 3; + for (yy = im->rgb_height - 1, y = 0; y < im->rgb_height >> 1; y++, yy--) + { + ptr1 = im->rgb_data + (y * w3); + ptr2 = im->rgb_data + (yy * w3); + for (x = 0; x < im->rgb_width; x++) + { + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + r = *ptr1; + rr = *ptr2; + *ptr2++ = r; + *ptr1++ = rr; + } + } + w3 = im->border.top; + im->border.top = im->border.bottom; + im->border.bottom = w3; + dirty_images(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); +} + +void +Imlib_rotate_image(ImlibData * id, ImlibImage * im, int d) +{ + unsigned char *data; + int x, y, w3, w4; + unsigned char *ptr1, *ptr2; + + if (!im) + return; + w3 = im->rgb_width * 3; + w4 = im->rgb_height * 3; + data = _imlib_malloc_image(im->rgb_width, im->rgb_height); + if (data == NULL) + return; + for (y = 0; y < im->rgb_height; y++) + { + ptr1 = im->rgb_data + (y * w3); + ptr2 = data + (y * 3); + for (x = 0; x < im->rgb_width; x++) + { + *ptr2++ = *ptr1++; + *ptr2++ = *ptr1++; + *ptr2 = *ptr1++; + ptr2 += w4 - 2; + } + } + free(im->rgb_data); + im->rgb_data = data; + w3 = im->rgb_width; + im->rgb_width = im->rgb_height; + im->rgb_height = w3; + w3 = im->border.top; + im->border.top = im->border.left; + im->border.left = w3; + w3 = im->border.bottom; + im->border.bottom = im->border.right; + im->border.right = w3; + dirty_images(id, im); + if (im->pixmap) + { + free_pixmappmap(id, im->pixmap); + im->pixmap = 0; + } + dirty_pixmaps(id, im); +} + +ImlibImage * +Imlib_create_image_from_data(ImlibData * id, unsigned char *data, unsigned char *alpha, int w, int h) +{ + ImlibImage *im; + char s[1024]; + + if ((!data) || (w <= 0) || (h <= 0)) + return NULL; + im = malloc(sizeof(ImlibImage)); + if (!im) + return NULL; + im->rgb_width = w; + im->rgb_height = h; + im->rgb_data = _imlib_malloc_image(im->rgb_width, im->rgb_height); + if (!im->rgb_data) + { + free(im); + return NULL; + } + memcpy(im->rgb_data, data, im->rgb_width * im->rgb_height * 3); +/* im->alpha_data=alpha; */ + im->alpha_data = NULL; + snprintf(s, sizeof(s), "creat_%x_%x", (int)time(NULL), (int)rand()); + im->filename = malloc(strlen(s) + 1); + if (im->filename) + strcpy(im->filename, s); + im->width = 0; + im->height = 0; + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + im->border.left = 0; + im->border.right = 0; + im->border.top = 0; + im->border.bottom = 0; + im->pixmap = 0; + im->shape_mask = 0; + im->cache = 1; + im->mod.gamma = id->mod.gamma; + im->mod.brightness = id->mod.brightness; + im->mod.contrast = id->mod.contrast; + im->rmod.gamma = id->rmod.gamma; + im->rmod.brightness = id->rmod.brightness; + im->rmod.contrast = id->rmod.contrast; + im->gmod.gamma = id->gmod.gamma; + im->gmod.brightness = id->gmod.brightness; + im->gmod.contrast = id->gmod.contrast; + im->bmod.gamma = id->bmod.gamma; + im->bmod.brightness = id->bmod.brightness; + im->bmod.contrast = id->bmod.contrast; + if (id->cache.on_image) + add_image(id, im, im->filename); + calc_map_tables(id, im); + return im; +} + +ImlibImage * +Imlib_clone_image(ImlibData * id, ImlibImage * im) +{ + ImlibImage *im2; + char *s; + + if (!im) + return NULL; + im2 = malloc(sizeof(ImlibImage)); + if (!im2) + return NULL; + im2->rgb_width = im->rgb_width; + im2->rgb_height = im->rgb_height; + im2->rgb_data = _imlib_malloc_image(im2->rgb_width, im2->rgb_height); + if (!im2->rgb_data) + { + free(im2); + return NULL; + } + memcpy(im2->rgb_data, im->rgb_data, im2->rgb_width * im2->rgb_height * 3); + if (im->alpha_data) + { + im2->alpha_data = malloc(im2->rgb_width * im2->rgb_height); + if (!im2->alpha_data) + { + free(im2->rgb_data); + free(im2); + return NULL; + } + memcpy(im2->alpha_data, im->alpha_data, im2->rgb_width * im2->rgb_height); + } + else + im2->alpha_data = NULL; + s = malloc(strlen(im->filename) + 320); + if (s) + { + snprintf(s, sizeof(s), "%s_%x_%x", im->filename, (int)time(NULL), (int)rand()); + im2->filename = malloc(strlen(s) + 1); + if (im2->filename) + strcpy(im2->filename, s); + free(s); + } + else + im2->filename = NULL; + im2->width = 0; + im2->height = 0; + im2->shape_color.r = im->shape_color.r; + im2->shape_color.g = im->shape_color.g; + im2->shape_color.b = im->shape_color.b; + im2->border.left = im->border.left; + im2->border.right = im->border.right; + im2->border.top = im->border.top; + im2->border.bottom = im->border.bottom; + im2->pixmap = 0; + im2->shape_mask = 0; + im2->cache = 1; + im2->mod.gamma = im->mod.gamma; + im2->mod.brightness = im->mod.brightness; + im2->mod.contrast = im->mod.contrast; + im2->rmod.gamma = im->rmod.gamma; + im2->rmod.brightness = im->rmod.brightness; + im2->rmod.contrast = im->rmod.contrast; + im2->gmod.gamma = im->gmod.gamma; + im2->gmod.brightness = im->gmod.brightness; + im2->gmod.contrast = im->gmod.contrast; + im2->bmod.gamma = im->bmod.gamma; + im2->bmod.brightness = im->bmod.brightness; + im2->bmod.contrast = im->bmod.contrast; + calc_map_tables(id, im2); + if (id->cache.on_image) + add_image(id, im2, im2->filename); + return im2; +} + +ImlibImage * +Imlib_clone_scaled_image(ImlibData * id, ImlibImage * im, int w, int h) +{ + ImlibImage *im2; + char *s; + + if ((!im) || (w <= 0) || (h <= 0)) + return NULL; + + im2 = malloc(sizeof(ImlibImage)); + if (!im2) + return NULL; + im2->rgb_width = w; + im2->rgb_height = h; + im2->rgb_data = _imlib_malloc_image(w, h); + if (!im2->rgb_data) + { + free(im2); + return NULL; + } + { + int x, y, *xarray; + unsigned char **yarray, *ptr, *ptr2, *ptr22; + int l, r, m, pos, inc, w3; + + xarray = malloc(sizeof(int) * w); + + if (!xarray) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate X co-ord buffer\n"); + free(im2->rgb_data); + free(im2); + return NULL; + } + yarray = malloc(sizeof(unsigned char *) * h); + + if (!yarray) + { + fprintf(stderr, "IMLIB ERROR: Cannot allocate Y co-ord buffer\n"); + free(xarray); + free(im2->rgb_data); + free(im2); + return NULL; + } + ptr22 = im->rgb_data; + w3 = im->rgb_width * 3; + inc = 0; + if (w < im->border.left + im->border.right) + { + l = w >> 1; + r = w - l; + m = 0; + } + else + { + l = im->border.left; + r = im->border.right; + m = w - l - r; + } + if (m > 0) + inc = ((im->rgb_width - im->border.left - im->border.right) << 16) / m; + pos = 0; + if (l) + for (x = 0; x < l; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + if (m) + { + for (x = l; x < l + m; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += inc; + } + } + pos = (im->rgb_width - r) << 16; + for (x = w - r; x < w; x++) + { + xarray[x] = (pos >> 16) + (pos >> 16) + (pos >> 16); + pos += 0x10000; + } + + if (h < im->border.top + im->border.bottom) + { + l = h >> 1; + r = h - l; + m = 0; + } + else + { + l = im->border.top; + r = im->border.bottom; + m = h - l - r; + } + if (m > 0) + inc = ((im->rgb_height - im->border.top - im->border.bottom) << 16) / m; + pos = 0; + for (x = 0; x < l; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + if (m) + { + for (x = l; x < l + m; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += inc; + } + } + pos = (im->rgb_height - r) << 16; + for (x = h - r; x < h; x++) + { + yarray[x] = ptr22 + ((pos >> 16) * w3); + pos += 0x10000; + } + + ptr = im2->rgb_data; + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + ptr2 = yarray[y] + xarray[x]; + *ptr++ = (int)*ptr2++; + *ptr++ = (int)*ptr2++; + *ptr++ = (int)*ptr2; + } + } + } + if (im->alpha_data) + { + im2->alpha_data = NULL; +/* yet to be filled in */ + } + else + im2->alpha_data = NULL; + s = malloc(strlen(im->filename) + 320); + if (s) + { + snprintf(s, sizeof(s), "%s_%x_%x_%x_%x", im->filename, (int)time(NULL), w, h, (int)rand()); + im2->filename = malloc(strlen(s) + 1); + if (im2->filename) + strcpy(im2->filename, s); + free(s); + } + else + im2->filename = NULL; + im2->width = 0; + im2->height = 0; + im2->shape_color.r = im->shape_color.r; + im2->shape_color.g = im->shape_color.g; + im2->shape_color.b = im->shape_color.b; + im2->border.left = im->border.left; + im2->border.right = im->border.right; + im2->border.top = im->border.top; + im2->border.bottom = im->border.bottom; + im2->pixmap = 0; + im2->shape_mask = 0; + im2->cache = 1; + im2->mod.gamma = im->mod.gamma; + im2->mod.brightness = im->mod.brightness; + im2->mod.contrast = im->mod.contrast; + im2->rmod.gamma = im->rmod.gamma; + im2->rmod.brightness = im->rmod.brightness; + im2->rmod.contrast = im->rmod.contrast; + im2->gmod.gamma = im->gmod.gamma; + im2->gmod.brightness = im->gmod.brightness; + im2->gmod.contrast = im->gmod.contrast; + im2->bmod.gamma = im->bmod.gamma; + im2->bmod.brightness = im->bmod.brightness; + im2->bmod.contrast = im->bmod.contrast; + calc_map_tables(id, im2); + if (id->cache.on_image) + add_image(id, im2, im2->filename); + return im2; +} + +ImlibImage * +Imlib_create_image_from_xpm_data(ImlibData * id, char **data) +{ + ImlibImage *im; + unsigned char *ptr, *end; + int c, i, j, k, ncolors, cpp, comment, transp, quote, context, + len, count, done; + int w, h; + char *line, s[256], tok[128], col[256]; + XColor xcol; + struct _cmap + { + char str[6]; + char transp; + short r, g, b; + } + *cmap; + short lookup[128 - 32][128 - 32]; + + if (!data) + return NULL; + if (! id->x.disp) + return NULL; + im = malloc(sizeof(ImlibImage)); + if (!im) + return NULL; + count = 0; + transp = 0; + done = 0; + + j = 0; + cmap = NULL; + c = ' '; + comment = 0; + quote = 0; + context = 0; + ptr = NULL; + end = NULL; + + while (!done) + { + line = data[count++]; + if (context == 0) + { + /* Header */ + sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp); + if (ncolors > 32766) + { + fprintf(stderr, "IMLIB ERROR: XPM data wth colors > 32766 not supported\n"); + free(im); + return NULL; + } + if (cpp > 5) + { + fprintf(stderr, "IMLIB ERROR: XPM data with characters per pixel > 5 not supported\n"); + free(im); + return NULL; + } + if (w > 32767) + { + fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for data\n"); + free(im); + return NULL; + } + if (h > 32767) + { + fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for data\n"); + free(im); + return NULL; + } + cmap = malloc(sizeof(struct _cmap) * ncolors); + + if (!cmap) + { + free(im); + return NULL; + } + im->rgb_width = w; + im->rgb_height = h; + im->rgb_data = malloc(im->rgb_width * im->rgb_height * 3); + if (!im->rgb_data) + { + free(cmap); + free(im); + return NULL; + } + im->alpha_data = NULL; + snprintf (s, sizeof (s), "creat_%lx_%x", time(NULL), rand()); + im->filename = strdup(s); + im->width = 0; + im->height = 0; + im->border.left = 0; + im->border.right = 0; + im->border.top = 0; + im->border.bottom = 0; + im->pixmap = 0; + im->shape_mask = 0; + im->cache = 1; + im->mod.gamma = id->mod.gamma; + im->mod.brightness = id->mod.brightness; + im->mod.contrast = id->mod.contrast; + im->rmod.gamma = id->rmod.gamma; + im->rmod.brightness = id->rmod.brightness; + im->rmod.contrast = id->rmod.contrast; + im->gmod.gamma = id->gmod.gamma; + im->gmod.brightness = id->gmod.brightness; + im->gmod.contrast = id->gmod.contrast; + im->bmod.gamma = id->bmod.gamma; + im->bmod.brightness = id->bmod.brightness; + im->bmod.contrast = id->bmod.contrast; + ptr = im->rgb_data; + end = im->rgb_data + (im->rgb_width * im->rgb_height * 3); + j = 0; + context++; + } + else if (context == 1) + { + int colptr; + int hascolor, iscolor; + + /* Color Table */ + if (j < ncolors) + { + iscolor = 0; + hascolor = 0; + tok[0] = 0; + col[0] = 0; + s[0] = 0; + colptr = 0; + len = strlen(line); + strncpy(cmap[j].str, line, cpp); + cmap[j].str[cpp] = 0; + cmap[j].r = -1; + cmap[j].transp = 0; + for (k = cpp; k < len; k++) + { + if (line[k] != ' ') + { + sscanf(&line[k], "%65536s", s); + k += strlen(s); + if (!strcmp(s, "c")) + iscolor = 1; + if ((!strcmp(s, "m")) || (!strcmp(s, "s")) || + (!strcmp(s, "g4")) || (!strcmp(s, "g")) || + (!strcmp(s, "c")) || (k >= len)) + { + if (k >= len) + { + int ls; + + ls = strlen(s); + + if (col[0] && colptr < sizeof(col)) + { + strcpy(col + colptr, " "); + colptr++; + } + if (colptr + ls <= sizeof(col)) + { + strcpy(col + colptr, s); + colptr += ls; + } + + } + if (col[0]) + { + if (!strcasecmp(col, "none")) + { + transp = 1; + cmap[j].transp = 1; + } + else + { + if ((((cmap[j].r < 0) || + (!strcmp(tok, "c"))) && + (!hascolor))) + { + XParseColor(id->x.disp, + id->x.root_cmap, + col, &xcol); + cmap[j].r = xcol.red >> 8; + cmap[j].g = xcol.green >> 8; + cmap[j].b = xcol.blue >> 8; + if ((cmap[j].r == 255) && + (cmap[j].g == 0) && + (cmap[j].b == 255)) + cmap[j].r = 254; + if (iscolor) + hascolor = 1; + } + } + } + if (strlen(s) < sizeof(tok)) + strcpy(tok, s); + col[0] = 0; + } + else + { + int ls; + + ls = strlen(s); + if (col[0] && colptr < sizeof(col)) + { + strcpy(col + colptr, " "); + colptr++; + } + if (ls + colptr < sizeof(col)) + { + strcpy(col + colptr, s); + colptr += ls; + } + } + } + } + } + j++; + if (j >= ncolors) + { + if (cpp == 1) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0] - 32][0] = i; + else if (cpp == 2) + for (i = 0; i < ncolors; i++) + lookup[(int)cmap[i].str[0] - 32][(int)cmap[i].str[1] - 32] = i; + context++; + } + } + else + { + /* Image Data */ + i = 0; + if (cpp == 0) + { + } + else if (cpp == 1) + { + if (transp) + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i]; + if (cmap[lookup[(int)col[0] - 32][0]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; + } + } + } + else if (cpp == 2) + { + if (transp) + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + if (cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].b; + } + } + } + else + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + col[0] = line[i++]; + col[1] = line[i]; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].r; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].g; + *ptr++ = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].b; + } + } + } + else + { + if (transp) + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + if (cmap[j].transp) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + } + else + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + } + j = ncolors; + } + } + } + } + else + { + for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) + { + for (j = 0; j < cpp; j++, i++) + { + col[j] = line[i]; + } + col[j] = 0; + i--; + for (j = 0; j < ncolors; j++) + { + if (!strcmp(col, cmap[j].str)) + { + *ptr++ = (unsigned char)cmap[j].r; + *ptr++ = (unsigned char)cmap[j].g; + *ptr++ = (unsigned char)cmap[j].b; + j = ncolors; + } + } + } + } + } + } + if ((ptr) && ((ptr - im->rgb_data) >= w * h * 3)) + done = 1; + } + if (!transp) + { + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + } + else + { + im->shape_color.r = 255; + im->shape_color.g = 0; + im->shape_color.b = 255; + } + if (id->cache.on_image) + add_image(id, im, im->filename); + calc_map_tables(id, im); + free(cmap); + return im; +} + +int +Imlib_data_to_pixmap(ImlibData * id, char **data, Pixmap * pmap, Pixmap * mask) +{ + ImlibImage *im; + + im = Imlib_create_image_from_xpm_data(id, data); + if (!im) + { + if (pmap) + *pmap = 0; + if (mask) + *mask = 0; + return 0; + } + if (!Imlib_render(id, im, im->rgb_width, im->rgb_height)) + { + Imlib_destroy_image(id, im); + if (pmap) + *pmap = 0; + if (mask) + *mask = 0; + return 0; + } + if (pmap) + *pmap = Imlib_move_image(id, im); + if (mask) + *mask = Imlib_move_mask(id, im); + Imlib_kill_image(id, im); + return 1; +} + +struct _io_info +{ + unsigned char *data; + unsigned char *ptr; + unsigned char *end; +}; + +#ifdef HAVE_LIBPNG +static void +_png_io_read(png_structp png_ptr, + png_bytep data, png_uint_32 size) +{ + struct _io_info *io_ptr; + int bytes; + + io_ptr = (struct _io_info *)png_get_io_ptr(png_ptr); + + if ((io_ptr->end - io_ptr->ptr) >= size) + { + memcpy(data, io_ptr->ptr, size); + io_ptr->ptr += size; + return; + } + bytes = io_ptr->end - io_ptr->ptr; + memcpy(data, io_ptr->ptr, bytes); + io_ptr->ptr = io_ptr->end; + return; +} +#endif /* HAVE_LIBPNG */ + +ImlibImage * +Imlib_inlined_png_to_image(ImlibData *id, unsigned char *data, int data_size) +{ +#ifdef HAVE_LIBPNG + ImlibImage *im; + png_structp png_ptr; + png_infop info_ptr; + unsigned char *ptr, **lines, *ptr2, r, g, b, a; + int i, x, y, transp, bit_depth, color_type, interlace_type; + png_uint_32 ww, hh; + char s[512]; + struct _io_info io_info; + + im = malloc(sizeof(ImlibImage)); + if (!im) + return NULL; + im->rgb_width = 0; + im->rgb_height = 0; + im->rgb_data = NULL; + im->alpha_data = NULL; + snprintf(s, sizeof(s), "creat_%x_%x", (int)time(NULL), (int)rand()); + im->filename = malloc(strlen(s) + 1); + if (im->filename) + strcpy(im->filename, s); + im->width = 0; + im->height = 0; + im->border.left = 0; + im->border.right = 0; + im->border.top = 0; + im->border.bottom = 0; + im->pixmap = 0; + im->shape_mask = 0; + im->cache = 1; + im->mod.gamma = id->mod.gamma; + im->mod.brightness = id->mod.brightness; + im->mod.contrast = id->mod.contrast; + im->rmod.gamma = id->rmod.gamma; + im->rmod.brightness = id->rmod.brightness; + im->rmod.contrast = id->rmod.contrast; + im->gmod.gamma = id->gmod.gamma; + im->gmod.brightness = id->gmod.brightness; + im->gmod.contrast = id->gmod.contrast; + im->bmod.gamma = id->bmod.gamma; + im->bmod.brightness = id->bmod.brightness; + im->bmod.contrast = id->bmod.contrast; + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + /* Init PNG Reader */ + transp = 0; + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) + return NULL; + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) + { + png_destroy_read_struct(&png_ptr, NULL, NULL); + return NULL; + } + + if (setjmp(png_ptr->jmpbuf)) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + + if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + + io_info.data = data; + io_info.ptr = data; + io_info.end = data + data_size; + png_set_read_fn(png_ptr, (void *)(&io_info), (png_rw_ptr)_png_io_read); + + /* Read Header */ + png_read_info(png_ptr, info_ptr); + png_get_IHDR(png_ptr, info_ptr, &ww, &hh, &bit_depth, &color_type, &interlace_type, + NULL, NULL); + im->rgb_width = ww; + im->rgb_height = hh; + /* Setup Translators */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand(png_ptr); + png_set_strip_16(png_ptr); + png_set_packing(png_ptr); + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) + png_set_expand(png_ptr); + png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); + im->rgb_data = malloc(ww * hh * 3); + if (!(im->rgb_data)) + { + free(im->filename); + free(im); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + lines = (unsigned char **)malloc(hh * sizeof(unsigned char *)); + + if (lines == NULL) + { + free(im->filename); + free(im); + free(im->rgb_data); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + for (i = 0; i < hh; i++) + { + if ((lines[i] = malloc(ww * (sizeof(unsigned char) * 4))) == NULL) + { + int n; + + free(im->filename); + free(im); + free(im->rgb_data); + for (n = 0; n < i; n++) + free(lines[n]); + free(lines); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + } + png_read_image(png_ptr, lines); + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + ptr = im->rgb_data; + if ((color_type == PNG_COLOR_TYPE_GRAY) || + (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) + { + for (y = 0; y < hh; y++) + { + ptr2 = lines[y]; + for (x = 0; x < ww; x++) + { + r = *ptr2++; + a = *ptr2++; + if (a < 128) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + transp = 1; + } + else + { + *ptr++ = r; + *ptr++ = r; + *ptr++ = r; + } + } + } + } + else + { + for (y = 0; y < hh; y++) + { + ptr2 = lines[y]; + for (x = 0; x < ww; x++) + { + r = *ptr2++; + g = *ptr2++; + b = *ptr2++; + a = *ptr2++; + if (a < 128) + { + *ptr++ = 255; + *ptr++ = 0; + *ptr++ = 255; + transp = 1; + } + else + { + if ((r == 255) && (g == 0) && (b == 255)) + r = 254; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + } + for (i = 0; i < hh; i++) + free(lines[i]); + free(lines); + if (transp) + { + im->shape_color.r = 255; + im->shape_color.g = 0; + im->shape_color.b = 255; + } + if (id->cache.on_image) + add_image(id, im, im->filename); + calc_map_tables(id, im); + return im; +#else + return NULL; +#endif /* HAVE_LIBPNG */ +} + + +#include <signal.h> +#include <sys/wait.h> + +/* Helper library */ + +static int hpid; +void (*oldpiper) (int); /* actually sighandler_t but BSD uses sig_t. */ + +static char x_error = 0; + +static void +__handle_x_error(Display * d, XErrorEvent * ev) +{ + d = NULL; + ev = NULL; + x_error = 1; +} + +ImlibImage * +Imlib_create_image_from_drawable(ImlibData * id, Drawable win, Pixmap mask, + int x, int y, int width, int height) +{ + unsigned char *data = NULL, *ptr, r, g, b; + unsigned long pixel; + int i, xx, yy, w, h, inx, iny, clipx, clipy, rx, ry; + XImage *xim; + +#ifdef HAVE_SHM + XShmSegmentInfo shminfo; + +#endif + XWindowAttributes xatt, ratt; + Colormap cmap; + static char shm_checked = 0, shm = 1; + XErrorHandler erh = NULL; + Window chld; + char is_pixmap = 0; + Visual *vis; + ImlibImage *im; + ImlibColor ctab[256]; + Display *disp; + + inx = 0; + iny = 0; + w = width; + h = height; + vis = id->x.visual; + disp = id->x.disp; + + XGrabServer(disp); + erh = XSetErrorHandler((XErrorHandler) __handle_x_error); + x_error = 0; + XGetWindowAttributes(disp, win, &xatt); + XFlush(disp); + if (x_error) + { + x_error = 0; + is_pixmap = 1; + XGetGeometry(disp, win, &chld, &rx, &rx, + (unsigned int *)&xatt.width, (unsigned int *)&xatt.height, + (unsigned int *)&rx, (unsigned int *)&xatt.depth); + XFlush(disp); + if (x_error) + { + XUngrabServer(disp); + XFlush(disp); + XSetErrorHandler((XErrorHandler) erh); + return NULL; + } + } + XSetErrorHandler((XErrorHandler) erh); + if (!is_pixmap) + { + XGetWindowAttributes(disp, xatt.root, &ratt); + XTranslateCoordinates(disp, win, xatt.root, 0, 0, &rx, &ry, &chld); + if ((xatt.map_state != IsViewable) && + (xatt.backing_store == NotUseful)) + { + XUngrabServer(disp); + XFlush(disp); + return NULL; + } + } + clipx = 0; + clipy = 0; + + x = x - inx; + y = y - iny; + + width = xatt.width - x; + height = xatt.height - y; + if (width > w) + width = w; + if (height > h) + height = h; + + if (!is_pixmap) + { + if ((rx + x + width) > ratt.width) + width = ratt.width - (rx + x); + if ((ry + y + height) > ratt.height) + height = ratt.height - (ry + y); + } + if (x < 0) + { + clipx = -x; + width += x; + x = 0; + } + if (y < 0) + { + clipy = -y; + height += y; + y = 0; + } + if (!is_pixmap) + { + if ((rx + x) < 0) + { + clipx -= (rx + x); + width += (rx + x); + x = -rx; + } + if ((ry + y) < 0) + { + clipy -= (ry + y); + height += (ry + y); + y = -ry; + } + } + if ((width <= 0) || (height <= 0)) + { + XUngrabServer(disp); + XSync(disp, False); + return NULL; + } +#ifdef HAVE_SHM + if (shm) + { + if (!shm_checked) + { + erh = XSetErrorHandler((XErrorHandler) __handle_x_error); + } + xim = XShmCreateImage(disp, vis, xatt.depth, ZPixmap, NULL, + &shminfo, width, height); + if (!shm_checked) + { + XSync(disp, False); + if (x_error) + { + shm = 0; + XDestroyImage(xim); + xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap); + XSetErrorHandler((XErrorHandler) erh); + shm_checked = 1; + } + else + { + shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * + xim->height, IPC_CREAT | 0666); + if (shminfo.shmid < 0) + { + shm = 0; + XDestroyImage(xim); + xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap); + XSetErrorHandler((XErrorHandler) erh); + shm_checked = 1; + } + else + { + shminfo.shmaddr = xim->data = shmat(shminfo.shmid, 0, 0); + if (shminfo.shmaddr == (char *)-1) + { + shm = 0; + XDestroyImage(xim); + shmctl(shminfo.shmid, IPC_RMID, 0); + xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap); + XSetErrorHandler((XErrorHandler) erh); + shm_checked = 1; + } + else + { + shminfo.readOnly = False; + XShmAttach(disp, &shminfo); + } + } + } + } + else + { + shminfo.shmid = shmget(IPC_PRIVATE, xim->bytes_per_line * + xim->height, IPC_CREAT | 0666); + if (shminfo.shmid < 0) + { + shm = 0; + XDestroyImage(xim); + xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap); + XSetErrorHandler((XErrorHandler) erh); + shm_checked = 1; + } + else + { + shminfo.shmaddr = xim->data = shmat(shminfo.shmid, 0, 0); + if (shminfo.shmaddr == (char *)-1) + { + shm = 0; + XDestroyImage(xim); + shmctl(shminfo.shmid, IPC_RMID, 0); + xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap); + XSetErrorHandler((XErrorHandler) erh); + shm_checked = 1; + } + else + { + shminfo.readOnly = False; + XShmAttach(disp, &shminfo); + } + } + } + if (!shm_checked) + { + XSync(disp, False); + if (x_error) + { + shm = 0; + XDestroyImage(xim); + xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap); + shm_checked = 1; + } + XSetErrorHandler((XErrorHandler) erh); + shm_checked = 1; + } + } + else +#endif /* HAVE_SHM */ + xim = XGetImage(disp, win, x, y, width, height, 0xffffffff, ZPixmap); +#ifdef HAVE_SHM + if (shm) + XShmGetImage(disp, win, xim, x, y, 0xffffffff); +#endif + XUngrabServer(disp); + XFlush(disp); + + if (xatt.depth == 1) + { + ctab[0].r = 255; + ctab[0].g = 255; + ctab[0].b = 255; + ctab[1].r = 0; + ctab[1].g = 0; + ctab[1].b = 0; + } + else if (xatt.depth <= 8) + { + XColor cols[256]; + + if (!is_pixmap) + { + cmap = xatt.colormap; + if (cmap == None) + cmap = id->x.root_cmap; + } + else + cmap = id->x.root_cmap; + + for (i = 0; i < (1 << id->x.depth); i++) + { + cols[i].pixel = i; + cols[i].flags = DoRed | DoGreen | DoBlue; + } + XQueryColors(disp, cmap, cols, 1 << id->x.depth); + for (i = 0; i < (1 << id->x.depth); i++) + { + ctab[i].r = cols[i].red >> 8; + ctab[i].g = cols[i].green >> 8; + ctab[i].b = cols[i].blue >> 8; + ctab[i].pixel = cols[i].pixel; + } + } + data = malloc(width * height * 3); + if (data) + { + ptr = data; + switch (xatt.depth) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + for (yy = 0; yy < height; yy++) + { + for (xx = 0; xx < width; xx++) + { + pixel = XGetPixel(xim, xx, yy); + r = ctab[pixel & 0xff].r; + g = ctab[pixel & 0xff].g; + b = ctab[pixel & 0xff].b; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + break; + case 16: + case 15: + if (id->x.render_depth == 16) + { + for (yy = 0; yy < height; yy++) + { + for (xx = 0; xx < width; xx++) + { + pixel = XGetPixel(xim, xx, yy); + r = (pixel >> 8) & 0xf8; + g = (pixel >> 3) & 0xfc; + b = (pixel << 3) & 0xf8; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + else + { + for (yy = 0; yy < height; yy++) + { + for (xx = 0; xx < width; xx++) + { + pixel = XGetPixel(xim, xx, yy); + r = (pixel >> 7) & 0xf8; + g = (pixel >> 2) & 0xf8; + b = (pixel << 3) & 0xf8; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + } + break; + case 24: + case 32: + for (yy = 0; yy < height; yy++) + { + for (xx = 0; xx < width; xx++) + { + pixel = XGetPixel(xim, xx, yy); + r = (pixel >> 16) & 0xff; + g = (pixel >> 8) & 0xff; + b = pixel & 0xff; + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + break; + default: + for (yy = 0; yy < height; yy++) + { + for (xx = 0; xx < width; xx++) + { + r = rand(); + g = rand(); + b = rand(); + *ptr++ = r; + *ptr++ = g; + *ptr++ = b; + } + } + break; + } + } + +#ifdef HAVE_SHM + if (shm) + { + XSync(disp, False); + XShmDetach(disp, &shminfo); + shmdt(shminfo.shmaddr); + shmctl(shminfo.shmid, IPC_RMID, 0); + } +#endif + XDestroyImage(xim); + + if (data) + { + im = Imlib_create_image_from_data(id, data, NULL, width, height); + free(data); + return im; + } + else + return NULL; +} |