diff options
Diffstat (limited to 'debian/imlib/imlib-1.9.15/gdk_imlib')
26 files changed, 16605 insertions, 0 deletions
diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/ChangeLog b/debian/imlib/imlib-1.9.15/gdk_imlib/ChangeLog new file mode 100644 index 00000000..af4ec88d --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/ChangeLog @@ -0,0 +1,334 @@ +2004-08-20 Mark Crichton <[email protected]> + + * io-bmp.c: Fixed BMP vunerability + +2002-09-11 jacob berkman <[email protected]> + + * Makefile.am (common_ldflags): add -module + +2002-03-25 Mark Crichton <[email protected]> + + * Makefile.am: Fixed some hacks to work around a broekn libtool. + Should work now. + +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: Forgot to bump up the revision number. Doh. + +2002-03-04 Mark Crichton <[email protected]> + + * io-*.c: Fixed potential buffer overflows. Were malloc-ing memory + and not checking to see if we were getting too much (or too little!). + Fixed with _gdk_malloc_image. + + * load.c, save.c: Nuked use of external helpers for loading files. + Risks outweigh the benefits on this one. + + * Makefile.am: Bumped up the revision number. + +2001-11-06 Mark Crichton <[email protected]> + + * Makefile.am: Fix stupid libtool braindeadness. Bug #62654 + +2001-09-10 Mark Crichton <[email protected]> + + * Makefile.am: Argh, colors.c uses X libs, added dependency to + lib (also covers the XPM loader) Resolves bug #59915. + +2001-08-29 Mark Crichton <[email protected]> + + * save.c, utils.c: Bug #56004. Improved error messages. + +2001-07-28 Mark Crichton <[email protected]> + + * io-png.c: Fixed PNG loader to handle greyscale PNGs. + Resolves bug #57858 + +2001-05-29 Mark Crichton <[email protected]> + + * Makefile.am: Added loader dependencies on libgdk_imlib.la + Resolves bug #53863 + +2001-05-29 Mark Crichton <[email protected]> + + * misc.c: made x_error static. Resolves bug #52838 + +2001-03-27 Mark Crichton <[email protected]> + + * Makefile.am: cosmetic changes so vars can be changed at build + time. + +2000-08-29 Mark Crichton <[email protected]> + + * rend.c: Added 12 bit rendering functions. Note, it's an + ugly hack, and really requires a rewrite of that code. + + * misc.c (gdk_imlib_init): Added detection of a 12 bit visual. + (gdk_imlib_init_params): ditto + + * utils.c: Disabled caching of generated data. The way you get + data from the Imlib cache is by a key, which is the filename. + Autogenerated data used a timestamp and *random number* as the + filename. So, you'd put stuff into the cache, and you can never + get it out. Disabled that, hopefully mem usage will look better. + +2000-05-20 Mark Crichton <[email protected]> + + * misc.c (gdk_imlib_init): uses GdkRGB visual instead of X's + default visual. Behaves better on Solaris. + (gdk_imlib_init_params): ditto + +2000-04-14 Miguel de Icaza <[email protected]> + + * misc.c (gdk_imlib_init_params): Use the correct parsing method + to get the visual number from the specified file. + (gdk_imlib_init): ditto. + +2000-02-24 Federico Mena Quintero <[email protected]> + + * colors.c (alloc_colors): New function to allocate a color array. + This is the meaty part from gdk_imlib_load_colors() moved over to + its own function. + (gdk_imlib_load_colors): Use alloc_colors(). Do not print a + message if we cannot open the file, since we are already returning + an error code. + (gdk_imlib_load_default_colors__private): New function to allocate + a hardcoded default palette. + (PaletteAlloc): Made static, renamed from _gdk_imlib_PaletteAlloc. + + * gdk_imlib_private.h: Added prototype for + gdk_imlib_load_default_colors__private(). + + * misc.c (gdk_imlib_init): Load a default palette if the palette + file could not be loaded. Bail out if no colors could be + allocated. Maybe we could just use BlackPixel and WhitePixel. + +2000-02-22 Morten Welinder <[email protected]> + + * utils.c (gdk_imlib_create_image_from_xpm_data): Leak fix. + +1999-10-16 Kjartan Maraas <[email protected]> + + * colors.c (PaletteLUTSet): Removed unused variables. + +1999-09-02 Raja R Harinath <[email protected]> + + * rend.c (gdk_imlib_best_color_match): + Fix typo - `g_return_val_if_fail', not `g_return_val_fail'. + (_gdk_imlib_index_best_color_match): Likewise. + +1999-09-02 Pavel Machek <[email protected]> + + * rend.c, globals.c, misc.c: No need to allocate structure + dynamically - it is needed, always. + Turned some fprintf(stderr) into g_return_val_if_fail as they + seem much cleaner to me. + +Fri Apr 2 15:28:28 1999 Asbjorn Pettersen <[email protected]> + + * gdk_imlib_private.h: replace <sys/types.h>. + Needed for OS/2 version. + +1999-03-22 Pavel Machek <[email protected]> + + * globals.c: robustness: you better keep gdk_imlib_data + initialized to NULL + +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) + +1999-01-15 Miguel de Icaza <[email protected]> + + * modules.c: Make the gdk_imlib_load_alpha and + gdk_imlib_inlined_png_to_image routines be exported. + +1999-01-16 Jeff Garzik <[email protected]> + + * gdk_imlib_private.h: + Include gdkx.h for definition of gdk_window_foreign_new in misc.c. + + * io-png.c (_loader_alpha_png): + Correct variable declarations to get rid of unused vars; + + * modules.c (get_module_loader_saver): + Function now returns value. FIXME: The value is never used, + should probably be converted to a void function. + +1998-12-15 Miguel de Icaza <[email protected]> + + * cache.c (gdk_imlib_set_cache_info, gdk_imlib_get_cache_info): + To control the cache externally. + + * cache.c (gdk_imlib_flush_old_entries, gdk_imlib_flush_cache): + New empty routines. An API we might use in the future. Better + have it here before :-) + +1998-12-13 Miguel de Icaza <[email protected]> + + * gdk_imlib_private.h: Moved structure members that depended on + HAVE_SHM to the end of the strucutre, where they do not hurt us. + + The problem is as follows: If HAVE_SHM is defined at Imlib compile + time, then the Xdata structure is expanded to have these two + fields. Since we do not test for SHM in other places where we + access _gdk_imlib_data (which caused the Alpha crashes and the + duplicated icons due to the cache changes). + +1998-12-12 Miguel de Icaza <[email protected]> + + * load.c (_gdk_imlib_LoadBMP): This code got lost by accident. + +1998-12-07 Miguel de Icaza <[email protected]> + + * rend.c (gdk_imlib_render): Small typo correction. + +1998-12-06 Miguel de Icaza <[email protected]> + + * misc.c (gdk_imlib_init): Use sizeof (s) instead of 4096 while + reading from the files. If someone ever changed these, we would + be in trouble. + + * load.c (gdk_imlib_load_image): Use "file" instead of "fil" in + the call to _gdk_imlib_LoadTIFF (to make it work with wierd filenames). + + * gdk_imlib_private.h: Clean up the name space. All of the + internal routines that were previously exposed are now prefixed + with _gdk_imlib_ instead of a mix of g_ and g. + + GdkImlibData data variable "id" is now called _gdk_imlib_data. + + * misc.c (HandleXError): This one is static. + + * load.c (gdk_imlib_load_image): On GNOME we do not enable + spawning any external processes. Specially with the setup + currently implemented. Play it safe, we do not want to appear on + BUGTRAQ because of this feature. + + * utils.c (gdk_imlib_set_image_red_curve, + gdk_imlib_set_image_green_curve): Code changes to make it work + with the new im->map setup. Make it check its input arguments, + according to GTK+/GDK conventions. + ( + (gdk_imlib_apply_modifiers_to_rgb): Adapt as well. + + * cache.c (gnullify_image): Release im->map if it exists. + + * rend.c (gdk_imlib_render): Instead of testing for the defaults + here, we need only to test againt im->map now (as the im->map will + have a non-NULL value if a map even exists). + + * utils.c (gcalc_map_tables): Test here if the color modifiers are + the defaults, and if so mark do not compute the modifier table, + and free any existing modifier table if it exists. + +Wed Sep 23 11:21:49 1998 Owen Taylor <[email protected]> + + * rend.c (gdk_imlib_pixmap_foreign_new): Create pixmap + with g_new0, instead of g_new, to increase the chances + that all fields are initialized properly. + +1998-06-28 Miguel de Icaza <[email protected]> + + * misc.c (gdk_imlib_init): Let the user use --no-xshm by checking + the setting on Gdk. + +1998-05-18 Miguel de Icaza <[email protected]> + + * misc.c (gdk_imlib_init): Initialize uninitialized variables. + + * rend.c: Remove unused variables. + +1998-05-07 Raja R Harinath <[email protected]> + + * save.c (gdk_imlib_save_image): Replaces `snprintf' with + `g_snprintf' calls. + * utils.c (gdk_imlib_create_image_from_data): Likewise. + +Tue May 5 15:11:59 1998 Radek Doulik <[email protected]> + + * replaced snprintf calls with g_snprintf ones, so it + compiles now on SunOS + +Sat Apr 11 12:30:13 1998 George Lebl <[email protected]> + + * utils.c: fixed yet one more SIGFPE on alpha + +Fri Mar 20 00:02:43 1998 Tom Tromey <[email protected]> + + * gdk_imlib.h: Replaced `()' with `(void)'. + +Sun Mar 15 12:34:45 1998 Owen Taylor <[email protected]> + + * Makefile.am (INCLUDES): Added GTK_CFLAGS + +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 (gdk_imlib_copy_image): The drawable passed to gdk_gc_new + should be the dest drawable, not the base imlib window. This + caused BadMatches all over the place (especially in copy_mask). + (gdk_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 (libgdk_imlib_la_SOURCES): + (lib_LTLIBRARIES): changed gdk_imlib to use the libtool+automake + formalisms. + + * load.c (gdk_imlib_load_image): changed JPEG_PATH to DJPEG_PROG + and removed %s/djpeg, sine DJPEG_PROG is the full program path. + +1998-02-17 Federico Mena Quintero <[email protected]> + + * Makefile.in (install): Make directory for config files. + + * configure.in: Fixed ENL_LIB_SUPPORT function for non-existing libraries. + +1998-02-16 Federico Mena Quintero <[email protected]> + + * misc.c (gdk_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 (gdk_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 return function + +1998-02-18 The Rasterman <[email protected]> + + Fixed load.c - missed a not (!) in an if clause diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/Makefile.am b/debian/imlib/imlib-1.9.15/gdk_imlib/Makefile.am new file mode 100644 index 00000000..cd97a6e0 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/Makefile.am @@ -0,0 +1,108 @@ +common_ldflags = -avoid-version -module + +# The modules for loading/saving the various graphics formats +# are located in $(moduledir). Default it to libdir for backwards +# compatibility. +# +moduledir = $(libdir) + +libimlib_gif_la_SOURCES = io-gif.c +libimlib_gif_la_LDFLAGS = $(common_ldflags) +libimlib_gif_la_LIBADD = $(GIFLIBS) libgdk_imlib.la + +libimlib_jpeg_la_SOURCES = io-jpeg.c +libimlib_jpeg_la_LDFLAGS = $(common_ldflags) +libimlib_jpeg_la_LIBADD = $(JPEGLIBS) libgdk_imlib.la + +libimlib_png_la_SOURCES = io-png.c +libimlib_png_la_LDFLAGS = $(common_ldflags) +libimlib_png_la_LIBADD = $(PNGLIBS) libgdk_imlib.la + +libimlib_tiff_la_SOURCES = io-tiff.c +libimlib_tiff_la_LDFLAGS = $(common_ldflags) +libimlib_tiff_la_LIBADD = $(TIFFLIBS) libgdk_imlib.la + +libimlib_ps_la_SOURCES = io-ps.c +libimlib_ps_la_LDFLAGS = $(common_ldflags) +libimlib_ps_la_LIBADD = libgdk_imlib.la + +libimlib_bmp_la_SOURCES = io-bmp.c +libimlib_bmp_la_LDFLAGS = $(common_ldflags) +libimlib_bmp_la_LIBADD = libgdk_imlib.la + +libimlib_xpm_la_SOURCES = io-xpm.c +libimlib_xpm_la_LDFLAGS = $(common_ldflags) +libimlib_xpm_la_LIBADD = libgdk_imlib.la + +libimlib_ppm_la_SOURCES = io-ppm.c +libimlib_ppm_la_LDFLAGS = $(common_ldflags) +libimlib_ppm_la_LIBADD = libgdk_imlib.la + +if DYNAMIC_MODULES_WORK + +if HAVE_GIF +GIF = libimlib-gif.la +endif + +if HAVE_JPEG +JPEG = libimlib-jpeg.la +endif + +if HAVE_PNG +PNG = libimlib-png.la +endif + +if HAVE_TIFF +TIFF = libimlib-tiff.la +endif + +OTHER = \ + libimlib-bmp.la \ + libimlib-xpm.la \ + libimlib-ppm.la \ + libimlib-ps.la + +DYNAMIC_LIBS = \ + $(OTHER) $(GIF) $(JPEG) $(TIFF) $(PNG) + +else + +DYNAMIC_LIBS = + +endif + +lib_LTLIBRARIES = libgdk_imlib.la +module_LTLIBRARIES = $(DYNAMIC_LIBS) + +libgdk_imlib_la_SOURCES = \ + cache.c \ + colors.c \ + globals.c \ + load.c \ + misc.c \ + rend.c \ + utils.c \ + save.c \ + modules.c + + +libgdk_imlib_la_LDFLAGS = -version-info 10:15:9 +libgdk_imlib_la_LIBADD = $(GX_LIBS) + + +include_HEADERS = gdk_imlib.h gdk_imlib_private.h gdk_imlib_types.h + + + +DEFS = -DSYSTEM_IMRC=\"$(sysconfdir)/imrc\" \ + -DIMLIB_LIB=\""$(moduledir)"\" -DSYSCONFDIR=\"$(sysconfdir)\" + +INCLUDES = -I. -I$(srcdir) -I.. -I$(srcdir)/.. \ + $(GTK_CFLAGS) $(X_CFLAGS) $(GMODULE_FLAGS) + + +# These programs are built only to check that the plugin +# libs have correct library information. + +check_PROGRAMS = t-load +t_load_LDADD = libgdk_imlib.la diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/Makefile.in b/debian/imlib/imlib-1.9.15/gdk_imlib/Makefile.in new file mode 100644 index 00000000..67dc33a9 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/Makefile.in @@ -0,0 +1,690 @@ +# 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@ + +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\" \ + -DIMLIB_LIB=\""$(moduledir)"\" -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@ +common_ldflags = -avoid-version -module + +# The modules for loading/saving the various graphics formats +# are located in $(moduledir). Default it to libdir for backwards +# compatibility. +# +moduledir = $(libdir) + +libimlib_gif_la_SOURCES = io-gif.c +libimlib_gif_la_LDFLAGS = $(common_ldflags) +libimlib_gif_la_LIBADD = $(GIFLIBS) libgdk_imlib.la + +libimlib_jpeg_la_SOURCES = io-jpeg.c +libimlib_jpeg_la_LDFLAGS = $(common_ldflags) +libimlib_jpeg_la_LIBADD = $(JPEGLIBS) libgdk_imlib.la + +libimlib_png_la_SOURCES = io-png.c +libimlib_png_la_LDFLAGS = $(common_ldflags) +libimlib_png_la_LIBADD = $(PNGLIBS) libgdk_imlib.la + +libimlib_tiff_la_SOURCES = io-tiff.c +libimlib_tiff_la_LDFLAGS = $(common_ldflags) +libimlib_tiff_la_LIBADD = $(TIFFLIBS) libgdk_imlib.la + +libimlib_ps_la_SOURCES = io-ps.c +libimlib_ps_la_LDFLAGS = $(common_ldflags) +libimlib_ps_la_LIBADD = libgdk_imlib.la + +libimlib_bmp_la_SOURCES = io-bmp.c +libimlib_bmp_la_LDFLAGS = $(common_ldflags) +libimlib_bmp_la_LIBADD = libgdk_imlib.la + +libimlib_xpm_la_SOURCES = io-xpm.c +libimlib_xpm_la_LDFLAGS = $(common_ldflags) +libimlib_xpm_la_LIBADD = libgdk_imlib.la + +libimlib_ppm_la_SOURCES = io-ppm.c +libimlib_ppm_la_LDFLAGS = $(common_ldflags) +libimlib_ppm_la_LIBADD = libgdk_imlib.la + +@DYNAMIC_MODULES_WORK_TRUE@@HAVE_GIF_TRUE@GIF = libimlib-gif.la + +@DYNAMIC_MODULES_WORK_TRUE@@HAVE_JPEG_TRUE@JPEG = libimlib-jpeg.la + +@DYNAMIC_MODULES_WORK_TRUE@@HAVE_PNG_TRUE@PNG = libimlib-png.la + +@DYNAMIC_MODULES_WORK_TRUE@@HAVE_TIFF_TRUE@TIFF = libimlib-tiff.la + +@DYNAMIC_MODULES_WORK_TRUE@OTHER = \ +@DYNAMIC_MODULES_WORK_TRUE@ libimlib-bmp.la \ +@DYNAMIC_MODULES_WORK_TRUE@ libimlib-xpm.la \ +@DYNAMIC_MODULES_WORK_TRUE@ libimlib-ppm.la \ +@DYNAMIC_MODULES_WORK_TRUE@ libimlib-ps.la + + +@DYNAMIC_MODULES_WORK_FALSE@DYNAMIC_LIBS = + +@DYNAMIC_MODULES_WORK_TRUE@DYNAMIC_LIBS = \ +@DYNAMIC_MODULES_WORK_TRUE@ $(OTHER) $(GIF) $(JPEG) $(TIFF) $(PNG) + + +lib_LTLIBRARIES = libgdk_imlib.la +module_LTLIBRARIES = $(DYNAMIC_LIBS) + +libgdk_imlib_la_SOURCES = \ + cache.c \ + colors.c \ + globals.c \ + load.c \ + misc.c \ + rend.c \ + utils.c \ + save.c \ + modules.c + + +libgdk_imlib_la_LDFLAGS = -version-info 10:15:9 +libgdk_imlib_la_LIBADD = $(GX_LIBS) + +include_HEADERS = gdk_imlib.h gdk_imlib_private.h gdk_imlib_types.h + +INCLUDES = -I. -I$(srcdir) -I.. -I$(srcdir)/.. \ + $(GTK_CFLAGS) $(X_CFLAGS) $(GMODULE_FLAGS) + + + +# These programs are built only to check that the plugin +# libs have correct library information. +check_PROGRAMS = t-load +t_load_LDADD = libgdk_imlib.la +subdir = gdk_imlib +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(lib_LTLIBRARIES) $(module_LTLIBRARIES) + +libgdk_imlib_la_DEPENDENCIES = +am_libgdk_imlib_la_OBJECTS = cache.lo colors.lo globals.lo load.lo \ + misc.lo rend.lo utils.lo save.lo modules.lo +libgdk_imlib_la_OBJECTS = $(am_libgdk_imlib_la_OBJECTS) +libimlib_bmp_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_bmp_la_OBJECTS = io-bmp.lo +libimlib_bmp_la_OBJECTS = $(am_libimlib_bmp_la_OBJECTS) +libimlib_gif_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_gif_la_OBJECTS = io-gif.lo +libimlib_gif_la_OBJECTS = $(am_libimlib_gif_la_OBJECTS) +libimlib_jpeg_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_jpeg_la_OBJECTS = io-jpeg.lo +libimlib_jpeg_la_OBJECTS = $(am_libimlib_jpeg_la_OBJECTS) +libimlib_png_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_png_la_OBJECTS = io-png.lo +libimlib_png_la_OBJECTS = $(am_libimlib_png_la_OBJECTS) +libimlib_ppm_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_ppm_la_OBJECTS = io-ppm.lo +libimlib_ppm_la_OBJECTS = $(am_libimlib_ppm_la_OBJECTS) +libimlib_ps_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_ps_la_OBJECTS = io-ps.lo +libimlib_ps_la_OBJECTS = $(am_libimlib_ps_la_OBJECTS) +libimlib_tiff_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_tiff_la_OBJECTS = io-tiff.lo +libimlib_tiff_la_OBJECTS = $(am_libimlib_tiff_la_OBJECTS) +libimlib_xpm_la_DEPENDENCIES = libgdk_imlib.la +am_libimlib_xpm_la_OBJECTS = io-xpm.lo +libimlib_xpm_la_OBJECTS = $(am_libimlib_xpm_la_OBJECTS) +check_PROGRAMS = t-load$(EXEEXT) +t_load_SOURCES = t-load.c +t_load_OBJECTS = t-load.$(OBJEXT) +t_load_DEPENDENCIES = libgdk_imlib.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)/globals.Plo ./$(DEPDIR)/io-bmp.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/io-gif.Plo ./$(DEPDIR)/io-jpeg.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/io-png.Plo ./$(DEPDIR)/io-ppm.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/io-ps.Plo ./$(DEPDIR)/io-tiff.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/io-xpm.Plo ./$(DEPDIR)/load.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/misc.Plo ./$(DEPDIR)/modules.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/rend.Plo ./$(DEPDIR)/save.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/t-load.Po ./$(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 = $(libgdk_imlib_la_SOURCES) $(libimlib_bmp_la_SOURCES) \ + $(libimlib_gif_la_SOURCES) $(libimlib_jpeg_la_SOURCES) \ + $(libimlib_png_la_SOURCES) $(libimlib_ppm_la_SOURCES) \ + $(libimlib_ps_la_SOURCES) $(libimlib_tiff_la_SOURCES) \ + $(libimlib_xpm_la_SOURCES) t-load.c +HEADERS = $(include_HEADERS) + +DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.in ChangeLog \ + Makefile.am install-sh mkinstalldirs +SOURCES = $(libgdk_imlib_la_SOURCES) $(libimlib_bmp_la_SOURCES) $(libimlib_gif_la_SOURCES) $(libimlib_jpeg_la_SOURCES) $(libimlib_png_la_SOURCES) $(libimlib_ppm_la_SOURCES) $(libimlib_ps_la_SOURCES) $(libimlib_tiff_la_SOURCES) $(libimlib_xpm_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 gdk_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 +moduleLTLIBRARIES_INSTALL = $(INSTALL) +install-moduleLTLIBRARIES: $(module_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(moduledir) + @list='$(module_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=install $(moduleLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(moduledir)/$$f"; \ + $(LIBTOOL) --mode=install $(moduleLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) $$p $(DESTDIR)$(moduledir)/$$f; \ + else :; fi; \ + done + +uninstall-moduleLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(module_LTLIBRARIES)'; for p in $$list; do \ + p="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(moduledir)/$$p"; \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(moduledir)/$$p; \ + done + +clean-moduleLTLIBRARIES: + -test -z "$(module_LTLIBRARIES)" || rm -f $(module_LTLIBRARIES) + @list='$(module_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 +libgdk_imlib.la: $(libgdk_imlib_la_OBJECTS) $(libgdk_imlib_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libgdk_imlib_la_LDFLAGS) $(libgdk_imlib_la_OBJECTS) $(libgdk_imlib_la_LIBADD) $(LIBS) +libimlib-bmp.la: $(libimlib_bmp_la_OBJECTS) $(libimlib_bmp_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_bmp_la_LDFLAGS) $(libimlib_bmp_la_OBJECTS) $(libimlib_bmp_la_LIBADD) $(LIBS) +libimlib-gif.la: $(libimlib_gif_la_OBJECTS) $(libimlib_gif_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_gif_la_LDFLAGS) $(libimlib_gif_la_OBJECTS) $(libimlib_gif_la_LIBADD) $(LIBS) +libimlib-jpeg.la: $(libimlib_jpeg_la_OBJECTS) $(libimlib_jpeg_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_jpeg_la_LDFLAGS) $(libimlib_jpeg_la_OBJECTS) $(libimlib_jpeg_la_LIBADD) $(LIBS) +libimlib-png.la: $(libimlib_png_la_OBJECTS) $(libimlib_png_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_png_la_LDFLAGS) $(libimlib_png_la_OBJECTS) $(libimlib_png_la_LIBADD) $(LIBS) +libimlib-ppm.la: $(libimlib_ppm_la_OBJECTS) $(libimlib_ppm_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_ppm_la_LDFLAGS) $(libimlib_ppm_la_OBJECTS) $(libimlib_ppm_la_LIBADD) $(LIBS) +libimlib-ps.la: $(libimlib_ps_la_OBJECTS) $(libimlib_ps_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_ps_la_LDFLAGS) $(libimlib_ps_la_OBJECTS) $(libimlib_ps_la_LIBADD) $(LIBS) +libimlib-tiff.la: $(libimlib_tiff_la_OBJECTS) $(libimlib_tiff_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_tiff_la_LDFLAGS) $(libimlib_tiff_la_OBJECTS) $(libimlib_tiff_la_LIBADD) $(LIBS) +libimlib-xpm.la: $(libimlib_xpm_la_OBJECTS) $(libimlib_xpm_la_DEPENDENCIES) + $(LINK) -rpath $(moduledir) $(libimlib_xpm_la_LDFLAGS) $(libimlib_xpm_la_OBJECTS) $(libimlib_xpm_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)/globals.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-bmp.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-gif.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-jpeg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-png.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-ppm.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-ps.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-tiff.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io-xpm.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)/modules.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)/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)$(moduledir) $(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 clean-moduleLTLIBRARIES 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-moduleLTLIBRARIES + +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 uninstall-moduleLTLIBRARIES + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-checkPROGRAMS \ + clean-generic clean-libLTLIBRARIES clean-libtool \ + clean-moduleLTLIBRARIES 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-moduleLTLIBRARIES \ + 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 uninstall-moduleLTLIBRARIES + +# 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/gdk_imlib/cache.c b/debian/imlib/imlib-1.9.15/gdk_imlib/cache.c new file mode 100644 index 00000000..9d8513c7 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/cache.c @@ -0,0 +1,512 @@ +#define _GNU_SOURCE +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +/* uncomment this to compile imlib's cahce with pixmap accounting output */ +/*#define PIXMAP_ACCOUNTING */ + +void +_gdk_imlib_dirty_pixmaps(GdkImlibImage * im) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->im == im) && ((!ptr->file) || (!strcmp(im->filename, ptr->file)))) + ptr->dirty = 1; + ptr = ptr->next; + } +} + +void +_gdk_imlib_dirty_images(GdkImlibImage * 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; + } +} + +void +_gdk_imlib_find_pixmap(GdkImlibImage * im, int width, int height, GdkPixmap ** pmap, GdkBitmap ** mask) +{ + struct pixmap_cache *ptr; + + ptr = id->cache.pixmap; + while (ptr) + { + if ((ptr->im == im) && (ptr->width == width) && (ptr->height == height) && + ((!ptr->file) || (!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 = NULL; + *mask = NULL; +} + +GdkImlibImage * +_gdk_imlib_find_image(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 +_gdk_imlib_free_pixmappmap(GdkPixmap * 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; + } + gdk_pixmap_unref(pmap); +} + +void +_gdk_imlib_free_image(GdkImlibImage * im) +{ + struct image_cache *ptr; + + ptr = id->cache.image; + while (ptr) + { + if (im == ptr->im) + { + if (ptr->refnum) + { + ptr->refnum--; + if (!ptr->refnum) + { + id->cache.num_image--; + id->cache.used_image += ptr->im->rgb_width * ptr->im->rgb_height * 3; + } + } + return; + } + ptr = ptr->next; + } + _gdk_imlib_nullify_image(im); +} + +void +_gdk_imlib_flush_image(GdkImlibImage * im) +{ + if (im) + im->cache = 0; +} + +void +_gdk_imlib_add_image(GdkImlibImage * 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 +_gdk_imlib_add_pixmap(GdkImlibImage * 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 +_gdk_imlib_clean_caches() +{ + { + struct image_cache *ptr = NULL; + struct image_cache *last = NULL; + int newlast; + + /* 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; + _gdk_imlib_nullify_image(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; + _gdk_imlib_nullify_image(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; + + printf("--------- Pixmap cashe zise %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) + { + printf("Pmap for file %s 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; + } + printf("Accounting Data:\n"); + printf("*** total pixmap's in cache %i with %i pixmaps\n", + total, num); + printf("*** total unreffed pixmap's in cache %i with %i pixmaps\n\n", + total2, num2); +#endif + /* find the back of the list */ + ptr = id->cache.pixmap; + 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 pixmaps */ + while (id->cache.used_pixmap > id->cache.size_pixmap) + { + if (newlast) + { + ptr = id->cache.pixmap; + last = NULL; + while (ptr) + { + last = ptr; + ptr = ptr->next; + } + ptr = last; + newlast = 0; + } + while (ptr) + { + if (ptr->refnum < 1) + { + 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) + gdk_pixmap_unref(ptr->pmap); + if (ptr->shape_mask) + gdk_pixmap_unref(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); + newlast = 1; + } + else + ptr = ptr->prev; + if (id->cache.used_pixmap <= id->cache.size_pixmap) + ptr = NULL; + } + } + } +} + +void +_gdk_imlib_nullify_image(GdkImlibImage * im) +{ + if (!im) + return; + if (im->rgb_data) + free(im->rgb_data); + if (im->alpha_data) + free(im->alpha_data); + if (im->pixmap) + _gdk_imlib_free_pixmappmap(im->pixmap); + if (im->filename) + free(im->filename); + if (im->map) + free(im->map); + free(im); +} + +void +gdk_imlib_get_cache_info (int *cache_pixmaps, int *cache_images) +{ + if (cache_pixmaps) + *cache_pixmaps = id->cache.on_pixmap; + if (cache_images) + *cache_images = id->cache.on_image; +} + +void +gdk_imlib_set_cache_info (int cache_pixmaps, int cache_images) +{ + id->cache.on_pixmap = cache_pixmaps; + id->cache.on_image = cache_images; +} + +void +gdk_imlib_flush_cache (void) +{ + /* nothing yet, just to be forward compatible */ +} + +void +gdk_imlib_flush_old_entries (void) +{ + /* Nothing yet, just to be forward compatible */ +} diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/colors.c b/debian/imlib/imlib-1.9.15/gdk_imlib/colors.c new file mode 100644 index 00000000..aad3b358 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/colors.c @@ -0,0 +1,320 @@ +#define _GNU_SOURCE +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +static int PaletteLUTGet(void) +{ + 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(void) +{ + 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); +} + +static void PaletteAlloc(int num, const 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(GdkImlibColor) * num); + if (id->palette_orig) + free(id->palette_orig); + id->palette_orig = malloc(sizeof(GdkImlibColor) * 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; +} + +static void alloc_colors(const int *pal, int i) +{ + int r, g, b; + int rr, gg, bb; + + XGrabServer(id->x.disp); + PaletteAlloc((i / 3), pal); + if (!PaletteLUTGet()) { + 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) = + _gdk_imlib_index_best_color_match(&rr, &gg, &bb); + } + } + } + PaletteLUTSet(); + } + XUngrabServer(id->x.disp); +} + +gint gdk_imlib_load_colors(char *file) +{ + FILE *f; + char s[1024]; + int i; + int pal[768]; + int r, g, b; + + f = fopen(file, "r"); + if (!f) { + char *name = g_basename(file); + + if (name) { + char *path; + + path = g_strconcat(SYSCONFDIR, G_DIR_SEPARATOR_S, name, NULL); + f = fopen(path, "r"); + g_free(path); + } + + } + + if (!f) + 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); + + alloc_colors(pal, i); + return 1; +} + +void gdk_imlib_load_default_colors__private(void) +{ + static const int default_pal[] = { + 0x0, 0x0, 0x0, + 0xff, 0xff, 0xff, + 0xff, 0x0, 0x0, + 0xff, 0xff, 0x0, + 0x0, 0xff, 0x0, + 0x0, 0x0, 0xff, + 0x0, 0xff, 0xff, + 0x99, 0x99, 0x99, + 0xff, 0x88, 0x0, + 0x88, 0x0, 0x0, + 0x0, 0x88, 0x88, + 0x88, 0x88, 0x0, + 0xff, 0xcc, 0x97, + 0xbb, 0xbb, 0xbb, + 0x9f, 0x6b, 0x42, + 0x55, 0x55, 0x55, + 0xdd, 0xdd, 0xdd, + 0x77, 0x77, 0x77, + 0x33, 0x33, 0x33, + 0xcc, 0x0, 0x0, + 0xff, 0x44, 0x0, + 0xff, 0xcc, 0x0, + 0xcc, 0xcc, 0x0, + 0x60, 0x60, 0x0, + 0x0, 0x43, 0x0, + 0x0, 0x7f, 0x0, + 0x0, 0xcc, 0x0, + 0x0, 0x44, 0x44, + 0x0, 0x0, 0x44, + 0x0, 0x0, 0x88, + 0xef, 0xb1, 0x7b, + 0xdf, 0x98, 0x5f, + 0xbf, 0x87, 0x56, + 0x7f, 0x57, 0x26, + 0x5f, 0x39, 0xc, + 0x3f, 0x1c, 0x0, + 0x21, 0x0, 0x0, + 0x0, 0x43, 0x87, + 0x2d, 0x70, 0xaf, + 0x5a, 0x9e, 0xd7, + 0x87, 0xcc, 0xff, + 0xff, 0xe0, 0xba, + 0x21, 0x43, 0xf, + 0x3d, 0x5d, 0x25, + 0x59, 0x78, 0x3a, + 0x75, 0x93, 0x4f, + 0x91, 0xae, 0x64, + 0xad, 0xc8, 0x7a, + 0xf0, 0xa8, 0xef, + 0xd0, 0x88, 0xd0, + 0xaf, 0x66, 0xaf, + 0x8e, 0x44, 0x8e, + 0x6d, 0x22, 0x6d, + 0x4b, 0x0, 0x4b, + 0xff, 0xc0, 0xbc, + 0xff, 0x93, 0x91, + 0xff, 0x66, 0x67, + 0xd8, 0xf2, 0xbf, + 0xff, 0xc9, 0x68, + 0xff, 0x96, 0x67, + 0xa5, 0x60, 0xff, + 0x51, 0xff, 0x99, + 0x3f, 0xa5, 0x63, + 0x98, 0x90, 0x67 + }; + + alloc_colors(default_pal, + sizeof(default_pal) / sizeof(default_pal[0])); +} + +void gdk_imlib_free_colors() +{ + 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; +} + +void gdk_imlib_best_color_get(GdkColor * c) +{ + int r, g, b, rr, gg, bb; + + rr = r = c->red >> 8; + gg = g = c->green >> 8; + bb = b = c->blue >> 8; + c->pixel = gdk_imlib_best_color_match(&r, &g, &b); + rr = rr - r; + gg = gg - g; + bb = bb - b; + if (rr > 0xff) + rr = 0xff; + if (gg > 0xff) + gg = 0xff; + if (bb > 0xff) + bb = 0xff; + c->red = (rr << 8) | rr; + c->green = (gg << 8) | gg; + c->blue = (bb << 8) | bb; +} diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib.h b/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib.h new file mode 100644 index 00000000..17703489 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib.h @@ -0,0 +1,83 @@ + +#ifndef __GDK_IMLIB_H__ +#define __GDK_IMLIB_H__ + +#include <gdk_imlib_types.h> + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + void gdk_imlib_init(void); + void gdk_imlib_init_params(GdkImlibInitParams * p); + gint gdk_imlib_get_render_type(void); + void gdk_imlib_set_render_type(gint rend_type); + gint gdk_imlib_load_colors(char *file); + GdkImlibImage *gdk_imlib_load_image(char *file); + GdkImlibImage *gdk_imlib_load_alpha (char *file); + gint gdk_imlib_best_color_match(gint * r, gint * g, gint * b); + void gdk_imlib_best_color_get(GdkColor * c); + gint gdk_imlib_render(GdkImlibImage * image, gint width, gint height); + GdkPixmap *gdk_imlib_copy_image(GdkImlibImage * image); + GdkBitmap *gdk_imlib_copy_mask(GdkImlibImage * image); + GdkPixmap *gdk_imlib_move_image(GdkImlibImage * image); + GdkBitmap *gdk_imlib_move_mask(GdkImlibImage * image); + void gdk_imlib_destroy_image(GdkImlibImage * image); + void gdk_imlib_kill_image(GdkImlibImage * image); + void gdk_imlib_free_colors(void); + void gdk_imlib_free_pixmap(GdkPixmap * pixmap); + void gdk_imlib_free_bitmap(GdkBitmap * bitmap); + void gdk_imlib_get_image_border(GdkImlibImage * image, GdkImlibBorder * border); + void gdk_imlib_set_image_border(GdkImlibImage * image, GdkImlibBorder * border); + void gdk_imlib_get_image_shape(GdkImlibImage * image, GdkImlibColor * color); + void gdk_imlib_set_image_shape(GdkImlibImage * image, GdkImlibColor * color); + gint gdk_imlib_save_image_to_eim(GdkImlibImage * image, char *file); + gint gdk_imlib_add_image_to_eim(GdkImlibImage * image, char *file); + gint gdk_imlib_save_image_to_ppm(GdkImlibImage * image, char *file); + gint gdk_imlib_load_file_to_pixmap(char *filename, GdkPixmap ** pmap, GdkBitmap ** mask); + void gdk_imlib_set_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_get_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod); + void gdk_imlib_set_image_red_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_set_image_green_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_set_image_blue_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_get_image_red_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_get_image_green_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_get_image_blue_curve(GdkImlibImage * im, unsigned char *mod); + void gdk_imlib_apply_modifiers_to_rgb(GdkImlibImage * im); + void gdk_imlib_changed_image(GdkImlibImage * im); + void gdk_imlib_apply_image(GdkImlibImage * im, GdkWindow * p); + void gdk_imlib_paste_image(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h); + void gdk_imlib_paste_image_border(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h); + void gdk_imlib_flip_image_horizontal(GdkImlibImage * im); + void gdk_imlib_flip_image_vertical(GdkImlibImage * im); + void gdk_imlib_rotate_image(GdkImlibImage * im, gint d); + GdkImlibImage *gdk_imlib_create_image_from_data(unsigned char *data, unsigned char *alpha, gint w, gint h); + GdkImlibImage *gdk_imlib_clone_image(GdkImlibImage * im); + GdkImlibImage *gdk_imlib_clone_scaled_image(GdkImlibImage * im, int w, int h); + gint gdk_imlib_get_fallback(void); + void gdk_imlib_set_fallback(gint fallback); + GdkVisual *gdk_imlib_get_visual(void); + GdkColormap *gdk_imlib_get_colormap(void); + gchar *gdk_imlib_get_sysconfig(void); + GdkImlibImage *gdk_imlib_create_image_from_xpm_data(char **data); + gint gdk_imlib_data_to_pixmap(char **data, GdkPixmap ** pmap, GdkBitmap ** mask); + void gdk_imlib_crop_image(GdkImlibImage * im, gint x, gint y, gint w, gint h); + gint gdk_imlib_save_image(GdkImlibImage * im, char *file, GdkImlibSaveInfo * info); + GdkImlibImage *gdk_imlib_crop_and_clone_image(GdkImlibImage * im, int x, int y, int w, int h); + GdkImlibImage *gdk_imlib_create_image_from_drawable(GdkWindow * gwin, GdkBitmap * gmask, int x, int y, int width, int height); + GdkImlibImage *gdk_imlib_inlined_png_to_image(unsigned char *data, int data_size); + + void gdk_imlib_get_cache_info (int *cache_pixmaps, int *cache_images); + void gdk_imlib_set_cache_info (int cache_pixmaps, int cache_images); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib_private.h b/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib_private.h new file mode 100644 index 00000000..983d0afd --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib_private.h @@ -0,0 +1,235 @@ +#ifndef _GDK_IMLIB_PRIVATE_H +#define _GDK_IMLIB_PRIVATE_H + +#ifndef CONVERT_PATH +#define CONVERT_PATH "/usr/local/bin" +#endif + +#ifndef NETPBM_PATH +#define NETPBM_PATH "/usr/local/bin" +#endif + +#ifndef CJPEG_PROG +#define CJPEG_PROG "/usr/bin/cjpeg" +#endif + +#ifndef DJPEG_PROG +#define DJPEG_PROG "/usr/local/bin/djpeg" +#endif + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <math.h> +#include <ctype.h> +#include <time.h> +#include <sys/types.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> + +#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> +#include <gdk/gdkprivate.h> +#include <gdk/gdkx.h> + +#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 + { + gchar *file; + GdkImlibImage *im; + gint refnum; + gchar dirty; + struct image_cache *prev; + struct image_cache *next; + }; + +struct pixmap_cache + { + GdkImlibImage *im; + gchar *file; + gchar dirty; + gint width, height; + GdkPixmap *pmap; + GdkBitmap *shape_mask; + XImage *xim, *sxim; + gint refnum; + struct pixmap_cache *prev; + struct pixmap_cache *next; + }; + +typedef struct _xdata + { + Display *disp; + gint screen; + Window root; + Visual *visual; + gint depth; + gint render_depth; + Colormap root_cmap; + gchar shm; + gchar shmp; + gint shm_event; + XImage *last_xim; + XImage *last_sxim; + Window base_window; + GdkWindow *gdk_win; + GdkColormap *gdk_cmap; + gint byte_order, bit_order; +#ifdef HAVE_SHM + XShmSegmentInfo last_shminfo; + XShmSegmentInfo last_sshminfo; +#endif + } +Xdata; + +typedef struct _imlibdata + { + gint num_colors; + GdkImlibColor *palette; + GdkImlibColor *palette_orig; + unsigned char *fast_rgb; + gint *fast_err; + gint *fast_erg; + gint *fast_erb; + gint render_type; + gint max_shm; + gint byte_order; + struct _cache + { + gchar on_image; + gint size_image; + gint num_image; + gint used_image; + struct image_cache *image; + gchar on_pixmap; + gint size_pixmap; + gint num_pixmap; + gint used_pixmap; + struct pixmap_cache *pixmap; + } + cache; + gchar fastrend; + gchar hiq; + GdkImlibColorModifier mod, rmod, gmod, bmod; + unsigned char rmap[256], gmap[256], bmap[256]; + gchar fallback; + gchar ordered_dither; + Xdata x; + } +ImlibData; + +extern ImlibData *_gdk_imlib_data; + +gint _gdk_imlib_index_best_color_match(gint * r, gint * g, gint * b); +void gdk_imlib_load_default_colors__private (void); + +void _gdk_imlib_dirty_pixmaps(GdkImlibImage * im); +void _gdk_imlib_dirty_images(GdkImlibImage * im); +void _gdk_imlib_find_pixmap(GdkImlibImage * im, int width, int height, GdkPixmap ** pmap, GdkBitmap ** mask); +GdkImlibImage *_gdk_imlib_find_image(char *file); +void _gdk_imlib_free_pixmappmap(GdkPixmap * pmap); +void _gdk_imlib_free_image(GdkImlibImage * im); +void _gdk_imlib_flush_image(GdkImlibImage * im); +void _gdk_imlib_add_image(GdkImlibImage * im, char *file); +void _gdk_imlib_add_pixmap(GdkImlibImage * im, int width, int height, XImage * xim, XImage * sxim); +void _gdk_imlib_clean_caches(void); +void _gdk_imlib_nullify_image(GdkImlibImage * im); + +/* char *g_SplitID(char *file); */ +char *_gdk_imlib_GetExtension(char *file); + +int _gdk_imlib_ispnm(FILE *f); +int _gdk_imlib_isjpeg(FILE *f); +int _gdk_imlib_ispng(FILE *f); +int _gdk_imlib_istiff(FILE *f); +int _gdk_imlib_iseim(FILE *f); +int _gdk_imlib_isgif(FILE *f); +int _gdk_imlib_isxpm(FILE *f); +int _gdk_imlib_isbmp(FILE *f); + +void * _gdk_malloc_image(unsigned int, unsigned int); + +GdkPixmap *gdk_imlib_pixmap_foreign_new(gint width, gint height, gint depth, Pixmap pmap); + +void _gdk_imlib_calc_map_tables(GdkImlibImage * im); + +FILE *_gdk_imlib_open_helper(const char *, const char *, const char *); +int _gdk_imlib_close_helper(FILE *); + +#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; + +typedef unsigned char *(*gdk_imlib_loader_fn) (FILE *, int *w, int *h, int *transp); +typedef unsigned char *(*gdk_imlib_loader_fn2)(FILE *, char *fname, int *w, int *h, int *trans); + +extern gdk_imlib_loader_fn _gdk_imlib_LoadBMP; +extern gdk_imlib_loader_fn _gdk_imlib_LoadXPM; +extern gdk_imlib_loader_fn _gdk_imlib_LoadGIF; +extern gdk_imlib_loader_fn2 _gdk_imlib_LoadTIFF; +extern gdk_imlib_loader_fn _gdk_imlib_LoadJPEG; +extern gdk_imlib_loader_fn _gdk_imlib_LoadPNG; +extern gdk_imlib_loader_fn _gdk_imlib_LoadPPM; + +typedef gint (*gdk_imlib_saver_fn)(GdkImlibImage *im, char *file, GdkImlibSaveInfo *info); + +extern gdk_imlib_saver_fn _gdk_imlib_SavePNG; +extern gdk_imlib_saver_fn _gdk_imlib_SaveTIFF; +extern gdk_imlib_saver_fn _gdk_imlib_SavePNG; +extern gdk_imlib_saver_fn _gdk_imlib_SaveJPEG; +extern gdk_imlib_saver_fn _gdk_imlib_SavePS; +extern gdk_imlib_saver_fn _gdk_imlib_SavePPM; + +typedef GdkImlibImage * (*gdk_imlib_inline_fn)(unsigned char *data, int data_size); + +extern gdk_imlib_inline_fn _gdk_imlib_inlined_png_to_image; + +typedef GdkImlibImage *(*gdk_imlib_load_alpha_fn)(char *file); + +extern gdk_imlib_load_alpha_fn _gdk_imlib_load_alpha_png; + +#endif diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib_types.h b/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib_types.h new file mode 100644 index 00000000..e9468f72 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/gdk_imlib_types.h @@ -0,0 +1,110 @@ +#include <gdk/gdk.h> + +#ifndef SYSTEM_IMRC +#define SYSTEM_IMRC "/etc/imrc" +#endif /* endef SYSTEM_IMRC */ + +typedef struct _GdkImlibBorder GdkImlibBorder; +typedef struct _GdkImlibColor GdkImlibColor; +typedef struct _GdkImlibColorModifier GdkImlibColorModifier; +typedef struct _GdkImlibImage GdkImlibImage; +typedef struct _GdkImlibSaveInfo GdkImlibSaveInfo; +typedef struct _GdkImlibInitParams GdkImlibInitParams; +typedef struct _GdkImlibModifierMap GdkImlibModifierMap; + +struct _GdkImlibBorder + { + gint left, right; + gint top, bottom; + }; + +struct _GdkImlibColor + { + gint r, g, b; + gint pixel; + }; + +struct _GdkImlibColorModifier + { + gint gamma; + gint brightness; + gint contrast; + }; + +struct _GdkImlibModifierMap + { + unsigned char rmap[256], gmap[256], bmap[256]; + }; + +struct _GdkImlibImage + { + gint rgb_width, rgb_height; + unsigned char *rgb_data; + unsigned char *alpha_data; + gchar *filename; +/* the below information is private */ + gint width, height; + GdkImlibColor shape_color; + GdkImlibBorder border; + GdkPixmap *pixmap; + GdkBitmap *shape_mask; + gchar cache; + GdkImlibColorModifier mod, rmod, gmod, bmod; + GdkImlibModifierMap *map; + int ref_count; + GHashTable *pixmaps; + }; + +struct _GdkImlibSaveInfo + { + int quality; + int scaling; + int xjustification; + int yjustification; + int page_size; + char color; + }; + +struct _GdkImlibInitParams + { + int flags; + int visualid; + char *palettefile; + char sharedmem; + char sharedpixmaps; + char paletteoverride; + char remap; + char fastrender; + char hiquality; + char dither; + int imagecachesize; + int pixmapcachesize; + }; + +#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 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/gdk_imlib/globals.c b/debian/imlib/imlib-1.9.15/gdk_imlib/globals.c new file mode 100644 index 00000000..301d4e8a --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/globals.c @@ -0,0 +1,8 @@ + +#define _GNU_SOURCE +#include <config.h> +#include "gdk_imlib.h" +#include "gdk_imlib_private.h" + +ImlibData _gdk_real_imlib_data = { 0, 0, }; +ImlibData *_gdk_imlib_data = &_gdk_real_imlib_data; diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/install-sh b/debian/imlib/imlib-1.9.15/gdk_imlib/install-sh new file mode 100755 index 00000000..89fc9b09 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_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/gdk_imlib/io-bmp.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-bmp.c new file mode 100644 index 00000000..7cacb1fb --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-bmp.c @@ -0,0 +1,380 @@ +#include <config.h> +#include "gdk_imlib.h" +#include "gdk_imlib_private.h" + +unsigned char * +loader_bmp (FILE *file, int *w, int *h, int *t) +{ + unsigned char *data, *ptr; + int done, i, bpp, planes, comp, ncolors, line, column, + linesize, linepos, rshift = 0, gshift = 0, bshift = 0; + unsigned char byte; + short int word; + long int dbuf[4], dword, rmask = 0xff, gmask = 0xff, bmask = 0xff, offset, + size; + signed char bbuf[4]; + struct _cmap + { + unsigned char r, g, b; + } + *cmap = NULL; + +#define BI_RGB 0 +#define BI_RLE8 1 +#define BI_RLE4 2 +#define BI_BITFIELDS 3 + + 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 *)_gdk_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; + + 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; +} + diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/io-gif.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-gif.c new file mode 100644 index 00000000..2b2a01d7 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-gif.c @@ -0,0 +1,179 @@ +#include <config.h> +#include "gdk_imlib.h" +#include "gdk_imlib_private.h" + +#ifndef HAVE_LIBGIF +unsigned char loader_gif (FILE *f, int *w, int *h, int *t) +{ + return NULL; +} +#else +#include <gif_lib.h> + +unsigned char * +loader_gif(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; + + fd = fileno(f); + /* Apparently rewind(f) isn't sufficient */ + lseek(fd, (long) 0, 0); + gif = DGifOpenFileHandle(fd); + + transp = -1; + data = NULL; + rows = NULL; + + 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 = _gdk_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 diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/io-jpeg.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-jpeg.c new file mode 100644 index 00000000..f619d2e7 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-jpeg.c @@ -0,0 +1,171 @@ +#include <config.h> +#include <setjmp.h> +#include "gdk_imlib.h" +#include "gdk_imlib_private.h" + +#ifdef HAVE_LIBJPEG +#include <jpeglib.h> + +/** + * 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; + +static void +g_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 * +loader_jpeg (FILE * f, int *w, int *h, int *t) +{ + struct jpeg_decompress_struct cinfo; + struct ImLib_JPEG_error_mgr jerr; + unsigned char *data, *line[16], *ptr; + int x, y, i; + + *t = 0; + cinfo.err = jpeg_std_error(&(jerr.pub)); + jerr.pub.error_exit = g_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 = _gdk_malloc_image(*w, *h); + if (!data) + { + jpeg_destroy_decompress(&cinfo); + return NULL; + } + ptr = data; + + if (cinfo.rec_outbuf_height > 16) + { + fprintf(stderr, "gdk_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; +} + +gint +saver_jpeg (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + JSAMPROW row_pointer[1]; + int row_stride; + FILE *f; + + 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; + } + return 0; +} + +#else +unsigned char * +loader_jpeg (FILE * f, int *w, int *h, int *t) +{ + return NULL; +} + +gint +saver_jpeg (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return 0; +} +#endif diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/io-png.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-png.c new file mode 100644 index 00000000..49154b34 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-png.c @@ -0,0 +1,722 @@ +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +#ifdef HAVE_LIBPNG +#include <png.h> + +unsigned char * +loader_png (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; +#if 0 + /* + *Corrupting images on load is better than no image at all + */ + if (!strcmp("1.0.2", png_libpng_ver)) + { + fprintf(stderr, "WARNING! You have libpng 1.0.2\n" + "It has a known bug that corrupts images on load.\n" + "please use 1.0.1. PNG support is disabled.\n"); + return NULL; + } +#endif + 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 = _gdk_malloc_image(*w, *h); + if (!data) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + /* SAFE - the 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 - the malloc_image will fail first */ + 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; +} + +struct _io_info +{ + unsigned char *data; + unsigned char *ptr; + unsigned char *end; +}; + +static void +_gdk_imlib_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; +} + +GdkImlibImage * +inline_png(unsigned char *data, int data_size) +{ + GdkImlibImage *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; + struct _io_info io_info; + char s [64]; + +#if 0 + /* + *Corrupting images on load is better than no image at all + */ + if (!strcmp("1.0.2", png_libpng_ver)) + { + fprintf(stderr, "WARNING! You have libpng 1.0.2\n" + "It has a known bug that corrupts images on load.\n" + "please use 1.0.1.\n"); + return NULL; + } +#endif + im = malloc(sizeof(GdkImlibImage)); + if (!im) + return NULL; + im->map = NULL; + im->rgb_width = 0; + im->rgb_height = 0; + im->rgb_data = NULL; + im->alpha_data = NULL; + g_snprintf (s, sizeof (s), "creat_%x_%x", (int)time(NULL), (int)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; + 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)_gdk_imlib_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 = _gdk_malloc_image(ww, hh); + 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 0 + /* Generated data... We can't cache this! */ + if (id->cache.on_image) + _gdk_imlib_add_image(im, im->filename); +#endif + + _gdk_imlib_calc_map_tables(im); + return im; +} + +static unsigned char * +_loader_alpha_png (FILE * f, int *w, int *h, int *t, unsigned char **alpha) +{ + png_structp png_ptr; + png_infop info_ptr; + unsigned char *data, *ptr, **lines, *ptr2, *aptr; + 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) + 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 = _gdk_malloc_image(*w, *h); + if (!data) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + if (color_type != PNG_COLOR_TYPE_GRAY){ + *alpha = malloc(*w * *h); + if (!*alpha) + { + png_destroy_read_struct(&png_ptr, &info_ptr, NULL); + return NULL; + } + transp = 1; + } else { + *alpha = NULL; + transp = 0; + } + + 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++) + { + if ((lines[i] = malloc(*w * (sizeof(unsigned char) * 4))) == NULL) + { + int n; + + free(data); + free(*alpha); + 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; + aptr = *alpha; + if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + unsigned char r; + + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + r = *ptr2++; + *aptr++ = *ptr2++; + *ptr++ = r; + *ptr++ = r; + *ptr++ = r; + } + } + } + else if (color_type == PNG_COLOR_TYPE_GRAY) + { + unsigned char r; + + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + r = *ptr2++; + *ptr++ = r; + *ptr++ = r; + *ptr++ = r; + } + } + } + else + { + for (y = 0; y < *h; y++) + { + ptr2 = lines[y]; + for (x = 0; x < *w; x++) + { + *ptr++ = *ptr2++; + *ptr++ = *ptr2++; + *ptr++ = *ptr2++; + *aptr++ = *ptr2++; + } + } + } + for (i = 0; i < *h; i++) + free(lines[i]); + free(lines); + *t = transp; + return data; +} + +GdkImlibImage * +loader_alpha_png (char *file) +{ + FILE *f; + int w, h, trans; + GdkImlibImage *im; + unsigned char *data, *alpha; + + g_return_val_if_fail (file != NULL, NULL); + + f = fopen (file, "rb"); + if (!f) + return NULL; + + data = _loader_alpha_png (f, &w, &h, &trans, &alpha); + fclose (f); + + if (!data) + return NULL; + + im = (GdkImlibImage *) malloc (sizeof (GdkImlibImage)); + if (!im){ + free (data); + if (alpha) + free (alpha); + return NULL; + } + memset (im, 0, sizeof (GdkImlibImage)); + + im->alpha_data = alpha; + im->shape_color.r = -1; + im->shape_color.g = -1; + im->shape_color.b = -1; + im->rgb_data = data; + im->rgb_width = w; + im->rgb_height = h; + + return im; +} + +gint +saver_png (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + png_structp png_ptr; + png_infop info_ptr; + unsigned char *data, *ptr; + int x, y; + png_bytep row_ptr; + png_color_8 sig_bit; + FILE *f; + + 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); + if(im->rgb_width >= 0x40000000) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) NULL); + return 0; + } + 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; + } + return 0; +} + +#else +unsigned char * +loader_png (FILE * f, int *w, int *h, int *t) +{ + return NULL; +} + +gint +saver_png (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return 0; +} + +GdkImlibImage * +inline_png (unsigned char *data, int data_size) +{ + return NULL; +} + +GdkImlibImage * +loader_alpha_png (char *file) +{ + return NULL; +} +#endif + diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/io-ppm.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-ppm.c new file mode 100644 index 00000000..b2d855b8 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-ppm.c @@ -0,0 +1,302 @@ +#include <config.h> +#include <setjmp.h> +#define id _gdk_imlib_data +#include "gdk_imlib.h" +#include "gdk_imlib_private.h" + +unsigned char * +loader_ppm (FILE * f, int *w, int *h, int *t) +{ + int done; + unsigned char *ptr; + unsigned char chr; + char s[256]; + int a, b, i, j; + int color, scale, ascii, bw; + + *t = 0; + 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, "gdk_imlib ERROR: Image width > 32767 pixels for file\n"); + return NULL; + } + if (b > 32767) + { + fprintf(stderr, "gdk_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 *)_gdk_malloc_image(a, b); + if (!ptr) + { + fprintf(stderr, "gdk_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; +} + +gint +saver_ppm (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + char *ext = _gdk_imlib_GetExtension (file); + int x, y; + unsigned char *ptr, val; + int v; + FILE *f; + + f = fopen(file, "wb"); + if (!f) + return 0; + + if (strcmp (ext, "pgm") == 0){ + 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 (!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; + } +} diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/io-ps.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-ps.c new file mode 100644 index 00000000..c9233166 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-ps.c @@ -0,0 +1,201 @@ +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +int +saver_ps (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + int bx, by, bxx, byy; + int w, h; + int sx, sy; + int tx = 35, ty = 35; + int x, y; + unsigned char *ptr; + int v; + FILE *f; + + 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; + } + return 0; +} diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/io-tiff.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-tiff.c new file mode 100644 index 00000000..26790b75 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-tiff.c @@ -0,0 +1,143 @@ +#include <config.h> +#include <setjmp.h> +#define id _gdk_imlib_data +#include "gdk_imlib.h" +#include "gdk_imlib_private.h" + +#ifdef HAVE_LIBTIFF +#include <tiffio.h> + +unsigned char * +loader_tiff(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; +} + +gint +saver_tiff (GdkImlibImage * im, char *file, GdkImlibSaveInfo * info) +{ + 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; + } + return 0; +} + +#else +unsigned char * +loader_tiff (FILE * f, int *w, int *h, int *t) +{ + return NULL; +} + +gint +saver_tiff (GdkImlibImage * im, char *file, GdkImlibSaveInfo * info) +{ + return 0; +} +#endif diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/io-xpm.c b/debian/imlib/imlib-1.9.15/gdk_imlib/io-xpm.c new file mode 100644 index 00000000..8b88bb3d --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/io-xpm.c @@ -0,0 +1,370 @@ +#include <config.h> +#include <setjmp.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +unsigned char * +loader_xpm(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; + + *w = 10; + *h = 10; + + ptr = NULL; + end = NULL; + data = NULL; + c = ' '; + comment = 0; + quote = 0; + context = 0; + i = j = 0; + cmap = NULL; + + 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, "gdk_imlib ERROR: XPM files wth colors > 32766 not supported\n"); + free(line); + return NULL; + } + if (cpp > 5) + { + fprintf(stderr, "gdk_imlib ERROR: XPM files with characters per pixel > 5 not supported\n"); + free(line); + return NULL; + } + if (*w > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for file\n"); + free(line); + return NULL; + } + if (*h > 32767) + { + fprintf(stderr, "gdk_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; + } + data = _gdk_malloc_image(*w, *h); + if (!data) + { + free(line); + free(cmap); + 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; + + hascolor = 0; + iscolor = 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; + 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) + { + /* 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; +} + diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/load.c b/debian/imlib/imlib-1.9.15/gdk_imlib/load.c new file mode 100644 index 00000000..f7c01d7f --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/load.c @@ -0,0 +1,538 @@ +#define _GNU_SOURCE +#include <config.h> +#include <glib.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +#include <setjmp.h> + +/* Split the ID - damages input */ + +static char * +g_SplitID(char *file) +{ + char *p = strrchr(file, ':'); + + if (p == NULL) + return ""; + else + { + *p++ = 0; + return p; + } +} + +/* + * Doesn't damage the input + */ + +char * +_gdk_imlib_GetExtension(char *file) +{ + char *p = strrchr(file, '.'); + + if (p == NULL) + return ""; + else + return p + 1; +} + +int +_gdk_imlib_ispnm(FILE *f) +{ + char buf[8]; + + if (!f) + return 0; + fgets(buf, 8, f); + rewind(f); + if (!strcmp("P6\n", buf)) + return 1; + if (!strcmp("P5\n", buf)) + return 1; + if (!strcmp("P4\n", buf)) + return 1; + if (!strcmp("P3\n", buf)) + return 1; + if (!strcmp("P2\n", buf)) + return 1; + if (!strcmp("P1\n", buf)) + return 1; + return 0; +} + +int +_gdk_imlib_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 +_gdk_imlib_ispng(FILE *f) +{ + unsigned char buf[8]; + + if (!f) + return 0; + fread(buf, 1, 8, f); + rewind(f); + if (buf [0] != 0x89 || + buf [1] != 'P' || + buf [2] != 'N' || + buf [3] != 'G' || + buf [4] != 0x0d || + buf [5] != 0x0a || + buf [6] != 0x1a || + buf [7] != 0x0a) + return FALSE; + return TRUE; +} + +int +_gdk_imlib_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 +_gdk_imlib_iseim(FILE *f) +{ + char buf[8]; + + if (!f) + return 0; + fread(buf, 1, 4, f); + rewind(f); + if (!strncmp("EIM ", buf, 4)) + return 1; + return 0; +} + +int +_gdk_imlib_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 +_gdk_imlib_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 +_gdk_imlib_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; +} + + + +GdkImlibImage * +gdk_imlib_load_image(char *file) +{ + int w, h; + unsigned char *data; + GdkImlibImage *im; + char *e; + FILE *p; + int eim; + int fmt; + int trans; + + eim = 0; + fmt = 0; + p = NULL; + data = NULL; + + if (!file) + return NULL; + if (id->cache.on_image) + if ((im = _gdk_imlib_find_image(file))) + { + if (im->rgb_width == 0 || im->rgb_height == 0) + { + gdk_imlib_destroy_image(im); + return NULL; + } + else + return im; + } + if (!strcmp(file,"-")) + p = stdin; + else + p = fopen(file, "rb"); + if (!p) + return NULL; + + + e = _gdk_imlib_GetExtension(file); + + if (_gdk_imlib_ispnm(p)) + { + fmt = 0; + } + else if (_gdk_imlib_isjpeg(p)) + { + fmt = 2; + } + else if (_gdk_imlib_istiff(p)) + { + fmt = 3; + } + else if (_gdk_imlib_iseim(p)) + { + eim = 1; + fmt = 9999; + } + else if (_gdk_imlib_isxpm(p)) + { + fmt = 5; + } + else if (_gdk_imlib_ispng(p)) + { + fmt = 1; + } + else if (_gdk_imlib_isgif(p)) + { + fmt = 4; + } + else if (_gdk_imlib_isbmp(p)) + { + fmt = 6; + } + + trans = 0; + if (!eim && !data) + { + switch (fmt) + { + case 6: + if (p) + data = (*_gdk_imlib_LoadBMP)(p, &w, &h, &trans); + break; + case 5: + if (p) + data = (*_gdk_imlib_LoadXPM)(p, &w, &h, &trans); + break; + case 4: + if (p) + data = (*_gdk_imlib_LoadGIF)(p, &w, &h, &trans); + break; + case 3: + if (p) + data = (*_gdk_imlib_LoadTIFF)(p, file, &w, &h, &trans); + break; + case 2: + if (p) + data = (*_gdk_imlib_LoadJPEG)(p, &w, &h, &trans); + break; + case 1: + if (p) + data = (*_gdk_imlib_LoadPNG)(p, &w, &h, &trans); + break; + case 0: + if (p) + data = (*_gdk_imlib_LoadPPM)(p, &w, &h, &trans); + break; + } + } + + if (p != stdin) + fclose(p); + + if (!eim && !data) + { + fprintf(stderr, "gdk_imlib ERROR: Cannot load image: %s\n" + "All fallbacks failed.\n", file); + return NULL; + } + + if (w == 0 || h == 0) + { + if (data) + free(data); + return NULL; + } + + im = (GdkImlibImage *) malloc(sizeof(GdkImlibImage)); + if (!im) + { + fprintf(stderr, "gdk_imlib ERROR: Cannot allocate RAM for image data\n"); + if (data) + free(data); + return NULL; + } + im->alpha_data = NULL; + im->map = 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 = NULL; + im->shape_mask = NULL; + +#if THIS_CODE_IS_BROKEN_WITH_REGARD_TO_FILENAMES_WITH_COLONS + + /* + * The code here depends on the filenames not having a ':', + * which is not the case for a lot of my files. + */ + if (eim) + { + char s1[256], s2[256]; + char s[4096]; + 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 + p = fopen(file, "r"); + if (!p) + { + free(im); + return NULL; + } + fgets(s, sizeof (s), 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, sizeof (s), 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 = _gdk_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); + } +#endif + + 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)) + _gdk_imlib_add_image(im, file); + _gdk_imlib_calc_map_tables(im); + return im; +} + +gint +gdk_imlib_save_image_to_eim(GdkImlibImage * im, char *file) +{ + char fil[4096]; + char *iden; + FILE *f; + int size; + + if ((!id) || (!im) || (!file)) + return 0; + strncpy(fil, file, sizeof(fil)); + iden = g_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; +} + +gint +gdk_imlib_add_image_to_eim(GdkImlibImage * im, char *file) +{ + char fil[4096]; + char *iden; + FILE *f; + int size; + + if ((!id) || (!im) || (!file)) + return 0; + strncpy(fil, file, sizeof(fil)); + + iden = g_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; +} + +gint +gdk_imlib_save_image_to_ppm(GdkImlibImage * im, char *file) +{ + FILE *f; + + if ((!id) || (!im) || (!file)) + return 0; + f = fopen(file, "w"); + 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/gdk_imlib/misc.c b/debian/imlib/imlib-1.9.15/gdk_imlib/misc.c new file mode 100644 index 00000000..b372dde4 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/misc.c @@ -0,0 +1,1365 @@ +#define _GNU_SOURCE +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" +#include <gdk/gdk.h> +#include <gdk/gdkx.h> +#include <locale.h> + +static char x_error; + +static void +HandleXError(Display * d, XErrorEvent * ev) +{ + x_error = 1; +} + +gint +gdk_imlib_get_render_type() +{ + if (id->x.disp) + return id->render_type; + else + return -1; +} + +void +gdk_imlib_set_render_type(gint rend_type) +{ + 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; +} + +static void +gdk_imlib_set_fast_render(ImlibData * id, Display * disp) +{ + /* Turn off fastrender if there is an endianess diff between */ + /* client and Xserver in all but 24 bit mode */ + 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; /* We ignore this for now in the fastrend */ + /* 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; +} + +static int +gdk_imlib_set_color_map(ImlibData * id, Display * disp) +{ + XSetWindowAttributes at; + unsigned long mask; + int newcm = 0; + GdkWindowPrivate *private; + + 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; + private = (GdkWindowPrivate *) & gdk_root_parent; + if (id->x.visual != DefaultVisual(disp, id->x.screen)) + { + Colormap cm; + + cm = XCreateColormap(id->x.disp, private->xwindow, + 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, private->xwindow, + -100, -100, 10, 10, 0, + id->x.depth, InputOutput, + id->x.visual, mask, &at); + id->x.gdk_win = gdk_window_foreign_new(id->x.base_window); + if (newcm) + id->x.gdk_cmap = gdk_colormap_new(gdk_window_get_visual + (id->x.gdk_win), FALSE); + else + id->x.gdk_cmap = gdk_colormap_get_system(); + return newcm; +} + +#ifdef HAVE_SHM +int + XShmGetEventBase(Display * disp); + +#endif + +static int initialized = 0; + +void +gdk_imlib_init() +{ + Display *disp; + XWindowAttributes xwa; + XVisualInfo xvi, *xvir; + GdkVisual *visual; + char *homedir; + char s[4096]; + char *s1; + char *s2; + FILE *f; + int override = 0; + int dither = 0; + int remap = 1; + int num; + int i, max, maxn; + int clas; + char *palfile = 0; + int loadpal; + int vis; + int newcm; + char *old_locale; + + disp = (Display *) gdk_display; + if (!disp) + { + fprintf(stderr, "gdk_imlib ERROR: gdk has not connected to the display\n"); + return; + } + vis = -1; + loadpal = 0; + if (initialized) + return; + + initialized = 1; + 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 */ + visual = gdk_rgb_get_visual(); + id->x.visual = GDK_VISUAL_XVISUAL(visual); /* the visual type */ + id->x.depth = visual->depth; /* the depth of the screen in bpp */ + + id->x.shm = 0; + id->x.shmp = 0; + id->max_shm = 0; +#ifdef HAVE_SHM + if (gdk_get_use_xshm()) + { + if (XShmQueryExtension(id->x.disp) == True) + { + 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"); + g_snprintf(s, sizeof(s), "%s/.imrc", homedir); + old_locale = g_strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + f = fopen(s, "r"); + if (!f) + f = fopen(SYSTEM_IMRC, "r"); + if (f) + { + while (fgets(s, sizeof (s), 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)) + { + if (sscanf (s2, "%x", &num) == 1) + 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); + g_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, "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 = 16; + /* This is a butt ugly hack to get the iPAQ to work! */ + /* The proper way is to fix it, counting bits and storing + * mask values, but I dont think I can do this w/o breaking + * the API! Damn... + */ + else if (xvir->red_mask == 0xf000) { + printf("Detected an iPAQ...\n"); + id->x.render_depth = 12; + } else + 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) + { + int have_pal; + + 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; + } + + have_pal = 0; + + if (palfile != NULL) + have_pal = gdk_imlib_load_colors(palfile); + + if (!have_pal) + gdk_imlib_load_default_colors__private (); + + if (id->num_colors == 0) + { + fprintf(stderr, "gdk_imlib: Unable to allocate a palette.\n"); + if (palfile) + free(palfile); + exit (EXIT_FAILURE); + } + } + else + { + if (id->hiq == 1) + id->render_type = RT_DITHER_TRUECOL; + else + id->render_type = RT_PLAIN_TRUECOL; + } + + newcm = gdk_imlib_set_color_map(id, disp); + + gdk_imlib_set_fast_render(id, disp); + + 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 + { + XErrorHandler preh; + + id->x.last_shminfo.shmaddr = xim->data = + shmat(id->x.last_shminfo.shmid, 0, 0); + id->x.last_shminfo.readOnly = False; + preh = 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); + XSetErrorHandler((XErrorHandler) preh); + } + } + } +#endif /* HAVE_SHM */ +} + +void +gdk_imlib_init_params(GdkImlibInitParams * p) +{ + Display *disp; + XWindowAttributes xwa; + XVisualInfo xvi, *xvir; + GdkVisual *visual; + 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; + + palfile = NULL; + disp = (Display *) gdk_display; + if (!disp) + { + fprintf(stderr, "gdk_imlib ERROR: gdk has not connected to the display\n"); + return; + } + vis = -1; + loadpal = 0; + if (initialized) + return; + initialized = 1; + 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 */ + visual = gdk_rgb_get_visual(); + id->x.visual = GDK_VISUAL_XVISUAL(visual); /* the visual type */ + id->x.depth = visual->depth; /* 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; + + 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"); + g_snprintf(s, sizeof(s), "%s/.imrc", homedir); + + old_locale = g_strdup(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "C"); + + f = fopen(s, "r"); + if (!f) + f = fopen(SYSTEM_IMRC, "r"); + if (f) + { + while (fgets(s, sizeof (s), 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; + } + 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)) + { + if (sscanf (s2, "%x", &num) == 1) + 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); + g_free(old_locale); + + if (p) + { + if (p->flags & PARAMS_VISUALID) + vis = p->visualid; + if (p->flags & PARAMS_PALETTEFILE) + 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; + } + /* 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, "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 = 16; + /* This is a butt ugly hack to get the iPAQ to work! */ + /* The proper way is to fix it, counting bits and storing + * mask values, but I dont think I can do this w/o breaking + * the API! Damn... + */ + else if (xvir->red_mask == 0xf000) { + printf("Detected an iPAQ...\n"); + id->x.render_depth = 12; + } else + 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; + } + gdk_imlib_load_colors(palfile); + if (id->num_colors == 0) + { + fprintf(stderr, "gdk_imlib: Cannot Find Palette. A Palette is required for this mode\n"); + id->x.disp = NULL; + initialized = 0; + if (palfile) + free(palfile); + return; + } + } + else + { + if (id->hiq == 1) + id->render_type = RT_DITHER_TRUECOL; + else + id->render_type = RT_PLAIN_TRUECOL; + } + + newcm = gdk_imlib_set_color_map(id, disp); + gdk_imlib_set_fast_render(id, disp); + 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); + 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 /* HAVE_SHM */ +} + +GdkPixmap * +gdk_imlib_copy_image(GdkImlibImage * im) +{ + GdkPixmap *p; + GdkGC *gc; + + if ((!im) || (!im->pixmap)) + return NULL; + p = gdk_pixmap_new(id->x.gdk_win, im->width, im->height, id->x.depth); + gc = gdk_gc_new(p); + gdk_draw_pixmap(p, gc, im->pixmap, 0, 0, 0, 0, im->width, im->height); + gdk_gc_destroy(gc); + return p; +} + +GdkPixmap * +gdk_imlib_move_image(GdkImlibImage * im) +{ + GdkPixmap *p; + + if (!im) + return NULL; + p = im->pixmap; + im->pixmap = NULL; + return p; +} + +GdkBitmap * +gdk_imlib_copy_mask(GdkImlibImage * im) +{ + GdkBitmap *p; + GdkGC *gc; + + if ((!im) || (!im->shape_mask)) + return NULL; + p = gdk_pixmap_new(id->x.gdk_win, im->width, im->height, 1); + gc = gdk_gc_new(p); + gdk_draw_pixmap(p, gc, im->shape_mask, 0, 0, 0, 0, im->width, im->height); + gdk_gc_destroy(gc); + return p; +} + +GdkBitmap * +gdk_imlib_move_mask(GdkImlibImage * im) +{ + GdkBitmap *p; + + if (!im) + return NULL; + p = im->shape_mask; + im->shape_mask = NULL; + return p; +} + +void +gdk_imlib_destroy_image(GdkImlibImage * im) +{ + if (im) + { + if (id->cache.on_image) + { + _gdk_imlib_free_image(im); + _gdk_imlib_clean_caches(); + } + else + _gdk_imlib_nullify_image(im); + } +} + +void +gdk_imlib_kill_image(GdkImlibImage * im) +{ + if (im) + { + if (id->cache.on_image) + { + _gdk_imlib_free_image(im); + _gdk_imlib_flush_image(im); + _gdk_imlib_clean_caches(); + } + else + _gdk_imlib_nullify_image(im); + } +} + +void +gdk_imlib_free_pixmap(GdkPixmap * pmap) +{ + if (pmap) + { + _gdk_imlib_free_pixmappmap(pmap); + _gdk_imlib_clean_caches(); + } +} + +void +gdk_imlib_free_bitmap(GdkBitmap * pmap) +{ + if (pmap) + { + _gdk_imlib_free_pixmappmap(pmap); + _gdk_imlib_clean_caches(); + } +} + +void +gdk_imlib_set_image_border(GdkImlibImage * im, GdkImlibBorder * 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)) + { + _gdk_imlib_dirty_pixmaps(im); + + im->border.left = border->left; + im->border.right = border->right; + im->border.top = border->top; + im->border.bottom = border->bottom; + } + } +} + +void +gdk_imlib_get_image_border(GdkImlibImage * im, GdkImlibBorder * 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 +gdk_imlib_get_image_shape(GdkImlibImage * im, GdkImlibColor * color) +{ + if ((!im) || (!color)) + return; + color->r = im->shape_color.r; + color->g = im->shape_color.g; + color->b = im->shape_color.b; +} + +void +gdk_imlib_set_image_shape(GdkImlibImage * im, GdkImlibColor * color) +{ + if ((!im) || (!color)) + return; + im->shape_color.r = color->r; + im->shape_color.g = color->g; + im->shape_color.b = color->b; + _gdk_imlib_dirty_pixmaps(im); +} + +gint +gdk_imlib_get_fallback() +{ + return id->fallback; +} + +void +gdk_imlib_set_fallback(gint fallback) +{ + id->fallback = fallback; +} + +GdkVisual * +gdk_imlib_get_visual() +{ + return gdk_window_get_visual(id->x.gdk_win); +} + +GdkColormap * +gdk_imlib_get_colormap() +{ + return (id->x.gdk_cmap); +} + +gchar * +gdk_imlib_get_sysconfig() +{ + if (!id->x.disp) + return NULL; + return strdup(SYSTEM_IMRC); +} + +/* + * Make sure we don't wrap on our memory allocations + */ + +void *_gdk_malloc_image(unsigned int w, unsigned int h) +{ + if( w > 32767 || h > 32767) + return NULL; + return malloc(w * h * 3); +} diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/mkinstalldirs b/debian/imlib/imlib-1.9.15/gdk_imlib/mkinstalldirs new file mode 100755 index 00000000..91f6d04e --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_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/gdk_imlib/modules.c b/debian/imlib/imlib-1.9.15/gdk_imlib/modules.c new file mode 100644 index 00000000..d2c333dc --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/modules.c @@ -0,0 +1,288 @@ +/* + * modules.c: Dynamically loading the format handlers for save and load + * operations in Imlib. + * + * Author: + * Miguel de Icaza ([email protected]). + */ +#include <config.h> +#include <glib.h> +#include <gmodule.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +#ifdef USE_GMODULE + +static unsigned char *loader_bmp (FILE *f, int *w, int *h, int *t); +static unsigned char *loader_xpm (FILE *f, int *w, int *h, int *t); +static unsigned char *loader_gif (FILE *f, int *w, int *h, int *t); +static unsigned char *loader_tiff (FILE *f, char *n, int *w, int *h, int *t); +static unsigned char *loader_jpeg (FILE *f, int *w, int *h, int *t); +static unsigned char *loader_png (FILE *f, int *w, int *h, int *t); +static unsigned char *loader_ppm (FILE *f, int *w, int *h, int *t); + +static gint saver_tiff (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info); +static gint saver_png (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info); +static gint saver_jpeg (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info); +static gint saver_ps (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info); +static gint saver_ppm (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info); + +static GdkImlibImage *loader_alpha_png (char *file); + +static GdkImlibImage *inline_png (unsigned char *data, int data_size); + +#else +# include "io-png.c" +# include "io-bmp.c" +# include "io-gif.c" +# include "io-jpeg.c" +# include "io-ppm.c" +# include "io-ps.c" +# include "io-tiff.c" +# include "io-xpm.c" +#endif + +gdk_imlib_loader_fn _gdk_imlib_LoadBMP = loader_bmp; +gdk_imlib_loader_fn _gdk_imlib_LoadXPM = loader_xpm; +gdk_imlib_loader_fn _gdk_imlib_LoadGIF = loader_gif; +gdk_imlib_loader_fn2 _gdk_imlib_LoadTIFF = loader_tiff; +gdk_imlib_loader_fn _gdk_imlib_LoadJPEG = loader_jpeg; +gdk_imlib_loader_fn _gdk_imlib_LoadPNG = loader_png; +gdk_imlib_loader_fn _gdk_imlib_LoadPPM = loader_ppm; + +gdk_imlib_saver_fn _gdk_imlib_SaveTIFF = saver_tiff; +gdk_imlib_saver_fn _gdk_imlib_SavePNG = saver_png; +gdk_imlib_saver_fn _gdk_imlib_SaveJPEG = saver_jpeg; +gdk_imlib_saver_fn _gdk_imlib_SavePS = saver_ps; +gdk_imlib_saver_fn _gdk_imlib_SavePPM = saver_ppm; + +gdk_imlib_inline_fn _gdk_imlib_inlined_png_to_image = inline_png; +gdk_imlib_load_alpha_fn _gdk_imlib_load_alpha_png = loader_alpha_png; + +#ifdef USE_GMODULE +static unsigned char * +load_fail_fn (FILE *f, int *w, int *h, int *t) +{ + return NULL; +} + +static gint +save_fail_fn (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return 0; +} + +static gboolean +get_module_loader_saver (char *mod, + void **loader, void *def_loader, + void **saver, void *def_saver) +{ + char *path, *modname; + GModule *m; + gboolean v; + void *ptr; + + modname = g_strconcat ("imlib-", mod, NULL); + path = g_module_build_path (IMLIB_LIB, modname); + g_free (modname); + + m = g_module_open (path, G_MODULE_BIND_LAZY); + g_free (path); + if (!m){ + if (loader) + *loader = def_loader; + if (saver) + *saver = def_saver; + return FALSE; + } + + if (loader){ + char *loader_name; + + loader_name = g_strconcat ("loader_", mod, NULL); + v = g_module_symbol (m, loader_name, (void **) &ptr); + if (v) + *loader = ptr; + else + *loader = def_loader; + g_free (loader_name); + } + + if (saver){ + char *saver_name; + + saver_name = g_strconcat ("saver_", mod, NULL); + v = g_module_symbol (m, saver_name, (void **) &ptr); + if (v) + *saver = ptr; + else + *saver = def_saver; + g_free (saver_name); + } + + /* Ugly hack, this is an exception */ + if (strcmp (mod, "png") == 0){ + char *inline_name, *alpha_name; + + inline_name = g_strconcat ("inline_", mod, NULL); + v = g_module_symbol (m, inline_name, (void **) &ptr); + if (v) + _gdk_imlib_inlined_png_to_image = ptr; + else + _gdk_imlib_inlined_png_to_image = (gdk_imlib_inline_fn) load_fail_fn; + g_free (inline_name); + + alpha_name = g_strconcat ("loader_alpha_", mod, NULL); + v = g_module_symbol (m, alpha_name, (void **) &ptr); + if (v) + _gdk_imlib_load_alpha_png = ptr; + else + _gdk_imlib_load_alpha_png = (gdk_imlib_load_alpha_fn) load_fail_fn; + g_free (alpha_name); + } + + return TRUE; /* FIXME: return value is never checked */ +} + +static unsigned char * +load_module_relay (char *mod, gdk_imlib_loader_fn *lf, gdk_imlib_saver_fn *sf, FILE *f, int *w, int *h, int *t) +{ + get_module_loader_saver (mod, + (void **) lf, (void *) load_fail_fn, + (void **) sf, (void *) save_fail_fn); + + return (*lf)(f, w, h, t); +} + +static gint +save_module_relay (char *mod, gdk_imlib_loader_fn *lf, gdk_imlib_saver_fn *sf, + GdkImlibImage *im, char *fname, GdkImlibSaveInfo *info) +{ + get_module_loader_saver (mod, + (void **) lf, (void *) load_fail_fn, + (void **) sf, (void *) save_fail_fn); + + return (*sf)(im, fname, info); +} + +static unsigned char * +loader_tiff (FILE *f, char *n, int *w, int *h, int *t) +{ + get_module_loader_saver ("tiff", + (void **) &_gdk_imlib_LoadTIFF, (void *) load_fail_fn, + (void **) &_gdk_imlib_SaveTIFF, (void *) save_fail_fn); + + return _gdk_imlib_LoadTIFF (f, n, w, h, t); +} + +static unsigned char * +loader_bmp (FILE *f, int *w, int *h, int *t) +{ + return load_module_relay ("bmp", &_gdk_imlib_LoadBMP, NULL, f, w, h, t); +} + +static unsigned char * +loader_xpm (FILE *f, int *w, int *h, int *t) +{ + return load_module_relay ("xpm", &_gdk_imlib_LoadXPM, NULL, f, w, h, t); +} + +static unsigned char * +loader_gif (FILE *f, int *w, int *h, int *t) +{ + return load_module_relay ("gif", &_gdk_imlib_LoadGIF, NULL, f, w, h, t); +} + +static unsigned char * +loader_jpeg (FILE *f, int *w, int *h, int *t) +{ + return load_module_relay ("jpeg", + &_gdk_imlib_LoadJPEG, + &_gdk_imlib_SaveJPEG, f, w, h, t); +} + +static unsigned char * +loader_png (FILE *f, int *w, int *h, int *t) +{ + return load_module_relay ("png", + &_gdk_imlib_LoadPNG, + &_gdk_imlib_SavePNG, f, w, h, t); +} + +static unsigned char * +loader_ppm (FILE *f, int *w, int *h, int *t) +{ + return load_module_relay ("ppm", + &_gdk_imlib_LoadPPM, + &_gdk_imlib_SavePPM, f, w, h, t); +} + +static gint +saver_tiff (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return save_module_relay ("tiff", + (gdk_imlib_loader_fn *) &_gdk_imlib_LoadTIFF, + &_gdk_imlib_SaveTIFF, im, file, info); +} + +static gint +saver_png (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return save_module_relay ("png", + &_gdk_imlib_LoadPNG, + &_gdk_imlib_SavePNG, im, file, info); +} + +static gint +saver_jpeg (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return save_module_relay ("jpeg", + &_gdk_imlib_LoadJPEG, + &_gdk_imlib_SaveJPEG, im, file, info); +} + +static gint +saver_ps (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return save_module_relay ("ps", NULL, &_gdk_imlib_SavePS, im, file, info); +} + +static gint +saver_ppm (GdkImlibImage *im, char *file, GdkImlibSaveInfo *info) +{ + return save_module_relay ("ppm", &_gdk_imlib_LoadPPM, &_gdk_imlib_SavePPM, im, file, info); +} + +static GdkImlibImage * +inline_png (unsigned char *data, int data_size) +{ + get_module_loader_saver ("png", + (void **) &_gdk_imlib_LoadPNG, load_fail_fn, + (void **) &_gdk_imlib_SavePNG, save_fail_fn); + return _gdk_imlib_inlined_png_to_image (data, data_size); +} + +static GdkImlibImage * +loader_alpha_png (char *file) +{ + get_module_loader_saver ("png", + (void **) &_gdk_imlib_LoadPNG, load_fail_fn, + (void **) &_gdk_imlib_SavePNG, save_fail_fn); + return _gdk_imlib_load_alpha_png (file); +} +#endif + + +GdkImlibImage * +gdk_imlib_inlined_png_to_image(unsigned char *data, int data_size) +{ + return _gdk_imlib_inlined_png_to_image (data, data_size); +} + +GdkImlibImage * +gdk_imlib_load_alpha (char *file) +{ + /* We only support png for now */ + return _gdk_imlib_load_alpha_png (file); +} diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/rend.c b/debian/imlib/imlib-1.9.15/gdk_imlib/rend.c new file mode 100644 index 00000000..fa38e23b --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/rend.c @@ -0,0 +1,7062 @@ +#define _GNU_SOURCE +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +GdkPixmap * +gdk_imlib_pixmap_foreign_new(gint width, gint height, + gint depth, Pixmap pmap) +{ + GdkPixmap *pixmap; + GdkWindowPrivate *private; + GdkWindowPrivate *window_private; + + private = g_new0(GdkWindowPrivate, 1); + pixmap = (GdkPixmap *) private; + + window_private = (GdkWindowPrivate *) id->x.gdk_win; + + private->xdisplay = window_private->xdisplay; + private->window_type = GDK_WINDOW_PIXMAP; + private->xwindow = pmap; + private->colormap = id->x.gdk_cmap; + private->children = NULL; + private->parent = NULL; + private->x = 0; + private->y = 0; + private->width = width; + private->height = height; + private->resize_count = 0; + private->ref_count = 1; + private->destroyed = 0; + + gdk_xid_table_insert(&private->xwindow, pixmap); + + return pixmap; +} + +gint +gdk_imlib_best_color_match(gint * r, gint * g, gint * b) +{ + int i; + int dif; + int dr, dg, db; + int col; + int mindif = 0x7fffffff; + + col = 0; + g_return_val_if_fail(id->x.disp, -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 12: + *r = dr - (dr & 0xf0); + *g = dg - (dg & 0xf0); + *b = db - (db & 0xf0); + return ((dr & 0xf0) << 8) | ((dg & 0xf0) << 3) | ((db & 0xf0) >> 3); + break; + 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; +} + +gint +_gdk_imlib_index_best_color_match(gint * r, gint * g, gint * b) +{ + int i; + int dif; + int dr, dg, db; + int col; + int mindif = 0x7fffffff; + + col = 0; + g_return_val_if_fail(id->x.disp, -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 12: + *r = dr - (dr & 0xf0); + *g = dg - (dg & 0xf0); + *b = db - (db & 0xf0); + return ((dr & 0xf0) << 8) | ((dg & 0xf0) << 3) | ((db & 0xf0) >> 3); + break; + 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; +} + +static void +grender_shaped_15_fast_dither(GdkImlibImage * 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; + } +} + +static void +grender_shaped_15_fast_dither_ordered(GdkImlibImage * 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; + } +} + +static void +grender_15_fast_dither(GdkImlibImage * 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; + } +} + +static void +grender_15_fast_dither_ordered(GdkImlibImage * 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; + } +} + +static void +grender_shaped_16_fast_dither(GdkImlibImage * 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; + } +} + +static void +grender_shaped_16_fast_dither_ordered(GdkImlibImage * 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; + } +} + +static void +grender_16_fast_dither(GdkImlibImage * 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; + } +} + +static void +grender_16_fast_dither_ordered(GdkImlibImage * 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; + } +} + +static void +grender_shaped_15_dither(GdkImlibImage * 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); + } + } + } +} + +static void +grender_shaped_15_dither_ordered(GdkImlibImage * 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, 1, 5}, + {6, 2, 7, 3}, + {1, 5, 0, 4}, + {7, 3, 6, 2} + }; + 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); + } + } + } +} + +static void +grender_15_dither(GdkImlibImage * 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); + } + } +} + +static void +grender_15_dither_ordered(GdkImlibImage * 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); + } + } +} + +static void +grender_shaped_16_dither(GdkImlibImage * 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); + } + } + } +} + +static void +grender_shaped_16_dither_ordered(GdkImlibImage * 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); + } + } + } +} + +static void +grender_16_dither(GdkImlibImage * 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); + } + } +} + +static void +grender_16_dither_ordered(GdkImlibImage * 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); + } + } +} + +static void +grender_shaped_15_fast(GdkImlibImage * 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; + } +} + +static void +grender_15_fast(GdkImlibImage * 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; + } +} + +static void +grender_shaped_16_fast(GdkImlibImage * 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; + } +} + +static void +grender_16_fast(GdkImlibImage * 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; + } +} + +static void +grender_shaped_24_fast(GdkImlibImage * 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; + } + } + } +} + +static void +grender_24_fast(GdkImlibImage * 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->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; + } + } + } +} + +static void +grender_shaped_32_fast(GdkImlibImage * 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; + } + } +} + +static void +grender_32_fast(GdkImlibImage * 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; + } + } +} + +static void +grender_shaped_15(GdkImlibImage * 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); + } + } + } +} + +static void +grender_15(GdkImlibImage * 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); + } + } +} + +static void +grender_shaped_16(GdkImlibImage * 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); + } + } + } +} + +static void +grender_16(GdkImlibImage * 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); + } + } +} + +static void +grender_shaped_12(GdkImlibImage * 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 & 0xf0) << 8) | ((g & 0xf0) << 3) | ((b & 0xf0) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +static void +grender_12(GdkImlibImage * 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 & 0xf0) << 8) | ((g & 0xf0) << 3) | ((b & 0xf0) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +static void +grender_shaped_24(GdkImlibImage * 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); + } + } + } + } +} + +static void +grender_24(GdkImlibImage * 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); + } + } + } +} + +static void +grender_shaped(GdkImlibImage * 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 = gdk_imlib_best_color_match(&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 = gdk_imlib_best_color_match(&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 = gdk_imlib_best_color_match(&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 = gdk_imlib_best_color_match(&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 12: + printf("iPAQ1\n"); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_15_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_shaped_24_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_32_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 12: + grender_shaped_12(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_15_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_shaped_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + case 32: + grender_shaped_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + break; + } +} + +static void +grender(GdkImlibImage * 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 = gdk_imlib_best_color_match(&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 = gdk_imlib_best_color_match(&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 = gdk_imlib_best_color_match(&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 = gdk_imlib_best_color_match(&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 12: + printf("iPAQ3\n"); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_fast_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_fast_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_24_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_32_fast(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 12: + grender_12(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_dither_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_dither(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 32: + grender_24(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + break; + } + } +} + +static void +grender_shaped_15_fast_dither_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_shaped_15_fast_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_15_fast_dither_mod(GdkImlibImage * 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 = 0, eg = 0, eb = 0; + unsigned char *ptr2; + unsigned short *img; + int jmp; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_15_fast_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_shaped_16_fast_dither_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_shaped_16_fast_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_16_fast_dither_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_16_fast_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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; + } +} + +static void +grender_shaped_15_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } + } +} + +static void +grender_15_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } +} + +static void +grender_shaped_16_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } + } +} + +static void +grender_16_dither_mod_ordered(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } +} + +static void +grender_shaped_15_dither_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } + } +} + +static void +grender_15_dither_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } +} + +static void +grender_shaped_16_dither_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } + } +} + +static void +grender_16_dither_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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); + } + } +} + +static void +grender_shaped_15_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +static void +grender_15_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +static void +grender_shaped_16_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + } + img += jmp; + } +} + +static void +grender_16_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + *img++ = val; + } + img += jmp; + } +} + +static void +grender_shaped_24_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + } + } + img += jmp; + } + } + } +} + +static void +grender_24_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + *img++ = r; + *img++ = b; + *img++ = g; + } + img += jmp; + } + } + } +} + +static void +grender_shaped_32_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + } + img += jmp; + } + } +} + +static void +grender_32_fast_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = (g << 16) | (b << 8) | r; + *img++ = val; + } + img += jmp; + } + } +} + +static void +grender_shaped_15_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +static void +grender_15_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +static void +grender_shaped_16_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } + } +} + +static void +grender_16_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +static void +grender_12_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = ((r & 0xf0) << 8) | ((g & 0xf0) << 3) | ((b & 0xf0) >> 3); + XPutPixel(xim, x, y, val); + } + } +} + +static void +grender_shaped_24_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } + } +} + +static void +grender_24_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = (g << 16) | (b << 8) | r; + XPutPixel(xim, x, y, val); + } + } + } +} + +static void +grender_shaped_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 12: + printf("iPAQ5\n"); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_15_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_shaped_24_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_32_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 12: + printf("iPAQ6\n"); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + grender_shaped_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_15_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_shaped_16_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_shaped_16_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_shaped_16_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_shaped_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + case 32: + grender_shaped_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + break; + } +} + +static void +grender_mod(GdkImlibImage * 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; + GdkImlibModifierMap *map = im->map; + + 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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->bmap[b]; + val = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = gdk_imlib_best_color_match(&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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 = map->rmap[r]; + g = map->gmap[g]; + b = map->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 12: + printf("iPAQ7\n"); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_fast_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_fast_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + case 32: + if (xim->bits_per_pixel == 24) + grender_24_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_32_fast_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + } + else + { + switch (bpp) + { + case 8: + break; + case 12: + grender_12_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 15: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_15_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_15_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_15_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 16: + if (id->render_type == RT_DITHER_TRUECOL) + { + if (id->ordered_dither) + grender_16_dither_mod_ordered(im, w, h, xim, sxim, er1, er2, xarray, yarray); + else + grender_16_dither_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + } + else + grender_16_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 24: + grender_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + case 32: + grender_24_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray); + break; + default: + break; + } + break; + } + } +} + +gint +gdk_imlib_render(GdkImlibImage * im, gint w, gint h) +{ + XImage *xim, *sxim; + GC tgc, stgc; + XGCValues gcv; + unsigned char *tmp, *stmp, **yarray, *ptr22; + int w3, x, inc, pos, *error, *er1, *er2, *xarray, ex, bpp, + huge; + Pixmap pmap, mask; + GdkPixmap *pm, *mm; + int shared_pixmap, shared_image, ok; + + sxim = NULL; + xim = NULL; + tmp = NULL; + stmp = NULL; + pmap = 0; + mask = 0; + tgc = 0; + stgc = 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; + _gdk_imlib_find_pixmap(im, w, h, &pm, &mm); + if (pm) + { + im->width = w; + im->height = h; + im->pixmap = pm; + if (mm) + im->shape_mask = mm; + else + im->shape_mask = NULL; + return 1; + } + } + if (im->pixmap) + _gdk_imlib_free_pixmappmap(im->pixmap); + im->pixmap = NULL; + im->shape_mask = NULL; +/* 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)) + { + shared_pixmap = 1; + shared_image = 0; + } + 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); + 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); + 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); + 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 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); + stgc = XCreateGC(id->x.disp, mask, GCGraphicsExposures, &gcv); + } + } + } + } + } + } + } + } + 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; + } + 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; + } + 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->map) + { + if (id->x.depth <= 8) + grender_shaped(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender_shaped(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + else + { + if (id->x.depth <= 8) + grender_shaped_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender_shaped_mod(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); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, mask); + 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 = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, p2); + im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, 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); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = gdk_imlib_pixmap_foreign_new(w, h, 1, mask); + XDestroyImage(xim); + XDestroyImage(sxim); + xim = NULL; + sxim = NULL; + XFreeGC(id->x.disp, tgc); + XFreeGC(id->x.disp, stgc); + } + } + else + { + if (!im->map) + { + if (id->x.depth <= 8) + grender(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender(im, w, h, xim, sxim, er1, er2, xarray, yarray, id->x.render_depth); + } + else + { + if (id->x.depth <= 8) + grender_mod(im, w, h, xim, sxim, er1, er2, xarray, yarray, 8); + else + grender_mod(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); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = NULL; + 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 = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, p2); + im->shape_mask = NULL; + 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); + im->pixmap = gdk_imlib_pixmap_foreign_new(w, h, id->x.depth, pmap); + im->shape_mask = NULL; + 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 */ + _gdk_imlib_add_pixmap(im, w, h, xim, sxim); + return 1; +} diff --git a/debian/imlib/imlib-1.9.15/gdk_imlib/save.c b/debian/imlib/imlib-1.9.15/gdk_imlib/save.c new file mode 100644 index 00000000..1c865281 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/save.c @@ -0,0 +1,173 @@ +#define _GNU_SOURCE +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" + +gint +gdk_imlib_save_image(GdkImlibImage * im, char *file, GdkImlibSaveInfo * info) +{ + char *ext; + char cmd[10240]; + FILE *f; + GdkImlibSaveInfo 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 = _gdk_imlib_GetExtension(file); + + if ((!strcasecmp(ext, "ppm")) || (!strcasecmp(ext, "pnm")) || (!strcasecmp (ext, "pgm"))) + { + return _gdk_imlib_SavePPM (im, file, info); + } + else if (!strcasecmp(ext, "ps")) + { + return _gdk_imlib_SavePS (im, file, info); + } + else if ((!strcasecmp(ext, "jpeg")) || (!strcasecmp(ext, "jpg"))) + { + return _gdk_imlib_SaveJPEG (im, file, info); + } + else if (!strcasecmp(ext, "png")) + { + return _gdk_imlib_SavePNG (im, file, info); + } + else if ((!strcasecmp(ext, "tiff")) || (!strcasecmp(ext, "tif"))) + { + return _gdk_imlib_SaveTIFF (im, file, info); + } +#if 0 + /* Get rid of the "helpers" */ + if (id->fallback) + { + f = _gdk_imlib_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)) + { + _gdk_imlib_close_helper(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + _gdk_imlib_close_helper(f); + return 0; + } + if (_gdk_imlib_close_helper(f)) + return 0; + return 1; + } + + if (!strcasecmp(ext, "jpeg")) + g_snprintf(cmd, sizeof(cmd), "%%H -quality %i -progressive -outfile %%s", 100 * info->quality / 256); + else if (!strcasecmp(ext, "jpg")) + g_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 = _gdk_imlib_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)) + { + _gdk_imlib_close_helper(f); + return 0; + } + if (!fwrite(im->rgb_data, 1, (im->rgb_width * im->rgb_height * 3), f)) + { + _gdk_imlib_close_helper(f); + return 0; + } + if (_gdk_imlib_close_helper(f)) + return 0; + return 1; + } + } + } +#endif + fprintf(stderr, "gdk_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/gdk_imlib/t-load.c b/debian/imlib/imlib-1.9.15/gdk_imlib/t-load.c new file mode 100644 index 00000000..fa3df7fc --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/t-load.c @@ -0,0 +1,23 @@ +#include <stdio.h> +#include "gdk_imlib.h" + + +int +main( int ac, char* av[] ) +{ + GdkImlibImage* img; + + if (ac != 2) { + fprintf( stderr, "usage: %s filename\n", av[0] ); + return 33; + } + + img = gdk_imlib_load_image( 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/gdk_imlib/utils.c b/debian/imlib/imlib-1.9.15/gdk_imlib/utils.c new file mode 100644 index 00000000..bfcd6129 --- /dev/null +++ b/debian/imlib/imlib-1.9.15/gdk_imlib/utils.c @@ -0,0 +1,2018 @@ +#define _GNU_SOURCE +#include <config.h> +#include "gdk_imlib.h" +#define id _gdk_imlib_data +#include "gdk_imlib_private.h" +#include <gdk/gdkx.h> + +void +_gdk_imlib_calc_map_tables(GdkImlibImage * im) +{ + int i; + double g, b, c, ii, v; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + + /* If we are using the defaults, there is no need to get a map */ + 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 (im->map){ + free (im->map); + im->map = NULL; + } + return; + } + + if (!im->map){ + im->map = (GdkImlibModifierMap *) malloc (sizeof (GdkImlibModifierMap)); + if (!im->map) + return; + } + + map = im->map; + + 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; + map->rmap[i] = (unsigned char)v; + map->gmap[i] = (unsigned char)v; + map->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)map->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; + map->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)map->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; + map->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)map->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; + map->bmap[i] = (unsigned char)v; + } + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); +} + +gint +gdk_imlib_load_file_to_pixmap(char *filename, GdkPixmap ** pmap, GdkBitmap ** mask) +{ + GdkImlibImage *im; + + g_return_val_if_fail (filename != NULL, 0); + + im = gdk_imlib_load_image(filename); + if (!im) + { + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (!gdk_imlib_render(im, im->rgb_width, im->rgb_height)) + { + gdk_imlib_destroy_image(im); + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (pmap) + *pmap = gdk_imlib_move_image(im); + if (mask) + *mask = gdk_imlib_move_mask(im); + gdk_imlib_destroy_image(im); + return 1; +} + +void +gdk_imlib_set_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + im->mod.gamma = mod->gamma; + im->mod.brightness = mod->brightness; + im->mod.contrast = mod->contrast; + _gdk_imlib_calc_map_tables(im); +} + +void +gdk_imlib_set_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + im->rmod.gamma = mod->gamma; + im->rmod.brightness = mod->brightness; + im->rmod.contrast = mod->contrast; + _gdk_imlib_calc_map_tables(im); +} + +void +gdk_imlib_set_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + im->gmod.gamma = mod->gamma; + im->gmod.brightness = mod->brightness; + im->gmod.contrast = mod->contrast; + _gdk_imlib_calc_map_tables(im); +} + +void +gdk_imlib_set_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + im->bmod.gamma = mod->gamma; + im->bmod.brightness = mod->brightness; + im->bmod.contrast = mod->contrast; + _gdk_imlib_calc_map_tables(im); +} + +void +gdk_imlib_get_image_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + mod->gamma = im->mod.gamma; + mod->brightness = im->mod.brightness; + mod->contrast = im->mod.contrast; + _gdk_imlib_calc_map_tables(im); +} + +void +gdk_imlib_get_image_red_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + mod->gamma = im->rmod.gamma; + mod->brightness = im->rmod.brightness; + mod->contrast = im->rmod.contrast; +} + +void +gdk_imlib_get_image_green_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + mod->gamma = im->gmod.gamma; + mod->brightness = im->gmod.brightness; + mod->contrast = im->gmod.contrast; +} + +void +gdk_imlib_get_image_blue_modifier(GdkImlibImage * im, GdkImlibColorModifier * mod) +{ + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + mod->gamma = im->bmod.gamma; + mod->brightness = im->bmod.brightness; + mod->contrast = im->bmod.contrast; +} + +void +gdk_imlib_set_image_red_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + char same = 1; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + map = im->map; + if (map){ + for (i = 0; i < 256; i++) + { + if (map->rmap[i] != mod[i]) + { + same = 0; + i = 256; + } + } + if (same) + return; + } else { + im->map = map = (GdkImlibModifierMap *) malloc (sizeof (GdkImlibModifierMap)); + if (!map) + return; + } + + for (i = 0; i < 256; i++) + map->rmap[i] = mod[i]; + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); + im->mod.contrast = 257; +} + +void +gdk_imlib_set_image_green_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + char same = 1; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + map = im->map; + + if (map){ + for (i = 0; i < 256; i++) + { + if (map->gmap[i] != mod[i]) + { + same = 0; + i = 256; + } + } + if (same) + return; + } else { + im->map = map = (GdkImlibModifierMap *) malloc (sizeof (GdkImlibModifierMap)); + if (!map) + return; + } + for (i = 0; i < 256; i++) + map->gmap[i] = mod[i]; + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); + im->mod.contrast = 257; +} + +void +gdk_imlib_set_image_blue_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + char same = 1; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + map = im->map; + + if (map){ + for (i = 0; i < 256; i++) + { + if (map->bmap[i] != mod[i]) + { + same = 0; + i = 256; + } + } + if (same) + return; + } else { + im->map = map = (GdkImlibModifierMap *) malloc (sizeof (GdkImlibModifierMap)); + if (!map) + return; + } + for (i = 0; i < 256; i++) + map->bmap[i] = mod[i]; + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); + im->mod.contrast = 257; +} + +void +gdk_imlib_get_image_red_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + map = im->map; + if (map) + for (i = 0; i < 256; i++) + mod[i] = map->rmap[i]; + else + for (i = 0; i < 256; i++) + mod[i] = i; +} + +void +gdk_imlib_get_image_green_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + map = im->map; + + if (map) + for (i = 0; i < 256; i++) + mod[i] = map->gmap[i]; + else + for (i = 0; i < 256; i++) + mod[i] = i; +} + +void +gdk_imlib_get_image_blue_curve(GdkImlibImage * im, unsigned char *mod) +{ + int i; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + g_return_if_fail (mod != NULL); + + map = im->map; + if (map) + for (i = 0; i < 256; i++) + mod[i] = map->bmap[i]; + else + for (i = 0; i < 256; i++) + mod[i] = i; +} + +void +gdk_imlib_apply_modifiers_to_rgb(GdkImlibImage * im) +{ + int x, y; + unsigned char *ptr; + GdkImlibModifierMap *map; + + g_return_if_fail (im != NULL); + + ptr = im->rgb_data; + map = im->map; + if (map) + for (y = 0; y < im->rgb_height; y++) + { + for (x = 0; x < im->rgb_width; x++) + { + *ptr = map->rmap[*ptr]; + ptr++; + *ptr = map->gmap[*ptr]; + ptr++; + *ptr = map->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; + _gdk_imlib_calc_map_tables(im); + _gdk_imlib_dirty_images(im); + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); +} + +void +gdk_imlib_crop_image(GdkImlibImage * im, gint x, gint y, gint w, gint 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 = _gdk_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; + _gdk_imlib_dirty_images(im); + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); +} + +GdkImlibImage * +gdk_imlib_crop_and_clone_image(GdkImlibImage * im, int x, int y, int w, int h) +{ + unsigned char *data; + int xx, yy, w3, w4; + unsigned char *ptr1, *ptr2; + GdkImlibImage *im2; + char *s; + + if (!im) + return NULL; + im2 = malloc(sizeof(GdkImlibImage)); + if (!im2) + return NULL; + + im2->map = 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 = _gdk_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) + { + g_snprintf(s, strlen(im->filename) + 320, "%s_%lx_%x", im->filename, time(NULL), rand()); + im2->filename = strdup(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; + _gdk_imlib_calc_map_tables(im2); + +#if 0 + if (id->cache.on_image) + _gdk_imlib_add_image(im2, im2->filename); +#endif + + return im2; +} +void +gdk_imlib_changed_image(GdkImlibImage * im) +{ + if (!im) + return; + _gdk_imlib_dirty_images(im); + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); +} + +void +gdk_imlib_apply_image(GdkImlibImage * im, GdkWindow * p) +{ + GdkPixmap *pp, *mm; + int w, h; + + if (!im || !p) + return; + gdk_window_get_size(p, &w, &h); + if (w <= 0 || h <= 0) + return; + gdk_imlib_render(im, w, h); + pp = gdk_imlib_move_image(im); + mm = gdk_imlib_move_mask(im); + gdk_window_set_back_pixmap(p, pp, 0); + if (mm) + gdk_window_shape_combine_mask(p, mm, 0, 0); + gdk_window_clear(p); + gdk_imlib_free_pixmap(pp); +} + +void +gdk_imlib_paste_image(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h) +{ + GdkGC *gc; + GdkPixmap *pp, *mm; + + if (!im || !p) + return; + if ((w <= 0) || (h <= 0)) + return; + gc = gdk_gc_new(p); + gdk_imlib_render(im, w, h); + pp = gdk_imlib_move_image(im); + mm = gdk_imlib_move_mask(im); + if (mm) + { + gdk_gc_set_clip_mask(gc, mm); + gdk_gc_set_clip_origin(gc, x, y); + } + gdk_draw_pixmap(p, gc, pp, 0, 0, x, y, w, h); + gdk_imlib_free_pixmap(pp); + gdk_gc_destroy(gc); +} + +void +gdk_imlib_paste_image_border(GdkImlibImage * im, GdkWindow * p, gint x, gint y, gint w, gint h) +{ + GdkGC *gc; + GdkPixmap *pp, *mm; + + if (!im) + return; + + if (w <= 0 || h <= 0) + return; + gc = gdk_gc_new(p); + gdk_imlib_render(im, w, h); + pp = gdk_imlib_move_image(im); + mm = gdk_imlib_move_mask(im); + if (mm) + { + gdk_gc_set_clip_mask(gc, mm); + gdk_gc_set_clip_origin(gc, x, y); + } + if ((w <= (im->border.left + im->border.right)) || + (h <= (im->border.top + im->border.bottom))) + gdk_draw_pixmap(p, gc, pp, 0, 0, x, y, w, h); + else + { + gdk_draw_pixmap(p, gc, pp, + 0, 0, + x, y, + w, im->border.top); + gdk_draw_pixmap(p, gc, pp, + 0, h - im->border.bottom, + x, y + (h - im->border.bottom), + w, im->border.bottom); + gdk_draw_pixmap(p, gc, pp, + 0, im->border.top, + x, y + im->border.top, + im->border.left, h - (im->border.top + im->border.bottom)); + gdk_draw_pixmap(p, gc, pp, + 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)); + } + gdk_imlib_free_pixmap(pp); + gdk_gc_destroy(gc); +} + +void +gdk_imlib_flip_image_horizontal(GdkImlibImage * 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; + _gdk_imlib_dirty_images(im); + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); +} + +void +gdk_imlib_flip_image_vertical(GdkImlibImage * 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; + _gdk_imlib_dirty_images(im); + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); +} + +void +gdk_imlib_rotate_image(GdkImlibImage * im, gint 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 = _gdk_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; + _gdk_imlib_dirty_images(im); + _gdk_imlib_dirty_pixmaps(im); + _gdk_imlib_clean_caches(); +} + +GdkImlibImage * +gdk_imlib_create_image_from_data(unsigned char *data, unsigned char *alpha, gint w, gint h) +{ + GdkImlibImage *im; + char s[128]; + + g_return_val_if_fail (data != NULL, NULL); + g_return_val_if_fail (w > 0, NULL); + g_return_val_if_fail (h > 0, NULL); + + im = malloc(sizeof(GdkImlibImage)); + if (!im) + return NULL; + + im->map = NULL; + im->rgb_width = w; + im->rgb_height = h; + im->rgb_data = _gdk_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; + g_snprintf(s, sizeof(s), "creat_%lx_%x", time(NULL), rand()); + im->filename = strdup(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 = NULL; + im->shape_mask = NULL; + 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->map = NULL; + +#if 0 + if (id->cache.on_image) + _gdk_imlib_add_image(im, im->filename); +#endif + + _gdk_imlib_calc_map_tables(im); + return im; +} + +GdkImlibImage * +gdk_imlib_clone_image(GdkImlibImage * im) +{ + GdkImlibImage *im2; + char *s; + + g_return_val_if_fail (im != NULL, NULL); + + im2 = malloc(sizeof(GdkImlibImage)); + if (!im2) + return NULL; + im2->map = NULL; + im2->rgb_width = im->rgb_width; + im2->rgb_height = im->rgb_height; + im2->rgb_data = _gdk_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) + { + g_snprintf(s, strlen(im->filename) + 320, "%s_%lx_%x", im->filename, time(NULL), rand()); + im2->filename = strdup(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 = NULL; + im2->shape_mask = NULL; + 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; + _gdk_imlib_calc_map_tables(im2); + +#if 0 + if (id->cache.on_image) + _gdk_imlib_add_image(im2, im2->filename); +#endif + + return im2; +} + +GdkImlibImage * +gdk_imlib_clone_scaled_image(GdkImlibImage * im, int w, int h) +{ + GdkImlibImage *im2; + char *s; + + g_return_val_if_fail (im != NULL, NULL); + g_return_val_if_fail (w > 0, NULL); + g_return_val_if_fail (h > 0, NULL); + + im2 = malloc(sizeof(GdkImlibImage)); + if (!im2) + return NULL; + im2->map = NULL; + im2->rgb_width = w; + im2->rgb_height = h; + im2->rgb_data = _gdk_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, "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, "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) + { + g_snprintf(s, strlen(im->filename) + 320, "%s_%lx_%x_%x_%x", im->filename, time(NULL), w, h, rand()); + im2->filename = strdup(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 = NULL; + im2->shape_mask = NULL; + 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; + _gdk_imlib_calc_map_tables(im2); + +#if 0 + if (id->cache.on_image) + _gdk_imlib_add_image(im2, im2->filename); +#endif + + return im2; +} + +GdkImlibImage * +gdk_imlib_create_image_from_xpm_data(char **data) +{ + GdkImlibImage *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]; + + g_return_val_if_fail (data != NULL, NULL); + + j = 0; + cmap = NULL; + + im = malloc(sizeof(GdkImlibImage)); + if (!im) + return NULL; + im->map = NULL; + im->filename = NULL; + count = 0; + transp = 0; + done = 0; + + 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, "gdk_imlib ERROR: XPM data wth colors > 32766 not supported\n"); + free(im); + return NULL; + } + if (cpp > 5) + { + fprintf(stderr, "gdk_imlib ERROR: XPM data with characters per pixel > 5 not supported\n"); + free(im); + return NULL; + } + if (w > 32767) + { + fprintf(stderr, "gdk_imlib ERROR: Image width > 32767 pixels for data\n"); + free(im); + return NULL; + } + if (h > 32767) + { + fprintf(stderr, "gdk_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 = _gdk_malloc_image(im->rgb_width, im->rgb_height); + if (!im->rgb_data) + { + free(cmap); + free(im); + return NULL; + } + im->alpha_data = NULL; + g_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 = NULL; + im->shape_mask = NULL; + 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; + } + + i = 100 + strlen (data[0]) + strlen (data[1]) + strlen (data[3]); + if (im->filename) free (im->filename); + im->filename = (char *) malloc (i); + if (im->filename) + g_snprintf (im->filename, i, "%p.%i.%i.%s.%s.%s", data, im->rgb_width, + im->rgb_height, data[0], data[1], data [3]); + +#if 0 + if (id->cache.on_image) + _gdk_imlib_add_image(im, im->filename); +#endif + + _gdk_imlib_calc_map_tables(im); + free(cmap); + return im; +} + +gint +gdk_imlib_data_to_pixmap(char **data, GdkPixmap ** pmap, GdkBitmap ** mask) +{ + GdkImlibImage *im; + + g_return_val_if_fail (data != NULL, 0); + + im = gdk_imlib_create_image_from_xpm_data(data); + if (!im) + { + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (!gdk_imlib_render(im, im->rgb_width, im->rgb_height)) + { + gdk_imlib_destroy_image(im); + if (pmap) + *pmap = NULL; + if (mask) + *mask = NULL; + return 0; + } + if (pmap) + *pmap = gdk_imlib_move_image(im); + if (mask) + *mask = gdk_imlib_move_mask(im); + gdk_imlib_kill_image(im); + return 1; +} + +static char x_error = 0; + +static void +__handle_x_error(Display * d, XErrorEvent * ev) +{ + d = NULL; + ev = NULL; + x_error = 1; +} + +GdkImlibImage * +gdk_imlib_create_image_from_drawable(GdkWindow * gwin, GdkBitmap * gmask, + 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; + GdkImlibImage *im; + GdkImlibColor ctab[256]; + Display *disp; + Window win; + Pixmap mask; + + inx = 0; + iny = 0; + w = width; + h = height; + vis = id->x.visual; + disp = id->x.disp; + win = GDK_WINDOW_XWINDOW(gwin); + if (gmask) + mask = GDK_WINDOW_XWINDOW(gmask); + else + mask = 0; + 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; + } + 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 = _gdk_malloc_image(width, height); + 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 = gdk_imlib_create_image_from_data(data, NULL, width, height); + free(data); + return im; + } + else + return NULL; +} |