Sat Jul 12 21:06:14 EDT 2003

(KainX)

Patch from Yuri Hudobin <glassy_ape@users.sourceforge.net>
for Freetype2 support.


SVN revision: 7158
This commit is contained in:
Michael Jennings 2003-07-13 01:09:17 +00:00
parent 0896467998
commit 7c65468d34
49 changed files with 19098 additions and 18074 deletions

View File

@ -23,3 +23,4 @@ Lightman (Franz Marini) <marini@pcmenelao.mi.infn.it>
Mark Bainter <mark-e@cymry.org> Mark Bainter <mark-e@cymry.org>
Brian Lindholm <lindholm@aol.com> Brian Lindholm <lindholm@aol.com>
Renchi Raju <renchi@pooh.tam.uiuc.edu> Renchi Raju <renchi@pooh.tam.uiuc.edu>
Yuri Hudobin <glassy_ape@users.sourceforge.net>

View File

@ -2974,3 +2974,11 @@ Thu Apr 3 20:48:27 EST 2003
Minor Makefile.am tweak which apparently helps portability. Minor Makefile.am tweak which apparently helps portability.
_______________________________________________ _______________________________________________
Sat Jul 12 21:06:14 EDT 2003
(KainX)
Patch from Yuri Hudobin <glassy_ape@users.sourceforge.net>
for Freetype2 support.
_______________________________________________

4
TODO
View File

@ -1,6 +1,6 @@
* line code doesnt draw nice liens when clipping - fix * line code doesnt draw nice liens when clipping - fix
* filled polygons can break fill bounds on corner cases - fix * filled polygons can break fill bounds on corner cases - fix
* imlib2 needs freetype 1.x - shoudl graduate to 2.x * go thru TODOs and FIXMEs
evas2 has fixed code for these 3 in it that work just fine. just need to evas2 has fixed code for these 2 in it that work just fine. just need to
port over (should be fairly easy). port over (should be fairly easy).

View File

@ -7,14 +7,30 @@ AM_INIT_AUTOMAKE(imlib2, 1.0.7)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
freetype_libs=-lttf dnl here was freetype stuff (1)
AC_ARG_WITH(ttf,
[ --with-ttf=DIR use freetype rooted at <DIR>], # check for freetype
[freetype_libs="$freetype_libs -L$withval/lib"
freetype_includes="-I$withval/include" AC_ARG_WITH(freetype-config,
CPPFLAGS="$CPPFLAGS $freetype_includes" [ --with-freetype-config=FREETYPE_CONFIG use freetype-config specified ],
LIBS="$LIBS $freetype_libs" [
PROG_CONFIG=$withval;
echo "using "$PROG_CONFIG" for freetype-config";
],[
PROG="freetype-config";
AC_PATH_PROG(PROG_CONFIG, $PROG, "", $PATH)
]) ])
if [ test -z $PROG_CONFIG ]; then
echo $PROG " is not in your \$PATH. Please ensure it is.";
echo "You may need to install the librarya and/or development packages";
echo "that contain this configure-script.";
echo "FATAL ERROR. ABORT.";
exit -1;
fi
freetype_cflags=`$PROG_CONFIG --cflags`
freetype_libs=`$PROG_CONFIG --libs`
dnl /here was freetype stuff (1)
mmx=no mmx=no
AC_ARG_ENABLE(mmx,[ --enable-mmx attempt compiling using mmx assembly [default=yes]], AC_ARG_ENABLE(mmx,[ --enable-mmx attempt compiling using mmx assembly [default=yes]],
@ -138,47 +154,12 @@ LTLIBOBJS=`echo "$LIB@&t@OBJS" |
sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'` sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
AC_SUBST(LTLIBOBJS) AC_SUBST(LTLIBOBJS)
AC_CHECK_LIB(ttf, TT_Init_FreeType, TTF_LIBS=-lttf, [ dnl here was freetype headers checking
echo ""
echo "ERROR: Imlib 2 needs a system with libttf.so (TrueType Font Library)"
echo "You can obtain it from:"
echo "ftp://ftp.enlightenment.org/pub/enlightenment/"
echo "ftp://www.rasterman.com/pub/enlightenment/"
echo "You can also obtain it from:"
echo "http://www.freetype.org/"
echo "You can obtain some truetype fonts from:"
echo "http://voyager.cns.ohiou.edu/~sadkins/web_library/fonts/font_archive/"
echo ""
AC_MSG_ERROR([Fatal Error: no FreeType detected.])], -lm)
AC_CHECK_HEADERS(freetype.h freetype/freetype.h freetype1/freetype/freetype.h, [ break])
AC_CHECK_HEADER(freetype.h, [ ftype=yes ], [ ftype=no ])
AC_CHECK_HEADER(freetype/freetype.h, [ ftype_ftype=yes ], [ ftype_ftype=no ])
AC_CHECK_HEADER(freetype1/freetype/freetype.h, [ ftype1_ftype=yes ], [ ftype1_ftype=no ])
if test x$ftype = xno; then
if test x$ftype_ftype = xno; then dnl /here was freetype headers checking
if test x$ftype1_ftype = xno; then
echo ""
echo "ERROR: freetype.h not found in freetype.h or freetype/freetype.h include"
echo "paths. (ie /usr/include, /usr/local/include etc.). You need the freetype"
echo "header files to build Imlib 2. This may mean you have to install the"
echo "freetype-devel packages for your distribution or if all else fails"
echo "find the source for freetype and install that somewhere where Imlib 2"
echo "can find the header files."
echo ""
echo "You can obtain it from:"
echo "ftp://ftp.enlightenment.org/pub/enlightenment/"
echo "ftp://www.rasterman.com/pub/enlightenment/"
echo "You can also obtain it from:"
echo "http://www.freetype.org/"
echo "You can obtain some truetype fonts from:"
echo "http://voyager.cns.ohiou.edu/~sadkins/web_library/fonts/font_archive/"
echo ""
AC_MSG_ERROR([Fatal Error: no FreeType header files detected.])
fi
fi
fi
AC_CHECK_LIB(dl, dlopen, dlopen_libs=-ldl) AC_CHECK_LIB(dl, dlopen, dlopen_libs=-ldl)
EXTRA_LIBS="-L/usr/local/lib -L/usr/X11R6/lib" EXTRA_LIBS="-L/usr/local/lib -L/usr/X11R6/lib"
@ -323,8 +304,11 @@ AC_SUBST(x_includes)
AC_SUBST(x_ldflags) AC_SUBST(x_ldflags)
AC_SUBST(x_libs) AC_SUBST(x_libs)
AC_SUBST(dlopen_libs) AC_SUBST(dlopen_libs)
AC_SUBST(freetype_cflags)
AC_SUBST(freetype_libs) AC_SUBST(freetype_libs)
AC_SUBST(freetype_includes)
dnl AC_SUBST(freetype_libs)
dnl AC_SUBST(freetype_includes)
AC_CONFIG_FILES([imlib2-config imlib2.pc Makefile loaders/Makefile src/Makefile test/Makefile \ AC_CONFIG_FILES([imlib2-config imlib2.pc Makefile loaders/Makefile src/Makefile test/Makefile \
filters/Makefile demo/Makefile doc/Makefile \ filters/Makefile demo/Makefile doc/Makefile \

View File

@ -6,14 +6,28 @@ AM_INIT_AUTOMAKE(imlib2, 1.0.7)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
freetype_libs=-lttf dnl here was freetype stuff (1)
AC_ARG_WITH(ttf,
[ --with-ttf=DIR use freetype rooted at <DIR>], AC_ARG_WITH(freetype-config,
[freetype_libs="$freetype_libs -L$withval/lib" [ --with-freetype-config=FREETYPE_CONFIG use freetype-config specified ],
freetype_includes="-I$withval/include" [
CPPFLAGS="$CPPFLAGS $freetype_includes" PROG_CONFIG=$withval;
LIBS="$LIBS $freetype_libs" echo "using "$PROG_CONFIG" for freetype-config";
],[
PROG="freetype-config";
AC_PATH_PROG(PROG_CONFIG, $PROG, "", $PATH)
]) ])
if [ test -z $PROG_CONFIG ]; then
echo $PROG " is not in your \$PATH. Please ensure it is.";
echo "You may need to install the librarya and/or development packages";
echo "that contain this configure-script.";
echo "FATAL ERROR. ABORT.";
exit -1;
fi
freetype_cflags=`$PROG_CONFIG --cflags`
freetype_libs=`$PROG_CONFIG --libs`
dnl /here was freetype stuff (1)
mmx=no mmx=no
AC_ARG_ENABLE(mmx,[ --enable-mmx attempt compiling using mmx assembly [default=yes]], AC_ARG_ENABLE(mmx,[ --enable-mmx attempt compiling using mmx assembly [default=yes]],
@ -120,45 +134,15 @@ AC_SUBST(X_OBJS)
LTLIBOBJS=`echo "$LIBOBJS" | sed 's,.o ,.lo ,g;s,.o$,.lo,'` LTLIBOBJS=`echo "$LIBOBJS" | sed 's,.o ,.lo ,g;s,.o$,.lo,'`
AC_SUBST(LTLIBOBJS) AC_SUBST(LTLIBOBJS)
AC_CHECK_LIB(ttf, TT_Init_FreeType, TTF_LIBS=-lttf, [
echo ""
echo "ERROR: Imlib 2 needs a system with libttf.so (TrueType Font Library)"
echo "You can obtain it from:"
echo "ftp://ftp.enlightenment.org/pub/enlightenment/"
echo "ftp://www.rasterman.com/pub/enlightenment/"
echo "You can also obtain it from:"
echo "http://www.freetype.org/"
echo ""
AC_MSG_ERROR([Fatal Error: no FreeType detected.])], -lm)
AC_CHECK_HEADERS(freetype.h freetype/freetype.h freetype1/freetype/freetype.h, [ break]) dnl here was freetype headers checking
AC_CHECK_HEADER(freetype.h, [ ftype=yes ], [ ftype=no ])
AC_CHECK_HEADER(freetype/freetype.h, [ ftype_ftype=yes ], [ ftype_ftype=no ])
AC_CHECK_HEADER(freetype1/freetype/freetype.h, [ ftype1_ftype=yes ], [ ftype1_ftype=no ])
dnl /here was freetype headers checking
if test x$ftype = xno; then
if test x$ftype_ftype = xno; then
if test x$ftype1_ftype = xno; then
echo ""
echo "ERROR: freetype.h not found in freetype.h or freetype/freetype.h include"
echo "paths. (ie /usr/include, /usr/local/include etc.). You need the freetype"
echo "header files to build Imlib 2. This may mean you have to install the"
echo "freetype-devel packages for your distribution or if all else fails"
echo "find the source for freetype and install that somewhere where Imlib 2"
echo "can find the header files."
echo ""
echo "You can obtain it from:"
echo "ftp://ftp.enlightenment.org/pub/enlightenment/"
echo "ftp://www.rasterman.com/pub/enlightenment/"
echo "You can also obtain it from:"
echo "http://www.freetype.org/"
echo "You can obtain some truetype fonts from:"
echo "http://voyager.cns.ohiou.edu/~sadkins/web_library/fonts/font_archive/"
echo ""
AC_MSG_ERROR([Fatal Error: no FreeType header files detected.])
fi
fi
fi
AC_CHECK_LIB(dl, dlopen, dlopen_libs=-ldl) AC_CHECK_LIB(dl, dlopen, dlopen_libs=-ldl)
EXTRA_LIBS="-L/usr/local/lib -L/usr/X11R6/lib" EXTRA_LIBS="-L/usr/local/lib -L/usr/X11R6/lib"
@ -304,7 +288,10 @@ AC_SUBST(x_ldflags)
AC_SUBST(x_libs) AC_SUBST(x_libs)
AC_SUBST(dlopen_libs) AC_SUBST(dlopen_libs)
AC_SUBST(freetype_libs) AC_SUBST(freetype_libs)
AC_SUBST(freetype_includes) AC_SUBST(freetype_cflags)
dnl AC_SUBST(freetype_libs)
dnl AC_SUBST(freetype_includes)
AC_OUTPUT(imlib2-config imlib2.pc Makefile loaders/Makefile src/Makefile test/Makefile \ AC_OUTPUT(imlib2-config imlib2.pc Makefile loaders/Makefile src/Makefile test/Makefile \
filters/Makefile demo/Makefile doc/Makefile \ filters/Makefile demo/Makefile doc/Makefile \

View File

@ -12,80 +12,80 @@
#define PROG_NAME "imconvert" #define PROG_NAME "imconvert"
static void usage(int exit_status); static void usage(int exit_status);
int int
main(int argc, main(int argc, char **argv)
char **argv)
{ {
char *dot, *colon, *n, *oldn; char *dot, *colon, *n, *oldn;
Imlib_Image im; Imlib_Image im;
/* I'm just plain being lazy here.. get our basename. */ /* I'm just plain being lazy here.. get our basename. */
for (oldn = n = argv[0]; n; oldn = n) n = strchr(++oldn, '/'); for (oldn = n = argv[0]; n; oldn = n)
if (argc < 3 || !strcmp(argv[1], "-h")) usage(-1); n = strchr(++oldn, '/');
if((im = imlib_load_image(argv[1])) == NULL) if (argc < 3 || !strcmp(argv[1], "-h"))
{ usage(-1);
fprintf(stderr, PROG_NAME ": Error loading image: %s\n", argv[1]); if ((im = imlib_load_image(argv[1])) == NULL)
exit(-1); {
} fprintf(stderr, PROG_NAME ": Error loading image: %s\n", argv[1]);
exit(-1);
}
/* we only care what format the export format is. */ /* we only care what format the export format is. */
imlib_context_set_image(im); imlib_context_set_image(im);
/* hopefully the last one will be the one we want.. */ /* hopefully the last one will be the one we want.. */
dot = strrchr(argv[2], '.'); dot = strrchr(argv[2], '.');
/* if there's a format, snarf it and set the format. */ /* if there's a format, snarf it and set the format. */
if (dot && *(dot + 1)) if (dot && *(dot + 1))
{ {
colon = strrchr(++dot, ':'); colon = strrchr(++dot, ':');
/* if a db file with a key, export it to a db. */ /* if a db file with a key, export it to a db. */
if (colon && *(colon + 1)) if (colon && *(colon + 1))
{ {
*colon = 0; *colon = 0;
/* beats having to look for strcasecmp() */ /* beats having to look for strcasecmp() */
if (!strncmp(dot, "db", 2) || !strncmp(dot, "dB", 2) || if (!strncmp(dot, "db", 2) || !strncmp(dot, "dB", 2) ||
!strncmp(dot, "DB", 2) || !strncmp(dot, "Db", 2)) !strncmp(dot, "DB", 2) || !strncmp(dot, "Db", 2))
{ {
imlib_image_set_format("db"); imlib_image_set_format("db");
} }
*colon = ':'; *colon = ':';
} }
else else
{ {
char *p, *q; char *p, *q;
/* max length of 8 for format name. seems reasonable. */ /* max length of 8 for format name. seems reasonable. */
q = p = malloc(8); q = p = malloc(8);
memset(p, 0, 8); memset(p, 0, 8);
strncpy(p, dot, (strlen(dot) < 9) ? strlen(dot) : 8); strncpy(p, dot, (strlen(dot) < 9) ? strlen(dot) : 8);
/* Imlib2 only recognizes lowercase formats. convert it. */ /* Imlib2 only recognizes lowercase formats. convert it. */
for (q[8] = 0; *q; q++) *q = tolower(*q); for (q[8] = 0; *q; q++)
imlib_image_set_format(p); *q = tolower(*q);
free(p); imlib_image_set_format(p);
} free(p);
dot--; }
} dot--;
else }
imlib_image_set_format("jpg"); else
imlib_image_set_format("jpg");
imlib_save_image(argv[2]); imlib_save_image(argv[2]);
return 0; return 0;
} }
static void usage(int exit_status) static void
usage(int exit_status)
{ {
fprintf(exit_status?stderr:stdout, fprintf(exit_status ? stderr : stdout,
PROG_NAME ": Convert images between formats (part of the " \ PROG_NAME ": Convert images between formats (part of the "
"Imlib2 package)\n\n" \ "Imlib2 package)\n\n"
"Usage: " PROG_NAME " [ -h | <image1> <image2[.fmt]> ]\n" \ "Usage: " PROG_NAME " [ -h | <image1> <image2[.fmt]> ]\n"
" <fmt> defaults to jpg if not provided; images in " \ " <fmt> defaults to jpg if not provided; images in "
"edb files are supported via\n" \ "edb files are supported via\n"
" the file.db:/key/name convention.\n" \ " the file.db:/key/name convention.\n"
" -h shows this help.\n\n"); " -h shows this help.\n\n");
exit(exit_status); exit(exit_status);
} }

View File

@ -13,22 +13,22 @@
#include <errno.h> #include <errno.h>
#include "Imlib2.h" #include "Imlib2.h"
Display *disp; Display *disp;
Window win; Window win;
Pixmap pm = 0; Pixmap pm = 0;
Visual *vis; Visual *vis;
Colormap cm; Colormap cm;
int depth; int depth;
int image_width = 0, image_height = 0; int image_width = 0, image_height = 0;
Imlib_Image bg_im = NULL; Imlib_Image bg_im = NULL;
static int
progress(Imlib_Image im, char percent, int update_x, int update_y,
int update_w, int update_h);
static int static int
progress(Imlib_Image im, char percent, int update_x, int update_y, progress(Imlib_Image im, char percent, int update_x, int update_y,
int update_w, int update_h); int update_w, int update_h)
static int
progress(Imlib_Image im, char percent, int update_x, int update_y,
int update_w, int update_h)
{ {
/* first time it's called */ /* first time it's called */
imlib_context_set_drawable(pm); imlib_context_set_drawable(pm);
@ -37,57 +37,57 @@ progress(Imlib_Image im, char percent, int update_x, int update_y,
imlib_context_set_blend(0); imlib_context_set_blend(0);
if (image_width == 0) if (image_width == 0)
{ {
int x, y, onoff; int x, y, onoff;
imlib_context_set_image(im); imlib_context_set_image(im);
image_width = imlib_image_get_width(); image_width = imlib_image_get_width();
image_height = imlib_image_get_height(); image_height = imlib_image_get_height();
if (pm) if (pm)
XFreePixmap(disp, pm); XFreePixmap(disp, pm);
pm = XCreatePixmap(disp, win, image_width, image_height, depth); pm = XCreatePixmap(disp, win, image_width, image_height, depth);
imlib_context_set_drawable(pm); imlib_context_set_drawable(pm);
if (bg_im) if (bg_im)
{ {
imlib_context_set_image(bg_im); imlib_context_set_image(bg_im);
imlib_free_image_and_decache(); imlib_free_image_and_decache();
} }
bg_im = imlib_create_image(image_width, image_height); bg_im = imlib_create_image(image_width, image_height);
imlib_context_set_image(bg_im); imlib_context_set_image(bg_im);
for (y = 0; y < image_height; y += 8) for (y = 0; y < image_height; y += 8)
{ {
onoff = (y / 8) & 0x1; onoff = (y / 8) & 0x1;
for (x = 0; x < image_width; x += 8) for (x = 0; x < image_width; x += 8)
{ {
if (onoff) if (onoff)
imlib_context_set_color(144, 144, 144, 255); imlib_context_set_color(144, 144, 144, 255);
else else
imlib_context_set_color(100, 100, 100, 255); imlib_context_set_color(100, 100, 100, 255);
imlib_image_fill_rectangle(x, y, 8, 8); imlib_image_fill_rectangle(x, y, 8, 8);
onoff++; onoff++;
if (onoff == 2) if (onoff == 2)
onoff = 0; onoff = 0;
} }
} }
imlib_render_image_part_on_drawable_at_size(0, 0, image_width, image_height, imlib_render_image_part_on_drawable_at_size(0, 0, image_width,
0, 0, image_width, image_height); image_height, 0, 0,
XSetWindowBackgroundPixmap(disp, win, pm); image_width, image_height);
XResizeWindow(disp, win, image_width, image_height); XSetWindowBackgroundPixmap(disp, win, pm);
XMapWindow(disp, win); XResizeWindow(disp, win, image_width, image_height);
XSync(disp, False); XMapWindow(disp, win);
XSync(disp, False);
} }
imlib_context_set_anti_alias(0); imlib_context_set_anti_alias(0);
imlib_context_set_dither(0); imlib_context_set_dither(0);
imlib_context_set_blend(1); imlib_context_set_blend(1);
imlib_blend_image_onto_image(im, 0, imlib_blend_image_onto_image(im, 0,
update_x, update_y, update_x, update_y,
update_w, update_h, update_w, update_h,
update_x, update_y, update_x, update_y, update_w, update_h);
update_w, update_h);
imlib_context_set_blend(0); imlib_context_set_blend(0);
imlib_render_image_part_on_drawable_at_size(update_x, update_y, imlib_render_image_part_on_drawable_at_size(update_x, update_y,
update_w, update_h, update_w, update_h,
update_x, update_y, update_x, update_y,
update_w, update_h); update_w, update_h);
XSetWindowBackgroundPixmap(disp, win, pm); XSetWindowBackgroundPixmap(disp, win, pm);
XClearArea(disp, win, update_x, update_y, update_w, update_h, False); XClearArea(disp, win, update_x, update_y, update_w, update_h, False);
XFlush(disp); XFlush(disp);
@ -95,24 +95,24 @@ progress(Imlib_Image im, char percent, int update_x, int update_y,
} }
int int
main (int argc, char **argv) main(int argc, char **argv)
{ {
Imlib_Image *im = NULL; Imlib_Image *im = NULL;
char *file = NULL; char *file = NULL;
int no = 1; int no = 1;
if (argc < 2) if (argc < 2)
return 1; return 1;
file = argv[no]; file = argv[no];
disp = XOpenDisplay(NULL); disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp)); vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp));
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10, 10, win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 10, 10,
0, 0, 0); 0, 0, 0);
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
ButtonMotionMask | PointerMotionMask); ButtonMotionMask | PointerMotionMask);
imlib_context_set_display(disp); imlib_context_set_display(disp);
imlib_context_set_visual(vis); imlib_context_set_visual(vis);
imlib_context_set_colormap(cm); imlib_context_set_colormap(cm);
@ -122,222 +122,224 @@ main (int argc, char **argv)
im = imlib_load_image(file); im = imlib_load_image(file);
while (!im) while (!im)
{ {
no++; no++;
if (no == argc) if (no == argc)
exit(0); exit(0);
file = argv[no]; file = argv[no];
image_width = 0; image_width = 0;
im = imlib_load_image(file); im = imlib_load_image(file);
imlib_context_set_image(im); imlib_context_set_image(im);
} }
if (!im) if (!im)
{ {
fprintf(stderr, "Image format not available\n"); fprintf(stderr, "Image format not available\n");
exit(0); exit(0);
} }
for(;;) for (;;)
{ {
int x, y, b, count, fdsize, xfd, timeout = 0; int x, y, b, count, fdsize, xfd, timeout = 0;
XEvent ev; XEvent ev;
static int zoom_mode = 0, zx, zy; static int zoom_mode = 0, zx, zy;
static double zoom = 1.0; static double zoom = 1.0;
struct timeval tval; struct timeval tval;
fd_set fdset; fd_set fdset;
double t1; double t1;
XFlush(disp); XFlush(disp);
while (XPending(disp)) while (XPending(disp))
{ {
XNextEvent(disp, &ev); XNextEvent(disp, &ev);
switch (ev.type) switch (ev.type)
{ {
case ButtonPress: case ButtonPress:
b = ev.xbutton.button; b = ev.xbutton.button;
x = ev.xbutton.x; x = ev.xbutton.x;
y = ev.xbutton.y; y = ev.xbutton.y;
if (b == 3) if (b == 3)
{ {
zoom_mode = 1; zoom_mode = 1;
zx = x; zx = x;
zy = y; zy = y;
imlib_context_set_drawable(pm); imlib_context_set_drawable(pm);
imlib_context_set_image(bg_im); imlib_context_set_image(bg_im);
imlib_context_set_anti_alias(0); imlib_context_set_anti_alias(0);
imlib_context_set_dither(0); imlib_context_set_dither(0);
imlib_context_set_blend(0); imlib_context_set_blend(0);
imlib_render_image_part_on_drawable_at_size imlib_render_image_part_on_drawable_at_size
(0, 0, image_width, image_height, (0, 0, image_width, image_height,
0, 0, image_width, image_height); 0, 0, image_width, image_height);
XSetWindowBackgroundPixmap(disp, win, pm); XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win); XClearWindow(disp, win);
} }
break; break;
case ButtonRelease: case ButtonRelease:
b = ev.xbutton.button; b = ev.xbutton.button;
x = ev.xbutton.x; x = ev.xbutton.x;
y = ev.xbutton.y; y = ev.xbutton.y;
if (b == 3) if (b == 3)
zoom_mode = 0; zoom_mode = 0;
if (b == 1) if (b == 1)
{ {
no++; no++;
if (no == argc) if (no == argc)
no = argc - 1; no = argc - 1;
file = argv[no]; file = argv[no];
image_width = 0; image_width = 0;
zoom = 1.0; zoom = 1.0;
zoom_mode = 0; zoom_mode = 0;
imlib_context_set_image(im); imlib_context_set_image(im);
imlib_free_image_and_decache(); imlib_free_image_and_decache();
im = imlib_load_image(file); im = imlib_load_image(file);
while (!im) while (!im)
{ {
no++; no++;
if (no == argc) if (no == argc)
exit(0); exit(0);
file = argv[no]; file = argv[no];
image_width = 0; image_width = 0;
im = imlib_load_image(file); im = imlib_load_image(file);
} }
imlib_context_set_image(im); imlib_context_set_image(im);
} }
if (b == 2) if (b == 2)
{ {
no--; no--;
if (no == 0) if (no == 0)
no = 1; no = 1;
file = argv[no]; file = argv[no];
image_width = 0; image_width = 0;
zoom = 1.0; zoom = 1.0;
zoom_mode = 0; zoom_mode = 0;
imlib_context_set_image(im); imlib_context_set_image(im);
imlib_free_image_and_decache(); imlib_free_image_and_decache();
im = imlib_load_image(file); im = imlib_load_image(file);
while (!im) while (!im)
{ {
no--; no--;
if (no == 0) if (no == 0)
no = 1; no = 1;
file = argv[no]; file = argv[no];
image_width = 0; image_width = 0;
im = imlib_load_image(file); im = imlib_load_image(file);
} }
imlib_context_set_image(im); imlib_context_set_image(im);
} }
break; break;
case MotionNotify: case MotionNotify:
while (XCheckTypedWindowEvent(disp, win, MotionNotify, &ev)); while (XCheckTypedWindowEvent
x = ev.xmotion.x; (disp, win, MotionNotify, &ev));
y = ev.xmotion.y; x = ev.xmotion.x;
if (zoom_mode) y = ev.xmotion.y;
{ if (zoom_mode)
int sx, sy, sw, sh, dx, dy, dw, dh; {
int sx, sy, sw, sh, dx, dy, dw, dh;
zoom = ((double)x - (double)zx) / 32.0; zoom = ((double)x - (double)zx) / 32.0;
if (zoom < 0) if (zoom < 0)
zoom = 1.0 + ((zoom * 32.0) / ((double)(zx + 1))); zoom = 1.0 + ((zoom * 32.0) / ((double)(zx + 1)));
else else
zoom += 1.0; zoom += 1.0;
if (zoom <= 0.0001) if (zoom <= 0.0001)
zoom = 0.0001; zoom = 0.0001;
if (zoom > 1.0) if (zoom > 1.0)
{ {
dx = 0; dx = 0;
dy = 0; dy = 0;
dw = image_width; dw = image_width;
dh = image_height; dh = image_height;
sx = zx - (zx / zoom); sx = zx - (zx / zoom);
sy = zy - (zy / zoom); sy = zy - (zy / zoom);
sw = image_width / zoom; sw = image_width / zoom;
sh = image_height / zoom; sh = image_height / zoom;
} }
else else
{ {
dx = zx - (zx * zoom); dx = zx - (zx * zoom);
dy = zy - (zy * zoom); dy = zy - (zy * zoom);
dw = image_width * zoom; dw = image_width * zoom;
dh = image_height * zoom; dh = image_height * zoom;
sx = 0; sx = 0;
sy = 0; sy = 0;
sw = image_width; sw = image_width;
sh = image_height; sh = image_height;
} }
imlib_context_set_anti_alias(0); imlib_context_set_anti_alias(0);
imlib_context_set_dither(0); imlib_context_set_dither(0);
imlib_context_set_blend(0); imlib_context_set_blend(0);
imlib_context_set_image(bg_im); imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh); (sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm); XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win); XClearWindow(disp, win);
XFlush(disp); XFlush(disp);
timeout = 1; timeout = 1;
} }
default: default:
break; break;
} }
t1 = 0.2; t1 = 0.2;
tval.tv_sec = (long)t1; tval.tv_sec = (long)t1;
tval.tv_usec = (long)((t1 - ((double)tval.tv_sec)) * 1000000); tval.tv_usec = (long)((t1 - ((double)tval.tv_sec)) * 1000000);
xfd = ConnectionNumber(disp); xfd = ConnectionNumber(disp);
fdsize = xfd + 1; fdsize = xfd + 1;
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(xfd, &fdset); FD_SET(xfd, &fdset);
if (timeout) if (timeout)
count = select(fdsize, &fdset, NULL, NULL, &tval); count = select(fdsize, &fdset, NULL, NULL, &tval);
else else
count = select(fdsize, &fdset, NULL, NULL, NULL); count = select(fdsize, &fdset, NULL, NULL, NULL);
if (count < 0) if (count < 0)
{ {
if ((errno == ENOMEM) || (errno == EINVAL) || (errno == EBADF)) if ((errno == ENOMEM) || (errno == EINVAL)
exit(1); || (errno == EBADF))
} exit(1);
else }
{ else
if ((count == 0) && (timeout)) {
{ if ((count == 0) && (timeout))
int sx, sy, sw, sh, dx, dy, dw, dh; {
int sx, sy, sw, sh, dx, dy, dw, dh;
if (zoom > 1.0) if (zoom > 1.0)
{ {
dx = 0; dx = 0;
dy = 0; dy = 0;
dw = image_width; dw = image_width;
dh = image_height; dh = image_height;
sx = zx - (zx / zoom); sx = zx - (zx / zoom);
sy = zy - (zy / zoom); sy = zy - (zy / zoom);
sw = image_width / zoom; sw = image_width / zoom;
sh = image_height / zoom; sh = image_height / zoom;
} }
else else
{ {
dx = zx - (zx * zoom); dx = zx - (zx * zoom);
dy = zy - (zy * zoom); dy = zy - (zy * zoom);
dw = image_width * zoom; dw = image_width * zoom;
dh = image_height * zoom; dh = image_height * zoom;
sx = 0; sx = 0;
sy = 0; sy = 0;
sw = image_width; sw = image_width;
sh = image_height; sh = image_height;
} }
imlib_context_set_anti_alias(1); imlib_context_set_anti_alias(1);
imlib_context_set_dither(1); imlib_context_set_dither(1);
imlib_context_set_blend(0); imlib_context_set_blend(0);
imlib_context_set_image(bg_im); imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh); (sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm); XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win); XClearWindow(disp, win);
XFlush(disp); XFlush(disp);
timeout = 0; timeout = 0;
} }
} }
} }
} }
return 0; return 0;
} }

View File

@ -16,245 +16,273 @@
#define PI (4 * atan(1)) #define PI (4 * atan(1))
static Imlib_Image static Imlib_Image
bump_map(Imlib_Image im, pIFunctionParam par) bump_map(Imlib_Image im, pIFunctionParam par)
{ {
Imlib_Image map = im; Imlib_Image map = im;
pIFunctionParam ptr; pIFunctionParam ptr;
double an = 0, el = 30, d = 0x200; double an = 0, el = 30, d = 0x200;
double red = 0x200, green = 0x200, blue = 0x200; double red = 0x200, green = 0x200, blue = 0x200;
double ambient = 0; double ambient = 0;
int free_map = 0; int free_map = 0;
DATA32 *src; DATA32 *src;
DATA32 *mp, *mpy, *mpp; DATA32 *mp, *mpy, *mpp;
double z, z_2, x2, y2; double z, z_2, x2, y2;
int w, h, i, j, w2, h2, wh2, mx, my; int w, h, i, j, w2, h2, wh2, mx, my;
for (ptr = par; ptr; ptr = ptr->next) { for (ptr = par; ptr; ptr = ptr->next)
ASSIGN_IMAGE("map", map); {
ASSIGN_INT ("angle", an); ASSIGN_IMAGE("map", map);
ASSIGN_INT ("elevation", el); ASSIGN_INT("angle", an);
ASSIGN_INT ("depth", d); ASSIGN_INT("elevation", el);
ASSIGN_INT ("red", red); ASSIGN_INT("depth", d);
ASSIGN_INT ("green", green); ASSIGN_INT("red", red);
ASSIGN_INT ("blue", blue); ASSIGN_INT("green", green);
ASSIGN_INT ("ambient", ambient); ASSIGN_INT("blue", blue);
} ASSIGN_INT("ambient", ambient);
if (!map) return im; }
if (!map)
return im;
red /= 0x100; red /= 0x100;
green /= 0x100; green /= 0x100;
blue /= 0x100; blue /= 0x100;
ambient /= 0x100; ambient /= 0x100;
d /= 0x100; d /= 0x100;
imlib_context_set_image(im); imlib_context_set_image(im);
src = imlib_image_get_data(); src = imlib_image_get_data();
w = imlib_image_get_width(); w = imlib_image_get_width();
h = imlib_image_get_height(); h = imlib_image_get_height();
imlib_context_set_image(map); imlib_context_set_image(map);
mpp = imlib_image_get_data_for_reading_only(); mpp = imlib_image_get_data_for_reading_only();
w2 = imlib_image_get_width(); w2 = imlib_image_get_width();
h2 = imlib_image_get_height(); h2 = imlib_image_get_height();
wh2 = w2 * h2; wh2 = w2 * h2;
an *= (PI / 180); an *= (PI / 180);
el *= (PI / 180); el *= (PI / 180);
x2 = sin(an) * cos(el); x2 = sin(an) * cos(el);
y2 = cos(an) * cos(el); y2 = cos(an) * cos(el);
z = sin(el); z = sin(el);
d /= (255 * (255 + 255 + 255)); d /= (255 * (255 + 255 + 255));
z_2 = z * z; z_2 = z * z;
my = h2; my = h2;
for (j = h; --j >= 0; ) { for (j = h; --j >= 0;)
mp = mpp; {
mpp += w2; mp = mpp;
if (--my <= 0) { mpp += w2;
mpp -= wh2; if (--my <= 0)
my = h2; {
} mpp -= wh2;
mpy = mpp; my = h2;
mx = w2; }
for (i = w; --i >= 0; ) { mpy = mpp;
double x1, y1, v; mx = w2;
int r, g, b, gr; for (i = w; --i >= 0;)
{
double x1, y1, v;
int r, g, b, gr;
gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)); gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp));
y1 = d * (double)(A_VAL(mpy) * (R_VAL(mpy) + y1 = d * (double)(A_VAL(mpy) * (R_VAL(mpy) +
G_VAL(mpy) + B_VAL(mpy)) - gr); G_VAL(mpy) + B_VAL(mpy)) - gr);
mp++; mp++;
mpy++; mpy++;
if (--mx <= 0) { if (--mx <= 0)
mp -= w2; {
mpy -= w2; mp -= w2;
mx = w2; mpy -= w2;
} mx = w2;
x1 = d * (double)(A_VAL(mp) * (R_VAL(mp) + }
G_VAL(mp) + B_VAL(mp)) - gr); x1 = d * (double)(A_VAL(mp) * (R_VAL(mp) +
v = x1 * x2 + y1 * y2 + z; G_VAL(mp) + B_VAL(mp)) - gr);
v /= sqrt((x1 * x1) + (y1 * y1) + 1.0); v = x1 * x2 + y1 * y2 + z;
v += ambient; v /= sqrt((x1 * x1) + (y1 * y1) + 1.0);
r = v * R_VAL(src) * red; v += ambient;
g = v * G_VAL(src) * green; r = v * R_VAL(src) * red;
b = v * B_VAL(src) * blue; g = v * G_VAL(src) * green;
if (r < 0) r = 0; b = v * B_VAL(src) * blue;
if (r > 255) r = 255; if (r < 0)
if (g < 0) g = 0; r = 0;
if (g > 255) g = 255; if (r > 255)
if (b < 0) b = 0; r = 255;
if (b > 255) b = 255; if (g < 0)
R_VAL(src) = r; g = 0;
G_VAL(src) = g; if (g > 255)
B_VAL(src) = b; g = 255;
if (b < 0)
b = 0;
if (b > 255)
b = 255;
R_VAL(src) = r;
G_VAL(src) = g;
B_VAL(src) = b;
src++; src++;
} }
} }
if (free_map) { if (free_map)
imlib_context_set_image(map); {
imlib_free_image(); imlib_context_set_image(map);
} imlib_free_image();
return im; }
return im;
} }
static Imlib_Image static Imlib_Image
bump_map_point(Imlib_Image im, pIFunctionParam par) bump_map_point(Imlib_Image im, pIFunctionParam par)
{ {
Imlib_Image map = im; Imlib_Image map = im;
pIFunctionParam ptr; pIFunctionParam ptr;
double x = 0, y = 0, z = 30, d = 0x200; double x = 0, y = 0, z = 30, d = 0x200;
double red = 0x200, green = 0x200, blue = 0x200; double red = 0x200, green = 0x200, blue = 0x200;
double ambient = 0; double ambient = 0;
int free_map = 0; int free_map = 0;
DATA32 *src; DATA32 *src;
DATA32 *mp, *mpy, *mpp; DATA32 *mp, *mpy, *mpp;
double z_2, x2, y2; double z_2, x2, y2;
int w, h, i, j, w2, h2, wh2, mx, my; int w, h, i, j, w2, h2, wh2, mx, my;
for (ptr = par; ptr; ptr = ptr->next) { for (ptr = par; ptr; ptr = ptr->next)
ASSIGN_IMAGE("map", map); {
ASSIGN_INT ("x", x); ASSIGN_IMAGE("map", map);
ASSIGN_INT ("y", y); ASSIGN_INT("x", x);
ASSIGN_INT ("z", z); ASSIGN_INT("y", y);
ASSIGN_INT ("depth", d); ASSIGN_INT("z", z);
ASSIGN_INT ("red", red); ASSIGN_INT("depth", d);
ASSIGN_INT ("green", green); ASSIGN_INT("red", red);
ASSIGN_INT ("blue", blue); ASSIGN_INT("green", green);
ASSIGN_INT ("ambient", ambient); ASSIGN_INT("blue", blue);
} ASSIGN_INT("ambient", ambient);
if (!map) return im; }
if (!map)
return im;
red /= 0x100; red /= 0x100;
green /= 0x100; green /= 0x100;
blue /= 0x100; blue /= 0x100;
ambient /= 0x100; ambient /= 0x100;
d /= 0x100; d /= 0x100;
imlib_context_set_image(im); imlib_context_set_image(im);
src = imlib_image_get_data(); src = imlib_image_get_data();
w = imlib_image_get_width(); w = imlib_image_get_width();
h = imlib_image_get_height(); h = imlib_image_get_height();
imlib_context_set_image(map); imlib_context_set_image(map);
mpp = imlib_image_get_data_for_reading_only(); mpp = imlib_image_get_data_for_reading_only();
w2 = imlib_image_get_width(); w2 = imlib_image_get_width();
h2 = imlib_image_get_height(); h2 = imlib_image_get_height();
wh2 = w2 * h2; wh2 = w2 * h2;
d /= (255 * (255 + 255 + 255)); d /= (255 * (255 + 255 + 255));
z_2 = z * z; z_2 = z * z;
my = h2; my = h2;
y2 = -y; y2 = -y;
for (j = h; --j >= 0; ) { for (j = h; --j >= 0;)
mp = mpp; {
mpp += w2; mp = mpp;
if (--my <= 0) { mpp += w2;
mpp -= wh2; if (--my <= 0)
my = h2; {
} mpp -= wh2;
mpy = mpp; my = h2;
mx = w2; }
x2 = -x; mpy = mpp;
for (i = w; --i >= 0; ) { mx = w2;
double x1, y1, v; x2 = -x;
int r, g, b, gr; for (i = w; --i >= 0;)
{
double x1, y1, v;
int r, g, b, gr;
gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp)); gr = A_VAL(mp) * (R_VAL(mp) + G_VAL(mp) + B_VAL(mp));
y1 = d * (double)(A_VAL(mpy) * (R_VAL(mpy) + y1 = d * (double)(A_VAL(mpy) * (R_VAL(mpy) +
G_VAL(mpy) + B_VAL(mpy)) - gr); G_VAL(mpy) + B_VAL(mpy)) - gr);
mp++; mp++;
mpy++; mpy++;
if (--mx <= 0) { if (--mx <= 0)
mp -= w2; {
mpy -= w2; mp -= w2;
mx = w2; mpy -= w2;
} mx = w2;
x1 = d * (double)(A_VAL(mp) * (R_VAL(mp) + }
G_VAL(mp) + B_VAL(mp)) - gr); x1 = d * (double)(A_VAL(mp) * (R_VAL(mp) +
v = x1 * x2 + y1 * y2 + z; G_VAL(mp) + B_VAL(mp)) - gr);
v /= sqrt((x1 * x1) + (y1 * y1) + 1.0); v = x1 * x2 + y1 * y2 + z;
v /= sqrt((x2 * x2) + (y2 * y2) + z_2); v /= sqrt((x1 * x1) + (y1 * y1) + 1.0);
v += ambient; v /= sqrt((x2 * x2) + (y2 * y2) + z_2);
r = v * R_VAL(src) * red; v += ambient;
g = v * G_VAL(src) * green; r = v * R_VAL(src) * red;
b = v * B_VAL(src) * blue; g = v * G_VAL(src) * green;
if (r < 0) r = 0; b = v * B_VAL(src) * blue;
if (r > 255) r = 255; if (r < 0)
if (g < 0) g = 0; r = 0;
if (g > 255) g = 255; if (r > 255)
if (b < 0) b = 0; r = 255;
if (b > 255) b = 255; if (g < 0)
R_VAL(src) = r; g = 0;
G_VAL(src) = g; if (g > 255)
B_VAL(src) = b; g = 255;
if (b < 0)
b = 0;
if (b > 255)
b = 255;
R_VAL(src) = r;
G_VAL(src) = g;
B_VAL(src) = b;
x2++; x2++;
src++; src++;
} }
y2++; y2++;
} }
if (free_map) { if (free_map)
imlib_context_set_image(map); {
imlib_free_image(); imlib_context_set_image(map);
} imlib_free_image();
return im; }
return im;
} }
void void
init(struct imlib_filter_info *info) init(struct imlib_filter_info *info)
{ {
char *filters[] = { "bump_map_point", "bump_map" }; char *filters[] = { "bump_map_point", "bump_map" };
int i = (sizeof(filters) / sizeof(*filters)); int i = (sizeof(filters) / sizeof(*filters));
info->name = strdup( "Bump Mapping" ); info->name = strdup("Bump Mapping");
info->author = strdup( "Willem Monsuwe (willem@stack.nl)" ); info->author = strdup("Willem Monsuwe (willem@stack.nl)");
info->description = strdup( "Provides bumpmapping to a point and bumpmapping from an infinite light source. *very* cool." ); info->description =
strdup
("Provides bumpmapping to a point and bumpmapping from an infinite light source. *very* cool.");
info->num_filters = i; info->num_filters = i;
info->filters = malloc(sizeof(char *) * i); info->filters = malloc(sizeof(char *) * i);
while (--i >= 0) while (--i >= 0)
info->filters[i] = strdup(filters[i]); info->filters[i] = strdup(filters[i]);
} }
void void
deinit() deinit()
{ {
return; return;
} }
void * void *
exec(char *filter, void *im, pIFunctionParam par) exec(char *filter, void *im, pIFunctionParam par)
{ {
if (!strcmp(filter, "bump_map")) if (!strcmp(filter, "bump_map"))
return bump_map((Imlib_Image)im, par); return bump_map((Imlib_Image) im, par);
if (!strcmp(filter, "bump_map_point")) if (!strcmp(filter, "bump_map_point"))
return bump_map_point((Imlib_Image)im, par); return bump_map_point((Imlib_Image) im, par);
return im; return im;
} }

View File

@ -27,173 +27,239 @@
static void static void
mod_brightness(double t[256], double v) mod_brightness(double t[256], double v)
{ {
int i; int i;
for (i = 256; --i >= 0; )
t[i] += v; for (i = 256; --i >= 0;)
t[i] += v;
} }
static void static void
mod_contrast(double t[256], double v) mod_contrast(double t[256], double v)
{ {
int i; int i;
for (i = 256; --i >= 0; )
t[i] = ((t[i] - 0.5) * v) + 0.5; for (i = 256; --i >= 0;)
t[i] = ((t[i] - 0.5) * v) + 0.5;
} }
static void static void
mod_gamma(double t[256], double v) mod_gamma(double t[256], double v)
{ {
int i; int i;
for (i = 256; --i >= 0; )
t[i] = pow(t[i], 1 / v); for (i = 256; --i >= 0;)
t[i] = pow(t[i], 1 / v);
} }
static void static void
mod_tint(double t[256], double v) mod_tint(double t[256], double v)
{ {
int i; int i;
for (i = 256; --i >= 0; )
t[i] *= v; for (i = 256; --i >= 0;)
t[i] *= v;
} }
static Imlib_Image static Imlib_Image
colormod(Imlib_Image im, pIFunctionParam par) colormod(Imlib_Image im, pIFunctionParam par)
{ {
double a_d[256], r_d[256], g_d[256], b_d[256]; double a_d[256], r_d[256], g_d[256], b_d[256];
DATA8 a_b[256], r_b[256], g_b[256], b_b[256]; DATA8 a_b[256], r_b[256], g_b[256], b_b[256];
pIFunctionParam ptr; pIFunctionParam ptr;
int x = 0, y = 0, h, w, i; int x = 0, y = 0, h, w, i;
double v=0.0; double v = 0.0;
imlib_context_set_image(im); imlib_context_set_image(im);
w = imlib_image_get_width(); w = imlib_image_get_width();
h = imlib_image_get_height(); h = imlib_image_get_height();
for (i = 256; --i >= 0; ) for (i = 256; --i >= 0;)
a_d[i] = r_d[i] = g_d[i] = b_d[i] = (double)i / 255; a_d[i] = r_d[i] = g_d[i] = b_d[i] = (double)i / 255;
for (ptr = par; ptr; ptr = ptr->next) { for (ptr = par; ptr; ptr = ptr->next)
if (!strcmp("x", ptr->key)) { {
GET_INT(x, ptr); if (!strcmp("x", ptr->key))
} else if (!strcmp("y", ptr->key)) { {
GET_INT(y, ptr); GET_INT(x, ptr);
} else if (!strcmp("w", ptr->key)) { }
GET_INT(w, ptr); else if (!strcmp("y", ptr->key))
} else if (!strcmp("h", ptr->key)) { {
GET_INT(h, ptr); GET_INT(y, ptr);
} else if (!memcmp("brightness", ptr->key, 10)) { }
GET_DOUBLE(v, ptr); else if (!strcmp("w", ptr->key))
if (!ptr->key[10]) { {
mod_brightness(r_d, v); GET_INT(w, ptr);
mod_brightness(g_d, v); }
mod_brightness(b_d, v); else if (!strcmp("h", ptr->key))
mod_brightness(a_d, v); {
} else if (!strcmp("_r", ptr->key + 10)) { GET_INT(h, ptr);
mod_brightness(r_d, v); }
} else if (!strcmp("_g", ptr->key + 10)) { else if (!memcmp("brightness", ptr->key, 10))
mod_brightness(g_d, v); {
} else if (!strcmp("_b", ptr->key + 10)) { GET_DOUBLE(v, ptr);
mod_brightness(b_d, v); if (!ptr->key[10])
} else if (!strcmp("_a", ptr->key + 10)) { {
mod_brightness(a_d, v); mod_brightness(r_d, v);
} mod_brightness(g_d, v);
} else if (!memcmp("contrast", ptr->key, 8)) { mod_brightness(b_d, v);
GET_DOUBLE(v, ptr); mod_brightness(a_d, v);
if (!ptr->key[8]) { }
mod_contrast(r_d, v); else if (!strcmp("_r", ptr->key + 10))
mod_contrast(g_d, v); {
mod_contrast(b_d, v); mod_brightness(r_d, v);
mod_contrast(a_d, v); }
} else if (!strcmp("_r", ptr->key + 8)) { else if (!strcmp("_g", ptr->key + 10))
mod_contrast(r_d, v); {
} else if (!strcmp("_g", ptr->key + 8)) { mod_brightness(g_d, v);
mod_contrast(g_d, v); }
} else if (!strcmp("_b", ptr->key + 8)) { else if (!strcmp("_b", ptr->key + 10))
mod_contrast(b_d, v); {
} else if (!strcmp("_a", ptr->key + 8)) { mod_brightness(b_d, v);
mod_contrast(a_d, v); }
} else if (!strcmp("_a", ptr->key + 10))
} else if (!memcmp("gamma", ptr->key, 5)) { {
GET_DOUBLE(v, ptr); mod_brightness(a_d, v);
if (!ptr->key[5]) { }
mod_gamma(r_d, v); }
mod_gamma(g_d, v); else if (!memcmp("contrast", ptr->key, 8))
mod_gamma(b_d, v); {
mod_gamma(a_d, v); GET_DOUBLE(v, ptr);
} else if (!strcmp("_r", ptr->key + 5)) { if (!ptr->key[8])
mod_gamma(r_d, v); {
} else if (!strcmp("_g", ptr->key + 5)) { mod_contrast(r_d, v);
mod_gamma(g_d, v); mod_contrast(g_d, v);
} else if (!strcmp("_b", ptr->key + 5)) { mod_contrast(b_d, v);
mod_gamma(b_d, v); mod_contrast(a_d, v);
} else if (!strcmp("_a", ptr->key + 5)) { }
mod_gamma(a_d, v); else if (!strcmp("_r", ptr->key + 8))
} {
} else if (!memcmp("tint", ptr->key, 4)) { mod_contrast(r_d, v);
GET_DOUBLE(v, ptr); }
if (!ptr->key[4]) { else if (!strcmp("_g", ptr->key + 8))
mod_tint(r_d, v); {
mod_tint(g_d, v); mod_contrast(g_d, v);
mod_tint(b_d, v); }
mod_tint(a_d, v); else if (!strcmp("_b", ptr->key + 8))
} else if (!strcmp("_r", ptr->key + 4)) { {
mod_tint(r_d, v); mod_contrast(b_d, v);
} else if (!strcmp("_g", ptr->key + 4)) { }
mod_tint(g_d, v); else if (!strcmp("_a", ptr->key + 8))
} else if (!strcmp("_b", ptr->key + 4)) { {
mod_tint(b_d, v); mod_contrast(a_d, v);
} else if (!strcmp("_a", ptr->key + 4)) { }
mod_tint(a_d, v); }
} else if (!memcmp("gamma", ptr->key, 5))
} {
} GET_DOUBLE(v, ptr);
for (i = 256; --i >= 0; ) { if (!ptr->key[5])
if (a_d[i] < 0) a_d[i] = 0; {
if (a_d[i] > 1) a_d[i] = 1; mod_gamma(r_d, v);
a_b[i] = a_d[i] * 255; mod_gamma(g_d, v);
if (r_d[i] < 0) r_d[i] = 0; mod_gamma(b_d, v);
if (r_d[i] > 1) r_d[i] = 1; mod_gamma(a_d, v);
r_b[i] = r_d[i] * 255; }
if (g_d[i] < 0) g_d[i] = 0; else if (!strcmp("_r", ptr->key + 5))
if (g_d[i] > 1) g_d[i] = 1; {
g_b[i] = g_d[i] * 255; mod_gamma(r_d, v);
if (b_d[i] < 0) b_d[i] = 0; }
if (b_d[i] > 1) b_d[i] = 1; else if (!strcmp("_g", ptr->key + 5))
b_b[i] = b_d[i] * 255; {
} mod_gamma(g_d, v);
imlib_context_set_color_modifier(imlib_create_color_modifier()); }
imlib_set_color_modifier_tables(r_b, g_b, b_b, a_b); else if (!strcmp("_b", ptr->key + 5))
imlib_apply_color_modifier_to_rectangle(x, y, w, h); {
imlib_free_color_modifier(); mod_gamma(b_d, v);
return im; }
else if (!strcmp("_a", ptr->key + 5))
{
mod_gamma(a_d, v);
}
}
else if (!memcmp("tint", ptr->key, 4))
{
GET_DOUBLE(v, ptr);
if (!ptr->key[4])
{
mod_tint(r_d, v);
mod_tint(g_d, v);
mod_tint(b_d, v);
mod_tint(a_d, v);
}
else if (!strcmp("_r", ptr->key + 4))
{
mod_tint(r_d, v);
}
else if (!strcmp("_g", ptr->key + 4))
{
mod_tint(g_d, v);
}
else if (!strcmp("_b", ptr->key + 4))
{
mod_tint(b_d, v);
}
else if (!strcmp("_a", ptr->key + 4))
{
mod_tint(a_d, v);
}
}
}
for (i = 256; --i >= 0;)
{
if (a_d[i] < 0)
a_d[i] = 0;
if (a_d[i] > 1)
a_d[i] = 1;
a_b[i] = a_d[i] * 255;
if (r_d[i] < 0)
r_d[i] = 0;
if (r_d[i] > 1)
r_d[i] = 1;
r_b[i] = r_d[i] * 255;
if (g_d[i] < 0)
g_d[i] = 0;
if (g_d[i] > 1)
g_d[i] = 1;
g_b[i] = g_d[i] * 255;
if (b_d[i] < 0)
b_d[i] = 0;
if (b_d[i] > 1)
b_d[i] = 1;
b_b[i] = b_d[i] * 255;
}
imlib_context_set_color_modifier(imlib_create_color_modifier());
imlib_set_color_modifier_tables(r_b, g_b, b_b, a_b);
imlib_apply_color_modifier_to_rectangle(x, y, w, h);
imlib_free_color_modifier();
return im;
} }
void void
init(struct imlib_filter_info *info) init(struct imlib_filter_info *info)
{ {
char *filters[] = { "colormod" }; char *filters[] = { "colormod" };
int i = (sizeof(filters) / sizeof(*filters)); int i = (sizeof(filters) / sizeof(*filters));
info->name = strdup( "Tinting" ); info->name = strdup("Tinting");
info->author = strdup( "Willem Monsuwe (willem@stack.nl)" ); info->author = strdup("Willem Monsuwe (willem@stack.nl)");
info->description = strdup( "Provides most common color modification filters." ); info->description =
strdup("Provides most common color modification filters.");
info->num_filters = i; info->num_filters = i;
info->filters = malloc(sizeof(char *) * i); info->filters = malloc(sizeof(char *) * i);
while (--i >= 0) while (--i >= 0)
info->filters[i] = strdup(filters[i]); info->filters[i] = strdup(filters[i]);
} }
void void
deinit() deinit()
{ {
return; return;
} }
void * void *
exec(char *filter, void *im, pIFunctionParam par) exec(char *filter, void *im, pIFunctionParam par)
{ {
if (!strcmp(filter, "colormod")) if (!strcmp(filter, "colormod"))
return colormod((Imlib_Image)im, par); return colormod((Imlib_Image) im, par);
return im; return im;
} }

View File

@ -11,101 +11,108 @@
#include "script.h" #include "script.h"
#include "dynamic_filters.h" #include "dynamic_filters.h"
void init( struct imlib_filter_info *info ); void init(struct imlib_filter_info *info);
void deinit(void); void deinit(void);
void *exec( char *filter, void *im, pIFunctionParam params ); void *exec(char *filter, void *im, pIFunctionParam params);
void init( struct imlib_filter_info *info ) void
init(struct imlib_filter_info *info)
{ {
char *filters[] = { "tint", "cool_text", "gradient" }; char *filters[] = { "tint", "cool_text", "gradient" };
int i = 0; int i = 0;
info->name = strdup( "Test Filter" ); info->name = strdup("Test Filter");
info->author = strdup( "Chris Ross - Boris - chris@darkrock.co.uk" ); info->author = strdup("Chris Ross - Boris - chris@darkrock.co.uk");
info->description = strdup( "This filter is used to show that the imlib2 filter system works!" ); info->description =
strdup
("This filter is used to show that the imlib2 filter system works!");
info->num_filters = 3; info->num_filters = 3;
info->filters = malloc(sizeof(char *)*3); info->filters = malloc(sizeof(char *) * 3);
for (i = 0; i < info->num_filters; i++) for (i = 0; i < info->num_filters; i++)
info->filters[i] = strdup(filters[i]); info->filters[i] = strdup(filters[i]);
} }
void deinit(void) void
deinit(void)
{ {
return; return;
} }
void *exec( char *filter, void *im, pIFunctionParam params ) void *
exec(char *filter, void *im, pIFunctionParam params)
{ {
Imlib_Image imge = im; Imlib_Image imge = im;
Imlib_Image anoim; Imlib_Image anoim;
IFunctionParam *ptr; IFunctionParam *ptr;
if (strcmp(filter, "tint") == 0)
{
Imlib_Color_Modifier cm;
DATA8 atab[256];
int x = 0, y = 0, w = 0, h = 0;
DATA8 r = 255, b = 255, g = 255, a = 255;
if( strcmp( filter, "tint" ) == 0 )
{
Imlib_Color_Modifier cm;
DATA8 atab[256];
int x = 0, y = 0, w = 0, h = 0;
DATA8 r = 255, b = 255, g = 255, a = 255;
/* /*
printf( "filter_test.c: tint called\n" ); printf( "filter_test.c: tint called\n" );
*/ */
/* Set friendly defaults */ /* Set friendly defaults */
imlib_context_set_image( imge ); imlib_context_set_image(imge);
w = imlib_image_get_width(); w = imlib_image_get_width();
h = imlib_image_get_height(); h = imlib_image_get_height();
for( ptr = params; ptr != NULL; ptr = ptr->next ) for (ptr = params; ptr != NULL; ptr = ptr->next)
{ {
ASSIGN_DATA8( "red", r ); ASSIGN_DATA8("red", r);
ASSIGN_DATA8( "blue", b ); ASSIGN_DATA8("blue", b);
ASSIGN_DATA8( "green", g ); ASSIGN_DATA8("green", g);
ASSIGN_INT( "x", x ); ASSIGN_INT("x", x);
ASSIGN_INT( "y", y ); ASSIGN_INT("y", y);
ASSIGN_INT( "w", w ); ASSIGN_INT("w", w);
ASSIGN_INT( "h", h ); ASSIGN_INT("h", h);
ASSIGN_DATA8( "alpha", a ); ASSIGN_DATA8("alpha", a);
} }
/* /*
printf( "Using values red=%d,blue=%d,green=%d,x=%d,y=%d,height=%d,width=%d,alpha=%d\n", r,b,g,x,y,w,h,a ); printf( "Using values red=%d,blue=%d,green=%d,x=%d,y=%d,height=%d,width=%d,alpha=%d\n", r,b,g,x,y,w,h,a );
*/ */
anoim = imlib_create_image( w, h ); anoim = imlib_create_image(w, h);
cm = imlib_create_color_modifier(); cm = imlib_create_color_modifier();
imlib_context_set_color_modifier(cm); imlib_context_set_color_modifier(cm);
imlib_context_set_image(anoim); imlib_context_set_image(anoim);
imlib_context_set_color(r, g, b, 255); imlib_context_set_color(r, g, b, 255);
imlib_image_fill_rectangle(0, 0, w, h); imlib_image_fill_rectangle(0, 0, w, h);
imlib_context_set_blend(1); imlib_context_set_blend(1);
imlib_image_set_has_alpha(1); imlib_image_set_has_alpha(1);
memset(atab, a, sizeof(atab)); memset(atab, a, sizeof(atab));
imlib_set_color_modifier_tables(NULL, NULL, NULL, atab); imlib_set_color_modifier_tables(NULL, NULL, NULL, atab);
imlib_apply_color_modifier_to_rectangle(0, 0, w, h); imlib_apply_color_modifier_to_rectangle(0, 0, w, h);
imlib_context_set_image( imge ); imlib_context_set_image(imge);
imlib_blend_image_onto_image( anoim, 0, 0, 0, w, h, x, y, w, h); imlib_blend_image_onto_image(anoim, 0, 0, 0, w, h, x, y, w, h);
imlib_free_color_modifier(); imlib_free_color_modifier();
imlib_context_set_image(anoim); imlib_context_set_image(anoim);
imlib_free_image_and_decache(); imlib_free_image_and_decache();
imlib_context_set_image(imge); imlib_context_set_image(imge);
return imge; return imge;
} }
if( strcmp( filter, "cool_text" ) == 0 ) if (strcmp(filter, "cool_text") == 0)
{ {
return imge; return imge;
} }
if( strcmp( filter, "gradient" ) == 0 ) if (strcmp(filter, "gradient") == 0)
{ {
int angle = 0; int angle = 0;
for( ptr = params; ptr != NULL; ptr = ptr->next )
{ for (ptr = params; ptr != NULL; ptr = ptr->next)
ASSIGN_INT( "angle", angle ); {
} ASSIGN_INT("angle", angle);
return imge; }
} return imge;
}
return imge; return imge;
} }

View File

@ -8,5 +8,5 @@ Description: Powerful image loading and rendering library
Version: @VERSION@ Version: @VERSION@
Requires: @REQUIREMENTS@ Requires: @REQUIREMENTS@
Libs: -L${libdir} -lImlib2 @freetype_libs@ -lm @x_libs@ @x_ldflags@ @dlopen_libs@ Libs: -L${libdir} -lImlib2 @freetype_libs@ -lm @x_libs@ @x_ldflags@ @dlopen_libs@
Cflags: -I${includedir} @x_includes@ @freetype_includes@ Cflags: -I${includedir} @x_includes@ @freetype_cflags@

View File

@ -9,11 +9,11 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "image.h" #include "image.h"
char load (ImlibImage *im, ImlibProgressFunction progress, char load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load); char progress_granularity, char immediate_load);
char save (ImlibImage *im, ImlibProgressFunction progress, char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity); char progress_granularity);
void formats (ImlibLoader *l); void formats(ImlibLoader * l);
#define SWAP32(x) (x) = \ #define SWAP32(x) (x) = \
((((x) & 0x000000ff ) << 24) |\ ((((x) & 0x000000ff ) << 24) |\
@ -22,10 +22,10 @@ void formats (ImlibLoader *l);
(((x) & 0xff000000 ) >> 24)) (((x) & 0xff000000 ) >> 24))
char char
load (ImlibImage *im, ImlibProgressFunction progress, load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load) char progress_granularity, char immediate_load)
{ {
int w, h, alpha; int w, h, alpha;
FILE *f; FILE *f;
if (im->data) if (im->data)
@ -35,91 +35,91 @@ load (ImlibImage *im, ImlibProgressFunction progress,
return 0; return 0;
/* header */ /* header */
{ {
char buf[256], buf2[256]; char buf[256], buf2[256];
if (!fgets(buf, 255, f)) if (!fgets(buf, 255, f))
{ {
fclose(f); fclose(f);
return 0; return 0;
} }
sscanf(buf, "%s %i %i %i", buf2, &w, &h, &alpha); sscanf(buf, "%s %i %i %i", buf2, &w, &h, &alpha);
if (strcmp(buf2, "ARGB")) if (strcmp(buf2, "ARGB"))
{ {
fclose(f); fclose(f);
return 0; return 0;
} }
im->w = w; im->w = w;
im->h = h; im->h = h;
if (!im->format) if (!im->format)
{ {
if (alpha) if (alpha)
SET_FLAG(im->flags, F_HAS_ALPHA); SET_FLAG(im->flags, F_HAS_ALPHA);
else else
UNSET_FLAG(im->flags, F_HAS_ALPHA); UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("argb"); im->format = strdup("argb");
} }
} }
if (((!im->data) && (im->loader)) || (immediate_load) || (progress)) if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
{ {
DATA32 *ptr; DATA32 *ptr;
int y, pl = 0; int y, pl = 0;
char pper = 0; char pper = 0;
/* must set the im->data member before callign progress function */ /* must set the im->data member before callign progress function */
ptr = im->data = malloc(w * h * sizeof(DATA32)); ptr = im->data = malloc(w * h * sizeof(DATA32));
if (!im->data) if (!im->data)
{ {
fclose(f); fclose(f);
return 0; return 0;
} }
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
{ {
int x; int x;
fread(ptr, im->w, 4, f); fread(ptr, im->w, 4, f);
for (x = 0; x < im->w; x++) for (x = 0; x < im->w; x++)
SWAP32(ptr[x]); SWAP32(ptr[x]);
} }
#else #else
fread(ptr, im->w, 4, f); fread(ptr, im->w, 4, f);
#endif #endif
ptr += im->w; ptr += im->w;
if (progress) if (progress)
{ {
char per; char per;
int l; int l;
per = (char)((100 * y) / im->h); per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) || if (((per - pper) >= progress_granularity) ||
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, (y - l), im->w, l)) if (!progress(im, per, 0, (y - l), im->w, l))
{ {
fclose(f); fclose(f);
return 2; return 2;
} }
pper = per; pper = per;
pl = y; pl = y;
} }
} }
} }
} }
fclose(f); fclose(f);
return 1; return 1;
} }
char char
save (ImlibImage *im, ImlibProgressFunction progress, save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
char progress_granularity)
{ {
FILE *f; FILE *f;
DATA32 *ptr; DATA32 *ptr;
int y, pl = 0, alpha = 0; int y, pl = 0, alpha = 0;
char pper = 0; char pper = 0;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
DATA32 *buf = (DATA32 *) malloc(im->w * 4); DATA32 *buf = (DATA32 *) malloc(im->w * 4);
#endif #endif
@ -132,47 +132,45 @@ save (ImlibImage *im, ImlibProgressFunction progress,
return 0; return 0;
if (im->flags & F_HAS_ALPHA) if (im->flags & F_HAS_ALPHA)
alpha = 1; alpha = 1;
fprintf(f, "ARGB %i %i %i\n", fprintf(f, "ARGB %i %i %i\n", im->w, im->h, alpha);
im->w, im->h, alpha);
ptr = im->data; ptr = im->data;
for (y = 0; y < im->h; y++) for (y = 0; y < im->h; y++)
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
{ {
int x; int x;
memcpy(buf, ptr, im->w * 4); memcpy(buf, ptr, im->w * 4);
for (x = 0; x < im->w; x++) for (x = 0; x < im->w; x++)
SWAP32(buf[x]); SWAP32(buf[x]);
fwrite(buf, im->w, 4, f); fwrite(buf, im->w, 4, f);
} }
#else #else
fwrite(ptr, im->w, 4, f); fwrite(ptr, im->w, 4, f);
#endif #endif
ptr += im->w; ptr += im->w;
if (progress) if (progress)
{ {
char per; char per;
int l; int l;
per = (char)((100 * y) / im->h); per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) || if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
(y == (im->h - 1))) {
{
l = y - pl; l = y - pl;
if(!progress(im, per, 0, (y - l), im->w, l)) if (!progress(im, per, 0, (y - l), im->w, l))
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (buf) if (buf)
free(buf); free(buf);
#endif #endif
fclose(f); fclose(f);
return 2; return 2;
} }
pper = per; pper = per;
pl = y; pl = y;
} }
} }
} }
/* finish off */ /* finish off */
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
@ -184,18 +182,16 @@ save (ImlibImage *im, ImlibProgressFunction progress,
} }
void void
formats (ImlibLoader *l) formats(ImlibLoader * l)
{ {
char *list_formats[] = char *list_formats[] = { "argb", "arg" };
{ "argb", "arg" };
{ {
int i; int i;
l->num_formats = (sizeof(list_formats) / sizeof (char *)); l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats); l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++) for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]); l->formats[i] = strdup(list_formats[i]);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -14,171 +14,211 @@
#include "image.h" #include "image.h"
#include <gif_lib.h> #include <gif_lib.h>
char load(ImlibImage *im, ImlibProgressFunction progress,char progress_granularity, char immediate_load); char load(ImlibImage * im, ImlibProgressFunction progress,
char save(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity); char progress_granularity, char immediate_load);
void formats(ImlibLoader *l); char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity);
void formats(ImlibLoader * l);
char char
load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity, char immediate_load) load(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity,
char immediate_load)
{ {
DATA32 *ptr; DATA32 *ptr;
GifFileType *gif; GifFileType *gif;
GifRowType *rows; GifRowType *rows;
GifRecordType rec; GifRecordType rec;
ColorMapObject *cmap; ColorMapObject *cmap;
int i, j, done, bg, r, g, b, w = 0, h = 0; int i, j, done, bg, r, g, b, w = 0, h = 0;
float per = 0.0, per_inc; float per = 0.0, per_inc;
int last_per = 0, last_y = 0; int last_per = 0, last_y = 0;
int intoffset[] = {0, 4, 2, 1}; int intoffset[] = { 0, 4, 2, 1 };
int intjump[] = {8, 8, 4, 2}; int intjump[] = { 8, 8, 4, 2 };
int transp; int transp;
int fd; int fd;
done = 0; done = 0;
rows = NULL; rows = NULL;
transp = -1; transp = -1;
/* if immediate_load is 1, then dont delay image laoding as below, or */ /* if immediate_load is 1, then dont delay image laoding as below, or */
/* already data in this image - dont load it again */ /* already data in this image - dont load it again */
if (im->data) if (im->data)
return 0; return 0;
#ifndef __EMX__ #ifndef __EMX__
fd = open(im->real_file, O_RDONLY); fd = open(im->real_file, O_RDONLY);
#else #else
fd = open(im->real_file, O_RDONLY | O_BINARY); fd = open(im->real_file, O_RDONLY | O_BINARY);
#endif #endif
if (fd < 0) if (fd < 0)
return 0; return 0;
gif = DGifOpenFileHandle(fd); gif = DGifOpenFileHandle(fd);
if (!gif) { if (!gif)
close(fd); {
return 0; close(fd);
}
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;
rows = malloc(h * sizeof(GifRowType *));
if (!rows) {
DGifCloseFile(gif);
return 0; return 0;
} }
for (i = 0; i < h; i++) { do
rows[i] = NULL; {
} if (DGifGetRecordType(gif, &rec) == GIF_ERROR)
for (i = 0; i < h; i++) { {
rows[i] = malloc(w * sizeof(GifPixelType)); /* PrintGifError(); */
if (!rows[i]) { rec = TERMINATE_RECORD_TYPE;
DGifCloseFile(gif);
for (i = 0; i < h; i++) {
if (rows[i]) {
free(rows[i]);
}
} }
free(rows); if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done))
return 0; {
} if (DGifGetImageDesc(gif) == GIF_ERROR)
} {
if (gif->Image.Interlace) { /* PrintGifError(); */
for (i = 0; i < 4; i++) { rec = TERMINATE_RECORD_TYPE;
for (j = intoffset[i]; j < h; j += intjump[i]) { }
DGifGetLine(gif, rows[j], w); w = gif->Image.Width;
h = gif->Image.Height;
rows = malloc(h * sizeof(GifRowType *));
if (!rows)
{
DGifCloseFile(gif);
return 0;
}
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);
return 0;
}
}
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)
} else { {
for (i = 0; i < h; i++) { int ext_code;
DGifGetLine(gif, rows[i], w); GifByteType *ext;
}
}
done = 1;
} else if (rec == EXTENSION_RECORD_TYPE) {
int ext_code;
GifByteType *ext;
ext = NULL; ext = NULL;
DGifGetExtension(gif, &ext_code, &ext); DGifGetExtension(gif, &ext_code, &ext);
while (ext) { while (ext)
if ((ext_code == 0xf9) && (ext[1] & 1) && (transp < 0)) { {
transp = (int) ext[4]; if ((ext_code == 0xf9) && (ext[1] & 1) && (transp < 0))
} {
ext = NULL; transp = (int)ext[4];
DGifGetExtensionNext(gif, &ext); }
} ext = NULL;
} DGifGetExtensionNext(gif, &ext);
} while (rec != TERMINATE_RECORD_TYPE); }
if (transp >= 0) { }
SET_FLAG(im->flags, F_HAS_ALPHA); } while (rec != TERMINATE_RECORD_TYPE);
} else { if (transp >= 0)
UNSET_FLAG(im->flags, F_HAS_ALPHA); {
} SET_FLAG(im->flags, F_HAS_ALPHA);
/* set the format string member to the lower-case full extension */ }
/* name for the format - so example names would be: */ else
/* "png", "jpeg", "tiff", "ppm", "pgm", "pbm", "gif", "xpm" ... */ {
UNSET_FLAG(im->flags, F_HAS_ALPHA);
}
/* set the format string member to the lower-case full extension */
/* name for the format - so example names would be: */
/* "png", "jpeg", "tiff", "ppm", "pgm", "pbm", "gif", "xpm" ... */
im->w = w; im->w = w;
im->h = h; im->h = h;
if (!im->format) if (!im->format)
im->format = strdup("gif"); im->format = strdup("gif");
if (im->loader || immediate_load || progress) { if (im->loader || immediate_load || progress)
bg = gif->SBackGroundColor; {
cmap = (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap); bg = gif->SBackGroundColor;
im->data = (DATA32 *) malloc(sizeof(DATA32) * w * h); cmap = (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap);
if (!im->data) { im->data = (DATA32 *) malloc(sizeof(DATA32) * w * h);
DGifCloseFile(gif); if (!im->data)
free(rows); {
return 0; DGifCloseFile(gif);
} free(rows);
ptr = im->data; return 0;
per_inc = 100.0 / (((float) w) * h);
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
if (rows[i][j] == transp) {
r = cmap->Colors[bg].Red;
g = cmap->Colors[bg].Green;
b = cmap->Colors[bg].Blue;
*ptr++ = 0x00ffffff & ((r << 16) | (g << 8) | b);
} else {
r = cmap->Colors[rows[i][j]].Red;
g = cmap->Colors[rows[i][j]].Green;
b = cmap->Colors[rows[i][j]].Blue;
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b;
}
per += per_inc;
if (progress && (((int) per) != last_per) && (((int) per) % progress_granularity == 0)) {
last_per = (int) per;
if (!(progress(im, (int) per, 0, last_y, w, i))) {
DGifCloseFile(gif);
for (i = 0; i < h; i++) {
free(rows[i]);
}
free(rows);
return 2;
} }
last_y = i; ptr = im->data;
} per_inc = 100.0 / (((float)w) * h);
} for (i = 0; i < h; i++)
} {
} for (j = 0; j < w; j++)
if (progress) { {
progress(im, 100, 0, last_y, w, h); if (rows[i][j] == transp)
} {
DGifCloseFile(gif); r = cmap->Colors[bg].Red;
for (i = 0; i < h; i++) { g = cmap->Colors[bg].Green;
free(rows[i]); b = cmap->Colors[bg].Blue;
} *ptr++ = 0x00ffffff & ((r << 16) | (g << 8) | b);
free(rows); }
return 1; else
{
r = cmap->Colors[rows[i][j]].Red;
g = cmap->Colors[rows[i][j]].Green;
b = cmap->Colors[rows[i][j]].Blue;
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b;
}
per += per_inc;
if (progress && (((int)per) != last_per)
&& (((int)per) % progress_granularity == 0))
{
last_per = (int)per;
if (!(progress(im, (int)per, 0, last_y, w, i)))
{
DGifCloseFile(gif);
for (i = 0; i < h; i++)
{
free(rows[i]);
}
free(rows);
return 2;
}
last_y = i;
}
}
}
}
if (progress)
{
progress(im, 100, 0, last_y, w, h);
}
DGifCloseFile(gif);
for (i = 0; i < h; i++)
{
free(rows[i]);
}
free(rows);
return 1;
} }
char char
save(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity) save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
{ {
return 0; return 0;
im = NULL; im = NULL;
@ -194,21 +234,19 @@ save(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity)
/* loader->formats = { "gif", "png", "jpeg", "jpg"} */ /* loader->formats = { "gif", "png", "jpeg", "jpg"} */
/* if it can load those formats. */ /* if it can load those formats. */
void void
formats (ImlibLoader *l) formats(ImlibLoader * l)
{ {
/* this is the only bit you have to change... */ /* this is the only bit you have to change... */
char *list_formats[] = char *list_formats[] = { "gif" };
{ "gif" };
/* don't bother changing any of this - it just reads this in and sets */ /* don't bother changing any of this - it just reads this in and sets */
/* the struct values and makes copies */ /* the struct values and makes copies */
{ {
int i; int i;
l->num_formats = (sizeof(list_formats) / sizeof (char *)); l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats); l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++) for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]); l->formats[i] = strdup(list_formats[i]);
} }
} }

View File

@ -23,9 +23,9 @@
#include "image.h" #include "image.h"
char load(ImlibImage * im, ImlibProgressFunction progress, char load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load); char progress_granularity, char immediate_load);
char save(ImlibImage * im, ImlibProgressFunction progress, char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity); char progress_granularity);
void formats(ImlibLoader * l); void formats(ImlibLoader * l);
static int static int
@ -83,16 +83,16 @@ load(ImlibImage * im, ImlibProgressFunction progress,
if ((strlen(ptr + 1) >= 2) && (!strcmp(ptr + 1, "gz"))) if ((strlen(ptr + 1) >= 2) && (!strcmp(ptr + 1, "gz")))
{ {
sprintf(str_gz, "gzip -d %s -c > %s/%s", im->real_file, tmpdir, sprintf(str_gz, "gzip -d %s -c > %s/%s", im->real_file, tmpdir,
pure_filename(file)); pure_filename(file));
} }
else if ((strlen(ptr + 1) >= 3) && (!strcmp(ptr + 1, "bz2"))) else if ((strlen(ptr + 1) >= 3) && (!strcmp(ptr + 1, "bz2")))
{ {
sprintf(str_gz, "bzip2 -d %s -c > %s/%s", im->real_file, tmpdir, sprintf(str_gz, "bzip2 -d %s -c > %s/%s", im->real_file, tmpdir,
pure_filename(file)); pure_filename(file));
} }
else else
return 0; /* Eeek why we are here? */ return 0; /* Eeek why we are here? */
if (system(str_gz) < 0) if (system(str_gz) < 0)
return 0; return 0;
free(im->real_file); free(im->real_file);
@ -105,8 +105,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
sub_loader->load(im, progress, progress_granularity, 1); sub_loader->load(im, progress, progress_granularity, 1);
else else
{ {
unlink(im->real_file); unlink(im->real_file);
return 0; return 0;
} }
unlink(im->real_file); unlink(im->real_file);
free(im->real_file); free(im->real_file);
@ -133,6 +133,6 @@ formats(ImlibLoader * l)
l->num_formats = (sizeof(list_formats) / sizeof(char *)); l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats); l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++) for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]); l->formats[i] = strdup(list_formats[i]);
} }
} }

View File

@ -11,27 +11,25 @@
#include <jpeglib.h> #include <jpeglib.h>
#include <setjmp.h> #include <setjmp.h>
struct ImLib_JPEG_error_mgr struct ImLib_JPEG_error_mgr {
{
struct jpeg_error_mgr pub; struct jpeg_error_mgr pub;
sigjmp_buf setjmp_buffer; sigjmp_buf setjmp_buffer;
}; };
typedef struct ImLib_JPEG_error_mgr *emptr; typedef struct ImLib_JPEG_error_mgr *emptr;
void _JPEGFatalErrorHandler(j_common_ptr cinfo); void _JPEGFatalErrorHandler(j_common_ptr cinfo);
void _JPEGErrorHandler(j_common_ptr cinfo); void _JPEGErrorHandler(j_common_ptr cinfo);
void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level); void _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level);
char load(ImlibImage * im, ImlibProgressFunction progress, char load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load); char progress_granularity, char immediate_load);
char save(ImlibImage * im, ImlibProgressFunction progress, char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity);
char progress_granularity); void formats(ImlibLoader * l);
void formats(ImlibLoader * l);
void void
_JPEGFatalErrorHandler(j_common_ptr cinfo) _JPEGFatalErrorHandler(j_common_ptr cinfo)
{ {
emptr errmgr; emptr errmgr;
errmgr = (emptr) cinfo->err; errmgr = (emptr) cinfo->err;
/* cinfo->err->output_message(cinfo);*/ /* cinfo->err->output_message(cinfo);*/
@ -42,7 +40,7 @@ _JPEGFatalErrorHandler(j_common_ptr cinfo)
void void
_JPEGErrorHandler(j_common_ptr cinfo) _JPEGErrorHandler(j_common_ptr cinfo)
{ {
emptr errmgr; emptr errmgr;
errmgr = (emptr) cinfo->err; errmgr = (emptr) cinfo->err;
/* cinfo->err->output_message(cinfo);*/ /* cinfo->err->output_message(cinfo);*/
@ -53,7 +51,7 @@ _JPEGErrorHandler(j_common_ptr cinfo)
void void
_JPEGErrorHandler2(j_common_ptr cinfo, int msg_level) _JPEGErrorHandler2(j_common_ptr cinfo, int msg_level)
{ {
emptr errmgr; emptr errmgr;
errmgr = (emptr) cinfo->err; errmgr = (emptr) cinfo->err;
/* cinfo->err->output_message(cinfo);*/ /* cinfo->err->output_message(cinfo);*/
@ -66,10 +64,10 @@ char
load(ImlibImage * im, ImlibProgressFunction progress, load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load) char progress_granularity, char immediate_load)
{ {
int w, h; int w, h;
struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct cinfo;
struct ImLib_JPEG_error_mgr jerr; struct ImLib_JPEG_error_mgr jerr;
FILE *f; FILE *f;
if (im->data) if (im->data)
return 0; return 0;
@ -81,11 +79,11 @@ load(ImlibImage * im, ImlibProgressFunction progress,
jerr.pub.emit_message = _JPEGErrorHandler2; jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler; jerr.pub.output_message = _JPEGErrorHandler;
if (sigsetjmp(jerr.setjmp_buffer, 1)) if (sigsetjmp(jerr.setjmp_buffer, 1))
{ {
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
return 0; return 0;
} }
jpeg_create_decompress(&cinfo); jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, f); jpeg_stdio_src(&cinfo, f);
jpeg_read_header(&cinfo, TRUE); jpeg_read_header(&cinfo, TRUE);
@ -93,135 +91,139 @@ load(ImlibImage * im, ImlibProgressFunction progress,
cinfo.do_block_smoothing = FALSE; cinfo.do_block_smoothing = FALSE;
jpeg_start_decompress(&cinfo); jpeg_start_decompress(&cinfo);
if ((!im->loader) && (!im->data)) if ((!im->loader) && (!im->data))
{ {
im->w = w = cinfo.output_width; im->w = w = cinfo.output_width;
im->h = h = cinfo.output_height; im->h = h = cinfo.output_height;
UNSET_FLAG(im->flags, F_HAS_ALPHA); UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("jpeg"); im->format = strdup("jpeg");
} }
if (((!im->data) && (im->loader)) || (immediate_load) || (progress)) if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
{ {
DATA8 *ptr, *line[16], *data; DATA8 *ptr, *line[16], *data;
DATA32 *ptr2; DATA32 *ptr2;
int x, y, l, i, scans, count, prevy; int x, y, l, i, scans, count, prevy;
im->w = w = cinfo.output_width; im->w = w = cinfo.output_width;
im->h = h = cinfo.output_height; im->h = h = cinfo.output_height;
if (cinfo.rec_outbuf_height > 16) if (cinfo.rec_outbuf_height > 16)
{ {
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
return 0; return 0;
} }
data = malloc(w * 16 * 3); data = malloc(w * 16 * 3);
if (!data) if (!data)
{ {
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
return 0; return 0;
} }
/* must set the im->data member before callign progress function */ /* must set the im->data member before callign progress function */
ptr2 = im->data = malloc(w * h * sizeof(DATA32)); ptr2 = im->data = malloc(w * h * sizeof(DATA32));
if (!im->data) if (!im->data)
{ {
free(data); free(data);
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
return 0; return 0;
} }
count = 0; count = 0;
prevy = 0; prevy = 0;
if (cinfo.output_components == 3) if (cinfo.output_components == 3)
{ {
for (i = 0; i < cinfo.rec_outbuf_height; i++) for (i = 0; i < cinfo.rec_outbuf_height; i++)
line[i] = data + (i * w * 3); line[i] = data + (i * w * 3);
for (l = 0; l < h; l += cinfo.rec_outbuf_height) for (l = 0; l < h; l += cinfo.rec_outbuf_height)
{
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height;
if ((h - l) < scans)
scans = h - l;
ptr = data;
for (y = 0; y < scans; y++)
{
for (x = 0; x < w; x++)
{ {
*ptr2 = jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
(0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) << 8) | scans = cinfo.rec_outbuf_height;
(ptr[2]); if ((h - l) < scans)
ptr += 3; scans = h - l;
ptr2++; ptr = data;
} for (y = 0; y < scans; y++)
} {
if (progress) for (x = 0; x < w; x++)
{ {
int per; *ptr2 =
(0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) <<
8) |
(ptr[2]);
ptr += 3;
ptr2++;
}
}
if (progress)
{
int per;
per = (l * 100) / h; per = (l * 100) / h;
if (((per - count) >= progress_granularity) if (((per - count) >= progress_granularity)
|| ((h - l) <= cinfo.rec_outbuf_height)) || ((h - l) <= cinfo.rec_outbuf_height))
{ {
count = per; count = per;
if (!progress(im, per, 0, prevy, w, scans + l - prevy)) if (!progress
{ (im, per, 0, prevy, w, scans + l - prevy))
free(data); {
jpeg_finish_decompress(&cinfo); free(data);
jpeg_destroy_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
fclose(f); jpeg_destroy_decompress(&cinfo);
return 2; fclose(f);
} return 2;
prevy = l + scans; }
prevy = l + scans;
}
}
} }
} }
} else if (cinfo.output_components == 1)
} {
else if (cinfo.output_components == 1) for (i = 0; i < cinfo.rec_outbuf_height; i++)
{ line[i] = data + (i * w);
for (i = 0; i < cinfo.rec_outbuf_height; i++) for (l = 0; l < h; l += cinfo.rec_outbuf_height)
line[i] = data + (i * w);
for (l = 0; l < h; l += cinfo.rec_outbuf_height)
{
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height;
if ((h - l) < scans)
scans = h - l;
ptr = data;
for (y = 0; y < scans; y++)
{
for (x = 0; x < w; x++)
{ {
*ptr2 = jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
(0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) << 8) | scans = cinfo.rec_outbuf_height;
(ptr[0]); if ((h - l) < scans)
ptr++; scans = h - l;
ptr2++; ptr = data;
} for (y = 0; y < scans; y++)
} {
if (progress) for (x = 0; x < w; x++)
{ {
int per; *ptr2 =
(0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) <<
8) |
(ptr[0]);
ptr++;
ptr2++;
}
}
if (progress)
{
int per;
per = (l * 100) / h; per = (l * 100) / h;
if (((per - count) >= progress_granularity) if (((per - count) >= progress_granularity)
|| ((h - l) <= cinfo.rec_outbuf_height)) || ((h - l) <= cinfo.rec_outbuf_height))
{ {
count = per; count = per;
if (!progress(im, per, 0, prevy, w, l + scans - prevy)) if (!progress
{ (im, per, 0, prevy, w, l + scans - prevy))
free(data); {
jpeg_finish_decompress(&cinfo); free(data);
jpeg_destroy_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
fclose(f); jpeg_destroy_decompress(&cinfo);
return 2; fclose(f);
} return 2;
prevy = l + scans; }
prevy = l + scans;
}
}
} }
} }
} free(data);
} }
free(data);
}
jpeg_finish_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
fclose(f); fclose(f);
@ -229,20 +231,18 @@ load(ImlibImage * im, ImlibProgressFunction progress,
} }
char char
save(ImlibImage * im, ImlibProgressFunction progress, save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
char progress_granularity)
{ {
struct jpeg_compress_struct cinfo; struct jpeg_compress_struct cinfo;
struct ImLib_JPEG_error_mgr jerr; struct ImLib_JPEG_error_mgr jerr;
FILE *f; FILE *f;
DATA8 *buf; DATA8 *buf;
DATA32 *ptr; DATA32 *ptr;
JSAMPROW *jbuf; JSAMPROW *jbuf;
int y = 0, quality = 75, compression = 2; int y = 0, quality = 75, compression = 2;
ImlibImageTag *tag; ImlibImageTag *tag;
int i, j, pl = 0; int i, j, pl = 0;
char pper = 0; char pper = 0;
/* no image data? abort */ /* no image data? abort */
if (!im->data) if (!im->data)
@ -253,22 +253,22 @@ save(ImlibImage * im, ImlibProgressFunction progress,
return 0; return 0;
f = fopen(im->real_file, "wb"); f = fopen(im->real_file, "wb");
if (!f) if (!f)
{ {
free(buf); free(buf);
return 0; return 0;
} }
/* set up error handling */ /* set up error handling */
jerr.pub.error_exit = _JPEGFatalErrorHandler; jerr.pub.error_exit = _JPEGFatalErrorHandler;
jerr.pub.emit_message = _JPEGErrorHandler2; jerr.pub.emit_message = _JPEGErrorHandler2;
jerr.pub.output_message = _JPEGErrorHandler; jerr.pub.output_message = _JPEGErrorHandler;
cinfo.err = jpeg_std_error(&(jerr.pub)); cinfo.err = jpeg_std_error(&(jerr.pub));
if (sigsetjmp(jerr.setjmp_buffer, 1)) if (sigsetjmp(jerr.setjmp_buffer, 1))
{ {
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
free(buf); free(buf);
fclose(f); fclose(f);
return 0; return 0;
} }
/* setup compress params */ /* setup compress params */
jpeg_create_compress(&cinfo); jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, f); jpeg_stdio_dest(&cinfo, f);
@ -284,13 +284,13 @@ save(ImlibImage * im, ImlibProgressFunction progress,
/* compression */ /* compression */
tag = __imlib_GetTag(im, "compression"); tag = __imlib_GetTag(im, "compression");
if (tag) if (tag)
{ {
compression = tag->val; compression = tag->val;
if (compression < 0) if (compression < 0)
compression = 0; compression = 0;
if (compression > 9) if (compression > 9)
compression = 9; compression = 9;
} }
/* convert to quality */ /* convert to quality */
quality = (9 - compression) * 10; quality = (9 - compression) * 10;
quality = quality * 10 / 9; quality = quality * 10 / 9;
@ -311,41 +311,41 @@ save(ImlibImage * im, ImlibProgressFunction progress,
ptr = im->data; ptr = im->data;
/* go one scanline at a time... and save */ /* go one scanline at a time... and save */
while (cinfo.next_scanline < cinfo.image_height) while (cinfo.next_scanline < cinfo.image_height)
{ {
/* convcert scaline from ARGB to RGB packed */ /* convcert scaline from ARGB to RGB packed */
for (j = 0, i = 0; i < im->w; i++) for (j = 0, i = 0; i < im->w; i++)
{ {
buf[j++] = ((*ptr) >> 16) & 0xff; buf[j++] = ((*ptr) >> 16) & 0xff;
buf[j++] = ((*ptr) >> 8) & 0xff; buf[j++] = ((*ptr) >> 8) & 0xff;
buf[j++] = ((*ptr)) & 0xff; buf[j++] = ((*ptr)) & 0xff;
ptr++; ptr++;
} }
/* write scanline */ /* write scanline */
jbuf = (JSAMPROW *) (&buf); jbuf = (JSAMPROW *) (&buf);
jpeg_write_scanlines(&cinfo, jbuf, 1); jpeg_write_scanlines(&cinfo, jbuf, 1);
y++; y++;
if (progress) if (progress)
{ {
char per; char per;
int l; int l;
per = (char) ((100 * y) / im->h); per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) || (y == (im->h - 1))) if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if (!progress(im, per, 0, (y - l), im->w, l)) if (!progress(im, per, 0, (y - l), im->w, l))
{ {
jpeg_finish_compress(&cinfo); jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
free(buf); free(buf);
fclose(f); fclose(f);
return 2; return 2;
} }
pper = per; pper = per;
pl = y; pl = y;
} }
} }
} }
/* finish off */ /* finish off */
jpeg_finish_compress(&cinfo); jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
@ -358,10 +358,10 @@ save(ImlibImage * im, ImlibProgressFunction progress,
void void
formats(ImlibLoader * l) formats(ImlibLoader * l)
{ {
char *list_formats[] = { "jpg", "jpeg", "jfif", "jfi" }; char *list_formats[] = { "jpg", "jpeg", "jfif", "jfi" };
{ {
int i; int i;
l->num_formats = (sizeof(list_formats) / sizeof(char *)); l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats); l->formats = malloc(sizeof(char *) * l->num_formats);

View File

@ -15,14 +15,13 @@
/* PNG stuff */ /* PNG stuff */
#define PNG_BYTES_TO_CHECK 4 #define PNG_BYTES_TO_CHECK 4
char load(ImlibImage * im, ImlibProgressFunction progress, char load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load); char progress_granularity, char immediate_load);
char save(ImlibImage * im, ImlibProgressFunction progress, char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity);
void formats(ImlibLoader * l);
char progress_granularity); static void comment_free(ImlibImage * im, void *data);
void formats(ImlibLoader * l);
static void comment_free(ImlibImage *im, void *data);
static void static void
comment_free(ImlibImage * im, void *data) comment_free(ImlibImage * im, void *data)
{ {
@ -33,13 +32,13 @@ char
load(ImlibImage * im, ImlibProgressFunction progress, load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load) char progress_granularity, char immediate_load)
{ {
png_uint_32 w32, h32; png_uint_32 w32, h32;
int w, h; int w, h;
char hasa = 0, hasg = 0; char hasa = 0, hasg = 0;
FILE *f; FILE *f;
png_structp png_ptr = NULL; png_structp png_ptr = NULL;
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
int bit_depth, color_type, interlace_type; int bit_depth, color_type, interlace_type;
/* if immediate_load is 1, then dont delay image laoding as below, or */ /* if immediate_load is 1, then dont delay image laoding as below, or */
/* already data in this image - dont load it again */ /* already data in this image - dont load it again */
@ -50,185 +49,186 @@ load(ImlibImage * im, ImlibProgressFunction progress,
return 0; return 0;
/* read header */ /* read header */
if (!im->data) if (!im->data)
{ {
unsigned char buf[PNG_BYTES_TO_CHECK]; unsigned char buf[PNG_BYTES_TO_CHECK];
/* if we havent read the header before, set the header data */ /* if we havent read the header before, set the header data */
fread(buf, 1, PNG_BYTES_TO_CHECK, f); fread(buf, 1, PNG_BYTES_TO_CHECK, f);
if (!png_check_sig(buf, PNG_BYTES_TO_CHECK)) if (!png_check_sig(buf, PNG_BYTES_TO_CHECK))
{ {
fclose(f); fclose(f);
return 0; return 0;
} }
rewind(f); rewind(f);
png_ptr = png_ptr =
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) if (!png_ptr)
{ {
fclose(f); fclose(f);
return 0; return 0;
} }
info_ptr = png_create_info_struct(png_ptr); info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) if (!info_ptr)
{ {
png_destroy_read_struct(&png_ptr, NULL, NULL); png_destroy_read_struct(&png_ptr, NULL, NULL);
fclose(f); fclose(f);
return 0; return 0;
} }
if (setjmp(png_ptr->jmpbuf)) if (setjmp(png_ptr->jmpbuf))
{ {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(f); fclose(f);
return 0; return 0;
} }
png_init_io(png_ptr, f); png_init_io(png_ptr, f);
png_read_info(png_ptr, info_ptr); png_read_info(png_ptr, info_ptr);
png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32), png_get_IHDR(png_ptr, info_ptr, (png_uint_32 *) (&w32),
(png_uint_32 *) (&h32), &bit_depth, &color_type, (png_uint_32 *) (&h32), &bit_depth, &color_type,
&interlace_type, NULL, NULL); &interlace_type, NULL, NULL);
im->w = (int) w32; im->w = (int)w32;
im->h = (int) h32; im->h = (int)h32;
if (color_type == PNG_COLOR_TYPE_PALETTE) if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr); png_set_expand(png_ptr);
if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA) if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
hasa = 1; hasa = 1;
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{ {
hasa = 1; hasa = 1;
hasg = 1; hasg = 1;
} }
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY) if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
hasg = 1; hasg = 1;
if (hasa) if (hasa)
SET_FLAG(im->flags, F_HAS_ALPHA); SET_FLAG(im->flags, F_HAS_ALPHA);
else else
UNSET_FLAG(im->flags, F_HAS_ALPHA); UNSET_FLAG(im->flags, F_HAS_ALPHA);
/* set the format string member to the lower-case full extension */ /* set the format string member to the lower-case full extension */
/* name for the format - so example names would be: */ /* name for the format - so example names would be: */
/* "png", "jpeg", "tiff", "ppm", "pgm", "pbm", "gif", "xpm" ... */ /* "png", "jpeg", "tiff", "ppm", "pgm", "pbm", "gif", "xpm" ... */
if (!im->loader) if (!im->loader)
im->format = strdup("png"); im->format = strdup("png");
} }
/* if its the second phase load OR its immediate load or a progress */ /* if its the second phase load OR its immediate load or a progress */
/* callback is set then load the data */ /* callback is set then load the data */
if ((im->loader) || (immediate_load) || (progress)) if ((im->loader) || (immediate_load) || (progress))
{ {
unsigned char **lines; unsigned char **lines;
int i; int i;
w = im->w; w = im->w;
h = im->h; h = im->h;
if (hasa) if (hasa)
png_set_expand(png_ptr); png_set_expand(png_ptr);
/* we want ARGB */ /* we want ARGB */
/* note form raster: */ /* note form raster: */
/* thanks to mustapha for helping debug this on PPC Linux remotely by */ /* thanks to mustapha for helping debug this on PPC Linux remotely by */
/* sending across screenshots all the tiem and me figuring out form them */ /* sending across screenshots all the tiem and me figuring out form them */
/* what the hell was up with the colors */ /* what the hell was up with the colors */
/* now png loading shoudl work on big endian machines nicely */ /* now png loading shoudl work on big endian machines nicely */
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
png_set_swap_alpha(png_ptr); png_set_swap_alpha(png_ptr);
png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE); png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
#else #else
png_set_bgr(png_ptr); png_set_bgr(png_ptr);
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
#endif #endif
/* 16bit color -> 8bit color */ /* 16bit color -> 8bit color */
png_set_strip_16(png_ptr); png_set_strip_16(png_ptr);
/* pack all pixels to byte boundaires */ /* pack all pixels to byte boundaires */
png_set_packing(png_ptr); png_set_packing(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand(png_ptr); png_set_expand(png_ptr);
if (im->data) if (im->data)
free(im->data); free(im->data);
im->data = malloc(w * h * sizeof(DATA32)); im->data = malloc(w * h * sizeof(DATA32));
if (!im->data) if (!im->data)
{ {
png_read_end(png_ptr, info_ptr); png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
fclose(f); fclose(f);
return 0; return 0;
} }
lines = (unsigned char **) malloc(h * sizeof(unsigned char *)); lines = (unsigned char **)malloc(h * sizeof(unsigned char *));
if (!lines) if (!lines)
{ {
free(im->data); free(im->data);
im->data = NULL; im->data = NULL;
png_read_end(png_ptr, info_ptr); png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
fclose(f); fclose(f);
return 0; return 0;
} }
if (hasg) if (hasg)
{ {
png_set_gray_to_rgb(png_ptr); png_set_gray_to_rgb(png_ptr);
if (png_get_bit_depth(png_ptr, info_ptr) < 8) if (png_get_bit_depth(png_ptr, info_ptr) < 8)
png_set_gray_1_2_4_to_8(png_ptr); png_set_gray_1_2_4_to_8(png_ptr);
} }
for (i = 0; i < h; i++) for (i = 0; i < h; i++)
lines[i] = lines[i] = ((unsigned char *)(im->data)) + (i * w * sizeof(DATA32));
((unsigned char *) (im->data)) + (i * w * sizeof(DATA32)); if (progress)
if (progress) {
{ int y, count, prevy, pass, number_passes, per,
int y, count, prevy, pass, number_passes, per, nrows = 1; nrows = 1;
count = 0; count = 0;
number_passes = png_set_interlace_handling(png_ptr); number_passes = png_set_interlace_handling(png_ptr);
for (pass = 0; pass < number_passes; pass++) for (pass = 0; pass < number_passes; pass++)
{ {
prevy = 0; prevy = 0;
per = 0; per = 0;
for (y = 0; y < h; y += nrows) for (y = 0; y < h; y += nrows)
{ {
png_read_rows(png_ptr, &lines[y], NULL, nrows); png_read_rows(png_ptr, &lines[y], NULL, nrows);
per = (((pass * h) + y) * 100) / (h * number_passes); per = (((pass * h) + y) * 100) / (h * number_passes);
if ((per - count) >= progress_granularity) if ((per - count) >= progress_granularity)
{ {
count = per; count = per;
if (!progress(im, per, 0, prevy, w, y - prevy + 1)) if (!progress(im, per, 0, prevy, w, y - prevy + 1))
{ {
free(lines); free(lines);
png_read_end(png_ptr, info_ptr); png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr, png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp) NULL); (png_infopp) NULL);
fclose(f); fclose(f);
return 2; return 2;
} }
prevy = y + 1; prevy = y + 1;
}
}
if (!progress(im, per, 0, prevy, w, y - prevy + 1))
{
free(lines);
png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp) NULL);
fclose(f);
return 2;
}
} }
} }
if (!progress(im, per, 0, prevy, w, y - prevy + 1)) else
{ png_read_image(png_ptr, lines);
free(lines); free(lines);
png_read_end(png_ptr, info_ptr); png_read_end(png_ptr, info_ptr);
png_destroy_read_struct(&png_ptr, &info_ptr,
(png_infopp) NULL);
fclose(f);
return 2;
}
}
}
else
png_read_image(png_ptr, lines);
free(lines);
png_read_end(png_ptr, info_ptr);
}
#ifdef PNG_TEXT_SUPPORTED
{
png_textp text;
int num;
int i;
num = 0;
png_get_text(png_ptr, info_ptr, &text, &num);
for(i = 0; i < num; i++)
{
if (!strcmp(text[i].key, "Imlib2-Comment"))
__imlib_AttachTag(im, "comment", 0, strdup(text[i].text), comment_free);
}
} }
#ifdef PNG_TEXT_SUPPORTED
{
png_textp text;
int num;
int i;
num = 0;
png_get_text(png_ptr, info_ptr, &text, &num);
for (i = 0; i < num; i++)
{
if (!strcmp(text[i].key, "Imlib2-Comment"))
__imlib_AttachTag(im, "comment", 0, strdup(text[i].text),
comment_free);
}
}
#endif #endif
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
fclose(f); fclose(f);
@ -236,63 +236,62 @@ load(ImlibImage * im, ImlibProgressFunction progress,
} }
char char
save(ImlibImage * im, ImlibProgressFunction progress, save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
char progress_granularity)
{ {
FILE *f; FILE *f;
png_structp png_ptr; png_structp png_ptr;
png_infop info_ptr; png_infop info_ptr;
DATA32 *ptr; DATA32 *ptr;
int x, y, j; int x, y, j;
png_bytep row_ptr, data = NULL; png_bytep row_ptr, data = NULL;
png_color_8 sig_bit; png_color_8 sig_bit;
int pl = 0; int pl = 0;
char pper = 0; char pper = 0;
ImlibImageTag *tag; ImlibImageTag *tag;
int quality = 75, compression = 3; int quality = 75, compression = 3;
f = fopen(im->real_file, "wb"); f = fopen(im->real_file, "wb");
if (!f) if (!f)
return 0; return 0;
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) if (!png_ptr)
{ {
fclose(f); fclose(f);
return 0; return 0;
} }
info_ptr = png_create_info_struct(png_ptr); info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) if (info_ptr == NULL)
{ {
fclose(f); fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) NULL); png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return 0; return 0;
} }
if (setjmp(png_ptr->jmpbuf)) if (setjmp(png_ptr->jmpbuf))
{ {
fclose(f); fclose(f);
png_destroy_write_struct(&png_ptr, (png_infopp) &info_ptr); png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
png_destroy_info_struct(png_ptr, (png_infopp) &info_ptr); png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
return 0; return 0;
} }
png_init_io(png_ptr, f); png_init_io(png_ptr, f);
if (im->flags & F_HAS_ALPHA) if (im->flags & F_HAS_ALPHA)
{ {
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8, png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8,
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
png_set_swap_alpha(png_ptr); png_set_swap_alpha(png_ptr);
#else #else
png_set_bgr(png_ptr); png_set_bgr(png_ptr);
#endif #endif
} }
else else
{ {
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8, PNG_COLOR_TYPE_RGB, png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8, PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
PNG_FILTER_TYPE_BASE); PNG_FILTER_TYPE_BASE);
data = malloc(im->w * 3 * sizeof(char)); data = malloc(im->w * 3 * sizeof(char));
} }
sig_bit.red = 8; sig_bit.red = 8;
sig_bit.green = 8; sig_bit.green = 8;
sig_bit.blue = 8; sig_bit.blue = 8;
@ -301,13 +300,13 @@ save(ImlibImage * im, ImlibProgressFunction progress,
/* quality */ /* quality */
tag = __imlib_GetTag(im, "quality"); tag = __imlib_GetTag(im, "quality");
if (tag) if (tag)
{ {
quality = tag->val; quality = tag->val;
if (quality < 1) if (quality < 1)
quality = 1; quality = 1;
if (quality > 99) if (quality > 99)
quality = 99; quality = 99;
} }
/* convert to compression */ /* convert to compression */
quality = quality / 10; quality = quality / 10;
compression = 9 - quality; compression = 9 - quality;
@ -323,12 +322,12 @@ save(ImlibImage * im, ImlibProgressFunction progress,
if (tag) if (tag)
{ {
#ifdef PNG_TEXT_SUPPORTED #ifdef PNG_TEXT_SUPPORTED
png_text text; png_text text;
text.key = "Imlib2-Comment"; text.key = "Imlib2-Comment";
text.text = tag->data; text.text = tag->data;
text.compression = PNG_TEXT_COMPRESSION_zTXt; text.compression = PNG_TEXT_COMPRESSION_zTXt;
png_set_text(png_ptr, info_ptr, &(text), 1); png_set_text(png_ptr, info_ptr, &(text), 1);
#endif #endif
} }
png_set_compression_level(png_ptr, compression); png_set_compression_level(png_ptr, compression);
@ -338,50 +337,52 @@ save(ImlibImage * im, ImlibProgressFunction progress,
ptr = im->data; ptr = im->data;
for (y = 0; y < im->h; y++) for (y = 0; y < im->h; y++)
{ {
if (im->flags & F_HAS_ALPHA) if (im->flags & F_HAS_ALPHA)
row_ptr = (png_bytep) ptr; row_ptr = (png_bytep) ptr;
else else
{ {
for (j = 0, x = 0; x < im->w; x++) for (j = 0, x = 0; x < im->w; x++)
{ {
data[j++] = (ptr[x] >> 16) & 0xff; data[j++] = (ptr[x] >> 16) & 0xff;
data[j++] = (ptr[x] >> 8) & 0xff; data[j++] = (ptr[x] >> 8) & 0xff;
data[j++] = (ptr[x]) & 0xff; data[j++] = (ptr[x]) & 0xff;
} }
row_ptr = (png_bytep) data; row_ptr = (png_bytep) data;
} }
png_write_rows(png_ptr, &row_ptr, 1); png_write_rows(png_ptr, &row_ptr, 1);
if (progress) if (progress)
{ {
char per; char per;
int l; int l;
per = (char) ((100 * y) / im->h); per = (char)((100 * y) / im->h);
if ((per - pper) >= progress_granularity) if ((per - pper) >= progress_granularity)
{ {
l = y - pl; l = y - pl;
if (!progress(im, per, 0, (y - l), im->w, l)) if (!progress(im, per, 0, (y - l), im->w, l))
{ {
if (data) if (data)
free(data); free(data);
png_write_end(png_ptr, info_ptr); png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp) &info_ptr); png_destroy_write_struct(&png_ptr,
png_destroy_info_struct(png_ptr, (png_infopp) &info_ptr); (png_infopp) & info_ptr);
fclose(f); png_destroy_info_struct(png_ptr,
return 2; (png_infopp) & info_ptr);
} fclose(f);
pper = per; return 2;
pl = y; }
} pper = per;
} pl = y;
ptr += im->w; }
} }
ptr += im->w;
}
if (data) if (data)
free(data); free(data);
png_write_end(png_ptr, info_ptr); png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, (png_infopp) &info_ptr); png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
png_destroy_info_struct(png_ptr, (png_infopp) &info_ptr); png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
fclose(f); fclose(f);
return 1; return 1;
@ -398,12 +399,12 @@ void
formats(ImlibLoader * l) formats(ImlibLoader * l)
{ {
/* this is the only bit you have to change... */ /* this is the only bit you have to change... */
char *list_formats[] = { "png" }; char *list_formats[] = { "png" };
/* don't bother changing any of this - it just reads this in and sets */ /* don't bother changing any of this - it just reads this in and sets */
/* the struct values and makes copies */ /* the struct values and makes copies */
{ {
int i; int i;
l->num_formats = (sizeof(list_formats) / sizeof(char *)); l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats); l->formats = malloc(sizeof(char *) * l->num_formats);

File diff suppressed because it is too large Load Diff

View File

@ -25,14 +25,14 @@
#include "colormod.h" #include "colormod.h"
#include "blend.h" #include "blend.h"
char load (ImlibImage *im, ImlibProgressFunction progress, char load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load); char progress_granularity, char immediate_load);
char save (ImlibImage *im, ImlibProgressFunction progress, char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity); char progress_granularity);
void formats (ImlibLoader *l); void formats(ImlibLoader * l);
/* flip an inverted image - see RLE reading below */ /* flip an inverted image - see RLE reading below */
static DATA32* flip(DATA32* in, int w, int h); static DATA32 *flip(DATA32 * in, int w, int h);
/* TGA pixel formats */ /* TGA pixel formats */
#define TGA_TYPE_MAPPED 1 #define TGA_TYPE_MAPPED 1
@ -50,74 +50,71 @@ static DATA32* flip(DATA32* in, int w, int h);
#define TGA_SIGNATURE "TRUEVISION-XFILE" #define TGA_SIGNATURE "TRUEVISION-XFILE"
typedef struct { typedef struct {
unsigned char idLength; unsigned char idLength;
unsigned char colorMapType; unsigned char colorMapType;
unsigned char imageType; unsigned char imageType;
unsigned char colorMapIndexLo, colorMapIndexHi; unsigned char colorMapIndexLo, colorMapIndexHi;
unsigned char colorMapLengthLo, colorMapLengthHi; unsigned char colorMapLengthLo, colorMapLengthHi;
unsigned char colorMapSize; unsigned char colorMapSize;
unsigned char xOriginLo, xOriginHi; unsigned char xOriginLo, xOriginHi;
unsigned char yOriginLo, yOriginHi; unsigned char yOriginLo, yOriginHi;
unsigned char widthLo, widthHi; unsigned char widthLo, widthHi;
unsigned char heightLo, heightHi; unsigned char heightLo, heightHi;
unsigned char bpp; unsigned char bpp;
unsigned char descriptor; unsigned char descriptor;
} tga_header; } tga_header;
typedef struct { typedef struct {
unsigned int extensionAreaOffset; unsigned int extensionAreaOffset;
unsigned int developerDirectoryOffset; unsigned int developerDirectoryOffset;
char signature[16]; char signature[16];
char dot; char dot;
char null; char null;
} tga_footer; } tga_footer;
/* /*
* Write an uncompressed RGBA 24- or 32-bit targa to disk * Write an uncompressed RGBA 24- or 32-bit targa to disk
* (If anyone wants to write a RLE saver, feel free =) * (If anyone wants to write a RLE saver, feel free =)
*/ */
char char
save (ImlibImage *im, ImlibProgressFunction progress, save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
char progress_granularity)
{ {
FILE *f; FILE *f;
DATA32 *dataptr; DATA32 *dataptr;
unsigned char *buf, *bufptr; unsigned char *buf, *bufptr;
int y, pl = 0; int y, pl = 0;
char pper = 0; char pper = 0;
tga_header header; tga_header header;
if(!im->data) if (!im->data)
return 0; return 0;
f = fopen(im->real_file, "wb"); f = fopen(im->real_file, "wb");
if(!f) if (!f)
return 0; return 0;
/* assemble the TGA header information */ /* assemble the TGA header information */
/* most entries are zero... */ /* most entries are zero... */
memset(&header, 0x0, sizeof(header)); memset(&header, 0x0, sizeof(header));
/* uncompressed RGB Targa identifier */ /* uncompressed RGB Targa identifier */
header.imageType = TGA_TYPE_COLOR; header.imageType = TGA_TYPE_COLOR;
/* image width, low byte */ /* image width, low byte */
header.widthLo = im->w & 0xFF; header.widthLo = im->w & 0xFF;
/* image width, high byte */ /* image width, high byte */
header.widthHi = im->w >> 8; header.widthHi = im->w >> 8;
/* image height, low byte */ /* image height, low byte */
header.heightLo = im->h & 0xFF; header.heightLo = im->h & 0xFF;
/* image height, high byte */ /* image height, high byte */
header.heightHi = im->h >> 8; header.heightHi = im->h >> 8;
/* total number of bits per pixel */ /* total number of bits per pixel */
header.bpp = (im->flags & F_HAS_ALPHA) ? 32 : 24; header.bpp = (im->flags & F_HAS_ALPHA) ? 32 : 24;
/* number of extra (alpha) bits per pixel */ /* number of extra (alpha) bits per pixel */
header.descriptor = (im->flags & F_HAS_ALPHA) ? 8 : 0; header.descriptor = (im->flags & F_HAS_ALPHA) ? 8 : 0;
@ -125,61 +122,65 @@ save (ImlibImage *im, ImlibProgressFunction progress,
header.descriptor |= TGA_DESC_VERTICAL; header.descriptor |= TGA_DESC_VERTICAL;
/* allocate a buffer to receive the BGRA-swapped pixel values */ /* allocate a buffer to receive the BGRA-swapped pixel values */
buf = malloc(im->w * im->h * ((im->flags & F_HAS_ALPHA) ? 4 : 3) ); buf = malloc(im->w * im->h * ((im->flags & F_HAS_ALPHA) ? 4 : 3));
if(!buf) { if (!buf)
fclose(f); {
return 0; fclose(f);
} return 0;
}
/* now we have to read from im->data into buf, swapping RGBA to BGRA */ /* now we have to read from im->data into buf, swapping RGBA to BGRA */
dataptr = im->data; bufptr = buf; dataptr = im->data;
bufptr = buf;
/* for each row */ /* for each row */
for(y = 0; y < im->h; y++) for (y = 0; y < im->h; y++)
{ {
int x; int x;
unsigned char r, g, b, a; unsigned char r, g, b, a;
/* for each pixel in the row */ /* for each pixel in the row */
for(x = 0; x < im->w; x++) { for (x = 0; x < im->w; x++)
if(im->flags & F_HAS_ALPHA) { {
READ_RGBA(dataptr, r, g, b, a); if (im->flags & F_HAS_ALPHA)
*bufptr++ = b; {
*bufptr++ = g; READ_RGBA(dataptr, r, g, b, a);
*bufptr++ = r; *bufptr++ = b;
*bufptr++ = a; *bufptr++ = g;
} else { *bufptr++ = r;
READ_RGB(dataptr, r, g, b); *bufptr++ = a;
*bufptr++ = b; }
*bufptr++ = g; else
*bufptr++ = r; {
} READ_RGB(dataptr, r, g, b);
dataptr++; *bufptr++ = b;
} /* end for (each pixel in row) */ *bufptr++ = g;
*bufptr++ = r;
}
dataptr++;
} /* end for (each pixel in row) */
/* report progress every row */
if (progress)
{
char per;
int l;
/* report progress every row */ per = (char)((100 * y) / im->h);
if (progress) if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
{ {
char per;
int l;
per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) ||
(y == (im->h - 1)))
{
l = y - pl; l = y - pl;
if(!progress(im, per, 0, (y - l), im->w, l)) if (!progress(im, per, 0, (y - l), im->w, l))
{ {
if(buf) if (buf)
free(buf); free(buf);
fclose(f); fclose(f);
return 2; return 2;
} }
pper = per; pper = per;
pl = y; pl = y;
} }
} }
} }
/* write the header */ /* write the header */
@ -188,7 +189,7 @@ save (ImlibImage *im, ImlibProgressFunction progress,
/* write the image data */ /* write the image data */
fwrite(buf, 1, im->w * im->h * ((im->flags & F_HAS_ALPHA) ? 4 : 3), f); fwrite(buf, 1, im->w * im->h * ((im->flags & F_HAS_ALPHA) ? 4 : 3), f);
if(buf) if (buf)
free(buf); free(buf);
fclose(f); fclose(f);
return 1; return 1;
@ -205,53 +206,53 @@ save (ImlibImage *im, ImlibProgressFunction progress,
*/ */
char char
load (ImlibImage *im, ImlibProgressFunction progress, load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load) char progress_granularity, char immediate_load)
{ {
FILE *fp; FILE *fp;
int bpp, vinverted = 0; int bpp, vinverted = 0;
int rle = 0, footer_present = 0; int rle = 0, footer_present = 0;
tga_header header; tga_header header;
tga_footer footer; tga_footer footer;
if(im->data) if (im->data)
return 0; return 0;
fp = fopen(im->real_file, "rb"); fp = fopen(im->real_file, "rb");
if(!fp) if (!fp)
return 0; return 0;
/* read the footer first */ /* read the footer first */
fseek (fp, 0L - (sizeof (tga_footer)), SEEK_END); fseek(fp, 0L - (sizeof(tga_footer)), SEEK_END);
if (fread (&footer, sizeof (tga_footer), 1, fp) != 1) if (fread(&footer, sizeof(tga_footer), 1, fp) != 1)
{ {
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* check the footer to see if we have a v2.0 TGA file */ /* check the footer to see if we have a v2.0 TGA file */
if (memcmp(footer.signature, TGA_SIGNATURE, sizeof (footer.signature)) == 0) if (memcmp(footer.signature, TGA_SIGNATURE, sizeof(footer.signature)) == 0)
footer_present = 1; footer_present = 1;
if (!footer_present) if (!footer_present)
{ {
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* now read the header */ /* now read the header */
if (fseek (fp, 0, SEEK_SET) || fread (&header, sizeof (header), 1, fp) != 1) if (fseek(fp, 0, SEEK_SET) || fread(&header, sizeof(header), 1, fp) != 1)
{ {
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* skip over alphanumeric ID field */ /* skip over alphanumeric ID field */
if (header.idLength && fseek (fp, header.idLength, SEEK_CUR)) if (header.idLength && fseek(fp, header.idLength, SEEK_CUR))
{ {
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* now parse the header */ /* now parse the header */
@ -261,28 +262,28 @@ load (ImlibImage *im, ImlibProgressFunction progress,
switch (header.imageType) switch (header.imageType)
{ {
case TGA_TYPE_COLOR_RLE: case TGA_TYPE_COLOR_RLE:
case TGA_TYPE_GRAY_RLE: case TGA_TYPE_GRAY_RLE:
rle = 1; rle = 1;
break; break;
case TGA_TYPE_COLOR: case TGA_TYPE_COLOR:
case TGA_TYPE_GRAY: case TGA_TYPE_GRAY:
rle = 0; rle = 0;
break; break;
default: default:
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* bits per pixel */ /* bits per pixel */
bpp = header.bpp; bpp = header.bpp;
if( ! ((bpp == 32) || (bpp == 24) || (bpp == 8)) ) if (!((bpp == 32) || (bpp == 24) || (bpp == 8)))
{ {
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* endian-safe loading of 16-bit sizes */ /* endian-safe loading of 16-bit sizes */
@ -291,323 +292,323 @@ load (ImlibImage *im, ImlibProgressFunction progress,
if ((im->w > 32767) || (im->w < 1) || (im->h > 32767) || (im->h < 1)) if ((im->w > 32767) || (im->w < 1) || (im->h > 32767) || (im->h < 1))
{ {
im->w = 0; im->w = 0;
fclose(fp); fclose(fp);
return 0; return 0;
} }
if(!im->format) if (!im->format)
{ {
if (bpp == 32) if (bpp == 32)
SET_FLAG(im->flags, F_HAS_ALPHA); SET_FLAG(im->flags, F_HAS_ALPHA);
else else
UNSET_FLAG(im->flags, F_HAS_ALPHA); UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("tga"); im->format = strdup("tga");
} }
/* if we need to actually read the pixel data... */ /* if we need to actually read the pixel data... */
if (((!im->data) && (im->loader)) || (immediate_load) || (progress)) if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
{ {
unsigned long datasize; unsigned long datasize;
struct stat ss; struct stat ss;
unsigned char *buf, *bufptr; unsigned char *buf, *bufptr;
DATA32 *dataptr; DATA32 *dataptr;
int y, pl = 0; int y, pl = 0;
char pper = 0; char pper = 0;
/* allocate the destination buffer */ /* allocate the destination buffer */
im->data = malloc(im->w * im->h * sizeof(DATA32)); im->data = malloc(im->w * im->h * sizeof(DATA32));
if(!im->data) if (!im->data)
{ {
im->w = 0; im->w = 0;
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* first we read the file data into a buffer for parsing */ /* first we read the file data into a buffer for parsing */
/* then we decode from RAM */ /* then we decode from RAM */
/* find out how much data must be read from the file */ /* find out how much data must be read from the file */
/* (this is NOT simply width*height*4, due to compression) */ /* (this is NOT simply width*height*4, due to compression) */
stat(im->real_file, &ss); stat(im->real_file, &ss);
datasize = ss.st_size - sizeof(tga_header) - header.idLength - datasize = ss.st_size - sizeof(tga_header) - header.idLength -
(footer_present ? sizeof(tga_footer) : 0); (footer_present ? sizeof(tga_footer) : 0);
buf = malloc(datasize); buf = malloc(datasize);
if(!buf) if (!buf)
{ {
im->w = 0; im->w = 0;
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* read in the pixel data */ /* read in the pixel data */
if( fread(buf, 1, datasize, fp) != datasize) if (fread(buf, 1, datasize, fp) != datasize)
{ {
fclose(fp); fclose(fp);
return 0; return 0;
} }
/* buffer is ready for parsing */ /* buffer is ready for parsing */
/* bufptr is the next byte to be read from the buffer */ /* bufptr is the next byte to be read from the buffer */
bufptr = buf; bufptr = buf;
/* dataptr is the next 32-bit pixel to be filled in */ /* dataptr is the next 32-bit pixel to be filled in */
dataptr = im->data; dataptr = im->data;
/* decode uncompressed BGRA data */ /* decode uncompressed BGRA data */
if(!rle) if (!rle)
{ {
for(y = 0; y < im->h; y++) /* for each row */ for (y = 0; y < im->h; y++) /* for each row */
{ {
int x; int x;
/* point dataptr at the beginning of the row */ /* point dataptr at the beginning of the row */
if(vinverted) if (vinverted)
/* some TGA's are stored upside-down! */ /* some TGA's are stored upside-down! */
dataptr = im->data + (im->h - (y+1)) * im->w; dataptr = im->data + (im->h - (y + 1)) * im->w;
else else
dataptr = im->data + y * im->w; dataptr = im->data + y * im->w;
for (x = 0; x < im->w; x++) /* for each pixel in the row */
{
switch (bpp)
{
for(x = 0; x < im->w; x++) /* for each pixel in the row */ /* 32-bit BGRA pixels */
{ case 32:
switch(bpp) { WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 1), /* G */
*(bufptr + 0), /* B */
*(bufptr + 3) /* A */
);
dataptr++;
bufptr += 4;
break;
/* 32-bit BGRA pixels */ /* 24-bit BGR pixels */
case 32: case 24:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 2), /* R */ *(bufptr + 1), /* G */
*(bufptr + 1), /* G */ *(bufptr + 0), /* B */
*(bufptr + 0), /* B */ (char)0xff /* A */
*(bufptr + 3) /* A */ );
); dataptr++;
dataptr++; bufptr += 3;
bufptr += 4; break;
break;
/* 24-bit BGR pixels */ /* 8-bit grayscale */
case 24: case 8:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *bufptr, /* grayscale */
*(bufptr + 2), /* R */ *bufptr, *bufptr, (char)0xff);
*(bufptr + 1), /* G */ dataptr++;
*(bufptr + 0), /* B */ bufptr += 1;
(char) 0xff /* A */ break;
); }
dataptr++;
bufptr += 3;
break;
/* 8-bit grayscale */ } /* end for (each pixel) */
case 8:
WRITE_RGBA(dataptr,
*bufptr, /* grayscale */
*bufptr,
*bufptr,
(char) 0xff
);
dataptr++;
bufptr += 1;
break;
}
} /* end for (each pixel) */ /* report progress every row */
if (progress)
{
char per;
int l;
/* report progress every row */ per = (char)((100 * y) / im->h);
if(progress) if (((per - pper) >= progress_granularity) ||
{ (y == (im->h - 1)))
char per; {
int l; l = y - pl;
if (!progress(im, per, 0, (y - l), im->w, l))
{
free(buf);
fclose(fp);
return 2;
}
pper = per;
pl = y;
}
}
per = (char)((100*y) / im->h); } /* end for (each row) */
if (((per - pper) >= progress_granularity) ||
(y == (im->h - 1)))
{
l = y - pl;
if(!progress(im, per, 0, (y - l), im->w, l))
{
free(buf);
fclose(fp);
return 2;
}
pper = per;
pl = y;
}
}
} /* end for (each row) */ } /* end if (RLE) */
} /* end if (RLE) */ /* decode RLE compressed data */
else
{
unsigned char curbyte, red, green, blue, alpha;
DATA32 *final_pixel = dataptr + im->w * im->h;
/* decode RLE compressed data */ /* loop until we've got all the pixels */
else while (dataptr < final_pixel)
{ {
unsigned char curbyte, red, green, blue, alpha; int count;
DATA32 *final_pixel = dataptr + im->w * im->h;
/* loop until we've got all the pixels */ curbyte = *bufptr++;
while(dataptr < final_pixel) count = (curbyte & 0x7F) + 1;
{
int count;
curbyte = *bufptr++; if (curbyte & 0x80) /* RLE packet */
count = (curbyte & 0x7F) + 1; {
int i;
if(curbyte & 0x80) /* RLE packet */ switch (bpp)
{ {
int i; case 32:
blue = *bufptr++;
green = *bufptr++;
red = *bufptr++;
alpha = *bufptr++;
for (i = 0; i < count; i++)
{
WRITE_RGBA(dataptr, red, green, blue, alpha);
dataptr++;
}
break;
switch(bpp) { case 24:
case 32: blue = *bufptr++;
blue = *bufptr++; green = *bufptr++; red = *bufptr++; green = *bufptr++;
alpha = *bufptr++; red = *bufptr++;
for(i = 0; i < count; i++) { for (i = 0; i < count; i++)
WRITE_RGBA(dataptr, red, green, blue, alpha); {
dataptr++; WRITE_RGBA(dataptr, red, green, blue,
} (char)0xff);
break; dataptr++;
}
break;
case 24: case 8:
blue = *bufptr++; green = *bufptr++; red = *bufptr++; alpha = *bufptr++;
for(i = 0; i < count; i++) { for (i = 0; i < count; i++)
WRITE_RGBA(dataptr, red, green, blue, (char) 0xff); {
dataptr++; WRITE_RGBA(dataptr, alpha, alpha, alpha,
} (char)0xff);
break; dataptr++;
}
break;
}
case 8: } /* end if (RLE packet) */
alpha = *bufptr++;
for(i = 0; i < count; i++) {
WRITE_RGBA(dataptr, alpha, alpha, alpha, (char) 0xff);
dataptr++;
}
break;
}
} /* end if (RLE packet) */ else /* raw packet */
{
int i;
else /* raw packet */ for (i = 0; i < count; i++)
{ {
int i; switch (bpp)
{
for(i = 0; i < count; i++) /* 32-bit BGRA pixels */
{ case 32:
switch(bpp) { WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 1), /* G */
*(bufptr + 0), /* B */
*(bufptr + 3) /* A */
);
dataptr++;
bufptr += 4;
break;
/* 32-bit BGRA pixels */ /* 24-bit BGR pixels */
case 32: case 24:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 2), /* R */ *(bufptr + 1), /* G */
*(bufptr + 1), /* G */ *(bufptr + 0), /* B */
*(bufptr + 0), /* B */ (char)0xff /* A */
*(bufptr + 3) /* A */ );
); dataptr++;
dataptr++; bufptr += 3;
bufptr += 4; break;
break;
/* 24-bit BGR pixels */ /* 8-bit grayscale */
case 24: case 8:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *bufptr, /* pseudo-grayscale */
*(bufptr + 2), /* R */ *bufptr, *bufptr, (char)0xff);
*(bufptr + 1), /* G */ dataptr++;
*(bufptr + 0), /* B */ bufptr += 1;
(char) 0xff /* A */ break;
); }
dataptr++; }
bufptr += 3; } /* end if (raw packet) */
break;
/* 8-bit grayscale */ /* report progress every packet */
case 8: if (progress)
WRITE_RGBA(dataptr, {
*bufptr, /* pseudo-grayscale */ char per;
*bufptr, int l;
*bufptr,
(char) 0xff
);
dataptr++;
bufptr += 1;
break;
}
}
} /* end if (raw packet) */
/* report progress every packet */ /* compute an approximate y value */
if(progress) /* can't be exact since packets don't necessarily */
{ /* end at the end of a row */
char per; y = (dataptr - im->data) / im->w;
int l;
/* compute an approximate y value */ per = (char)((100 * y) / im->h);
/* can't be exact since packets don't necessarily */
/* end at the end of a row */
y = (dataptr - im->data) / im->w;
per = (char)((100*y) / im->h); if (((per - pper) >= progress_granularity) ||
(y == (im->h - 1)))
{
l = y - pl;
if (!progress(im, per, 0, (y - l), im->w, l))
{
free(buf);
fclose(fp);
return 2;
}
pper = per;
pl = y;
}
} /* end progress report */
if (((per - pper) >= progress_granularity) || } /* end for (each packet) */
(y == (im->h - 1)))
{
l = y - pl;
if(!progress(im, per, 0, (y - l), im->w, l))
{
free(buf);
fclose(fp);
return 2;
}
pper = per;
pl = y;
}
} /* end progress report */
} /* end for (each packet) */ /* must now flip a bottom-up image */
/* must now flip a bottom-up image */ /* This is the best of several ugly implementations
* I considered. It's not very good since the image
* will be upside-down throughout the loading process.
* This could be done in-line with the de-RLE code
* above, but that would be messy to code. There's
* probably a better way... */
/* This is the best of several ugly implementations if (vinverted)
* I considered. It's not very good since the image {
* will be upside-down throughout the loading process. im->data = flip(im->data, im->w, im->h);
* This could be done in-line with the de-RLE code if (!im->data)
* above, but that would be messy to code. There's {
* probably a better way... */ fclose(fp);
free(buf);
return 0;
}
}
if(vinverted) { } /* end if (image is RLE) */
im->data = flip(im->data, im->w, im->h);
if(!im->data) {
fclose(fp);
free(buf);
return 0;
}
}
} /* end if (image is RLE) */ free(buf);
free(buf); } /* end if (loading pixel data) */
} /* end if (loading pixel data) */
fclose(fp); fclose(fp);
return 1; return 1;
} }
void void
formats (ImlibLoader *l) formats(ImlibLoader * l)
{ {
char *list_formats[] = char *list_formats[] = { "tga" };
{ "tga" };
{ {
int i; int i;
l->num_formats = (sizeof(list_formats) / sizeof (char *)); l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats); l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++) for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]); l->formats[i] = strdup(list_formats[i]);
} }
} }
/**********************/ /**********************/
@ -617,25 +618,26 @@ formats (ImlibLoader *l)
* the rows in reverse order * the rows in reverse order
*/ */
static DATA32* static DATA32 *
flip(DATA32* in, int w, int h) flip(DATA32 * in, int w, int h)
{ {
int adv, adv2, i; int adv, adv2, i;
DATA32* out; DATA32 *out;
out = malloc(w * h * sizeof(DATA32)); out = malloc(w * h * sizeof(DATA32));
if(!out) if (!out)
return NULL; return NULL;
adv = 0; adv2 = w * h; adv = 0;
adv2 = w * h;
for(i = 0; i < h; i++) { for (i = 0; i < h; i++)
adv2 -= w; {
memmove(out + adv, in + adv2, w * sizeof(DATA32)); adv2 -= w;
adv += w; memmove(out + adv, in + adv2, w * sizeof(DATA32));
} adv += w;
}
free(in); free(in);
return out; return out;
} }

View File

@ -19,68 +19,70 @@
/* This is a wrapper data structure for TIFFRGBAImage, so that data can be */ /* This is a wrapper data structure for TIFFRGBAImage, so that data can be */
/* passed into the callbacks. More elegent, I think, than a bunch of globals */ /* passed into the callbacks. More elegent, I think, than a bunch of globals */
struct TIFFRGBAImage_Extra {
struct TIFFRGBAImage_Extra TIFFRGBAImage rgba;
{ tileContigRoutine put_contig;
TIFFRGBAImage rgba; tileSeparateRoutine put_separate;
tileContigRoutine put_contig; ImlibImage *image;
tileSeparateRoutine put_separate; ImlibProgressFunction progress;
ImlibImage *image; char pper;
ImlibProgressFunction progress; char progress_granularity;
char pper; uint32 num_pixels;
char progress_granularity; uint32 py;
uint32 num_pixels;
uint32 py;
}; };
typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra; typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
static void put_contig_and_raster(TIFFRGBAImage*, uint32*, static void put_contig_and_raster(TIFFRGBAImage *, uint32 *,
uint32, uint32, uint32, uint32, int32, int32, unsigned char*); uint32, uint32, uint32, uint32, int32,
static void put_separate_and_raster(TIFFRGBAImage*, uint32*, int32, unsigned char *);
uint32, uint32, uint32, uint32, int32, int32, static void put_separate_and_raster(TIFFRGBAImage *, uint32 *, uint32,
unsigned char*, unsigned char*, unsigned char*, unsigned char*); uint32, uint32, uint32, int32,
static void raster(TIFFRGBAImage_Extra* img, uint32* raster, int32, unsigned char *,
uint32 x, uint32 y, uint32 w, uint32 h); unsigned char *, unsigned char *,
static void error_handler(const char *module, const char *fmt, va_list ap); unsigned char *);
char load (ImlibImage *im, ImlibProgressFunction progress, static void raster(TIFFRGBAImage_Extra * img, uint32 * raster, uint32 x,
char progress_granularity, char immediate_load); uint32 y, uint32 w, uint32 h);
char save (ImlibImage *im, ImlibProgressFunction progress, static void error_handler(const char *module, const char *fmt,
char progress_granularity); va_list ap);
void formats (ImlibLoader *l); char load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load);
char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity);
void formats(ImlibLoader * l);
static void static void
put_contig_and_raster(TIFFRGBAImage* img, uint32* rast, put_contig_and_raster(TIFFRGBAImage * img, uint32 * rast,
uint32 x, uint32 y, uint32 w, uint32 h, uint32 x, uint32 y, uint32 w, uint32 h,
int32 fromskew, int32 toskew, int32 fromskew, int32 toskew, unsigned char *cp)
unsigned char* cp)
{ {
(*(((TIFFRGBAImage_Extra *)img)->put_contig))(img, rast, x, y, w, h, (*(((TIFFRGBAImage_Extra *) img)->put_contig)) (img, rast, x, y, w, h,
fromskew, toskew, cp); fromskew, toskew, cp);
raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h); raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
} }
static void static void
put_separate_and_raster(TIFFRGBAImage* img, uint32* rast, put_separate_and_raster(TIFFRGBAImage * img, uint32 * rast,
uint32 x, uint32 y, uint32 w, uint32 h, uint32 x, uint32 y, uint32 w, uint32 h,
int32 fromskew, int32 toskew, int32 fromskew, int32 toskew,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) unsigned char *r, unsigned char *g, unsigned char *b,
unsigned char *a)
{ {
(*(((TIFFRGBAImage_Extra *)img)->put_separate)) (*(((TIFFRGBAImage_Extra *) img)->put_separate))
(img, rast, x, y, w, h, fromskew, toskew, r, g, b, a); (img, rast, x, y, w, h, fromskew, toskew, r, g, b, a);
raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h); raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
} }
/* needs orientation code */ /* needs orientation code */
static void static void
raster(TIFFRGBAImage_Extra *img, uint32* rast, raster(TIFFRGBAImage_Extra * img, uint32 * rast,
uint32 x, uint32 y, uint32 w, uint32 h) uint32 x, uint32 y, uint32 w, uint32 h)
{ {
uint32 image_width, image_height; uint32 image_width, image_height;
uint32 *pixel, pixel_value; uint32 *pixel, pixel_value;
int i, j, dy, rast_offset; int i, j, dy, rast_offset;
DATA32 *buffer_pixel, *buffer = img->image->data; DATA32 *buffer_pixel, *buffer = img->image->data;
image_width = img->image->w; image_width = img->image->w;
image_height = img->image->h; image_height = img->image->h;
@ -94,61 +96,60 @@ raster(TIFFRGBAImage_Extra *img, uint32* rast,
for (i = y, rast_offset = 0; i > dy; i--, rast_offset--) for (i = y, rast_offset = 0; i > dy; i--, rast_offset--)
{ {
pixel = rast + (rast_offset * image_width); pixel = rast + (rast_offset * image_width);
buffer_pixel = buffer + ((((image_height - 1) - i) * image_width) + x); buffer_pixel = buffer + ((((image_height - 1) - i) * image_width) + x);
for (j = 0; j < w; j++) for (j = 0; j < w; j++)
{ {
pixel_value = (*(pixel++)); pixel_value = (*(pixel++));
(*(buffer_pixel++)) = (*(buffer_pixel++)) =
(TIFFGetA(pixel_value) << 24) | (TIFFGetA(pixel_value) << 24) |
(TIFFGetR(pixel_value) << 16) | (TIFFGetG(pixel_value) << 8) | (TIFFGetR(pixel_value) << 16) | (TIFFGetG(pixel_value) << 8) |
TIFFGetB(pixel_value); TIFFGetB(pixel_value);
} }
} }
if (img->progress) if (img->progress)
{ {
char per; char per;
uint32 real_y = (image_height - 1) - y; uint32 real_y = (image_height - 1) - y;
if (w >= image_width) if (w >= image_width)
{ {
per = (char)(((real_y + h - 1) * 100)/image_height); per = (char)(((real_y + h - 1) * 100) / image_height);
if (((per - img->pper) >= img->progress_granularity) || if (((per - img->pper) >= img->progress_granularity) ||
(real_y + h) >= image_height) (real_y + h) >= image_height)
{ {
(*img->progress)(img->image, per, 0, img->py, w, (*img->progress) (img->image, per, 0, img->py, w,
(real_y + h) - img->py); (real_y + h) - img->py);
img->py = real_y + h; img->py = real_y + h;
img->pper = per; img->pper = per;
} }
} }
else else
{ {
/* for tile based images, we just progress each tile because */ /* for tile based images, we just progress each tile because */
/* of laziness. Couldn't think of a good way to do this */ /* of laziness. Couldn't think of a good way to do this */
per = (char)((w * h * 100) / img->num_pixels); per = (char)((w * h * 100) / img->num_pixels);
img->pper += per; img->pper += per;
(*img->progress)(img->image, img->pper, x, (*img->progress) (img->image, img->pper, x,
(image_height - 1) - y, w, h); (image_height - 1) - y, w, h);
} }
} }
} }
char char
load (ImlibImage *im, ImlibProgressFunction progress, load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load) char progress_granularity, char immediate_load)
{ {
TIFF *tif = NULL; TIFF *tif = NULL;
FILE *file; FILE *file;
int fd; int fd;
uint16 magic_number; uint16 magic_number;
TIFFRGBAImage_Extra rgba_image; TIFFRGBAImage_Extra rgba_image;
uint32 *rast = NULL; uint32 *rast = NULL;
uint32 width, height, num_pixels; uint32 width, height, num_pixels;
if (im->data) if (im->data)
return 0; return 0;
@ -165,8 +166,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */ if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */
&& (magic_number != TIFF_LITTLEENDIAN)) && (magic_number != TIFF_LITTLEENDIAN))
{ {
fclose(file); fclose(file);
return 0; return 0;
} }
fd = fileno(file); fd = fileno(file);
@ -180,11 +181,11 @@ load (ImlibImage *im, ImlibProgressFunction progress,
return 0; return 0;
if ((!TIFFRGBAImageOK(tif, "Cannot be processed by libtiff")) if ((!TIFFRGBAImageOK(tif, "Cannot be processed by libtiff"))
|| (!TIFFRGBAImageBegin((TIFFRGBAImage *) &rgba_image, tif, 0, || (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0,
"Error reading tiff"))) "Error reading tiff")))
{ {
TIFFClose(tif); TIFFClose(tif);
return 0; return 0;
} }
rgba_image.image = im; rgba_image.image = im;
@ -200,72 +201,72 @@ load (ImlibImage *im, ImlibProgressFunction progress,
if ((im->loader) || (immediate_load) || (progress)) if ((im->loader) || (immediate_load) || (progress))
{ {
rgba_image.progress = progress; rgba_image.progress = progress;
rgba_image.pper = rgba_image.py = 0; rgba_image.pper = rgba_image.py = 0;
rgba_image.progress_granularity = progress_granularity; rgba_image.progress_granularity = progress_granularity;
rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels); rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels);
im->data = (DATA32 *) malloc(sizeof(DATA32) * num_pixels); im->data = (DATA32 *) malloc(sizeof(DATA32) * num_pixels);
if ((!rast) || (!im->data)) /* Error checking */ if ((!rast) || (!im->data)) /* Error checking */
{ {
fprintf(stderr, "imlib2-tiffloader: Out of memory\n"); fprintf(stderr, "imlib2-tiffloader: Out of memory\n");
if (!rast) if (!rast)
_TIFFfree(rast); _TIFFfree(rast);
if (!im->data) if (!im->data)
{ {
free(im->data); free(im->data);
im->data = NULL; im->data = NULL;
} }
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image); TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif); TIFFClose(tif);
return 0; return 0;
} }
if (rgba_image.rgba.put.any == NULL) if (rgba_image.rgba.put.any == NULL)
{ {
fprintf(stderr, "imlib2-tiffloader: No put function"); fprintf(stderr, "imlib2-tiffloader: No put function");
_TIFFfree(rast); _TIFFfree(rast);
free(im->data); free(im->data);
im->data = NULL; im->data = NULL;
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image); TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif); TIFFClose(tif);
return 0; return 0;
} }
else else
{ {
if (rgba_image.rgba.isContig) if (rgba_image.rgba.isContig)
{ {
rgba_image.put_contig = rgba_image.rgba.put.contig; rgba_image.put_contig = rgba_image.rgba.put.contig;
rgba_image.rgba.put.contig = put_contig_and_raster; rgba_image.rgba.put.contig = put_contig_and_raster;
} }
else else
{ {
rgba_image.put_separate = rgba_image.rgba.put.separate; rgba_image.put_separate = rgba_image.rgba.put.separate;
rgba_image.rgba.put.separate = put_separate_and_raster; rgba_image.rgba.put.separate = put_separate_and_raster;
} }
} }
if (!TIFFRGBAImageGet((TIFFRGBAImage *) &rgba_image, if (!TIFFRGBAImageGet((TIFFRGBAImage *) & rgba_image,
rast, width, height)) rast, width, height))
{ {
_TIFFfree(rast); _TIFFfree(rast);
free(im->data); free(im->data);
im->data = NULL; im->data = NULL;
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image); TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif); TIFFClose(tif);
return 0; return 0;
} }
_TIFFfree(rast); _TIFFfree(rast);
} }
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image); TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif); TIFFClose(tif);
return 1; return 1;
@ -275,22 +276,22 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* this is a problem in libtiff */ /* this is a problem in libtiff */
char char
save (ImlibImage *im, ImlibProgressFunction progress, save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
char progress_granularity)
{ {
TIFF *tif = NULL; TIFF *tif = NULL;
uint8 *buf = NULL; uint8 *buf = NULL;
DATA32 pixel, *data = im->data; DATA32 pixel, *data = im->data;
double alpha_factor; double alpha_factor;
uint32 x, y; uint32 x, y;
uint8 r, g, b, a; uint8 r, g, b, a;
int has_alpha = IMAGE_HAS_ALPHA(im); int has_alpha = IMAGE_HAS_ALPHA(im);
int i = 0, pl = 0; int i = 0, pl = 0;
char pper = 0; char pper = 0;
/* By default uses patent-free use COMPRESSION_DEFLATE, /* By default uses patent-free use COMPRESSION_DEFLATE,
another lossless compression technique */ * another lossless compression technique */
ImlibImageTag *tag; ImlibImageTag *tag;
int compression_type = COMPRESSION_DEFLATE; int compression_type = COMPRESSION_DEFLATE;
if (!im->data) if (!im->data)
return 0; return 0;
@ -316,46 +317,72 @@ save (ImlibImage *im, ImlibProgressFunction progress,
/* compression */ /* compression */
tag = __imlib_GetTag(im, "compression_type"); tag = __imlib_GetTag(im, "compression_type");
if (tag) { if (tag)
compression_type = tag->val; {
switch (compression_type) { compression_type = tag->val;
case COMPRESSION_NONE: break; switch (compression_type)
case COMPRESSION_CCITTRLE: break; {
case COMPRESSION_CCITTFAX3: break; case COMPRESSION_NONE:
case COMPRESSION_CCITTFAX4: break; break;
case COMPRESSION_LZW: break; case COMPRESSION_CCITTRLE:
case COMPRESSION_OJPEG: break; break;
case COMPRESSION_JPEG: break; case COMPRESSION_CCITTFAX3:
case COMPRESSION_NEXT: break; break;
case COMPRESSION_CCITTRLEW: break; case COMPRESSION_CCITTFAX4:
case COMPRESSION_PACKBITS: break; break;
case COMPRESSION_THUNDERSCAN: break; case COMPRESSION_LZW:
case COMPRESSION_IT8CTPAD: break; break;
case COMPRESSION_IT8LW: break; case COMPRESSION_OJPEG:
case COMPRESSION_IT8MP: break; break;
case COMPRESSION_IT8BL: break; case COMPRESSION_JPEG:
case COMPRESSION_PIXARFILM: break; break;
case COMPRESSION_PIXARLOG: break; case COMPRESSION_NEXT:
case COMPRESSION_DEFLATE: break; break;
case COMPRESSION_ADOBE_DEFLATE: break; case COMPRESSION_CCITTRLEW:
case COMPRESSION_DCS: break; break;
case COMPRESSION_JBIG: break; case COMPRESSION_PACKBITS:
case COMPRESSION_SGILOG: break; break;
case COMPRESSION_SGILOG24: break; case COMPRESSION_THUNDERSCAN:
default: compression_type = COMPRESSION_DEFLATE; break;
} case COMPRESSION_IT8CTPAD:
break;
case COMPRESSION_IT8LW:
break;
case COMPRESSION_IT8MP:
break;
case COMPRESSION_IT8BL:
break;
case COMPRESSION_PIXARFILM:
break;
case COMPRESSION_PIXARLOG:
break;
case COMPRESSION_DEFLATE:
break;
case COMPRESSION_ADOBE_DEFLATE:
break;
case COMPRESSION_DCS:
break;
case COMPRESSION_JBIG:
break;
case COMPRESSION_SGILOG:
break;
case COMPRESSION_SGILOG24:
break;
default:
compression_type = COMPRESSION_DEFLATE;
}
} }
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression_type); TIFFSetField(tif, TIFFTAG_COMPRESSION, compression_type);
if (has_alpha) if (has_alpha)
{ {
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4); TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, EXTRASAMPLE_ASSOCALPHA); TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, EXTRASAMPLE_ASSOCALPHA);
} }
else else
{ {
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3); TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
} }
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0)); TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0));
@ -364,59 +391,59 @@ save (ImlibImage *im, ImlibProgressFunction progress,
if (!buf) if (!buf)
{ {
TIFFClose(tif); TIFFClose(tif);
return 0; return 0;
} }
for (y = 0; y < im->h; y++) for (y = 0; y < im->h; y++)
{ {
i = 0; i = 0;
for (x = 0; x < im->w; x++) for (x = 0; x < im->w; x++)
{ {
pixel = data[(y * im->w) + x]; pixel = data[(y * im->w) + x];
r = (pixel >> 16) & 0xff; r = (pixel >> 16) & 0xff;
g = (pixel >> 8) & 0xff; g = (pixel >> 8) & 0xff;
b = pixel & 0xff; b = pixel & 0xff;
if (has_alpha) if (has_alpha)
{ {
/* TIFF makes you pre-mutiply the rgb components by alpha */ /* TIFF makes you pre-mutiply the rgb components by alpha */
a = (pixel >> 24) & 0xff; a = (pixel >> 24) & 0xff;
alpha_factor = ((double) a / 255.0); alpha_factor = ((double)a / 255.0);
r *= alpha_factor; r *= alpha_factor;
g *= alpha_factor; g *= alpha_factor;
b *= alpha_factor; b *= alpha_factor;
} }
/* This might be endian dependent */ /* This might be endian dependent */
buf[i++] = r; buf[i++] = r;
buf[i++] = g; buf[i++] = g;
buf[i++] = b; buf[i++] = b;
if (has_alpha) if (has_alpha)
buf[i++] = a; buf[i++] = a;
} }
if (!TIFFWriteScanline(tif, buf, y, 0)) if (!TIFFWriteScanline(tif, buf, y, 0))
{ {
_TIFFfree(buf); _TIFFfree(buf);
TIFFClose(tif); TIFFClose(tif);
return 0; return 0;
} }
if (progress) if (progress)
{ {
char per; char per;
int l; int l;
per = (char)((100 * y) / im->h); per = (char)((100 * y) / im->h);
if ((per - pper) >= progress_granularity) if ((per - pper) >= progress_granularity)
{ {
l = y - pl; l = y - pl;
(*progress)(im, per, 0, (y - l), im->w, l); (*progress) (im, per, 0, (y - l), im->w, l);
pper = per; pper = per;
pl = y; pl = y;
} }
} }
} }
_TIFFfree(buf); _TIFFfree(buf);
@ -433,20 +460,19 @@ save (ImlibImage *im, ImlibProgressFunction progress,
/* loader->formats = { "gif", "png", "jpeg", "jpg"} */ /* loader->formats = { "gif", "png", "jpeg", "jpg"} */
/* if it can load those formats. */ /* if it can load those formats. */
void void
formats (ImlibLoader *l) formats(ImlibLoader * l)
{ {
/* this is the only bit you have to change... */ /* this is the only bit you have to change... */
char *list_formats[] = char *list_formats[] = { "tiff", "tif" };
{ "tiff", "tif" };
/* don't bother changing any of this - it just reads this in and sets */ /* don't bother changing any of this - it just reads this in and sets */
/* the struct values and makes copies */ /* the struct values and makes copies */
{ {
int i; int i;
l->num_formats = (sizeof(list_formats) / sizeof (char *)); l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats); l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++) for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]); l->formats[i] = strdup(list_formats[i]);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,8 @@ LDFLAGS = -L/usr/X11R6/lib
INCLUDES = -I. -I$(top_srcdir) -I$(top_srcdir)/src \ INCLUDES = -I. -I$(top_srcdir) -I$(top_srcdir)/src \
-I$(top_srcdir)/loaders -I$(top_srcdir)/libltdl \ -I$(top_srcdir)/loaders -I$(top_srcdir)/libltdl \
-I/usr/X11R6/include $(X_CFLAGS) \ -I/usr/X11R6/include $(X_CFLAGS) \
-I$(prefix)/include -I$(includedir) -I$(prefix)/include -I$(includedir) \
$(freetype_cflags)
MMX_SRCS = asm_blend.S asm_rgba.S asm_scale.S asm_rotate.S \ MMX_SRCS = asm_blend.S asm_rgba.S asm_scale.S asm_rotate.S \
asm_blend_cmod.S asm_blend_cmod.S
MMX_OBJS = $(MMX_SRCS:.S=.lo) MMX_OBJS = $(MMX_SRCS:.S=.lo)
@ -17,8 +18,9 @@ MMX_OBJS = $(MMX_SRCS:.S=.lo)
lib_LTLIBRARIES = libImlib2.la lib_LTLIBRARIES = libImlib2.la
include_HEADERS = Imlib2.h include_HEADERS = Imlib2.h
libImlib2_la_SOURCES = scale.c image.c blend.c file.c rgbadraw.c api.c \ libImlib2_la_SOURCES = scale.c image.c blend.c file.c rgbadraw.c api.c \
updates.c colormod.c font.c format.c grad.c rotate.c \ updates.c colormod.c format.c grad.c rotate.c \
filter.c script.c dynamic_filters.c color_helpers.c \ filter.c script.c dynamic_filters.c color_helpers.c \
font_main.c font_load.c font_query.c font_draw.c \
Imlib2.h image.h scale.h blend.h updates.h colormod.h \ Imlib2.h image.h scale.h blend.h updates.h colormod.h \
file.h common.h rgbadraw.h font.h format.h \ file.h common.h rgbadraw.h font.h format.h \
rotate.h grad.h filter.h script.h dynamic_filters.h \ rotate.h grad.h filter.h script.h dynamic_filters.h \
@ -32,12 +34,12 @@ libImlib2_la_LDFLAGS = -version-info 1:4:0
if HAVE_MMX if HAVE_MMX
libImlib2_la_LIBADD = $(X_OBJS) @DLLDFLAGS@ $(MMX_OBJS) \ libImlib2_la_LIBADD = $(X_OBJS) @DLLDFLAGS@ $(MMX_OBJS) \
$(top_builddir)/libltdl/libltdlc.la \ $(top_builddir)/libltdl/libltdlc.la \
$(x_libs) -lttf $(LDFLAGS) $(x_libs) $(freetype_libs) $(LDFLAGS)
libImlib2_la_DEPENDENCIES = $(top_builddir)/config.h $(X_OBJS) $(MMX_OBJS) libImlib2_la_DEPENDENCIES = $(top_builddir)/config.h $(X_OBJS) $(MMX_OBJS)
else else
libImlib2_la_LIBADD = $(X_OBJS) @DLLDFLAGS@ \ libImlib2_la_LIBADD = $(X_OBJS) @DLLDFLAGS@ \
$(top_builddir)/libltdl/libltdlc.la \ $(top_builddir)/libltdl/libltdlc.la \
$(x_libs) -lttf $(LDFLAGS) $(x_libs) $(freetype_libs) $(LDFLAGS)
libImlib2_la_DEPENDENCIES = $(top_builddir)/config.h $(X_OBJS) libImlib2_la_DEPENDENCIES = $(top_builddir)/config.h $(X_OBJS)
endif endif

3273
src/api.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,516 +3,553 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "color.h" #include "color.h"
DATA8 _pal_type = 0; DATA8 _pal_type = 0;
DATA16 _max_colors = 256; DATA16 _max_colors = 256;
int int
__imlib_XActualDepth(Display *d, Visual *v) __imlib_XActualDepth(Display * d, Visual * v)
{ {
XVisualInfo xvi, *xvir; XVisualInfo xvi, *xvir;
int depth = 0, num; int depth = 0, num;
xvi.visual = v; xvi.visual = v;
xvi.visualid = XVisualIDFromVisual(v); xvi.visualid = XVisualIDFromVisual(v);
xvir = XGetVisualInfo(d, VisualIDMask, &xvi, &num); xvir = XGetVisualInfo(d, VisualIDMask, &xvi, &num);
if (xvir) if (xvir)
{ {
depth = xvir[0].depth; depth = xvir[0].depth;
if ((depth == 16) && if ((depth == 16) &&
((xvir->red_mask | xvir->green_mask | xvir->blue_mask) == 0x7fff)) ((xvir->red_mask | xvir->green_mask | xvir->blue_mask) == 0x7fff))
depth = 15; depth = 15;
XFree(xvir); XFree(xvir);
} }
return depth; return depth;
} }
Visual * Visual *
__imlib_BestVisual(Display *d, int screen, int *depth_return) __imlib_BestVisual(Display * d, int screen, int *depth_return)
{ {
XVisualInfo xvi, *xvir; XVisualInfo xvi, *xvir;
int j, i, num, maxd = 0; int j, i, num, maxd = 0;
Visual *v = NULL; Visual *v = NULL;
const int visprefs[] = const int visprefs[] =
{PseudoColor, TrueColor, DirectColor, StaticColor, GrayScale, StaticGray}; { PseudoColor, TrueColor, DirectColor, StaticColor, GrayScale,
StaticGray };
xvi.screen = screen; xvi.screen = screen;
maxd = 0; maxd = 0;
for (j = 0; j < 6; j++) for (j = 0; j < 6; j++)
{ {
xvi.class = visprefs[j]; xvi.class = visprefs[j];
xvir = XGetVisualInfo(d, VisualScreenMask | VisualClassMask, xvir = XGetVisualInfo(d, VisualScreenMask | VisualClassMask,
&xvi, &num); &xvi, &num);
if (xvir) if (xvir)
{ {
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
if ((xvir[i].depth > 1) && if ((xvir[i].depth > 1) &&
(xvir[i].depth >= maxd) && (xvir[i].depth >= maxd) && (xvi.class == PseudoColor))
(xvi.class == PseudoColor)) {
{ maxd = xvir[i].depth;
maxd = xvir[i].depth; v = xvir[i].visual;
v = xvir[i].visual; }
} else if ((xvir[i].depth > maxd) && (xvir[i].depth <= 24))
else if ((xvir[i].depth > maxd) && {
(xvir[i].depth <= 24)) maxd = xvir[i].depth;
{ v = xvir[i].visual;
maxd = xvir[i].depth; }
v = xvir[i].visual; }
} XFree(xvir);
} }
XFree(xvir);
}
} }
if (depth_return) if (depth_return)
*depth_return = maxd; *depth_return = maxd;
return v; return v;
} }
DATA8 * DATA8 *
__imlib_AllocColorTable(Display *d, Colormap cmap, DATA8 *type_return, Visual *v) __imlib_AllocColorTable(Display * d, Colormap cmap, DATA8 * type_return,
Visual * v)
{ {
DATA8 *color_lut = NULL; DATA8 *color_lut = NULL;
if (v->bits_per_rgb > 1) if (v->bits_per_rgb > 1)
{ {
if ((_max_colors >= 256) && (color_lut = __imlib_AllocColors332(d, cmap, v))) if ((_max_colors >= 256)
{ && (color_lut = __imlib_AllocColors332(d, cmap, v)))
*type_return = _pal_type; {
return color_lut; *type_return = _pal_type;
} return color_lut;
if ((_max_colors >= 216) && (color_lut = __imlib_AllocColors666(d, cmap, v))) }
{ if ((_max_colors >= 216)
*type_return = _pal_type; && (color_lut = __imlib_AllocColors666(d, cmap, v)))
return color_lut; {
} *type_return = _pal_type;
if ((_max_colors >= 128) && (color_lut = __imlib_AllocColors232(d, cmap, v))) return color_lut;
{ }
*type_return = _pal_type; if ((_max_colors >= 128)
return color_lut; && (color_lut = __imlib_AllocColors232(d, cmap, v)))
} {
if ((_max_colors >= 64) && (color_lut = __imlib_AllocColors222(d, cmap, v))) *type_return = _pal_type;
{ return color_lut;
*type_return = _pal_type; }
return color_lut; if ((_max_colors >= 64)
} && (color_lut = __imlib_AllocColors222(d, cmap, v)))
if ((_max_colors >= 32) && (color_lut = __imlib_AllocColors221(d, cmap, v))) {
{ *type_return = _pal_type;
*type_return = _pal_type; return color_lut;
return color_lut; }
} if ((_max_colors >= 32)
if ((_max_colors >= 16) && (color_lut = __imlib_AllocColors121(d, cmap, v))) && (color_lut = __imlib_AllocColors221(d, cmap, v)))
{ {
*type_return = _pal_type; *type_return = _pal_type;
return color_lut; return color_lut;
} }
if ((_max_colors >= 16)
&& (color_lut = __imlib_AllocColors121(d, cmap, v)))
{
*type_return = _pal_type;
return color_lut;
}
} }
if ((_max_colors >= 8) && (color_lut = __imlib_AllocColors111(d, cmap, v))) if ((_max_colors >= 8) && (color_lut = __imlib_AllocColors111(d, cmap, v)))
{ {
*type_return = _pal_type; *type_return = _pal_type;
return color_lut; return color_lut;
} }
color_lut = __imlib_AllocColors1(d, cmap, v); color_lut = __imlib_AllocColors1(d, cmap, v);
*type_return = _pal_type; *type_return = _pal_type;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors332(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors332(Display * d, Colormap cmap, Visual * v)
{ {
int r, g, b, i; int r, g, b, i;
DATA8 *color_lut; DATA8 *color_lut;
int sig_mask = 0; int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++) sig_mask |= (0x1 << i); for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb); sig_mask <<= (16 - v->bits_per_rgb);
i = 0; i = 0;
color_lut = malloc(256 * sizeof(DATA8)); color_lut = malloc(256 * sizeof(DATA8));
for (r = 0; r < 8; r++) for (r = 0; r < 8; r++)
{ {
for (g = 0; g < 8; g++) for (g = 0; g < 8; g++)
{ {
for (b = 0; b < 4; b++) for (b = 0; b < 4; b++)
{ {
XColor xcl; XColor xcl;
XColor xcl_in; XColor xcl_in;
int val; int val;
Status ret; Status ret;
val = (r << 6) | (r << 3) | (r); val = (r << 6) | (r << 3) | (r);
xcl.red = (unsigned short)((val << 7) | (val >> 2)); xcl.red = (unsigned short)((val << 7) | (val >> 2));
val = (g << 6) | (g << 3) | (g); val = (g << 6) | (g << 3) | (g);
xcl.green = (unsigned short)((val << 7) | (val >> 2)); xcl.green = (unsigned short)((val << 7) | (val >> 2));
val = (b << 6) | (b << 4) | (b << 2) | (b); val = (b << 6) | (b << 4) | (b << 2) | (b);
xcl.blue = (unsigned short)((val << 8) | (val)); xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl; xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl); ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) || if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) || ((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) || ((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask))) ((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{ {
unsigned long pixels[256]; unsigned long pixels[256];
int j; int j;
if (i > 0) if (i > 0)
{ {
for(j = 0; j < i; j++) for (j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j]; pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0); XFreeColors(d, cmap, pixels, i, 0);
} }
free(color_lut); free(color_lut);
return NULL; return NULL;
} }
color_lut[i] = xcl.pixel; color_lut[i] = xcl.pixel;
i++; i++;
} }
} }
} }
_pal_type = 0; _pal_type = 0;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors666(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors666(Display * d, Colormap cmap, Visual * v)
{ {
int r, g, b, i; int r, g, b, i;
DATA8 *color_lut; DATA8 *color_lut;
int sig_mask = 0; int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++) sig_mask |= (0x1 << i); for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb); sig_mask <<= (16 - v->bits_per_rgb);
i = 0; i = 0;
color_lut = malloc(256 * sizeof(DATA8)); color_lut = malloc(256 * sizeof(DATA8));
for (r = 0; r < 6; r++) for (r = 0; r < 6; r++)
{ {
for (g = 0; g < 6; g++) for (g = 0; g < 6; g++)
{ {
for (b = 0; b < 6; b++) for (b = 0; b < 6; b++)
{ {
XColor xcl; XColor xcl;
XColor xcl_in; XColor xcl_in;
int val; int val;
Status ret; Status ret;
val = (int)((((double)r) / 5.0) * 65535); val = (int)((((double)r) / 5.0) * 65535);
xcl.red = (unsigned short)(val); xcl.red = (unsigned short)(val);
val = (int)((((double)g) / 5.0) * 65535); val = (int)((((double)g) / 5.0) * 65535);
xcl.green = (unsigned short)(val); xcl.green = (unsigned short)(val);
val = (int)((((double)b) / 5.0) * 65535); val = (int)((((double)b) / 5.0) * 65535);
xcl.blue = (unsigned short)(val); xcl.blue = (unsigned short)(val);
xcl_in = xcl; xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl); ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) || if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) || ((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) || ((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask))) ((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{ {
unsigned long pixels[256]; unsigned long pixels[256];
int j; int j;
if (i > 0) if (i > 0)
{ {
for(j = 0; j < i; j++) for (j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j]; pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0); XFreeColors(d, cmap, pixels, i, 0);
} }
free(color_lut); free(color_lut);
return NULL; return NULL;
} }
color_lut[i] = xcl.pixel; color_lut[i] = xcl.pixel;
i++; i++;
} }
} }
} }
_pal_type = 7; _pal_type = 7;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors232(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors232(Display * d, Colormap cmap, Visual * v)
{ {
int r, g, b, i; int r, g, b, i;
DATA8 *color_lut; DATA8 *color_lut;
int sig_mask = 0; int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++) sig_mask |= (0x1 << i); for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb); sig_mask <<= (16 - v->bits_per_rgb);
i = 0; i = 0;
color_lut = malloc(128 * sizeof(DATA8)); color_lut = malloc(128 * sizeof(DATA8));
for (r = 0; r < 4; r++) for (r = 0; r < 4; r++)
{ {
for (g = 0; g < 8; g++) for (g = 0; g < 8; g++)
{ {
for (b = 0; b < 4; b++) for (b = 0; b < 4; b++)
{ {
XColor xcl; XColor xcl;
XColor xcl_in; XColor xcl_in;
int val; int val;
Status ret; Status ret;
val = (r << 6) | (r << 4) | (r << 2) | (r); val = (r << 6) | (r << 4) | (r << 2) | (r);
xcl.red = (unsigned short)((val << 8) | (val)); xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 6) | (g << 3) | (g); val = (g << 6) | (g << 3) | (g);
xcl.green = (unsigned short)((val << 7) | (val >> 2)); xcl.green = (unsigned short)((val << 7) | (val >> 2));
val = (b << 6) | (b << 4) | (b << 2) | (b); val = (b << 6) | (b << 4) | (b << 2) | (b);
xcl.blue = (unsigned short)((val << 8) | (val)); xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl; xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl); ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) || if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) || ((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) || ((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask))) ((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{ {
unsigned long pixels[256]; unsigned long pixels[256];
int j; int j;
if (i > 0) if (i > 0)
{ {
for(j = 0; j < i; j++) for (j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j]; pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0); XFreeColors(d, cmap, pixels, i, 0);
} }
free(color_lut); free(color_lut);
return NULL; return NULL;
} }
color_lut[i] = xcl.pixel; color_lut[i] = xcl.pixel;
i++; i++;
} }
} }
} }
_pal_type = 1; _pal_type = 1;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors222(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors222(Display * d, Colormap cmap, Visual * v)
{ {
int r, g, b, i; int r, g, b, i;
DATA8 *color_lut; DATA8 *color_lut;
int sig_mask = 0; int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++) sig_mask |= (0x1 << i); for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb); sig_mask <<= (16 - v->bits_per_rgb);
i = 0; i = 0;
color_lut = malloc(64 * sizeof(DATA8)); color_lut = malloc(64 * sizeof(DATA8));
for (r = 0; r < 4; r++) for (r = 0; r < 4; r++)
{ {
for (g = 0; g < 4; g++) for (g = 0; g < 4; g++)
{ {
for (b = 0; b < 4; b++) for (b = 0; b < 4; b++)
{ {
XColor xcl; XColor xcl;
XColor xcl_in; XColor xcl_in;
int val; int val;
Status ret; Status ret;
val = (r << 6) | (r << 4) | (r << 2) | (r); val = (r << 6) | (r << 4) | (r << 2) | (r);
xcl.red = (unsigned short)((val << 8) | (val)); xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 6) | (g << 4) | (g << 2) | (g); val = (g << 6) | (g << 4) | (g << 2) | (g);
xcl.green = (unsigned short)((val << 8) | (val)); xcl.green = (unsigned short)((val << 8) | (val));
val = (b << 6) | (b << 4) | (b << 2) | (b); val = (b << 6) | (b << 4) | (b << 2) | (b);
xcl.blue = (unsigned short)((val << 8) | (val)); xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl; xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl); ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) || if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) || ((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) || ((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask))) ((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{ {
unsigned long pixels[256]; unsigned long pixels[256];
int j; int j;
if (i > 0) if (i > 0)
{ {
for(j = 0; j < i; j++) for (j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j]; pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0); XFreeColors(d, cmap, pixels, i, 0);
} }
free(color_lut); free(color_lut);
return NULL; return NULL;
} }
color_lut[i] = xcl.pixel; color_lut[i] = xcl.pixel;
i++; i++;
} }
} }
} }
_pal_type = 2; _pal_type = 2;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors221(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors221(Display * d, Colormap cmap, Visual * v)
{ {
int r, g, b, i; int r, g, b, i;
DATA8 *color_lut; DATA8 *color_lut;
int sig_mask = 0; int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++) sig_mask |= (0x1 << i); for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb); sig_mask <<= (16 - v->bits_per_rgb);
i = 0; i = 0;
color_lut = malloc(32 * sizeof(DATA8)); color_lut = malloc(32 * sizeof(DATA8));
for (r = 0; r < 4; r++) for (r = 0; r < 4; r++)
{ {
for (g = 0; g < 4; g++) for (g = 0; g < 4; g++)
{ {
for (b = 0; b < 2; b++) for (b = 0; b < 2; b++)
{ {
XColor xcl; XColor xcl;
XColor xcl_in; XColor xcl_in;
int val; int val;
Status ret; Status ret;
val = (r << 6) | (r << 4) | (r << 2) | (r); val = (r << 6) | (r << 4) | (r << 2) | (r);
xcl.red = (unsigned short)((val << 8) | (val)); xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 6) | (g << 4) | (g << 2) | (g); val = (g << 6) | (g << 4) | (g << 2) | (g);
xcl.green = (unsigned short)((val << 8) | (val)); xcl.green = (unsigned short)((val << 8) | (val));
val = (b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b << 2) | (b << 1) | (b); val =
xcl.blue = (unsigned short)((val << 8) | (val)); (b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
xcl_in = xcl; <<
ret = XAllocColor(d, cmap, &xcl); 2)
if ((ret == Success) || | (b << 1) | (b);
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) || xcl.blue = (unsigned short)((val << 8) | (val));
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) || xcl_in = xcl;
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask))) ret = XAllocColor(d, cmap, &xcl);
{ if ((ret == Success) ||
unsigned long pixels[256]; ((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
int j; ((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0) if (i > 0)
{ {
for(j = 0; j < i; j++) for (j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j]; pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0); XFreeColors(d, cmap, pixels, i, 0);
} }
free(color_lut); free(color_lut);
return NULL; return NULL;
} }
color_lut[i] = xcl.pixel; color_lut[i] = xcl.pixel;
i++; i++;
} }
} }
} }
_pal_type = 3; _pal_type = 3;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors121(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors121(Display * d, Colormap cmap, Visual * v)
{ {
int r, g, b, i; int r, g, b, i;
DATA8 *color_lut; DATA8 *color_lut;
int sig_mask = 0; int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++) sig_mask |= (0x1 << i); for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb); sig_mask <<= (16 - v->bits_per_rgb);
i = 0; i = 0;
color_lut = malloc(16 * sizeof(DATA8)); color_lut = malloc(16 * sizeof(DATA8));
for (r = 0; r < 2; r++) for (r = 0; r < 2; r++)
{ {
for (g = 0; g < 4; g++) for (g = 0; g < 4; g++)
{ {
for (b = 0; b < 2; b++) for (b = 0; b < 2; b++)
{ {
XColor xcl; XColor xcl;
XColor xcl_in; XColor xcl_in;
int val; int val;
Status ret; Status ret;
val = (r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r << 2) | (r << 1) | (r); val =
xcl.red = (unsigned short)((val << 8) | (val)); (r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r
val = (g << 6) | (g << 4) | (g << 2) | (g); <<
xcl.green = (unsigned short)((val << 8) | (val)); 2)
val = (b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b << 2) | (b << 1) | (b); | (r << 1) | (r);
xcl.blue = (unsigned short)((val << 8) | (val)); xcl.red = (unsigned short)((val << 8) | (val));
xcl_in = xcl; val = (g << 6) | (g << 4) | (g << 2) | (g);
ret = XAllocColor(d, cmap, &xcl); xcl.green = (unsigned short)((val << 8) | (val));
if ((ret == Success) || val =
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) || (b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) || <<
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask))) 2)
{ | (b << 1) | (b);
unsigned long pixels[256]; xcl.blue = (unsigned short)((val << 8) | (val));
int j; xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0) if (i > 0)
{ {
for(j = 0; j < i; j++) for (j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j]; pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0); XFreeColors(d, cmap, pixels, i, 0);
} }
free(color_lut); free(color_lut);
return NULL; return NULL;
} }
color_lut[i] = xcl.pixel; color_lut[i] = xcl.pixel;
i++; i++;
} }
} }
} }
_pal_type = 4; _pal_type = 4;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors111(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors111(Display * d, Colormap cmap, Visual * v)
{ {
int r, g, b, i ; int r, g, b, i;
DATA8 *color_lut; DATA8 *color_lut;
int sig_mask = 0; int sig_mask = 0;
for (i = 0; i < v->bits_per_rgb; i++) sig_mask |= (0x1 << i); for (i = 0; i < v->bits_per_rgb; i++)
sig_mask |= (0x1 << i);
sig_mask <<= (16 - v->bits_per_rgb); sig_mask <<= (16 - v->bits_per_rgb);
i = 0; i = 0;
color_lut = malloc(8 * sizeof(DATA8)); color_lut = malloc(8 * sizeof(DATA8));
for (r = 0; r < 2; r++) for (r = 0; r < 2; r++)
{ {
for (g = 0; g < 2; g++) for (g = 0; g < 2; g++)
{ {
for (b = 0; b < 2; b++) for (b = 0; b < 2; b++)
{ {
XColor xcl; XColor xcl;
XColor xcl_in; XColor xcl_in;
int val; int val;
Status ret; Status ret;
val = (r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r << 2) | (r << 1) | (r); val =
xcl.red = (unsigned short)((val << 8) | (val)); (r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r
val = (g << 7) | (g << 6) | (g << 5) | (g << 4) | (g << 3) | (g << 2) | (g << 1) | (g); <<
xcl.green = (unsigned short)((val << 8) | (val)); 2)
val = (b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b << 2) | (b << 1) | (b); | (r << 1) | (r);
xcl.blue = (unsigned short)((val << 8) | (val)); xcl.red = (unsigned short)((val << 8) | (val));
xcl_in = xcl; val =
ret = XAllocColor(d, cmap, &xcl); (g << 7) | (g << 6) | (g << 5) | (g << 4) | (g << 3) | (g
if ((ret == Success) || <<
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) || 2)
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) || | (g << 1) | (g);
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask))) xcl.green = (unsigned short)((val << 8) | (val));
{ val =
unsigned long pixels[256]; (b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
int j; <<
2)
| (b << 1) | (b);
xcl.blue = (unsigned short)((val << 8) | (val));
xcl_in = xcl;
ret = XAllocColor(d, cmap, &xcl);
if ((ret == Success) ||
((xcl_in.red & sig_mask) != (xcl.red & sig_mask)) ||
((xcl_in.green & sig_mask) != (xcl.green & sig_mask)) ||
((xcl_in.blue & sig_mask) != (xcl.blue & sig_mask)))
{
unsigned long pixels[256];
int j;
if (i > 0) if (i > 0)
{ {
for(j = 0; j < i; j++) for (j = 0; j < i; j++)
pixels[j] = (unsigned long) color_lut[j]; pixels[j] = (unsigned long)color_lut[j];
XFreeColors(d, cmap, pixels, i, 0); XFreeColors(d, cmap, pixels, i, 0);
} }
free(color_lut); free(color_lut);
return NULL; return NULL;
} }
color_lut[i] = xcl.pixel; color_lut[i] = xcl.pixel;
i++; i++;
} }
} }
} }
_pal_type = 5; _pal_type = 5;
return color_lut; return color_lut;
} }
DATA8 * DATA8 *
__imlib_AllocColors1(Display *d, Colormap cmap, Visual *v) __imlib_AllocColors1(Display * d, Colormap cmap, Visual * v)
{ {
XColor xcl; XColor xcl;
DATA8 *color_lut; DATA8 *color_lut;
color_lut = malloc(2 * sizeof(DATA8)); color_lut = malloc(2 * sizeof(DATA8));
xcl.red = (unsigned short)(0x0000); xcl.red = (unsigned short)(0x0000);

View File

@ -5,185 +5,231 @@
*/ */
void void
__imlib_rgb_to_hsv(int r, int g, int b, float *hue, float *saturation, float *value) __imlib_rgb_to_hsv(int r, int g, int b, float *hue, float *saturation,
float *value)
{ {
int f; int f;
float i,j,k,max,min,d; float i, j, k, max, min, d;
i = ((float)r)/255.0; i = ((float)r) / 255.0;
j = ((float)g)/255.0; j = ((float)g) / 255.0;
k = ((float)b)/255.0; k = ((float)b) / 255.0;
f = 0; f = 0;
max = min = i; max = min = i;
if (j>max) { max = j; f = 1; } else min = j; if (j > max)
if (k>max) { max = k; f = 2; } else if (k<min) min = k; {
max = j;
f = 1;
}
else
min = j;
if (k > max)
{
max = k;
f = 2;
}
else if (k < min)
min = k;
d = max - min; d = max - min;
*value = max; *value = max;
if (max!=0) *saturation = d/max; else *saturation = 0; if (max != 0)
if (*saturation==0) *saturation = d / max;
else
*saturation = 0;
if (*saturation == 0)
*hue = 0; *hue = 0;
else else
{ {
switch (f) switch (f)
{ {
case 0: case 0:
*hue = (j - k)/d; *hue = (j - k) / d;
break; break;
case 1: case 1:
*hue = 2 + (k - i)/d; *hue = 2 + (k - i) / d;
break; break;
case 2: case 2:
*hue = 4 + (i - j)/d; *hue = 4 + (i - j) / d;
break; break;
} }
*hue *= 60.0; *hue *= 60.0;
if (*hue<0) *hue += 360.0; if (*hue < 0)
} *hue += 360.0;
}
} }
void void
__imlib_hsv_to_rgb(float hue, float saturation, float value, int *r, int *g, int *b) __imlib_hsv_to_rgb(float hue, float saturation, float value, int *r, int *g,
int *b)
{ {
int i,p,q,t,h; int i, p, q, t, h;
float vs,vsf; float vs, vsf;
i = (int)(value*255.0); i = (int)(value * 255.0);
if (saturation==0) if (saturation == 0)
*r = *g = *b = i; *r = *g = *b = i;
else else
{ {
if (hue==360) hue = 0; if (hue == 360)
hue = hue/60.0; hue = 0;
h = (int)hue; hue = hue / 60.0;
vs = value * saturation; h = (int)hue;
vsf = vs * (hue - h); vs = value * saturation;
p = (int)(255.0 * (value - vs)); vsf = vs * (hue - h);
q = (int)(255.0 * (value - vsf)); p = (int)(255.0 * (value - vs));
t = (int)(255.0 * (value - vs + vsf)); q = (int)(255.0 * (value - vsf));
switch (h) t = (int)(255.0 * (value - vs + vsf));
{ switch (h)
case 0: {
*r = i; case 0:
*g = t; *r = i;
*b = p; *g = t;
break; *b = p;
case 1: break;
*r = q; case 1:
*g = i; *r = q;
*b = p; *g = i;
break; *b = p;
case 2: break;
*r = p; case 2:
*g = i; *r = p;
*b = t; *g = i;
break; *b = t;
case 3: break;
*r = p; case 3:
*g = q; *r = p;
*b = i; *g = q;
break; *b = i;
case 4: break;
*r = t; case 4:
*g = p; *r = t;
*b = i; *g = p;
break; *b = i;
case 5: break;
*r = i; case 5:
*g = p; *r = i;
*b = q; *g = p;
break; *b = q;
} break;
} }
}
} }
void void
__imlib_rgb_to_hls(int r, int g, int b, float *hue, float *lightness, float *saturation) __imlib_rgb_to_hls(int r, int g, int b, float *hue, float *lightness,
float *saturation)
{ {
int f; int f;
float i,j,k,max,min,d; float i, j, k, max, min, d;
i = ((float)r)/255.0; i = ((float)r) / 255.0;
j = ((float)g)/255.0; j = ((float)g) / 255.0;
k = ((float)b)/255.0; k = ((float)b) / 255.0;
f = 0; f = 0;
max = min = i; max = min = i;
if (j>max) { max = j; f = 1; } else min = j; if (j > max)
if (k>max) { max = k; f = 2; } else if (k<min) min = k; {
max = j;
f = 1;
}
else
min = j;
if (k > max)
{
max = k;
f = 2;
}
else if (k < min)
min = k;
d = max - min; d = max - min;
*lightness = (max + min)/2.0; *lightness = (max + min) / 2.0;
if (d==0) if (d == 0)
{ {
*saturation = 0; *saturation = 0;
*hue = 0; *hue = 0;
} }
else else
{ {
if (*lightness < 0.5) *saturation = d/(max + min); else *saturation = d/(2 - max - min); if (*lightness < 0.5)
switch (f) *saturation = d / (max + min);
{ else
case 0: *saturation = d / (2 - max - min);
*hue = (j - k)/d; switch (f)
break; {
case 1: case 0:
*hue = 2 + (k - i)/d; *hue = (j - k) / d;
break; break;
case 2: case 1:
*hue = 4 + (i - j)/d; *hue = 2 + (k - i) / d;
break; break;
} case 2:
*hue *= 60.0; *hue = 4 + (i - j) / d;
if (*hue<0) *hue += 360.0; break;
} }
*hue *= 60.0;
if (*hue < 0)
*hue += 360.0;
}
} }
void void
__imlib_hls_to_rgb(float hue, float lightness, float saturation, int *r, int *g, int *b) __imlib_hls_to_rgb(float hue, float lightness, float saturation, int *r, int *g,
int *b)
{ {
float m1,m2,m21,h; float m1, m2, m21, h;
if (saturation==0) if (saturation == 0)
*r = *g = *b = (int)(lightness * 255.0); *r = *g = *b = (int)(lightness * 255.0);
else else
{ {
if (lightness<=0.5) if (lightness <= 0.5)
m2 = lightness * (1 + saturation); m2 = lightness * (1 + saturation);
else else
m2 = lightness + saturation + lightness * saturation; m2 = lightness + saturation + lightness * saturation;
m1 = 2 * lightness - m2; m1 = 2 * lightness - m2;
m21 = m2 - m1; m21 = m2 - m1;
h = hue + 120; h = hue + 120;
if (h>360) h -= 360; else if (h<0) h += 360; if (h > 360)
if (h<60) h -= 360;
*r = (int)(255.0 * (m1 + m21 * h/60.0)); else if (h < 0)
else if (h<180) h += 360;
*r = (int)(255.0 * m2); if (h < 60)
else if (h<240) *r = (int)(255.0 * (m1 + m21 * h / 60.0));
*r = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0)); else if (h < 180)
else *r = (int)(255.0 * m2);
*r = (int)(255.0 * m1); else if (h < 240)
h = hue; *r = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
if (h>360) h -= 360; else if (h<0) h += 360; else
if (h<60) *r = (int)(255.0 * m1);
*g = (int)(255.0 * (m1 + m21 * h/60.0)); h = hue;
else if (h<180) if (h > 360)
*g = (int)(255.0 * m2); h -= 360;
else if (h<240) else if (h < 0)
*g = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0)); h += 360;
else if (h < 60)
*g = (int)(255.0 * m1); *g = (int)(255.0 * (m1 + m21 * h / 60.0));
h = hue - 120; else if (h < 180)
if (h>360) h -= 360; else if (h<0) h += 360; *g = (int)(255.0 * m2);
if (h<60) else if (h < 240)
*b = (int)(255.0 * (m1 + m21 * h/60.0)); *g = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else if (h<180) else
*b = (int)(255.0 * m2); *g = (int)(255.0 * m1);
else if (h<240) h = hue - 120;
*b = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0)); if (h > 360)
else h -= 360;
*b = (int)(255.0 * m1); else if (h < 0)
} h += 360;
if (h < 60)
*b = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*b = (int)(255.0 * m2);
else if (h < 240)
*b = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else
*b = (int)(255.0 * m1);
}
} }

View File

@ -6,121 +6,121 @@
#include "image.h" #include "image.h"
#include "blend.h" #include "blend.h"
static DATABIG mod_count = 0; static DATABIG mod_count = 0;
ImlibColorModifier * ImlibColorModifier *
__imlib_CreateCmod(void) __imlib_CreateCmod(void)
{ {
ImlibColorModifier *cm; ImlibColorModifier *cm;
int i; int i;
cm = malloc(sizeof(ImlibColorModifier)); cm = malloc(sizeof(ImlibColorModifier));
cm->modification_count = mod_count; cm->modification_count = mod_count;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
cm->red_mapping[i] = (DATA8)i; cm->red_mapping[i] = (DATA8) i;
cm->green_mapping[i] = (DATA8)i; cm->green_mapping[i] = (DATA8) i;
cm->blue_mapping[i] = (DATA8)i; cm->blue_mapping[i] = (DATA8) i;
cm->alpha_mapping[i] = (DATA8)i; cm->alpha_mapping[i] = (DATA8) i;
} }
return cm; return cm;
} }
void void
__imlib_FreeCmod(ImlibColorModifier *cm) __imlib_FreeCmod(ImlibColorModifier * cm)
{ {
free(cm); free(cm);
} }
void void
__imlib_CmodChanged(ImlibColorModifier *cm) __imlib_CmodChanged(ImlibColorModifier * cm)
{ {
mod_count++; mod_count++;
cm->modification_count = mod_count; cm->modification_count = mod_count;
} }
void void
__imlib_CmodSetTables(ImlibColorModifier *cm, __imlib_CmodSetTables(ImlibColorModifier * cm,
DATA8 *r, DATA8 *g, DATA8 *b, DATA8 *a) DATA8 * r, DATA8 * g, DATA8 * b, DATA8 * a)
{ {
int i; int i;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
if (r) if (r)
cm->red_mapping[i] = r[i]; cm->red_mapping[i] = r[i];
if (g) if (g)
cm->green_mapping[i] = g[i]; cm->green_mapping[i] = g[i];
if (b) if (b)
cm->blue_mapping[i] = b[i]; cm->blue_mapping[i] = b[i];
if (a) if (a)
cm->alpha_mapping[i] = a[i]; cm->alpha_mapping[i] = a[i];
} }
__imlib_CmodChanged(cm); __imlib_CmodChanged(cm);
} }
void void
__imlib_CmodReset(ImlibColorModifier *cm) __imlib_CmodReset(ImlibColorModifier * cm)
{ {
int i; int i;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
cm->red_mapping[i] = (DATA8)i; cm->red_mapping[i] = (DATA8) i;
cm->green_mapping[i] = (DATA8)i; cm->green_mapping[i] = (DATA8) i;
cm->blue_mapping[i] = (DATA8)i; cm->blue_mapping[i] = (DATA8) i;
cm->alpha_mapping[i] = (DATA8)i; cm->alpha_mapping[i] = (DATA8) i;
} }
__imlib_CmodChanged(cm); __imlib_CmodChanged(cm);
} }
void void
__imlib_DataCmodApply(DATA32 *data, int w, int h, int jump, __imlib_DataCmodApply(DATA32 * data, int w, int h, int jump,
ImlibImageFlags *fl, ImlibColorModifier *cm) ImlibImageFlags * fl, ImlibColorModifier * cm)
{ {
int x, y; int x, y;
DATA32 *p; DATA32 *p;
DATA8 r, g, b, a; DATA8 r, g, b, a;
/* We might be adding alpha */ /* We might be adding alpha */
if (fl && !(*fl & F_HAS_ALPHA)) if (fl && !(*fl & F_HAS_ALPHA))
{ {
p = data; p = data;
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
R_VAL(p) = R_CMOD(cm, R_VAL(p)); R_VAL(p) = R_CMOD(cm, R_VAL(p));
G_VAL(p) = G_CMOD(cm, G_VAL(p)); G_VAL(p) = G_CMOD(cm, G_VAL(p));
B_VAL(p) = B_CMOD(cm, B_VAL(p)); B_VAL(p) = B_CMOD(cm, B_VAL(p));
A_VAL(p) = A_CMOD(cm, 255); A_VAL(p) = A_CMOD(cm, 255);
p++; p++;
} }
p += jump; p += jump;
} }
if (A_CMOD(cm, 255) != 255) if (A_CMOD(cm, 255) != 255)
*fl |= F_HAS_ALPHA; *fl |= F_HAS_ALPHA;
return; return;
} }
p = data; p = data;
for (y = 0; y < h; y++) for (y = 0; y < h; y++)
{ {
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
R_VAL(p) = R_CMOD(cm, R_VAL(p)); R_VAL(p) = R_CMOD(cm, R_VAL(p));
G_VAL(p) = G_CMOD(cm, G_VAL(p)); G_VAL(p) = G_CMOD(cm, G_VAL(p));
B_VAL(p) = B_CMOD(cm, B_VAL(p)); B_VAL(p) = B_CMOD(cm, B_VAL(p));
A_VAL(p) = A_CMOD(cm, A_VAL(p)); A_VAL(p) = A_CMOD(cm, A_VAL(p));
p++; p++;
} }
p += jump; p += jump;
} }
} }
void void
__imlib_CmodGetTables(ImlibColorModifier *cm, DATA8 *r, DATA8 *g, __imlib_CmodGetTables(ImlibColorModifier * cm, DATA8 * r, DATA8 * g,
DATA8 *b, DATA8 *a) DATA8 * b, DATA8 * a)
{ {
if (r) if (r)
memcpy(r, cm->red_mapping, (256 * sizeof(DATA8))); memcpy(r, cm->red_mapping, (256 * sizeof(DATA8)));
@ -133,86 +133,122 @@ __imlib_CmodGetTables(ImlibColorModifier *cm, DATA8 *r, DATA8 *g,
} }
void void
__imlib_CmodModBrightness(ImlibColorModifier *cm, double v) __imlib_CmodModBrightness(ImlibColorModifier * cm, double v)
{ {
int i, val, val2; int i, val, val2;
val = (int)(v * 255); val = (int)(v * 255);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
val2 = (int)cm->red_mapping[i] + val; val2 = (int)cm->red_mapping[i] + val;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->red_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->red_mapping[i] = (DATA8) val2;
val2 = (int)cm->green_mapping[i] + val; val2 = (int)cm->green_mapping[i] + val;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->green_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->green_mapping[i] = (DATA8) val2;
val2 = (int)cm->blue_mapping[i] + val; val2 = (int)cm->blue_mapping[i] + val;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->blue_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->blue_mapping[i] = (DATA8) val2;
val2 = (int)cm->alpha_mapping[i] + val; val2 = (int)cm->alpha_mapping[i] + val;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->alpha_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->alpha_mapping[i] = (DATA8) val2;
} }
} }
void void
__imlib_CmodModContrast(ImlibColorModifier *cm, double v) __imlib_CmodModContrast(ImlibColorModifier * cm, double v)
{ {
int i, val2; int i, val2;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
val2 = (int)(((double)cm->red_mapping[i] - 127) * v) + 127; val2 = (int)(((double)cm->red_mapping[i] - 127) * v) + 127;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->red_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->red_mapping[i] = (DATA8) val2;
val2 = (int)(((double)cm->green_mapping[i] - 127) * v) + 127; val2 = (int)(((double)cm->green_mapping[i] - 127) * v) + 127;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->green_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->green_mapping[i] = (DATA8) val2;
val2 = (int)(((double)cm->blue_mapping[i] - 127) * v) + 127; val2 = (int)(((double)cm->blue_mapping[i] - 127) * v) + 127;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->blue_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->blue_mapping[i] = (DATA8) val2;
val2 = (int)(((double)cm->alpha_mapping[i] - 127) * v) + 127; val2 = (int)(((double)cm->alpha_mapping[i] - 127) * v) + 127;
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->alpha_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->alpha_mapping[i] = (DATA8) val2;
} }
} }
void void
__imlib_CmodModGamma(ImlibColorModifier *cm, double v) __imlib_CmodModGamma(ImlibColorModifier * cm, double v)
{ {
int i, val2; int i, val2;
if (v < 0.01) if (v < 0.01)
v = 0.01; v = 0.01;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
val2 = (int)(pow(((double)cm->red_mapping[i] / 255), (1 / v)) * 255); val2 = (int)(pow(((double)cm->red_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->red_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->red_mapping[i] = (DATA8) val2;
val2 = (int)(pow(((double)cm->green_mapping[i] / 255), (1 / v)) * 255); val2 = (int)(pow(((double)cm->green_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->green_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->green_mapping[i] = (DATA8) val2;
val2 = (int)(pow(((double)cm->blue_mapping[i] / 255), (1 / v)) * 255); val2 = (int)(pow(((double)cm->blue_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->blue_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->blue_mapping[i] = (DATA8) val2;
val2 = (int)(pow(((double)cm->alpha_mapping[i] / 255), (1 / v)) * 255); val2 = (int)(pow(((double)cm->alpha_mapping[i] / 255), (1 / v)) * 255);
if (val2 < 0) val2 = 0; if (val2 > 255) val2 = 255; if (val2 < 0)
cm->alpha_mapping[i] = (DATA8)val2; val2 = 0;
if (val2 > 255)
val2 = 255;
cm->alpha_mapping[i] = (DATA8) val2;
} }
} }
#if 0 #if 0
void void
__imlib_ImageCmodApply(ImlibImage *im, ImlibColorModifier *cm) __imlib_ImageCmodApply(ImlibImage * im, ImlibColorModifier * cm)
{ {
__imlib_DataCmodApply(im->data, im->w, im->h, 0, cm); __imlib_DataCmodApply(im->data, im->w, im->h, 0, cm);
} }

View File

@ -5,9 +5,9 @@
#include "color.h" #include "color.h"
#include "rgba.h" #include "rgba.h"
static Context *context = NULL; static Context *context = NULL;
static int max_context_count = 128; static int max_context_count = 128;
static int context_counter = 0; static int context_counter = 0;
void void
__imlib_SetMaxContexts(int num) __imlib_SetMaxContexts(int num)
@ -25,125 +25,125 @@ __imlib_GetMaxContexts(void)
void void
__imlib_FlushContexts(void) __imlib_FlushContexts(void)
{ {
Context *ct, *pct, *ctt; Context *ct, *pct, *ctt;
ct = context; ct = context;
pct = NULL; pct = NULL;
while (ct) while (ct)
{ {
ctt = ct; ctt = ct;
ct = ct->next; ct = ct->next;
/* it hasnt been referenced in the last max_context_count refernces */ /* it hasnt been referenced in the last max_context_count refernces */
/* thus old and getrid of it */ /* thus old and getrid of it */
if (ctt->last_use < (context_counter - max_context_count)) if (ctt->last_use < (context_counter - max_context_count))
{ {
if (pct) if (pct)
context = ctt->next; context = ctt->next;
else else
pct->next = ctt->next; pct->next = ctt->next;
if (ctt->palette) if (ctt->palette)
{ {
int i, num[] = { 256, 128, 64, 32, 16, 8, 1 }; int i, num[] = { 256, 128, 64, 32, 16, 8, 1 };
unsigned long pixels[256]; unsigned long pixels[256];
for (i = 0; i < num[ctt->palette_type]; i++) for (i = 0; i < num[ctt->palette_type]; i++)
pixels[i] = (unsigned long)ctt->palette[i]; pixels[i] = (unsigned long)ctt->palette[i];
XFreeColors(ctt->display, ctt->colormap, pixels, XFreeColors(ctt->display, ctt->colormap, pixels,
num[ctt->palette_type], 0); num[ctt->palette_type], 0);
free(ctt->palette); free(ctt->palette);
free(ctt->r_dither); free(ctt->r_dither);
free(ctt->g_dither); free(ctt->g_dither);
free(ctt->b_dither); free(ctt->b_dither);
} }
else if (ctt->r_dither) else if (ctt->r_dither)
{ {
free(ctt->r_dither); free(ctt->r_dither);
free(ctt->g_dither); free(ctt->g_dither);
free(ctt->b_dither); free(ctt->b_dither);
} }
free(ctt); free(ctt);
} }
else else
pct = ctt; pct = ctt;
} }
} }
void void
__imlib_FreeContextForDisplay(Display *d) __imlib_FreeContextForDisplay(Display * d)
{ {
Context *ct; Context *ct;
ct = context; ct = context;
while (ct) while (ct)
{ {
if (ct->display == d) if (ct->display == d)
ct->last_use = - (max_context_count * 2); ct->last_use = -(max_context_count * 2);
ct = ct->next; ct = ct->next;
} }
__imlib_FlushContexts(); __imlib_FlushContexts();
} }
void void
__imlib_FreeContextForColormap(Display *d, Colormap cm) __imlib_FreeContextForColormap(Display * d, Colormap cm)
{ {
Context *ct; Context *ct;
ct = context; ct = context;
while (ct) while (ct)
{ {
if ((ct->display == d) && (ct->colormap == cm)) if ((ct->display == d) && (ct->colormap == cm))
ct->last_use = - (max_context_count * 2); ct->last_use = -(max_context_count * 2);
ct = ct->next; ct = ct->next;
} }
__imlib_FlushContexts(); __imlib_FlushContexts();
} }
void void
__imlib_FreeContextForVisual(Display *d, Visual *v) __imlib_FreeContextForVisual(Display * d, Visual * v)
{ {
Context *ct; Context *ct;
ct = context; ct = context;
while (ct) while (ct)
{ {
if ((ct->display == d) && (ct->visual == v)) if ((ct->display == d) && (ct->visual == v))
ct->last_use = - (max_context_count * 2); ct->last_use = -(max_context_count * 2);
ct = ct->next; ct = ct->next;
} }
__imlib_FlushContexts(); __imlib_FlushContexts();
} }
Context * Context *
__imlib_FindContext(Display *d, Visual *v, Colormap c, int depth) __imlib_FindContext(Display * d, Visual * v, Colormap c, int depth)
{ {
Context *ct, *pct; Context *ct, *pct;
pct = NULL; pct = NULL;
ct = context; ct = context;
while (ct) while (ct)
{ {
if ((ct->display == d) && (ct->visual == v) && if ((ct->display == d) && (ct->visual == v) &&
(ct->colormap == c) && (ct->depth == depth)) (ct->colormap == c) && (ct->depth == depth))
{ {
if (pct) if (pct)
{ {
pct->next = ct->next; pct->next = ct->next;
ct->next = context; ct->next = context;
context = ct; context = ct;
} }
return ct; return ct;
} }
pct = ct; pct = ct;
ct = ct->next; ct = ct->next;
} }
return NULL; return NULL;
} }
Context * Context *
__imlib_NewContext(Display *d, Visual *v, Colormap c, int depth) __imlib_NewContext(Display * d, Visual * v, Colormap c, int depth)
{ {
Context *ct; Context *ct;
context_counter++; context_counter++;
ct = malloc(sizeof(Context)); ct = malloc(sizeof(Context));
@ -156,47 +156,47 @@ __imlib_NewContext(Display *d, Visual *v, Colormap c, int depth)
if (depth <= 8) if (depth <= 8)
{ {
ct->palette = __imlib_AllocColorTable(d, c, &(ct->palette_type), v); ct->palette = __imlib_AllocColorTable(d, c, &(ct->palette_type), v);
ct->r_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256); ct->r_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256);
ct->g_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256); ct->g_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256);
ct->b_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256); ct->b_dither = malloc(sizeof(DATA8) * DM_X * DM_Y * 256);
__imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither, __imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither,
(void *)ct->b_dither, depth, ct->palette_type); (void *)ct->b_dither, depth, ct->palette_type);
} }
else else
{ {
ct->palette = NULL; ct->palette = NULL;
ct->palette_type = 0; ct->palette_type = 0;
if ((depth > 8) && (depth <= 16)) if ((depth > 8) && (depth <= 16))
{ {
ct->r_dither = malloc(sizeof(DATA16) * 4 * 4 * 256); ct->r_dither = malloc(sizeof(DATA16) * 4 * 4 * 256);
ct->g_dither = malloc(sizeof(DATA16) * 4 * 4 * 256); ct->g_dither = malloc(sizeof(DATA16) * 4 * 4 * 256);
ct->b_dither = malloc(sizeof(DATA16) * 4 * 4 * 256); ct->b_dither = malloc(sizeof(DATA16) * 4 * 4 * 256);
__imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither,
(void *)ct->b_dither, depth, 0);
}
else
{
ct->r_dither = NULL;
ct->g_dither = NULL;
ct->b_dither = NULL;
__imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither, __imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither,
(void *)ct->b_dither, depth, 0); (void *)ct->b_dither, depth, 0);
} }
else
{
ct->r_dither = NULL;
ct->g_dither = NULL;
ct->b_dither = NULL;
__imlib_RGBA_init((void *)ct->r_dither, (void *)ct->g_dither,
(void *)ct->b_dither, depth, 0);
}
} }
return ct; return ct;
} }
Context * Context *
__imlib_GetContext(Display *d, Visual *v, Colormap c, int depth) __imlib_GetContext(Display * d, Visual * v, Colormap c, int depth)
{ {
Context *ct; Context *ct;
ct = __imlib_FindContext(d, v, c, depth); ct = __imlib_FindContext(d, v, c, depth);
if (ct) if (ct)
{ {
ct->last_use = context_counter; ct->last_use = context_counter;
return ct; return ct;
} }
ct = __imlib_NewContext(d, v, c, depth); ct = __imlib_NewContext(d, v, c, depth);
ct->next = context; ct->next = context;

View File

@ -8,50 +8,49 @@
#include "draw.h" #include "draw.h"
char char
__imlib_CreatePixmapsForImage(Display *d, Drawable w, Visual *v, int depth, __imlib_CreatePixmapsForImage(Display * d, Drawable w, Visual * v, int depth,
Colormap cm, ImlibImage *im, Pixmap *p, Mask *m, Colormap cm, ImlibImage * im, Pixmap * p,
int sx, int sy, int sw, int sh, Mask * m, int sx, int sy, int sw, int sh, int dw,
int dw, int dh, int dh, char antialias, char hiq,
char antialias, char hiq, char dither_mask, char dither_mask, ImlibColorModifier * cmod)
ImlibColorModifier *cmod)
{ {
ImlibImagePixmap *ip = NULL; ImlibImagePixmap *ip = NULL;
Pixmap pmap = 0; Pixmap pmap = 0;
Pixmap mask = 0; Pixmap mask = 0;
long long mod_count = 0; long long mod_count = 0;
if (cmod) if (cmod)
mod_count = cmod->modification_count; mod_count = cmod->modification_count;
ip = __imlib_FindCachedImagePixmap(im, dw, dh, d, v, depth, sx, sy, ip = __imlib_FindCachedImagePixmap(im, dw, dh, d, v, depth, sx, sy,
sw, sh, cm, antialias, hiq, dither_mask, sw, sh, cm, antialias, hiq, dither_mask,
mod_count); mod_count);
if (ip) if (ip)
{ {
if (p) if (p)
*p = ip->pixmap; *p = ip->pixmap;
if (m) if (m)
*m = ip->mask; *m = ip->mask;
ip->references++; ip->references++;
#ifdef DEBUG_CACHE #ifdef DEBUG_CACHE
fprintf(stderr, "[Imlib2] Match found in cache. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", fprintf(stderr,
ip->references, ip->pixmap, ip->mask); "[Imlib2] Match found in cache. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n",
ip->references, ip->pixmap, ip->mask);
#endif #endif
return 2; return 2;
} }
if (p) if (p)
{ {
pmap = XCreatePixmap(d, w, dw, dh, depth); pmap = XCreatePixmap(d, w, dw, dh, depth);
*p = pmap; *p = pmap;
} }
if (m) if (m)
{ {
if (IMAGE_HAS_ALPHA(im)) if (IMAGE_HAS_ALPHA(im))
mask = XCreatePixmap(d, w, dw, dh, 1); mask = XCreatePixmap(d, w, dw, dh, 1);
*m = mask; *m = mask;
} }
__imlib_RenderImage(d, im, pmap, mask, v, cm, depth, sx, sy, sw, sh, 0, 0, __imlib_RenderImage(d, im, pmap, mask, v, cm, depth, sx, sy, sw, sh, 0, 0,
dw, dh, antialias, hiq, 0, dither_mask, cmod, dw, dh, antialias, hiq, 0, dither_mask, cmod, OP_COPY);
OP_COPY);
ip = __imlib_ProduceImagePixmap(); ip = __imlib_ProduceImagePixmap();
ip->visual = v; ip->visual = v;
ip->depth = depth; ip->depth = depth;
@ -79,9 +78,9 @@ __imlib_CreatePixmapsForImage(Display *d, Drawable w, Visual *v, int depth,
ip->mask = mask; ip->mask = mask;
__imlib_AddImagePixmapToCache(ip); __imlib_AddImagePixmapToCache(ip);
#ifdef DEBUG_CACHE #ifdef DEBUG_CACHE
fprintf(stderr, "[Imlib2] Created pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", fprintf(stderr,
ip->references, ip->pixmap, ip->mask); "[Imlib2] Created pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n",
ip->references, ip->pixmap, ip->mask);
#endif #endif
return 1; return 1;
} }

View File

@ -16,9 +16,8 @@
#include "script.h" #include "script.h"
#include "loaderpath.h" #include "loaderpath.h"
pImlibExternalFilter filters = NULL;
pImlibExternalFilter filters = NULL; int dyn_initialised = 0;
int dyn_initialised = 0;
#define MALLOCSHOW #define MALLOCSHOW
#define FREESHOW #define FREESHOW
@ -26,132 +25,138 @@ int dyn_initialised = 0;
#define FDEBUG #define FDEBUG
*/ */
pImlibExternalFilter __imlib_LoadFilter( char *file ) pImlibExternalFilter
__imlib_LoadFilter(char *file)
{ {
ImlibExternalFilter *ptr; ImlibExternalFilter *ptr;
struct imlib_filter_info *info; struct imlib_filter_info *info;
/* printf( "Loading filter %s\n", file ); */ /* printf( "Loading filter %s\n", file ); */
MALLOCSHOW; MALLOCSHOW;
ptr = malloc( sizeof( ImlibExternalFilter ) ); ptr = malloc(sizeof(ImlibExternalFilter));
ptr->filename = strdup(file); ptr->filename = strdup(file);
ptr->handle = lt_dlopenext(file); ptr->handle = lt_dlopenext(file);
if( !ptr->handle ) if (!ptr->handle)
{ {
FREESHOW; FREESHOW;
free( ptr->filename ); free(ptr->filename);
FREESHOW; FREESHOW;
free( ptr ); free(ptr);
return NULL; return NULL;
} }
ptr->init_filter = lt_dlsym( ptr->handle, "init" ); ptr->init_filter = lt_dlsym(ptr->handle, "init");
ptr->deinit_filter = lt_dlsym( ptr->handle, "deinit" ); ptr->deinit_filter = lt_dlsym(ptr->handle, "deinit");
ptr->exec_filter = lt_dlsym( ptr->handle, "exec" ); ptr->exec_filter = lt_dlsym(ptr->handle, "exec");
if( !ptr->init_filter || !ptr->deinit_filter || !ptr->exec_filter ) if (!ptr->init_filter || !ptr->deinit_filter || !ptr->exec_filter)
{ {
lt_dlclose( ptr->handle ); lt_dlclose(ptr->handle);
FREESHOW; FREESHOW;
free( ptr->filename ); free(ptr->filename);
FREESHOW; FREESHOW;
free( ptr ); free(ptr);
return NULL; return NULL;
} }
info = malloc( sizeof( struct imlib_filter_info ) ); info = malloc(sizeof(struct imlib_filter_info));
ptr->init_filter( info ); ptr->init_filter(info);
ptr->num_filters = info->num_filters; ptr->num_filters = info->num_filters;
ptr->filters = info->filters; ptr->filters = info->filters;
ptr->name = info->name; ptr->name = info->name;
ptr->author = info->author; ptr->author = info->author;
ptr->description = info->description; ptr->description = info->description;
free( info ); free(info);
#ifdef FDEBUG #ifdef FDEBUG
printf( "Filter has %d filters in it.\n", ptr->num_filters ); printf("Filter has %d filters in it.\n", ptr->num_filters);
for( i = 0; i < ptr->num_filters; i++ ) for (i = 0; i < ptr->num_filters; i++)
printf( " -> \"%s\"\n", ptr->filters[i] ); printf(" -> \"%s\"\n", ptr->filters[i]);
#endif #endif
ptr->next = NULL; ptr->next = NULL;
return ptr; return ptr;
} }
void __imlib_dynamic_filters_init() void
__imlib_dynamic_filters_init()
{ {
char **list; char **list;
int num_filters, i = 0; int num_filters, i = 0;
ImlibExternalFilter *ptr, *tptr; ImlibExternalFilter *ptr, *tptr;
if( ! dyn_initialised ) if (!dyn_initialised)
{ {
MALLOCSHOW; MALLOCSHOW;
filters = malloc( sizeof( ImlibExternalFilter ) ); filters = malloc(sizeof(ImlibExternalFilter));
filters->filename = ""; filters->filename = "";
filters->next = NULL; filters->next = NULL;
ptr = filters; ptr = filters;
#ifdef FDEBUG #ifdef FDEBUG
printf( "DEBUG: Dynamic filters Initisialising\n" ); printf("DEBUG: Dynamic filters Initisialising\n");
#endif #endif
dyn_initialised = 1; dyn_initialised = 1;
#ifdef FDEBUG #ifdef FDEBUG
printf( "DEBUG: Loading Filters\n" ); printf("DEBUG: Loading Filters\n");
#endif #endif
list = __imlib_ListFilters( &num_filters ); list = __imlib_ListFilters(&num_filters);
for( i = num_filters - 1; i >= 0; i -- ) for (i = num_filters - 1; i >= 0; i--)
{ {
tptr = NULL; tptr = NULL;
if((tptr = __imlib_LoadFilter( list[i] )) != NULL ) if ((tptr = __imlib_LoadFilter(list[i])) != NULL)
{ {
ptr->next = tptr; ptr->next = tptr;
ptr = ptr->next; ptr = ptr->next;
} }
if( list[i] ){ if (list[i])
FREESHOW; {
free( list[i] ); FREESHOW;
} free(list[i]);
} }
FREESHOW; }
if( list ) FREESHOW;
free( list ); if (list)
} free(list);
}
} }
void __imlib_dynamic_filters_deinit() void
__imlib_dynamic_filters_deinit()
{ {
} }
pImlibExternalFilter __imlib_get_dynamic_filter( char *name ) pImlibExternalFilter
__imlib_get_dynamic_filter(char *name)
{ {
pImlibExternalFilter f_ptr; pImlibExternalFilter f_ptr;
int i = 0; int i = 0;
/* scan the filters */ /* scan the filters */
for( f_ptr = filters->next; f_ptr != NULL; f_ptr = f_ptr->next ) for (f_ptr = filters->next; f_ptr != NULL; f_ptr = f_ptr->next)
{ {
/* scan the methods provided */ /* scan the methods provided */
for( i = 0; i < f_ptr->num_filters; i++ ) for (i = 0; i < f_ptr->num_filters; i++)
{ {
if( strcmp( f_ptr->filters[i], name ) == 0 ) if (strcmp(f_ptr->filters[i], name) == 0)
{ {
#ifdef FDEBUG #ifdef FDEBUG
printf( "DEBUG: Found filter \"%s\"\n", name ); printf("DEBUG: Found filter \"%s\"\n", name);
#endif #endif
return f_ptr; return f_ptr;
} }
} }
} }
return NULL; return NULL;
} }
/* loader dir */ /* loader dir */
char **__imlib_ListFilters(int *num_ret) char **
__imlib_ListFilters(int *num_ret)
{ {
char **list = NULL, **l, *s; char **list = NULL, **l, *s;
int num, i, pi = 0; int num, i, pi = 0;
*num_ret = 0; *num_ret = 0;
/* same for system loader path */ /* same for system loader path */
s = (char *) malloc(sizeof(SYS_LOADERS_PATH) + 7 + 1); s = (char *)malloc(sizeof(SYS_LOADERS_PATH) + 7 + 1);
sprintf(s, SYS_LOADERS_PATH "/filter"); sprintf(s, SYS_LOADERS_PATH "/filter");
#ifndef __EMX__ #ifndef __EMX__
l = __imlib_FileDir(s, &num); l = __imlib_FileDir(s, &num);
@ -159,21 +164,23 @@ char **__imlib_ListFilters(int *num_ret)
l = __imlib_FileDir(__XOS2RedirRoot(s), &num); l = __imlib_FileDir(__XOS2RedirRoot(s), &num);
#endif #endif
if (num > 0) if (num > 0)
{ {
*num_ret += num; *num_ret += num;
list = realloc(list, sizeof(char *) * *num_ret); list = realloc(list, sizeof(char *) * *num_ret);
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
s = (char *) realloc(s, sizeof(SYS_LOADERS_PATH) + 8 + strlen(l[i]) + 1); s = (char *)realloc(s,
sprintf(s, SYS_LOADERS_PATH "/filter/%s", l[i]); sizeof(SYS_LOADERS_PATH) + 8 + strlen(l[i]) +
1);
sprintf(s, SYS_LOADERS_PATH "/filter/%s", l[i]);
#ifndef __EMX__ #ifndef __EMX__
list[pi + i] = strdup(s); list[pi + i] = strdup(s);
#else #else
list[pi + i] = strdup(__XOS2RedirRoot(s)); list[pi + i] = strdup(__XOS2RedirRoot(s));
#endif #endif
} }
__imlib_FileFreeDirList(l, num); __imlib_FileFreeDirList(l, num);
} }
free(s); free(s);
/* List currently contains *everything in there* we need to weed out /* List currently contains *everything in there* we need to weed out

View File

@ -13,81 +13,85 @@
#include <pwd.h> #include <pwd.h>
#include "file.h" #include "file.h"
static void __imlib_FileFieldWord(char *s, int num, char *wd); static void __imlib_FileFieldWord(char *s, int num, char *wd);
char * char *
__imlib_FileKey(const char *file) __imlib_FileKey(const char *file)
{ {
char *newfile; char *newfile;
newfile = malloc(strlen(file) + 1); newfile = malloc(strlen(file) + 1);
if (!newfile) return NULL; if (!newfile)
return NULL;
newfile[0] = 0; newfile[0] = 0;
{ {
char *p1, *p2; char *p1, *p2;
int go; int go;
go = 0; go = 0;
p1 = (char *)file; p1 = (char *)file;
p2 = newfile; p2 = newfile;
while (p1[0]) while (p1[0])
{ {
if (go) if (go)
{ {
p2[0] = p1[0]; p2[0] = p1[0];
p2++; p2++;
} }
if ((p1[0] == ':') && (p1[1] != ':')) if ((p1[0] == ':') && (p1[1] != ':'))
go = 1; go = 1;
if ((p1[0] == ':') && (p1[1] == ':')) if ((p1[0] == ':') && (p1[1] == ':'))
p1++; p1++;
p1++; p1++;
} }
p2[0] = p1[0]; p2[0] = p1[0];
} }
if (newfile[0]) return newfile; if (newfile[0])
else free(newfile); return newfile;
else
free(newfile);
return NULL; return NULL;
} }
char * char *
__imlib_FileRealFile(const char *file) __imlib_FileRealFile(const char *file)
{ {
char *newfile; char *newfile;
newfile = malloc(strlen(file) + 1); newfile = malloc(strlen(file) + 1);
if (!newfile) return NULL; if (!newfile)
return NULL;
newfile[0] = 0; newfile[0] = 0;
{ {
char *p1, *p2; char *p1, *p2;
p1 = (char *)file; p1 = (char *)file;
p2 = newfile; p2 = newfile;
while (p1[0]) while (p1[0])
{ {
if (p1[0] == ':') if (p1[0] == ':')
{ {
if (p1[1] == ':') if (p1[1] == ':')
{ {
p2[0] = ':'; p2[0] = ':';
p2++; p2++;
p1++; p1++;
} }
else else
{ {
p2[0] = 0; p2[0] = 0;
return newfile; return newfile;
} }
} }
else else
{ {
p2[0] = p1[0]; p2[0] = p1[0];
p2++; p2++;
} }
p1++; p1++;
} }
p2[0] = p1[0]; p2[0] = p1[0];
} }
return newfile; return newfile;
} }
@ -98,16 +102,17 @@ __imlib_FileExtension(const char *file)
char *fl; char *fl;
fl = __imlib_FileRealFile(file); fl = __imlib_FileRealFile(file);
if (!fl) return strdup(""); if (!fl)
return strdup("");
p = strrchr(file, '.'); p = strrchr(file, '.');
if (p) if (p)
{ {
char *ret; char *ret;
ret = strdup(p + 1); ret = strdup(p + 1);
free(fl); free(fl);
return ret; return ret;
} }
free(fl); free(fl);
return strdup(""); return strdup("");
} }
@ -118,14 +123,18 @@ __imlib_FileExists(const char *s)
struct stat st; struct stat st;
char *fl; char *fl;
if ((!s) || (!*s)) return 0; if ((!s) || (!*s))
if (__imlib_IsRealFile(s)) fl = strdup(s); return 0;
else fl = __imlib_FileRealFile(s); if (__imlib_IsRealFile(s))
if (!fl) return 0; fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0) if (stat(fl, &st) < 0)
{ {
free(fl); free(fl);
return 0; return 0;
} }
free(fl); free(fl);
return 1; return 1;
@ -137,19 +146,23 @@ __imlib_FileIsFile(const char *s)
struct stat st; struct stat st;
char *fl; char *fl;
if ((!s) || (!*s)) return 0; if ((!s) || (!*s))
if (__imlib_IsRealFile(s)) fl = strdup(s); return 0;
else fl = __imlib_FileRealFile(s); if (__imlib_IsRealFile(s))
if (!fl) return 0; fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0) if (stat(fl, &st) < 0)
{ {
free(fl); free(fl);
return 0; return 0;
} }
if (S_ISREG(st.st_mode)) if (S_ISREG(st.st_mode))
{ {
free(fl); free(fl);
return 1; return 1;
} }
free(fl); free(fl);
return 0; return 0;
@ -161,19 +174,23 @@ __imlib_FileIsDir(const char *s)
struct stat st; struct stat st;
char *fl; char *fl;
if ((!s) || (!*s)) return 0; if ((!s) || (!*s))
if (__imlib_IsRealFile(s)) fl = strdup(s); return 0;
else fl = __imlib_FileRealFile(s); if (__imlib_IsRealFile(s))
if (!fl) return 0; fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0) if (stat(fl, &st) < 0)
{ {
free(fl); free(fl);
return 0; return 0;
} }
if (S_ISDIR(st.st_mode)) if (S_ISDIR(st.st_mode))
{ {
free(fl); free(fl);
return 1; return 1;
} }
free(fl); free(fl);
return 0; return 0;
@ -185,14 +202,18 @@ __imlib_FilePermissions(const char *s)
struct stat st; struct stat st;
char *fl; char *fl;
if ((!s) || (!*s)) return 0; if ((!s) || (!*s))
if (__imlib_IsRealFile(s)) fl = strdup(s); return 0;
else fl = __imlib_FileRealFile(s); if (__imlib_IsRealFile(s))
if (!fl) return 0; fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0) if (stat(fl, &st) < 0)
{ {
free(fl); free(fl);
return 0; return 0;
} }
free(fl); free(fl);
return st.st_mode; return st.st_mode;
@ -204,13 +225,16 @@ __imlib_FileCanRead(const char *s)
char *fl; char *fl;
int val; int val;
if (__imlib_IsRealFile(s)) fl = strdup(s); if (__imlib_IsRealFile(s))
else fl = __imlib_FileRealFile(s); fl = strdup(s);
if (!fl) return 0; else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (!(__imlib_FilePermissions(fl) & (S_IRUSR | S_IRGRP | S_IROTH))) if (!(__imlib_FilePermissions(fl) & (S_IRUSR | S_IRGRP | S_IROTH)))
{ {
free(fl); free(fl);
return 0; return 0;
} }
val = (1 + access(fl, R_OK)); val = (1 + access(fl, R_OK));
@ -228,61 +252,61 @@ __imlib_FileDir(char *dir, int *num)
struct dirent *dp; struct dirent *dp;
if ((!dir) || (!*dir)) if ((!dir) || (!*dir))
return(0); return (0);
dirp = opendir(dir); dirp = opendir(dir);
if (!dirp) if (!dirp)
{ {
*num = 0; *num = 0;
return(NULL); return (NULL);
} }
/* count # of entries in dir (worst case) */ /* count # of entries in dir (worst case) */
for (dirlen = 0; (dp = readdir(dirp)) != NULL; dirlen++); for (dirlen = 0; (dp = readdir(dirp)) != NULL; dirlen++);
if (!dirlen) if (!dirlen)
{ {
closedir(dirp); closedir(dirp);
*num = dirlen; *num = dirlen;
return(NULL); return (NULL);
} }
names = (char **)malloc(dirlen * sizeof(char *)); names = (char **)malloc(dirlen * sizeof(char *));
if (!names) if (!names)
return(NULL); return (NULL);
rewinddir(dirp); rewinddir(dirp);
for (i = 0; i < dirlen;) for (i = 0; i < dirlen;)
{ {
dp = readdir(dirp); dp = readdir(dirp);
if (!dp) if (!dp)
break; break;
if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, ".."))) if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
{ {
names[i] = strdup(dp->d_name); names[i] = strdup(dp->d_name);
i++; i++;
} }
} }
if (i < dirlen) if (i < dirlen)
dirlen = i; /* dir got shorter... */ dirlen = i; /* dir got shorter... */
closedir(dirp); closedir(dirp);
*num = dirlen; *num = dirlen;
/* do a simple bubble sort here to alphanumberic it */ /* do a simple bubble sort here to alphanumberic it */
while (!done) while (!done)
{ {
done = 1; done = 1;
for (i = 0; i < dirlen - 1; i++) for (i = 0; i < dirlen - 1; i++)
{ {
if (strcmp(names[i], names[i + 1]) > 0) if (strcmp(names[i], names[i + 1]) > 0)
{ {
char *tmp; char *tmp;
tmp = names[i]; tmp = names[i];
names[i] = names[i + 1]; names[i] = names[i + 1];
names[i + 1] = tmp; names[i + 1] = tmp;
done = 0; done = 0;
} }
} }
} }
return(names); return (names);
} }
void void
@ -292,7 +316,7 @@ __imlib_FileFreeDirList(char **l, int num)
return; return;
while (num--) while (num--)
if (l[num]) if (l[num])
free(l[num]); free(l[num]);
free(l); free(l);
return; return;
} }
@ -309,7 +333,8 @@ __imlib_FileDel(char *s)
int int
__imlib_IsRealFile(const char *s) __imlib_IsRealFile(const char *s)
{ {
struct stat st; struct stat st;
return ((stat(s, &st) != -1) && (S_ISREG(st.st_mode))); return ((stat(s, &st) != -1) && (S_ISREG(st.st_mode)));
} }
@ -319,19 +344,23 @@ __imlib_FileModDate(const char *s)
struct stat st; struct stat st;
char *fl; char *fl;
if ((!s) || (!*s)) return 0; if ((!s) || (!*s))
if (__imlib_IsRealFile(s)) fl = strdup(s); return 0;
else fl = __imlib_FileRealFile(s); if (__imlib_IsRealFile(s))
if (!fl) return 0; fl = strdup(s);
else
fl = __imlib_FileRealFile(s);
if (!fl)
return 0;
if (stat(fl, &st) < 0) if (stat(fl, &st) < 0)
{ {
free(fl); free(fl);
return 0; return 0;
} }
if (st.st_mtime > st.st_ctime) if (st.st_mtime > st.st_ctime)
{ {
free(fl); free(fl);
return st.st_mtime; return st.st_mtime;
} }
free(fl); free(fl);
return st.st_ctime; return st.st_ctime;
@ -344,6 +373,7 @@ __imlib_FileHomeDir(int uid)
static char *usr_s = NULL; static char *usr_s = NULL;
char *s; char *s;
struct passwd *pwd; struct passwd *pwd;
#ifndef __EMX__ #ifndef __EMX__
s = getenv("HOME"); s = getenv("HOME");
if (s) if (s)
@ -352,15 +382,15 @@ __imlib_FileHomeDir(int uid)
usr_uid = getuid(); usr_uid = getuid();
if ((uid == usr_uid) && (usr_s)) if ((uid == usr_uid) && (usr_s))
{ {
return(strdup(usr_s)); return (strdup(usr_s));
} }
pwd = getpwuid(uid); pwd = getpwuid(uid);
if (pwd) if (pwd)
{ {
s = strdup(pwd->pw_dir); s = strdup(pwd->pw_dir);
if (uid == usr_uid) if (uid == usr_uid)
usr_s = strdup(s); usr_s = strdup(s);
return(s); return (s);
} }
#else #else
if ((s = getenv("HOME")) != NULL) if ((s = getenv("HOME")) != NULL)
@ -371,7 +401,6 @@ __imlib_FileHomeDir(int uid)
return NULL; return NULL;
} }
/* gets word number [num] in the string [s] and copies it into [wd] */ /* gets word number [num] in the string [s] and copies it into [wd] */
/* wd is NULL terminated. If word [num] does not exist wd = "" */ /* wd is NULL terminated. If word [num] does not exist wd = "" */
/* NB: this function now handles quotes so for a line: */ /* NB: this function now handles quotes so for a line: */
@ -391,23 +420,13 @@ __imlib_FileField(char *s, int field)
__imlib_FileFieldWord(s, field + 1, buf); __imlib_FileFieldWord(s, field + 1, buf);
if (buf[0]) if (buf[0])
{ {
if ((!strcmp(buf, "NULL")) || if ((!strcmp(buf, "NULL")) || (!strcmp(buf, "(null)")))
(!strcmp(buf, "(null)"))) return (NULL);
return(NULL); return (strdup(buf));
return(strdup(buf));
} }
return(NULL); return (NULL);
} }
static void static void
__imlib_FileFieldWord(char *s, int num, char *wd) __imlib_FileFieldWord(char *s, int num, char *wd)
{ {
@ -429,45 +448,45 @@ __imlib_FileFieldWord(char *s, int num, char *wd)
end = NULL; end = NULL;
while ((*cur) && (count < num)) while ((*cur) && (count < num))
{ {
if (inword) if (inword)
{ {
if (inquote) if (inquote)
{ {
if (*cur == '"') if (*cur == '"')
{ {
inquote = 0; inquote = 0;
inword = 0; inword = 0;
end = cur; end = cur;
count++; count++;
} }
} }
else else
{ {
if (isspace(*cur)) if (isspace(*cur))
{ {
end = cur; end = cur;
inword = 0; inword = 0;
count++; count++;
} }
} }
} }
else else
{ {
if (!isspace(*cur)) if (!isspace(*cur))
{ {
if (*cur == '"') if (*cur == '"')
{ {
inquote = 1; inquote = 1;
start = cur + 1; start = cur + 1;
} }
else else
start = cur; start = cur;
inword = 1; inword = 1;
} }
} }
if (count == num) if (count == num)
break; break;
cur++; cur++;
} }
if (!start) if (!start)
return; return;
@ -480,9 +499,8 @@ __imlib_FileFieldWord(char *s, int num, char *wd)
len = 4000; len = 4000;
if (len > 0) if (len > 0)
{ {
strncpy(wd, start, len); strncpy(wd, start, len);
wd[len] = 0; wd[len] = 0;
} }
return; return;
} }

View File

@ -5,31 +5,34 @@
#include "filter.h" #include "filter.h"
/*\ Create and return an empty filter struct \*/ /*\ Create and return an empty filter struct \*/
ImlibFilter * ImlibFilter *
__imlib_CreateFilter(int size) __imlib_CreateFilter(int size)
{ {
ImlibFilter *fil; ImlibFilter *fil;
fil = malloc(sizeof(ImlibFilter)); fil = malloc(sizeof(ImlibFilter));
if (size > 0) { if (size > 0)
fil->alpha.pixels = malloc(size * sizeof(ImlibFilterPixel)); {
fil->red.pixels = malloc(size * sizeof(ImlibFilterPixel)); fil->alpha.pixels = malloc(size * sizeof(ImlibFilterPixel));
fil->green.pixels = malloc(size * sizeof(ImlibFilterPixel)); fil->red.pixels = malloc(size * sizeof(ImlibFilterPixel));
fil->blue.pixels = malloc(size * sizeof(ImlibFilterPixel)); fil->green.pixels = malloc(size * sizeof(ImlibFilterPixel));
fil->alpha.size = size; fil->blue.pixels = malloc(size * sizeof(ImlibFilterPixel));
fil->red.size = size; fil->alpha.size = size;
fil->green.size = size; fil->red.size = size;
fil->blue.size = size; fil->green.size = size;
} else { fil->blue.size = size;
fil->alpha.pixels = 0; }
fil->red.pixels = 0; else
fil->green.pixels = 0; {
fil->blue.pixels = 0; fil->alpha.pixels = 0;
fil->alpha.size = 0; fil->red.pixels = 0;
fil->red.size = 0; fil->green.pixels = 0;
fil->green.size = 0; fil->blue.pixels = 0;
fil->blue.size = 0; fil->alpha.size = 0;
} fil->red.size = 0;
fil->green.size = 0;
fil->blue.size = 0;
}
fil->alpha.entries = 0; fil->alpha.entries = 0;
fil->red.entries = 0; fil->red.entries = 0;
fil->green.entries = 0; fil->green.entries = 0;
@ -47,7 +50,7 @@ __imlib_CreateFilter(int size)
/*\ Free a filter struct \*/ /*\ Free a filter struct \*/
void void
__imlib_FreeFilter(ImlibFilter *fil) __imlib_FreeFilter(ImlibFilter * fil)
{ {
free(fil->alpha.pixels); free(fil->alpha.pixels);
free(fil->red.pixels); free(fil->red.pixels);
@ -57,36 +60,44 @@ __imlib_FreeFilter(ImlibFilter *fil)
} }
void void
__imlib_FilterSetColor(ImlibFilterColor *fil, int x, int y, __imlib_FilterSetColor(ImlibFilterColor * fil, int x, int y,
int a, int r, int g, int b) int a, int r, int g, int b)
{ {
int i; int i;
ImlibFilterPixel *pix = fil->pixels; ImlibFilterPixel *pix = fil->pixels;
/*\ Look for an entry matching (x, y) \*/ /*\ Look for an entry matching (x, y) \ */
for (i = fil->entries; --i >= 0; ) { for (i = fil->entries; --i >= 0;)
if ((pix[i].xoff == x) && (pix[i].yoff == y)) {
break; if ((pix[i].xoff == x) && (pix[i].yoff == y))
} break;
/*\ If all zero, remove the found entry \*/ }
if (!(a | r | g | b)) { /*\ If all zero, remove the found entry \ */
if (i >= 0) { if (!(a | r | g | b))
while (i < fil->entries) { {
pix[i] = pix[i + 1]; if (i >= 0)
} {
fil->entries--; while (i < fil->entries)
} {
return; pix[i] = pix[i + 1];
} }
/*\ No match, then make a new entry \*/ fil->entries--;
if (i < 0) i = fil->entries; }
if (i >= fil->size) { return;
fil->size += 4; }
pix = realloc(pix, (fil->size * sizeof(ImlibFilterPixel))); /*\ No match, then make a new entry \ */
if (!pix) return; if (i < 0)
fil->pixels = pix; i = fil->entries;
} if (i >= fil->size)
if (i >= fil->entries) fil->entries = i + 1; {
fil->size += 4;
pix = realloc(pix, (fil->size * sizeof(ImlibFilterPixel)));
if (!pix)
return;
fil->pixels = pix;
}
if (i >= fil->entries)
fil->entries = i + 1;
pix[i].xoff = x; pix[i].xoff = x;
pix[i].yoff = y; pix[i].yoff = y;
pix[i].a = a; pix[i].a = a;
@ -97,7 +108,7 @@ __imlib_FilterSetColor(ImlibFilterColor *fil, int x, int y,
/*\ Set the divisors manually \*/ /*\ Set the divisors manually \*/
void void
__imlib_FilterDivisors(ImlibFilter *fil, int a, int r, int g, int b) __imlib_FilterDivisors(ImlibFilter * fil, int a, int r, int g, int b)
{ {
fil->alpha.div = a; fil->alpha.div = a;
fil->red.div = r; fil->red.div = r;
@ -107,7 +118,7 @@ __imlib_FilterDivisors(ImlibFilter *fil, int a, int r, int g, int b)
/*\ Set the constants \*/ /*\ Set the constants \*/
void void
__imlib_FilterConstants(ImlibFilter *fil, int a, int r, int g, int b) __imlib_FilterConstants(ImlibFilter * fil, int a, int r, int g, int b)
{ {
fil->alpha.cons = a; fil->alpha.cons = a;
fil->red.cons = r; fil->red.cons = r;
@ -116,44 +127,51 @@ __imlib_FilterConstants(ImlibFilter *fil, int a, int r, int g, int b)
} }
static int static int
__imlib_FilterCalcDiv(ImlibFilterColor *fil) __imlib_FilterCalcDiv(ImlibFilterColor * fil)
{ {
int i, ret; int i, ret;
ImlibFilterPixel *pix; ImlibFilterPixel *pix;
if (fil->div) return fil->div; if (fil->div)
return fil->div;
ret = 0; ret = 0;
pix = fil->pixels; pix = fil->pixels;
for (i = fil->entries; --i >= 0; ) { for (i = fil->entries; --i >= 0;)
ret += pix->a + pix->r + pix->g + pix->b; {
pix++; ret += pix->a + pix->r + pix->g + pix->b;
} pix++;
}
return ret; return ret;
} }
static int static int
__imlib_FilterGet(ImlibFilterColor *fil, DATA32 *data, __imlib_FilterGet(ImlibFilterColor * fil, DATA32 * data,
int w, int h, int x, int y) int w, int h, int x, int y)
{ {
int i, off, ret; int i, off, ret;
ImlibFilterPixel *pix; ImlibFilterPixel *pix;
DATA32 *p; DATA32 *p;
ret = fil->cons; ret = fil->cons;
pix = fil->pixels; pix = fil->pixels;
for (i = fil->entries; --i >= 0; ) { for (i = fil->entries; --i >= 0;)
off = x + pix->xoff; {
if (off < 0) off = 0; off = x + pix->xoff;
if (off >= w) off = w - 1; if (off < 0)
p = data + off; off = 0;
off = y + pix->yoff; if (off >= w)
if (off < 0) off = 0; off = w - 1;
if (off >= h) off = h - 1; p = data + off;
p += off * w; off = y + pix->yoff;
ret += A_VAL(p) * pix->a + R_VAL(p) * pix->r + if (off < 0)
G_VAL(p) * pix->g + B_VAL(p) * pix->b; off = 0;
pix++; if (off >= h)
} off = h - 1;
p += off * w;
ret += A_VAL(p) * pix->a + R_VAL(p) * pix->r +
G_VAL(p) * pix->g + B_VAL(p) * pix->b;
pix++;
}
return ret; return ret;
} }
@ -164,13 +182,14 @@ __imlib_FilterGet(ImlibFilterColor *fil, DATA32 *data,
|*| NB: This is currently not very optimal, and could probably be improved |*| NB: This is currently not very optimal, and could probably be improved
\*/ \*/
void void
__imlib_FilterImage(ImlibImage *im, ImlibFilter *fil) __imlib_FilterImage(ImlibImage * im, ImlibFilter * fil)
{ {
int x, y, a, r, g, b, ad, rd, gd, bd; int x, y, a, r, g, b, ad, rd, gd, bd;
DATA32 *data, *p1, *p2; DATA32 *data, *p1, *p2;
data = malloc(im->w * im->h * sizeof(DATA32)); data = malloc(im->w * im->h * sizeof(DATA32));
if (!data) return; if (!data)
return;
ad = __imlib_FilterCalcDiv(&fil->alpha); ad = __imlib_FilterCalcDiv(&fil->alpha);
rd = __imlib_FilterCalcDiv(&fil->red); rd = __imlib_FilterCalcDiv(&fil->red);
@ -180,33 +199,43 @@ __imlib_FilterImage(ImlibImage *im, ImlibFilter *fil)
p1 = im->data; p1 = im->data;
p2 = data; p2 = data;
for (y = 0; y < im->h; y++) { for (y = 0; y < im->h; y++)
for (x = 0; x < im->w; x++) { {
*p2 = *p1; for (x = 0; x < im->w; x++)
if (ad) { {
a = __imlib_FilterGet(&fil->alpha, im->data, im->w, im->h, x, y); *p2 = *p1;
a /= ad; if (ad)
A_VAL(p2) = SATURATE(a); {
} a = __imlib_FilterGet(&fil->alpha, im->data, im->w, im->h, x,
if (rd) { y);
r = __imlib_FilterGet(&fil->red, im->data, im->w, im->h, x, y); a /= ad;
r /= rd; A_VAL(p2) = SATURATE(a);
R_VAL(p2) = SATURATE(r); }
} if (rd)
if (gd) { {
g = __imlib_FilterGet(&fil->green, im->data, im->w, im->h, x, y); r = __imlib_FilterGet(&fil->red, im->data, im->w, im->h, x,
g /= gd; y);
G_VAL(p2) = SATURATE(g); r /= rd;
} R_VAL(p2) = SATURATE(r);
if (bd) { }
b = __imlib_FilterGet(&fil->blue, im->data, im->w, im->h, x, y); if (gd)
b /= bd; {
B_VAL(p2) = SATURATE(b); g = __imlib_FilterGet(&fil->green, im->data, im->w, im->h, x,
} y);
p1++; g /= gd;
p2++; G_VAL(p2) = SATURATE(g);
} }
} if (bd)
{
b = __imlib_FilterGet(&fil->blue, im->data, im->w, im->h, x,
y);
b /= bd;
B_VAL(p2) = SATURATE(b);
}
p1++;
p2++;
}
}
free(im->data); free(im->data);
im->data = data; im->data = data;
} }

View File

@ -1,229 +1,130 @@
#ifndef __FONT
#define __FONT 1
typedef struct _imlib_font_header ImlibFontHeader; #include <ft2build.h>
typedef struct _imlib_ttffont ImlibTtfFont; #include FT_FREETYPE_H
typedef struct _imlib_xfont ImlibXFontSet; #include FT_GLYPH_H
typedef union _imlib_font ImlibFont;
typedef struct _imlib_encoding_map ImlibEncodingMap;
typedef unsigned short ImlibWideChar;
#define TTF_FONT_CACHE 1 /* TODO separate fonts and data stuff */
#define TTF_HASH_SIZE (256*1)
#ifdef TTF_FONT_CACHE typedef struct _Imlib_Font ImlibFont;
typedef struct _imlib_ttf_hash ImlibTTFHash; typedef struct _Imlib_Font_Glyph Imlib_Font_Glyph;
typedef struct _imlib_ttf_hash_elm ImlibTTFHashElm;
struct _imlib_ttf_hash_elm typedef struct _Imlib_Object_List Imlib_Object_List;
typedef struct _Imlib_Hash Imlib_Hash;
typedef struct _Imlib_Hash_El Imlib_Hash_El;
struct _Imlib_Object_List
{ {
wchar_t wc; Imlib_Object_List *next, *prev;
TT_Glyph *glyph; Imlib_Object_List *last;
TT_Raster_Map *glyph_raster;
}; };
struct _imlib_ttf_hash struct _Imlib_Hash
{ {
ImlibTTFHash *next; int population;
char *name; Imlib_Object_List *buckets[256];
int references;
int type;
int size;
ImlibTTFHashElm **hash;
int mem_use;
}; };
#endif
struct _imlib_font_header struct _Imlib_Hash_El
{ {
int type; Imlib_Object_List _list_data;
char *key;
ImlibFont *next; void *data;
char *name;
int references;
}; };
struct _imlib_ttffont struct _Imlib_Font
{ {
int type; Imlib_Object_List _list_data;
char *name;
char *file;
int size;
ImlibFont *next; struct
char *name; {
int references; FT_Face face;
}
ft;
Imlib_Hash *glyphs;
int usage;
int references;
TT_Engine engine;
TT_Face face;
TT_Instance instance;
TT_Face_Properties properties;
int num_glyph;
#ifdef TTF_FONT_CACHE
ImlibTTFHash *glyph_hash;
TT_CharMap char_map;
#else
TT_Glyph *glyphs;
TT_Raster_Map **glyphs_cached_right;
#endif
int max_descent;
int max_ascent;
int descent;
int ascent;
int mem_use;
}; };
struct _imlib_encoding_map { struct _Imlib_Font_Glyph
ImlibWideChar char_map[96];
};
#define XMB_FONT_CACHE level2
#define XMB_HASH_SIZE (256*1)
#define XMB_HASH_VAL1 8
#define XMB_HASH_VAL2 8
#define XMB_HASH_VAL3 3
#ifdef XMB_FONT_CACHE
typedef struct _imlib_xfd_hash ImlibXmbHash;
typedef struct _imlib_xfd_hash_elm ImlibXmbHashElm;
struct _imlib_xfd_hash_elm
{ {
ImlibXmbHashElm *next; FT_Glyph glyph;
wchar_t wc; FT_BitmapGlyph glyph_out;
int w, h;
DATA32 *im;
}; };
struct _imlib_xfd_hash /* functions */
{
ImlibXmbHash *next;
char *name;
int references;
int type; void imlib_font_init(void);
int size; int imlib_font_ascent_get(ImlibFont * fn);
ImlibXmbHashElm **hash; int imlib_font_descent_get(ImlibFont * fn);
int hash_count; int imlib_font_max_ascent_get(ImlibFont * fn);
int collision_count; int imlib_font_max_descent_get(ImlibFont * fn);
int mem_use; int imlib_font_get_line_advance(ImlibFont * fn);
}; int imlib_font_utf8_get_next(unsigned char *buf, int *iindex);
#endif void imlib_font_add_font_path(const char *path);
void imlib_font_del_font_path(const char *path);
int imlib_font_path_exists(const char *path);
char **imlib_font_list_font_path(int *num_ret);
char **imlib_font_list_fonts(int *num_ret);
struct _imlib_xfont ImlibFont *imlib_font_load_joined(const char *name);
{ ImlibFont *imlib_font_load(const char *name, int size);
int type; void imlib_font_free(ImlibFont * fn);
static int font_modify_cache_cb(Imlib_Hash * hash, const char *key,
void *data, void *fdata);
int imlib_font_cache_get(void);
void imlib_font_cache_set(int size);
void imlib_font_flush(void);
static int font_flush_free_glyph_cb(Imlib_Hash * hash, const char *key,
void *data, void *fdata);
void imlib_font_modify_cache_by(ImlibFont * fn, int dir);
void imlib_font_modify_cache_by(ImlibFont * fn, int dir);
void imlib_font_flush_last(void);
ImlibFont *imlib_font_find(const char *name, int size);
ImlibFont *next; void imlib_font_query_size(ImlibFont * fn, const char *text,
char *name; int *w, int *h);
int references; int imlib_font_query_inset(ImlibFont * fn, const char *text);
void imlib_font_query_advance(ImlibFont * fn, const char *text,
int *h_adv, int *v_adv);
int imlib_font_query_char_coords(ImlibFont * fn,
const char *text, int pos,
int *cx, int *cy, int *cw,
int *ch);
int imlib_font_query_text_at_pos(ImlibFont * fn,
const char *text, int x, int y,
int *cx, int *cy, int *cw,
int *ch);
XFontSet xfontset; Imlib_Font_Glyph *imlib_font_cache_glyph_get(ImlibFont * fn, FT_UInt index);
int font_count; void imlib_render_str(ImlibImage * im, ImlibFont * f, int drx,
XFontStruct **font_struct; int dry, const char *text, DATA8 r,
char **font_name; DATA8 g, DATA8 b, DATA8 a, char dir,
int ascent; double angle, int *retw, int *reth,
int descent; int blur, int *nextx, int *nexty,
int max_ascent; ImlibOp op, int clx, int cly, int clw,
int max_descent; int clh);
int max_width; void imlib_font_draw(ImlibImage * dst, DATA32 col,
ImlibFont * fn, int x, int y,
const char *text, int *nextx, int *nexty,
int clx, int cly, int clw, int clh);
ImlibFont *ttffont; /* data manipulation */
int total_ascent;
int total_descent;
#ifdef XMB_FONT_CACHE void *imlib_object_list_prepend(void *in_list, void *in_item);
ImlibXmbHash *hash; void *imlib_object_list_remove(void *in_list, void *in_item);
#endif Imlib_Hash *imlib_hash_add(Imlib_Hash * hash, const char *key,
}; const void *data);
void *imlib_hash_find(Imlib_Hash * hash, const char *key);
union _imlib_font void imlib_hash_free(Imlib_Hash * hash);
{ void imlib_hash_foreach(Imlib_Hash * hash,
int type; int (*func) (Imlib_Hash * hash,
ImlibFontHeader hdr; const char *key, void *data,
ImlibTtfFont ttf; void *fdata),
ImlibXFontSet xf; const void *fdata);
};
/* Imlib font type */
#define IMLIB_FONT_TYPE_TTF 1 /* find ttf font only */
#define IMLIB_FONT_TYPE_X (1<<1) /* find x font only */
#define IMLIB_FONT_TYPE_TTF_X (IMLIB_FONT_TYPE_TTF | IMLIB_FONT_TYPE_X)
/* Imlib encoding */
#define IMLIB_ENCOING_ISO_8859_1 0
#define IMLIB_ENCOING_ISO_8859_2 1
#define IMLIB_ENCOING_ISO_8859_3 2
#define IMLIB_ENCOING_ISO_8859_4 3
TT_Raster_Map *__imlib_create_font_raster(int width, int height);
void __imlib_destroy_font_raster(TT_Raster_Map * rmap);
void __imlib_add_font_path(const char *path);
void __imlib_del_font_path(const char *path);
int __imlib_font_path_exists(const char *path);
char **__imlib_list_font_path(int *num_ret);
ImlibFont *__imlib_find_cached_font(const char *ttffontname, const char *xfontname, int mode);
ImlibFont *__imlib_load_font(const char *fontname);
ImlibFont *__imlib_load_xfontset(Display *display, const char *fontname);
#ifdef XMB_FONT_CACHE
ImlibXmbHash *__imlib_create_font_hash_table(const char *xfontsetname, int type);
#endif
#ifdef TTF_FONT_CACHE
ImlibTTFHash *__imlib_create_ttf_font_hash_table(const char *ttfontname, int type, int argsize);
#endif
ImlibFont *__imlib_clone_cached_font(ImlibFont *fn);
void __imlib_free_font(ImlibFont *font);
void __imlib_calc_size(ImlibFont *f, int *width, int *height,
const char *text);
void __imlib_calc_advance(ImlibFont *f, int *adv_w, int *adv_h,
const char *text);
int __imlib_calc_inset(ImlibFont *f, const char *text);
void __imlib_render_str(ImlibImage *im, ImlibFont *fn, int drx,
int dry, const char *text,
DATA8 r, DATA8 g, DATA8 b, DATA8 a,
char dir, double angle, int *retw, int *reth, int blur,
int *nextx, int *nexty, ImlibOp op,
int cx, int cy, int cw, int ch);
void __imlib_xfd_draw_str(Display *display, Drawable drawable,
Visual *v, int depth, Colormap cm,
ImlibImage *im, ImlibFont *fn, int x,
int y, const char *text, DATA8 r, DATA8 g,
DATA8 b, DATA8 a, char dir, double angle,
char blend, ImlibColorModifier *cmod,
char hiq, char dmask, ImlibOp op,
int *retw, int *reth,
int *nextx, int *nexty,
int cx, int cy, int cw, int ch);
#ifdef XMB_FONT_CACHE
void __imlib_xfd_build_str_image(Display *display, Drawable drawable,
Visual *v, ImlibFont *fn, ImlibImage *im,
const char *text, DATA8 r, DATA8 g, DATA8 b, DATA8 a);
#endif
#ifdef TTF_FONT_CACHE
unsigned short __imlib_find_hash_index(ImlibTtfFont *f, unsigned short argchar);
#endif
int __imlib_char_pos(ImlibFont *fn, const char *text, int x, int y,
int *cx, int *cy, int *cw, int *ch);
void __imlib_char_geom(ImlibFont *fn, const char *text, int num,
int *cx, int *cy, int *cw, int *ch);
int __imlib_xfd_char_pos(ImlibFont *f, const char *text, int x, int y,
int *cx, int *cy, int *cw, int *ch);
void __imlib_xfd_char_geom(ImlibFont *fn, const char *text, int num,
int *cx, int *cy, int *cw, int *ch);
char **__imlib_list_fonts(int *num_ret);
void __imlib_free_font_list(char **list, int num);
int __imlib_get_cached_font_size(void);
void __imlib_flush_font_cache(void);
void __imlib_purge_font_cache(void);
int __imlib_get_font_cache_size(void);
void __imlib_set_font_cache_size(int size);
void __imlib_nuke_font(ImlibFont *font);
void __imlib_set_TTF_encoding(unsigned char enc);
void __imlib_init_encoding();
#ifdef XMB_FONT_CACHE
void __imlib_free_font_hash(ImlibXmbHash *h);
#endif
#ifdef TTF_FONT_CACHE
void __imlib_free_ttf_font_hash(ImlibTTFHash *h);
#endif
#endif

1027
src/grab.c

File diff suppressed because it is too large Load Diff

View File

@ -8,10 +8,10 @@
#include "grad.h" #include "grad.h"
#include "color_helpers.h" #include "color_helpers.h"
ImlibRange * ImlibRange *
__imlib_CreateRange(void) __imlib_CreateRange(void)
{ {
ImlibRange *rg = NULL; ImlibRange *rg = NULL;
rg = malloc(sizeof(ImlibRange)); rg = malloc(sizeof(ImlibRange));
rg->color = NULL; rg->color = NULL;
@ -19,25 +19,25 @@ __imlib_CreateRange(void)
} }
void void
__imlib_FreeRange(ImlibRange *rg) __imlib_FreeRange(ImlibRange * rg)
{ {
ImlibRangeColor *p, *pp; ImlibRangeColor *p, *pp;
p = rg->color; p = rg->color;
while(p) while (p)
{ {
pp = p; pp = p;
p = p->next; p = p->next;
free(pp); free(pp);
} }
free(rg); free(rg);
} }
void void
__imlib_AddRangeColor(ImlibRange *rg, DATA8 r, DATA8 g, DATA8 b, DATA8 a, __imlib_AddRangeColor(ImlibRange * rg, DATA8 r, DATA8 g, DATA8 b, DATA8 a,
int dist) int dist)
{ {
ImlibRangeColor *p, *rc; ImlibRangeColor *p, *rc;
if (dist < 1) if (dist < 1)
dist = 1; dist = 1;
@ -55,28 +55,28 @@ __imlib_AddRangeColor(ImlibRange *rg, DATA8 r, DATA8 g, DATA8 b, DATA8 a,
p = rg->color; p = rg->color;
if (p) if (p)
{ {
while (p) while (p)
{ {
if (!p->next) if (!p->next)
{ {
p->distance = dist; p->distance = dist;
p->next = rc; p->next = rc;
p = NULL; p = NULL;
} }
else else
p = p->next; p = p->next;
} }
} }
else else
rg->color = rc; rg->color = rc;
} }
DATA32 * DATA32 *
__imlib_MapRange(ImlibRange *rg, int len) __imlib_MapRange(ImlibRange * rg, int len)
{ {
ImlibRangeColor *p; ImlibRangeColor *p;
DATA32 *map, *pmap, v, vv; DATA32 *map, *pmap, v, vv;
int r, g, b, a, rr, gg, bb, aa, i, l, ll, v1, v2, inc, j; int r, g, b, a, rr, gg, bb, aa, i, l, ll, v1, v2, inc, j;
if (!rg->color) if (!rg->color)
return NULL; return NULL;
@ -90,156 +90,161 @@ __imlib_MapRange(ImlibRange *rg, int len)
i = 0; i = 0;
for (p = rg->color; p; p = p->next) for (p = rg->color; p; p = p->next)
{ {
if (p->next) if (p->next)
{ {
for (j = 0; j < p->distance; j++) for (j = 0; j < p->distance; j++)
{ {
v1 = (j << 16) / p->distance; v1 = (j << 16) / p->distance;
v2 = 65536 - v1; v2 = 65536 - v1;
r = ((p->red * v2) + (p->next->red * v1)) >> 16; r = ((p->red * v2) + (p->next->red * v1)) >> 16;
g = ((p->green * v2) + (p->next->green * v1)) >> 16; g = ((p->green * v2) + (p->next->green * v1)) >> 16;
b = ((p->blue * v2) + (p->next->blue * v1)) >> 16; b = ((p->blue * v2) + (p->next->blue * v1)) >> 16;
a = ((p->alpha * v2) + (p->next->alpha * v1)) >> 16; a = ((p->alpha * v2) + (p->next->alpha * v1)) >> 16;
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b; pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
} }
} }
else else
{ {
r = p->red; r = p->red;
g = p->green; g = p->green;
b = p->blue; b = p->blue;
a = p->alpha; a = p->alpha;
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b; pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
} }
} }
inc = ((ll - 1) << 16) / (len); inc = ((ll - 1) << 16) / (len);
l = 0; l = 0;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
v = pmap[l >> 16]; v = pmap[l >> 16];
if ((l >> 16) < ll) if ((l >> 16) < ll)
vv = pmap[(l >> 16) + 1]; vv = pmap[(l >> 16) + 1];
else else
vv = pmap[(l >> 16)]; vv = pmap[(l >> 16)];
v1 = l - ((l >> 16) << 16); v1 = l - ((l >> 16) << 16);
v2 = 65536 - v1; v2 = 65536 - v1;
b = ((v) ) & 0xff; b = ((v)) & 0xff;
g = ((v) >> 8 ) & 0xff; g = ((v) >> 8) & 0xff;
r = ((v) >> 16) & 0xff; r = ((v) >> 16) & 0xff;
a = ((v) >> 24) & 0xff; a = ((v) >> 24) & 0xff;
bb = ((vv) ) & 0xff; bb = ((vv)) & 0xff;
gg = ((vv) >> 8 ) & 0xff; gg = ((vv) >> 8) & 0xff;
rr = ((vv) >> 16) & 0xff; rr = ((vv) >> 16) & 0xff;
aa = ((vv) >> 24) & 0xff; aa = ((vv) >> 24) & 0xff;
r = ((r * v2) + (rr * v1)) >> 16; r = ((r * v2) + (rr * v1)) >> 16;
g = ((g * v2) + (gg * v1)) >> 16; g = ((g * v2) + (gg * v1)) >> 16;
b = ((b * v2) + (bb * v1)) >> 16; b = ((b * v2) + (bb * v1)) >> 16;
a = ((a * v2) + (aa * v1)) >> 16; a = ((a * v2) + (aa * v1)) >> 16;
map[i] = (a << 24) | (r << 16) | (g << 8) | b; map[i] = (a << 24) | (r << 16) | (g << 8) | b;
l += inc; l += inc;
} }
free(pmap); free(pmap);
return map; return map;
} }
DATA32 * DATA32 *
__imlib_MapHsvaRange(ImlibRange *rg, int len) __imlib_MapHsvaRange(ImlibRange * rg, int len)
{ {
ImlibRangeColor *p; ImlibRangeColor *p;
DATA32 *map, *pmap, k, kk; DATA32 *map, *pmap, k, kk;
int r, g, b, a, rr, gg, bb, aa, i, l, ll, inc, j; int r, g, b, a, rr, gg, bb, aa, i, l, ll, inc, j;
float h1, s1, v1, h2, s2, v2, h, s, v, k1, k2; float h1, s1, v1, h2, s2, v2, h, s, v, k1, k2;
if (!rg->color) if (!rg->color)
return NULL; return NULL;
if (!rg->color->next) if (!rg->color->next)
return NULL; return NULL;
ll = 1; ll = 1;
for (p = rg->color; p; p = p->next) for (p = rg->color; p; p = p->next)
ll += p->distance; ll += p->distance;
map = malloc(len * sizeof(DATA32)); map = malloc(len * sizeof(DATA32));
pmap = malloc(ll * sizeof(DATA32)); pmap = malloc(ll * sizeof(DATA32));
i = 0; i = 0;
for (p = rg->color; p; p = p->next) for (p = rg->color; p; p = p->next)
{ {
if (p->next) if (p->next)
{ {
for (j = 0; j < p->distance; j++) for (j = 0; j < p->distance; j++)
{ {
k1 = (j << 16) / (float)p->distance; k1 = (j << 16) / (float)p->distance;
k2 = 65536 - k1; k2 = 65536 - k1;
r = p->red; rr = p->next->red; r = p->red;
g = p->green; gg = p->next->green; rr = p->next->red;
b = p->blue; bb = p->next->blue; g = p->green;
__imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1); gg = p->next->green;
__imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2); b = p->blue;
h = ((h1 * k2) + (h2 * k1)) / 65536.0; bb = p->next->blue;
s = ((s1 * k2) + (s2 * k1)) / 65536.0; __imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1);
v = ((v1 * k2) + (v2 * k1)) / 65536.0; __imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2);
__imlib_hsv_to_rgb(h, s, v, &r, &g, &b); h = ((h1 * k2) + (h2 * k1)) / 65536.0;
a = (unsigned long int)((p->alpha * k2) + (p->next->alpha * k1)) >> 16; s = ((s1 * k2) + (s2 * k1)) / 65536.0;
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b; v = ((v1 * k2) + (v2 * k1)) / 65536.0;
} __imlib_hsv_to_rgb(h, s, v, &r, &g, &b);
} a = (unsigned long int)((p->alpha * k2) +
else (p->next->alpha * k1)) >> 16;
{ pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
r = p->red; }
g = p->green; }
b = p->blue; else
a = p->alpha; {
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b; r = p->red;
} g = p->green;
} b = p->blue;
inc = ((ll - 1) << 16) / (len); a = p->alpha;
l = 0; pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
for (i = 0; i < len; i++) }
{ }
k = pmap[l >> 16]; inc = ((ll - 1) << 16) / (len);
if ((l >> 16) < ll) l = 0;
kk = pmap[(l >> 16) + 1]; for (i = 0; i < len; i++)
else {
kk = pmap[(l >> 16)]; k = pmap[l >> 16];
k1 = l - (float)((l >> 16) << 16); if ((l >> 16) < ll)
k2 = 65536 - k1; kk = pmap[(l >> 16) + 1];
b = ((k) ) & 0xff; else
g = ((k) >> 8 ) & 0xff; kk = pmap[(l >> 16)];
r = ((k) >> 16) & 0xff; k1 = l - (float)((l >> 16) << 16);
a = ((k) >> 24) & 0xff; k2 = 65536 - k1;
bb = ((kk) ) & 0xff; b = ((k)) & 0xff;
gg = ((kk) >> 8 ) & 0xff; g = ((k) >> 8) & 0xff;
rr = ((kk) >> 16) & 0xff; r = ((k) >> 16) & 0xff;
aa = ((kk) >> 24) & 0xff; a = ((k) >> 24) & 0xff;
__imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1); bb = ((kk)) & 0xff;
__imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2); gg = ((kk) >> 8) & 0xff;
h = ((h1 * k2) + (h2 * k1)) / 65536.0; rr = ((kk) >> 16) & 0xff;
s = ((s1 * k2) + (s2 * k1)) / 65536.0; aa = ((kk) >> 24) & 0xff;
v = ((v1 * k2) + (v2 * k1)) / 65536.0; __imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1);
__imlib_hsv_to_rgb(h, s, v, &r, &g, &b); __imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2);
a = (unsigned long int)((a * k2) + (aa * k1)) >> 16; h = ((h1 * k2) + (h2 * k1)) / 65536.0;
map[i] = (a << 24) | (r << 16) | (g << 8) | b; s = ((s1 * k2) + (s2 * k1)) / 65536.0;
l += inc; v = ((v1 * k2) + (v2 * k1)) / 65536.0;
} __imlib_hsv_to_rgb(h, s, v, &r, &g, &b);
free(pmap); a = (unsigned long int)((a * k2) + (aa * k1)) >> 16;
return map; map[i] = (a << 24) | (r << 16) | (g << 8) | b;
l += inc;
}
free(pmap);
return map;
} }
void void
__imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h, __imlib_DrawGradient(ImlibImage * im, int x, int y, int w, int h,
ImlibRange *rg, double angle, ImlibOp op, ImlibRange * rg, double angle, ImlibOp op,
int clx, int cly, int clw, int clh) int clx, int cly, int clw, int clh)
{ {
DATA32 *map, *p, v; DATA32 *map, *p, v;
int *hlut, *vlut, len = 0, xx, yy, xoff = 0, yoff = 0, ww, hh, jump; int *hlut, *vlut, len = 0, xx, yy, xoff = 0, yoff =
int tmp, i, divw, divh; 0, ww, hh, jump;
DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na; int tmp, i, divw, divh;
DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na;
ww = w; ww = w;
hh = h; hh = h;
if (x < 0) if (x < 0)
{ {
w += x; w += x;
xoff = -x; xoff = -x;
x = 0; x = 0;
} }
if (w <= 0) if (w <= 0)
return; return;
@ -249,9 +254,9 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h,
return; return;
if (y < 0) if (y < 0)
{ {
h += y; h += y;
yoff = -y; yoff = -y;
y = 0; y = 0;
} }
if (h <= 0) if (h <= 0)
return; return;
@ -261,15 +266,16 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h,
return; return;
if (clw) if (clw)
{ {
int px, py; int px, py;
CLIP_TO(clx, cly, clw, clh, 0, 0, im->w, im->h); CLIP_TO(clx, cly, clw, clh, 0, 0, im->w, im->h);
px = x; px = x;
py = y; py = y;
CLIP_TO(x, y, w, h, clx, cly, clw, clh); CLIP_TO(x, y, w, h, clx, cly, clw, clh);
if ((w < 1) || (h < 1)) return; if ((w < 1) || (h < 1))
xoff += (x - px); return;
yoff += (y - py); xoff += (x - px);
yoff += (y - py);
} }
hlut = malloc(sizeof(int) * ww); hlut = malloc(sizeof(int) * ww);
@ -279,131 +285,134 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h,
else else
len = hh * 16; len = hh * 16;
map = __imlib_MapRange(rg, len); map = __imlib_MapRange(rg, len);
if (!map) return; if (!map)
return;
xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360)); xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360));
yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360)); yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360));
divw = ((ww - 1) << 5); divw = ((ww - 1) << 5);
divh = ((hh - 1) << 5); divh = ((hh - 1) << 5);
if (divw < 1) divw = 1; if (divw < 1)
if (divh < 1) divh = 1; divw = 1;
if (divh < 1)
divh = 1;
if (xx < 0) if (xx < 0)
{ {
for (i = 0; i < ww; i++) for (i = 0; i < ww; i++)
hlut[i] = (-xx * (ww - 1 - i) * len) / divw; hlut[i] = (-xx * (ww - 1 - i) * len) / divw;
} }
else else
{ {
for (i = 0; i < ww; i++) for (i = 0; i < ww; i++)
hlut[i] = (xx * i * len) / divw; hlut[i] = (xx * i * len) / divw;
} }
if (yy < 0) if (yy < 0)
{ {
for (i = 0; i < hh; i++) for (i = 0; i < hh; i++)
vlut[i] = (-yy * (hh - 1 - i) * len) / divh; vlut[i] = (-yy * (hh - 1 - i) * len) / divh;
} }
else else
{ {
for (i = 0; i < hh; i++) for (i = 0; i < hh; i++)
vlut[i] = (yy * i * len) / divh; vlut[i] = (yy * i * len) / divh;
} }
jump = im->w - w; jump = im->w - w;
p = im->data + (y * im->w) + x; p = im->data + (y * im->w) + x;
switch (op) switch (op)
{ {
case OP_COPY: case OP_COPY:
if (IMAGE_HAS_ALPHA(im)) if (IMAGE_HAS_ALPHA(im))
{ {
__imlib_build_pow_lut(); __imlib_build_pow_lut();
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_DST_ALPHA(r, g, b, a, p); BLEND_DST_ALPHA(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
} }
else else
{ {
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND(r, g, b, a, p); BLEND(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
} }
break; break;
case OP_ADD: case OP_ADD:
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_SUB(r, g, b, a, p); BLEND_SUB(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
break; break;
case OP_SUBTRACT: case OP_SUBTRACT:
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_SUB(r, g, b, a, p); BLEND_SUB(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
break; break;
case OP_RESHADE: case OP_RESHADE:
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_RE(r, g, b, a, p); BLEND_RE(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
break; break;
default: default:
break; break;
} }
free(vlut); free(vlut);
@ -412,22 +421,23 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h,
} }
void void
__imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int h, __imlib_DrawHsvaGradient(ImlibImage * im, int x, int y, int w, int h,
ImlibRange *rg, double angle, ImlibOp op, ImlibRange * rg, double angle, ImlibOp op,
int clx, int cly, int clw, int clh) int clx, int cly, int clw, int clh)
{ {
DATA32 *map, *p, v; DATA32 *map, *p, v;
int *hlut, *vlut, len = 0, xx, yy, xoff = 0, yoff = 0, ww, hh, jump; int *hlut, *vlut, len = 0, xx, yy, xoff = 0, yoff =
int tmp, i, divw, divh; 0, ww, hh, jump;
DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na; int tmp, i, divw, divh;
DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na;
ww = w; ww = w;
hh = h; hh = h;
if (x < 0) if (x < 0)
{ {
w += x; w += x;
xoff = -x; xoff = -x;
x = 0; x = 0;
} }
if (w <= 0) if (w <= 0)
return; return;
@ -437,9 +447,9 @@ __imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int h,
return; return;
if (y < 0) if (y < 0)
{ {
h += y; h += y;
yoff = -y; yoff = -y;
y = 0; y = 0;
} }
if (h <= 0) if (h <= 0)
return; return;
@ -449,15 +459,16 @@ __imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int h,
return; return;
if (clw) if (clw)
{ {
int px, py; int px, py;
CLIP_TO(clx, cly, clw, clh, 0, 0, im->w, im->h); CLIP_TO(clx, cly, clw, clh, 0, 0, im->w, im->h);
px = x; px = x;
py = y; py = y;
CLIP_TO(x, y, w, h, clx, cly, clw, clh); CLIP_TO(x, y, w, h, clx, cly, clw, clh);
if ((w < 1) || (h < 1)) return; if ((w < 1) || (h < 1))
xoff += (x - px); return;
yoff += (y - py); xoff += (x - px);
yoff += (y - py);
} }
hlut = malloc(sizeof(int) * ww); hlut = malloc(sizeof(int) * ww);
@ -467,135 +478,137 @@ __imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int h,
else else
len = hh * 16; len = hh * 16;
map = __imlib_MapHsvaRange(rg, len); map = __imlib_MapHsvaRange(rg, len);
if (!map) return; if (!map)
return;
xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360)); xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360));
yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360)); yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360));
divw = ((ww - 1) << 5); divw = ((ww - 1) << 5);
divh = ((hh - 1) << 5); divh = ((hh - 1) << 5);
if (divw < 1) divw = 1; if (divw < 1)
if (divh < 1) divh = 1; divw = 1;
if (divh < 1)
divh = 1;
if (xx < 0) if (xx < 0)
{ {
for (i = 0; i < ww; i++) for (i = 0; i < ww; i++)
hlut[i] = (-xx * (ww - 1 - i) * len) / divw; hlut[i] = (-xx * (ww - 1 - i) * len) / divw;
} }
else else
{ {
for (i = 0; i < ww; i++) for (i = 0; i < ww; i++)
hlut[i] = (xx * i * len) / divw; hlut[i] = (xx * i * len) / divw;
} }
if (yy < 0) if (yy < 0)
{ {
for (i = 0; i < hh; i++) for (i = 0; i < hh; i++)
vlut[i] = (-yy * (hh - 1 - i) * len) / divh; vlut[i] = (-yy * (hh - 1 - i) * len) / divh;
} }
else else
{ {
for (i = 0; i < hh; i++) for (i = 0; i < hh; i++)
vlut[i] = (yy * i * len) / divh; vlut[i] = (yy * i * len) / divh;
} }
jump = im->w - w; jump = im->w - w;
p = im->data + (y * im->w) + x; p = im->data + (y * im->w) + x;
switch (op) switch (op)
{ {
case OP_COPY: case OP_COPY:
if (IMAGE_HAS_ALPHA(im)) if (IMAGE_HAS_ALPHA(im))
{ {
__imlib_build_pow_lut(); __imlib_build_pow_lut();
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_DST_ALPHA(r, g, b, a, p); BLEND_DST_ALPHA(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
} }
else else
{ {
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND(r, g, b, a, p); BLEND(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
} }
break; break;
case OP_ADD: case OP_ADD:
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_SUB(r, g, b, a, p); BLEND_SUB(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
break; break;
case OP_SUBTRACT: case OP_SUBTRACT:
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_SUB(r, g, b, a, p); BLEND_SUB(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
break; break;
case OP_RESHADE: case OP_RESHADE:
for (yy = 0; yy < h; yy++) for (yy = 0; yy < h; yy++)
{ {
for (xx = 0; xx < w; xx++) for (xx = 0; xx < w; xx++)
{ {
i = vlut[yoff + yy] + hlut[xoff + xx]; i = vlut[yoff + yy] + hlut[xoff + xx];
if (i < 0) if (i < 0)
i = 0; i = 0;
else if (i >= len) else if (i >= len)
i = len - 1; i = len - 1;
READ_RGBA(&(map[i]), r, g, b, a); READ_RGBA(&(map[i]), r, g, b, a);
BLEND_RE(r, g, b, a, p); BLEND_RE(r, g, b, a, p);
p++; p++;
} }
p += jump; p += jump;
} }
break; break;
default: default:
break; break;
} }
free(vlut); free(vlut);
free(hlut); free(hlut);
free(map); free(map);
} }

File diff suppressed because it is too large Load Diff

View File

@ -18,166 +18,166 @@
#define LINESIZE 16 #define LINESIZE 16
DATA32 DATA32
__imlib_RenderGetPixel(Display *d, Drawable w, Visual *v, Colormap cm, int depth, DATA8 r, DATA8 g, DATA8 b) __imlib_RenderGetPixel(Display * d, Drawable w, Visual * v, Colormap cm,
int depth, DATA8 r, DATA8 g, DATA8 b)
{ {
Context *ct; Context *ct;
int actual_depth; int actual_depth;
ct = __imlib_GetContext(d, v, cm, depth); ct = __imlib_GetContext(d, v, cm, depth);
actual_depth = depth; actual_depth = depth;
if (depth == 16) actual_depth = __imlib_XActualDepth(d, v); if (depth == 16)
actual_depth = __imlib_XActualDepth(d, v);
if (ct->palette) if (ct->palette)
{ {
switch (ct->palette_type) switch (ct->palette_type)
{ {
case 0: /* 332 */ case 0: /* 332 */
return ct->palette[((r >> 0) & 0xe0) | return ct->palette[((r >> 0) & 0xe0) |
((g >> 3) & 0x1b) | ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
((b >> 6) & 0x02)]; break;
break; case 1: /* 232 */
case 1: /* 232 */ return ct->palette[((r >> 0) & 0xe0) |
return ct->palette[((r >> 0) & 0xe0) | ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
((g >> 3) & 0x1b) | break;
((b >> 6) & 0x02)]; case 2: /* 222 */
break; return ct->palette[((r >> 0) & 0xe0) |
case 2: /* 222 */ ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
return ct->palette[((r >> 0) & 0xe0) | break;
((g >> 3) & 0x1b) | case 3: /* 221 */
((b >> 6) & 0x02)]; return ct->palette[((r >> 0) & 0xe0) |
break; ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
case 3: /* 221 */ break;
return ct->palette[((r >> 0) & 0xe0) | case 4: /* 121 */
((g >> 3) & 0x1b) | return ct->palette[((r >> 0) & 0xe0) |
((b >> 6) & 0x02)]; ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
break; break;
case 4: /* 121 */ case 5: /* 111 */
return ct->palette[((r >> 0) & 0xe0) | return ct->palette[((r >> 0) & 0xe0) |
((g >> 3) & 0x1b) | ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
((b >> 6) & 0x02)]; break;
break; case 6: /* 1 */
case 5: /* 111 */ return ct->palette[((r >> 0) & 0xe0) |
return ct->palette[((r >> 0) & 0xe0) | ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
((g >> 3) & 0x1b) | break;
((b >> 6) & 0x02)]; case 7: /* 666 */
break; return ct->palette[((int)(((double)r / 255) * 5.0) * 36) +
case 6: /* 1 */ ((int)(((double)g / 255) * 5.0) * 6) +
return ct->palette[((r >> 0) & 0xe0) | ((int)(((double)b / 255) * 5.0))];
((g >> 3) & 0x1b) | break;
((b >> 6) & 0x02)]; default:
break; return 0;
case 7: /* 666 */ }
return ct->palette[((int)(((double)r / 255) * 5.0) * 36) +
((int)(((double)g / 255) * 5.0) * 6 ) +
((int)(((double)b / 255) * 5.0) )];
break;
default:
return 0;
}
} }
else else
{ {
unsigned int rm, gm, bm; unsigned int rm, gm, bm;
int i, rshift, gshift, bshift; int i, rshift, gshift, bshift;
DATA32 val; DATA32 val;
rm = v->red_mask; rm = v->red_mask;
gm = v->green_mask; gm = v->green_mask;
bm = v->blue_mask; bm = v->blue_mask;
if ((rm == 0xf800) && (gm == 0x7e0) && (bm == 0x1f)) /* 565 */ if ((rm == 0xf800) && (gm == 0x7e0) && (bm == 0x1f)) /* 565 */
{ {
return (((r << 8) & 0xf800) | return (((r << 8) & 0xf800) |
((g << 3) & 0x07e0) | ((g << 3) & 0x07e0) | ((b >> 3) & 0x001f));
((b >> 3) & 0x001f)); }
} if ((rm == 0xff0000) && (gm == 0xff00) && (bm == 0xff)) /* 888 */
if ((rm == 0xff0000) && (gm == 0xff00) && (bm == 0xff)) /* 888 */ {
{ return (((r << 16) & 0xff0000) |
return (((r << 16) & 0xff0000) | ((g << 8) & 0x00ff00) | ((r) & 0x0000ff));
((g << 8 ) & 0x00ff00) | }
((r ) & 0x0000ff)); if ((rm == 0x7c00) && (gm == 0x3e0) && (bm == 0x1f)) /* 555 */
} {
if ((rm == 0x7c00) && (gm == 0x3e0) && (bm == 0x1f)) /* 555 */ return (((r << 7) & 0x7c00) |
{ ((g << 2) & 0x03e0) | ((b >> 3) & 0x001f));
return (((r << 7) & 0x7c00) | }
((g << 2) & 0x03e0) | for (i = 31; i >= 0; i--)
((b >> 3) & 0x001f)); {
} if (rm >= (1 << i))
for (i = 31; i >= 0; i--) {
{ rshift = i - 7;
if (rm >= (1 << i)) break;
{ }
rshift = i - 7; }
break; for (i = 31; i >= 0; i--)
} {
} if (gm >= (1 << i))
for (i = 31; i >= 0; i--) {
{ gshift = i - 7;
if (gm >= (1 << i)) break;
{ }
gshift = i - 7; }
break; for (i = 31; i >= 0; i--)
} {
} if (bm >= (1 << i))
for (i = 31; i >= 0; i--) {
{ bshift = i - 7;
if (bm >= (1 << i)) break;
{ }
bshift = i - 7; }
break; if (rshift >= 0)
} val = ((r << rshift) & rm);
} else
if (rshift >= 0) val = ((r << rshift) & rm); val = ((r >> (-rshift)) & rm);
else val = ((r >> (-rshift)) & rm); if (gshift >= 0)
if (gshift >= 0) val |= ((g << gshift) & gm); val |= ((g << gshift) & gm);
else val |= ((g >> (-gshift)) & gm); else
if (bshift >= 0) val |= ((b << bshift) & bm); val |= ((g >> (-gshift)) & gm);
else val |= ((b >> (-bshift)) & bm); if (bshift >= 0)
return val; val |= ((b << bshift) & bm);
else
val |= ((b >> (-bshift)) & bm);
return val;
} }
return 0; return 0;
} }
void void
__imlib_generic_render(DATA32 *src, int jump, int w, int h, int dx, int dy, __imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy,
XImage *xim, Visual *v, Context *ct); XImage * xim, Visual * v,
Context * ct);
void void
__imlib_generic_render(DATA32 *src, int jump, int w, int h, int dx, int dy, __imlib_generic_render(DATA32 * src, int jump, int w, int h, int dx, int dy,
XImage *xim, Visual *v, Context *ct) XImage * xim, Visual * v, Context * ct)
{ {
unsigned int x, y, r, g, b, val, hh; unsigned int x, y, r, g, b, val, hh;
unsigned int rmask, gmask, bmask; unsigned int rmask, gmask, bmask;
int i, rshift, gshift, bshift; int i, rshift, gshift, bshift;
const DATA8 _dither_88[8][8] = const DATA8 _dither_88[8][8] = {
{ {0, 32, 8, 40, 2, 34, 10, 42},
{ 0, 32, 8, 40, 2, 34, 10, 42 }, {48, 16, 56, 24, 50, 18, 58, 26},
{ 48, 16, 56, 24, 50, 18, 58, 26 }, {12, 44, 4, 36, 14, 46, 6, 38},
{ 12, 44, 4, 36, 14, 46, 6, 38 }, {60, 28, 52, 20, 62, 30, 54, 22},
{ 60, 28, 52, 20, 62, 30, 54, 22 }, {3, 35, 11, 43, 1, 33, 9, 41},
{ 3, 35, 11, 43, 1, 33, 9, 41 }, {51, 19, 59, 27, 49, 17, 57, 25},
{ 51, 19, 59, 27, 49, 17, 57, 25 }, {15, 47, 7, 39, 13, 45, 5, 37},
{ 15, 47, 7, 39, 13, 45, 5, 37 }, {63, 31, 55, 23, 61, 29, 53, 21}
{ 63, 31, 55, 23, 61, 29, 53, 21 } };
};
if (xim->depth == 1) if (xim->depth == 1)
{ {
hh = dy + h; hh = dy + h;
for (y = dy; y < hh; y++) for (y = dy; y < hh; y++)
{ {
for (x = dx; x < w; x++) for (x = dx; x < w; x++)
{ {
r = R_VAL(src); r = R_VAL(src);
g = G_VAL(src); g = G_VAL(src);
b = B_VAL(src); b = B_VAL(src);
val = (R_VAL(src) + G_VAL(src) + B_VAL(src)) / 12; val = (R_VAL(src) + G_VAL(src) + B_VAL(src)) / 12;
if (val > _dither_88[x & 0x3][y & 0x3]) val = ct->palette[1]; if (val > _dither_88[x & 0x3][y & 0x3])
else val = ct->palette[0]; val = ct->palette[1];
XPutPixel(xim, x, y, val); else
src++; val = ct->palette[0];
} XPutPixel(xim, x, y, val);
} src++;
return; }
}
return;
} }
rmask = xim->red_mask; rmask = xim->red_mask;
gmask = xim->green_mask; gmask = xim->green_mask;
@ -187,81 +187,81 @@ __imlib_generic_render(DATA32 *src, int jump, int w, int h, int dx, int dy,
bshift = 0; bshift = 0;
for (i = 31; i >= 0; i--) for (i = 31; i >= 0; i--)
{ {
if (rmask >= (1 << i)) if (rmask >= (1 << i))
{ {
rshift = i - 7; rshift = i - 7;
break; break;
} }
} }
for (i = 31; i >= 0; i--) for (i = 31; i >= 0; i--)
{ {
if (gmask >= (1 << i)) if (gmask >= (1 << i))
{ {
gshift = i - 7; gshift = i - 7;
break; break;
} }
} }
for (i = 31; i >= 0; i--) for (i = 31; i >= 0; i--)
{ {
if (bmask >= (1 << i)) if (bmask >= (1 << i))
{ {
bshift = i - 7; bshift = i - 7;
break; break;
} }
} }
hh = dy + h; hh = dy + h;
for (y = dy; y < hh; y++) for (y = dy; y < hh; y++)
{ {
for (x = dx; x < w; x++) for (x = dx; x < w; x++)
{ {
r = R_VAL(src); r = R_VAL(src);
if (rshift >= 0) if (rshift >= 0)
val = ((r << rshift) & rmask); val = ((r << rshift) & rmask);
else else
val = ((r >> (-rshift)) & rmask); val = ((r >> (-rshift)) & rmask);
g = G_VAL(src); g = G_VAL(src);
if (gshift >= 0) if (gshift >= 0)
val |= ((g << gshift) & gmask); val |= ((g << gshift) & gmask);
else else
val |= ((g >> (-gshift)) & gmask); val |= ((g >> (-gshift)) & gmask);
b = B_VAL(src); b = B_VAL(src);
if (bshift >= 0) if (bshift >= 0)
val |= ((b << bshift) & bmask); val |= ((b << bshift) & bmask);
else else
val |= ((b >> (-bshift)) & bmask); val |= ((b >> (-bshift)) & bmask);
XPutPixel(xim, x, y, val); XPutPixel(xim, x, y, val);
src++; src++;
} }
} }
} }
void void
__imlib_RenderImage(Display *d, ImlibImage *im, __imlib_RenderImage(Display * d, ImlibImage * im,
Drawable w, Drawable m, Drawable w, Drawable m,
Visual *v, Colormap cm, int depth, Visual * v, Colormap cm, int depth,
int sx, int sy, int sw, int sh, int sx, int sy, int sw, int sh,
int dx, int dy, int dw, int dh, int dx, int dy, int dw, int dh,
char antialias, char hiq, char blend, char dither_mask, char antialias, char hiq, char blend, char dither_mask,
ImlibColorModifier *cmod, ImlibOp op) ImlibColorModifier * cmod, ImlibOp op)
{ {
XImage *xim = NULL, *mxim = NULL; XImage *xim = NULL, *mxim = NULL;
Context *ct; Context *ct;
DATA32 *buf = NULL, *pointer = NULL, *back = NULL; DATA32 *buf = NULL, *pointer = NULL, *back = NULL;
int y, h, hh, jump; int y, h, hh, jump;
static Display *disp = NULL; static Display *disp = NULL;
static GC gc = 0; static GC gc = 0;
static GC gcm = 0; static GC gcm = 0;
XGCValues gcv; XGCValues gcv;
ImlibScaleInfo *scaleinfo = NULL; ImlibScaleInfo *scaleinfo = NULL;
int psx, psy, psw, psh; int psx, psy, psw, psh;
int actual_depth = 0; int actual_depth = 0;
char shm = 0; char shm = 0;
ImlibRGBAFunction rgbaer, masker = NULL; ImlibRGBAFunction rgbaer, masker = NULL;
ImlibBlendFunction blender = NULL; ImlibBlendFunction blender = NULL;
int do_mmx; int do_mmx;
blender = __imlib_GetBlendFunction(op, 1, 0, blender = __imlib_GetBlendFunction(op, 1, 0,
(!(im->flags & F_HAS_ALPHA)), NULL); (!(im->flags & F_HAS_ALPHA)), NULL);
/* dont do anything if we have a 0 widht or height image to render */ /* dont do anything if we have a 0 widht or height image to render */
if ((dw == 0) || (dh == 0)) if ((dw == 0) || (dh == 0))
@ -300,191 +300,203 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
/* if we are scaling the image at all make a scaling buffer */ /* if we are scaling the image at all make a scaling buffer */
if (!((sw == dw) && (sh == dh))) if (!((sw == dw) && (sh == dh)))
{ {
scaleinfo = __imlib_CalcScaleInfo(im, sw, sh, dw, dh, antialias); scaleinfo = __imlib_CalcScaleInfo(im, sw, sh, dw, dh, antialias);
if (!scaleinfo) return; if (!scaleinfo)
return;
} }
/* Sign not needed anymore */ /* Sign not needed anymore */
dw = abs(dw); dh = abs(dh); dw = abs(dw);
dh = abs(dh);
ct = __imlib_GetContext(d, v, cm, depth); ct = __imlib_GetContext(d, v, cm, depth);
actual_depth = depth; actual_depth = depth;
if (depth == 16) if (depth == 16)
actual_depth = __imlib_XActualDepth(d, v); actual_depth = __imlib_XActualDepth(d, v);
__imlib_RGBASetupContext(ct); __imlib_RGBASetupContext(ct);
if ((blend) && (IMAGE_HAS_ALPHA(im))) if ((blend) && (IMAGE_HAS_ALPHA(im)))
{ {
back = malloc(dw *dh *sizeof(DATA32)); back = malloc(dw * dh * sizeof(DATA32));
if (!__imlib_GrabDrawableToRGBA(back, 0, 0, dw, dh, d, w, 0, v, cm, depth, dx, dy, dw, dh, 0, 1)) if (!__imlib_GrabDrawableToRGBA
{ (back, 0, 0, dw, dh, d, w, 0, v, cm, depth, dx, dy, dw, dh, 0, 1))
free(back); {
back = NULL; free(back);
} back = NULL;
}
} }
/* get a new XImage - or get one from the cached list */ /* get a new XImage - or get one from the cached list */
xim = __imlib_ProduceXImage(d, v, depth, dw, dh, &shm); xim = __imlib_ProduceXImage(d, v, depth, dw, dh, &shm);
if (!xim) if (!xim)
{ {
__imlib_FreeScaleInfo(scaleinfo); __imlib_FreeScaleInfo(scaleinfo);
if (back) free(back); if (back)
return; free(back);
return;
} }
/* do a double check in 24/32bpp */ /* do a double check in 24/32bpp */
if ((xim->bits_per_pixel == 32) && (depth == 24)) if ((xim->bits_per_pixel == 32) && (depth == 24))
actual_depth = 32; actual_depth = 32;
if (m) if (m)
{ {
mxim = __imlib_ProduceXImage(d, v, 1, dw, dh, &shm); mxim = __imlib_ProduceXImage(d, v, 1, dw, dh, &shm);
if (!mxim) if (!mxim)
{ {
__imlib_ConsumeXImage(d, xim); __imlib_ConsumeXImage(d, xim);
__imlib_FreeScaleInfo(scaleinfo); __imlib_FreeScaleInfo(scaleinfo);
if (back) free(back); if (back)
return; free(back);
} return;
memset(mxim->data, 0, mxim->bytes_per_line * mxim->height); }
memset(mxim->data, 0, mxim->bytes_per_line * mxim->height);
} }
/* if we are scaling the image at all make a scaling buffer */ /* if we are scaling the image at all make a scaling buffer */
if (scaleinfo) if (scaleinfo)
{ {
/* allocate a buffer to render scaled RGBA data into */ /* allocate a buffer to render scaled RGBA data into */
buf = malloc(dw * LINESIZE * sizeof(DATA32)); buf = malloc(dw * LINESIZE * sizeof(DATA32));
if (!buf) if (!buf)
{ {
__imlib_ConsumeXImage(d, xim); __imlib_ConsumeXImage(d, xim);
if (m) if (m)
__imlib_ConsumeXImage(d, mxim); __imlib_ConsumeXImage(d, mxim);
__imlib_FreeScaleInfo(scaleinfo); __imlib_FreeScaleInfo(scaleinfo);
if (back) free(back); if (back)
return; free(back);
} return;
}
} }
/* setup h */ /* setup h */
h = dh; h = dh;
/* scale in LINESIZE Y chunks and convert to depth*/ /* scale in LINESIZE Y chunks and convert to depth */
/* Get rgba and mask functions for XImage rendering */ /* Get rgba and mask functions for XImage rendering */
rgbaer = __imlib_GetRGBAFunction(xim->bits_per_pixel, rgbaer = __imlib_GetRGBAFunction(xim->bits_per_pixel,
v->red_mask, v->green_mask, v->blue_mask, v->red_mask, v->green_mask, v->blue_mask,
hiq, ct->palette_type); hiq, ct->palette_type);
if (m) masker = __imlib_GetMaskFunction(dither_mask); if (m)
masker = __imlib_GetMaskFunction(dither_mask);
#ifdef DO_MMX_ASM #ifdef DO_MMX_ASM
do_mmx = __imlib_get_cpuid() & CPUID_MMX; do_mmx = __imlib_get_cpuid() & CPUID_MMX;
#endif #endif
for (y = 0; y < dh; y += LINESIZE) for (y = 0; y < dh; y += LINESIZE)
{ {
hh = LINESIZE; hh = LINESIZE;
if (h < LINESIZE) if (h < LINESIZE)
hh = h; hh = h;
/* if we're scaling it */ /* if we're scaling it */
if (scaleinfo) if (scaleinfo)
{ {
/* scale the imagedata for this LINESIZE lines chunk of image data */ /* scale the imagedata for this LINESIZE lines chunk of image data */
if (antialias) if (antialias)
{ {
#ifdef DO_MMX_ASM #ifdef DO_MMX_ASM
if (do_mmx) if (do_mmx)
__imlib_Scale_mmx_AARGBA(scaleinfo, buf, __imlib_Scale_mmx_AARGBA(scaleinfo, buf,
((sx * dw) / sw), ((sx * dw) / sw),
((sy * dh) / sh) + y, ((sy * dh) / sh) + y,
0, 0, dw, hh, dw, im->w); 0, 0, dw, hh, dw, im->w);
else else
#endif #endif
if (IMAGE_HAS_ALPHA(im)) if (IMAGE_HAS_ALPHA(im))
__imlib_ScaleAARGBA(scaleinfo, buf, ((sx * dw) / sw), __imlib_ScaleAARGBA(scaleinfo, buf, ((sx * dw) / sw),
((sy * dh) / sh) + y, ((sy * dh) / sh) + y,
0, 0, dw, hh, dw, im->w); 0, 0, dw, hh, dw, im->w);
else else
__imlib_ScaleAARGB(scaleinfo, buf, ((sx * dw) / sw), __imlib_ScaleAARGB(scaleinfo, buf, ((sx * dw) / sw),
((sy * dh) / sh) + y, ((sy * dh) / sh) + y,
0, 0, dw, hh, dw, im->w); 0, 0, dw, hh, dw, im->w);
} }
else else
__imlib_ScaleSampleRGBA(scaleinfo, buf, ((sx * dw) / sw), __imlib_ScaleSampleRGBA(scaleinfo, buf, ((sx * dw) / sw),
((sy * dh) / sh) + y, ((sy * dh) / sh) + y, 0, 0, dw, hh, dw);
0, 0, dw, hh, dw); jump = 0;
jump = 0; pointer = buf;
pointer = buf; if (cmod)
if (cmod) __imlib_DataCmodApply(buf, dw, hh, 0, NULL, cmod);
__imlib_DataCmodApply(buf, dw, hh, 0, NULL, cmod); }
} else
else {
{ if (cmod)
if (cmod) {
{ if (!buf)
if (!buf) buf = malloc(im->w * LINESIZE * sizeof(DATA32));
buf = malloc(im->w * LINESIZE * sizeof(DATA32)); if (!buf)
if (!buf) {
{ __imlib_ConsumeXImage(d, xim);
__imlib_ConsumeXImage(d, xim); if (m)
if (m) __imlib_ConsumeXImage(d, mxim);
__imlib_ConsumeXImage(d, mxim); __imlib_FreeScaleInfo(scaleinfo);
__imlib_FreeScaleInfo(scaleinfo); if (back)
if (back) free(back); free(back);
return; return;
} }
memcpy(buf, im->data + ((y + sy) * im->w) + sx, memcpy(buf, im->data + ((y + sy) * im->w) + sx,
im->w * hh * sizeof(DATA32)); im->w * hh * sizeof(DATA32));
__imlib_DataCmodApply(buf, dw, hh, im->w - dw, NULL, cmod); __imlib_DataCmodApply(buf, dw, hh, im->w - dw, NULL, cmod);
pointer = buf; pointer = buf;
jump = 0; jump = 0;
} }
else else
{ {
jump = im->w - sw; jump = im->w - sw;
pointer = im->data + ((y + sy) * im->w) + sx; pointer = im->data + ((y + sy) * im->w) + sx;
} }
} }
/* if we have a back buffer - we're blending to the bg */ /* if we have a back buffer - we're blending to the bg */
if (back) if (back)
{ {
blender(pointer, jump + dw, back + (y * dw), dw, dw, hh, NULL); blender(pointer, jump + dw, back + (y * dw), dw, dw, hh, NULL);
pointer = back + (y * dw); pointer = back + (y * dw);
jump = 0; jump = 0;
} }
/* once scaled... convert chunk to bit depth into XImage bufer */ /* once scaled... convert chunk to bit depth into XImage bufer */
if (rgbaer) if (rgbaer)
rgbaer(pointer, jump, rgbaer(pointer, jump,
((DATA8 *)xim->data) + (y * (xim->bytes_per_line)), ((DATA8 *) xim->data) + (y * (xim->bytes_per_line)),
xim->bytes_per_line, dw, hh, dx, dy + y); xim->bytes_per_line, dw, hh, dx, dy + y);
else else
__imlib_generic_render(pointer, jump, dw, hh, 0, y, xim, v, ct); __imlib_generic_render(pointer, jump, dw, hh, 0, y, xim, v, ct);
if (m) if (m)
masker(pointer, jump, masker(pointer, jump,
((DATA8 *)mxim->data) + (y * (mxim->bytes_per_line)), ((DATA8 *) mxim->data) + (y * (mxim->bytes_per_line)),
mxim->bytes_per_line, dw, hh, dx, dy + y); mxim->bytes_per_line, dw, hh, dx, dy + y);
h -= LINESIZE; h -= LINESIZE;
} }
/* free up our buffers and poit tables */ /* free up our buffers and poit tables */
if (buf) free(buf); if (buf)
if (scaleinfo) __imlib_FreeScaleInfo(scaleinfo); free(buf);
if (back) free(back); if (scaleinfo)
__imlib_FreeScaleInfo(scaleinfo);
if (back)
free(back);
/* if we changed diplays since last time... free old gc's */ /* if we changed diplays since last time... free old gc's */
if (disp != d) if (disp != d)
{ {
if (gc) XFreeGC(disp, gc); if (gc)
if (gcm) XFreeGC(disp, gcm); XFreeGC(disp, gc);
gc = 0; if (gcm)
gcm = 0; XFreeGC(disp, gcm);
gc = 0;
gcm = 0;
} }
/* if we didnt have a gc... create it */ /* if we didnt have a gc... create it */
if (!gc) if (!gc)
{ {
disp = d; disp = d;
gcv.graphics_exposures = False; gcv.graphics_exposures = False;
gc = XCreateGC(d, w, GCGraphicsExposures, &gcv); gc = XCreateGC(d, w, GCGraphicsExposures, &gcv);
} }
if (m) if (m)
{ {
if (!gcm) if (!gcm)
{ {
gcv.graphics_exposures = False; gcv.graphics_exposures = False;
gcm = XCreateGC(d, m, GCGraphicsExposures, &gcv); gcm = XCreateGC(d, m, GCGraphicsExposures, &gcv);
} }
/* write the mask */ /* write the mask */
if (shm) if (shm)
/* write shm XImage */ /* write shm XImage */
XShmPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh, False); XShmPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh, False);
/* write regular XImage */ /* write regular XImage */
else else
XPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh); XPutImage(d, m, gcm, mxim, 0, 0, dx, dy, dw, dh);
} }
/* write the image */ /* write the image */
if (shm) if (shm)
@ -503,50 +515,64 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
} }
void void
__imlib_RenderImageSkewed(Display *d, ImlibImage *im, Drawable w, Drawable m, __imlib_RenderImageSkewed(Display * d, ImlibImage * im, Drawable w, Drawable m,
Visual *v, Colormap cm, int depth, Visual * v, Colormap cm, int depth,
int sx, int sy, int sw, int sh, int dx, int dy, int sx, int sy, int sw, int sh, int dx, int dy,
int hsx, int hsy, int vsx, int vsy, int hsx, int hsy, int vsx, int vsy,
char antialias, char hiq, char blend, char antialias, char hiq, char blend,
char dither_mask, ImlibColorModifier *cmod, char dither_mask, ImlibColorModifier * cmod,
ImlibOp op) ImlibOp op)
{ {
Context *ct; Context *ct;
int dx1, dy1, dx2, dy2, dw, dh, tsx, tsy; int dx1, dy1, dx2, dy2, dw, dh, tsx, tsy;
ImlibImage *back; ImlibImage *back;
dx1 = dx2 = dx; dx1 = dx2 = dx;
dy1 = dy2 = dy; dy1 = dy2 = dy;
if (hsx < 0) dx1 += hsx; if (hsx < 0)
else dx2 += hsx; dx1 += hsx;
if (hsy < 0) dy1 += hsy; else
else dy2 += hsy; dx2 += hsx;
tsx = vsx; tsy = vsy; if (hsy < 0)
if (!tsx && !tsy) { dy1 += hsy;
tsy = (hsx * im->h) / im->w; else
tsx = -(hsy * im->h) / im->w; dy2 += hsy;
} tsx = vsx;
if (tsx < 0) dx1 += tsx; tsy = vsy;
else dx2 += tsx; if (!tsx && !tsy)
if (tsy < 0) dy1 += tsy; {
else dy2 += tsy; tsy = (hsx * im->h) / im->w;
tsx = -(hsy * im->h) / im->w;
}
if (tsx < 0)
dx1 += tsx;
else
dx2 += tsx;
if (tsy < 0)
dy1 += tsy;
else
dy2 += tsy;
if ((dx2 < 0) || (dy2 < 0)) return; if ((dx2 < 0) || (dy2 < 0))
return;
dw = dx2 - dx1; dw = dx2 - dx1;
dh = dy2 - dy1; dh = dy2 - dy1;
if ((dw <= 0) || (dh <= 0)) return; if ((dw <= 0) || (dh <= 0))
return;
if (dx1 < 0) { if (dx1 < 0)
dw += dx1; {
dx1 = 0; dw += dx1;
} dx1 = 0;
if (dy1 < 0) { }
dh += dy1; if (dy1 < 0)
dy1 = 0; {
} dh += dy1;
dy1 = 0;
}
ct = __imlib_GetContext(d, v, cm, depth); ct = __imlib_GetContext(d, v, cm, depth);
@ -554,13 +580,13 @@ __imlib_RenderImageSkewed(Display *d, ImlibImage *im, Drawable w, Drawable m,
back->data = malloc(dw * dh * sizeof(DATA32)); back->data = malloc(dw * dh * sizeof(DATA32));
memset(back->data, 0, dw * dh * sizeof(DATA32)); memset(back->data, 0, dw * dh * sizeof(DATA32));
__imlib_GrabDrawableToRGBA(back->data, 0, 0, dw, dh, d, w, 0, v, cm, __imlib_GrabDrawableToRGBA(back->data, 0, 0, dw, dh, d, w, 0, v, cm,
depth, dx1, dy1, dw, dh, 0, 1); depth, dx1, dy1, dw, dh, 0, 1);
__imlib_BlendImageToImageSkewed(im, back, antialias, 1, 0, sx, sy, sw, sh, __imlib_BlendImageToImageSkewed(im, back, antialias, 1, 0, sx, sy, sw, sh,
dx - dx1, dy - dy1, hsx, hsy, vsx, vsy, dx - dx1, dy - dy1, hsx, hsy, vsx, vsy,
cmod, op, 0, 0, 0, 0); cmod, op, 0, 0, 0, 0);
__imlib_RenderImage(d, back, w, m, v, cm, depth, 0, 0, dw, dh, __imlib_RenderImage(d, back, w, m, v, cm, depth, 0, 0, dw, dh,
dx1, dy1, dw, dh, 0, hiq, 0, dither_mask, 0, OP_COPY); dx1, dy1, dw, dh, 0, hiq, 0, dither_mask, 0, OP_COPY);
__imlib_FreeImage(back); __imlib_FreeImage(back);
} }

5666
src/rgba.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -50,58 +50,66 @@
/*\ Rotate by pixel sampling only, target inside source \*/ /*\ Rotate by pixel sampling only, target inside source \*/
static void static void
__imlib_RotateSampleInside(DATA32 *src, DATA32 *dest, int sow, int dow, __imlib_RotateSampleInside(DATA32 * src, DATA32 * dest, int sow, int dow,
int dw, int dh, int x, int y, int dw, int dh, int x, int y,
int dxh, int dyh, int dxv, int dyv) int dxh, int dyh, int dxv, int dyv)
{ {
int i; int i;
if ((dw < 1) || (dh < 1)) return; if ((dw < 1) || (dh < 1))
return;
while (1) { while (1)
i = dw - 1; {
do { i = dw - 1;
*dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)]; do
/*\ RIGHT; \*/ {
x += dxh; *dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)];
y += dyh; /*\ RIGHT; \ */
dest++; x += dxh;
} while (--i >= 0); y += dyh;
if (--dh <= 0) break; dest++;
/*\ DOWN/LEFT; \*/ } while (--i >= 0);
x += dxv - dw * dxh; if (--dh <= 0)
y += dyv - dw * dyh; break;
dest += (dow - dw); /*\ DOWN/LEFT; \ */
} x += dxv - dw * dxh;
y += dyv - dw * dyh;
dest += (dow - dw);
}
} }
/*\ Same as last function, but with antialiasing \*/ /*\ Same as last function, but with antialiasing \*/
static void static void
__imlib_RotateAAInside(DATA32 *src, DATA32 *dest, int sow, int dow, __imlib_RotateAAInside(DATA32 * src, DATA32 * dest, int sow, int dow,
int dw, int dh, int x, int y, int dw, int dh, int x, int y,
int dxh, int dyh, int dxv, int dyv) int dxh, int dyh, int dxv, int dyv)
{ {
int i; int i;
if ((dw < 1) || (dh < 1)) return; if ((dw < 1) || (dh < 1))
return;
while (1) { while (1)
i = dw - 1; {
do { i = dw - 1;
DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) + do
((y >> _ROTATE_PREC) * sow)); {
INTERP_ARGB(dest, src_x_y, sow, x, y); DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) +
/*\ RIGHT; \*/ ((y >> _ROTATE_PREC) * sow));
x += dxh; INTERP_ARGB(dest, src_x_y, sow, x, y);
y += dyh; /*\ RIGHT; \ */
dest++; x += dxh;
} while (--i >= 0); y += dyh;
if (--dh <= 0) break; dest++;
/*\ DOWN/LEFT; \*/ } while (--i >= 0);
x += dxv - dw * dxh; if (--dh <= 0)
y += dyv - dw * dyh; break;
dest += (dow - dw); /*\ DOWN/LEFT; \ */
} x += dxv - dw * dxh;
y += dyv - dw * dyh;
dest += (dow - dw);
}
} }
/*\ NOTE: To check if v is in [b .. t) ((v >= b) && (v < t)) /*\ NOTE: To check if v is in [b .. t) ((v >= b) && (v < t))
@ -113,20 +121,23 @@ __imlib_RotateAAInside(DATA32 *src, DATA32 *dest, int sow, int dow,
\*/ \*/
static int static int
__check_inside_coords(int x, int y, int dxh, int dyh, int dxv, int dyv, __check_inside_coords(int x, int y, int dxh, int dyh, int dxv, int dyv,
int dw, int dh, int sw, int sh) int dw, int dh, int sw, int sh)
{ {
sw <<= _ROTATE_PREC; sw <<= _ROTATE_PREC;
sh <<= _ROTATE_PREC; sh <<= _ROTATE_PREC;
if (((unsigned)x >= sw) || ((unsigned)y >= sh)) if (((unsigned)x >= sw) || ((unsigned)y >= sh))
return 0; return 0;
x += dxh * dw; y += dyh * dw; x += dxh * dw;
y += dyh * dw;
if (((unsigned)x >= sw) || ((unsigned)y >= sh)) if (((unsigned)x >= sw) || ((unsigned)y >= sh))
return 0; return 0;
x += dxv * dh; y += dyv * dh; x += dxv * dh;
y += dyv * dh;
if (((unsigned)x >= sw) || ((unsigned)y >= sh)) if (((unsigned)x >= sw) || ((unsigned)y >= sh))
return 0; return 0;
x -= dxh * dw; y -= dyh * dw; x -= dxh * dw;
y -= dyh * dw;
if (((unsigned)x >= sw) || ((unsigned)y >= sh)) if (((unsigned)x >= sw) || ((unsigned)y >= sh))
return 0; return 0;
@ -135,42 +146,48 @@ __check_inside_coords(int x, int y, int dxh, int dyh, int dxv, int dyv,
/*\ These ones don't need the target to be inside the source \*/ /*\ These ones don't need the target to be inside the source \*/
void void
__imlib_RotateSample(DATA32 *src, DATA32 *dest, int sow, int sw, int sh, __imlib_RotateSample(DATA32 * src, DATA32 * dest, int sow, int sw, int sh,
int dow, int dw, int dh, int x, int y, int dow, int dw, int dh, int x, int y,
int dxh, int dyh, int dxv, int dyv) int dxh, int dyh, int dxv, int dyv)
{ {
int i; int i;
if ((dw < 1) || (dh < 1)) return; if ((dw < 1) || (dh < 1))
if (__check_inside_coords(x, y, dxh, dyh, dxv, dyv, dw, dh, sw, sh)) {
__imlib_RotateSampleInside(src, dest, sow, dow, dw, dh, x, y,
dxh, dyh, dxv, dyv);
return; return;
} if (__check_inside_coords(x, y, dxh, dyh, dxv, dyv, dw, dh, sw, sh))
{
__imlib_RotateSampleInside(src, dest, sow, dow, dw, dh, x, y,
dxh, dyh, dxv, dyv);
return;
}
sw <<= _ROTATE_PREC; sw <<= _ROTATE_PREC;
sh <<= _ROTATE_PREC; sh <<= _ROTATE_PREC;
while (1) { while (1)
i = dw - 1; {
do { i = dw - 1;
if (((unsigned)x < sw) && ((unsigned)y < sh)) do
*dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)]; {
else *dest = 0; if (((unsigned)x < sw) && ((unsigned)y < sh))
/*\ RIGHT; \*/ *dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)];
x += dxh; else
y += dyh; *dest = 0;
dest++; /*\ RIGHT; \ */
x += dxh;
y += dyh;
dest++;
} while (--i >= 0); } while (--i >= 0);
if (--dh <= 0) break; if (--dh <= 0)
/*\ DOWN/LEFT; \*/ break;
x += dxv - dw * dxh; /*\ DOWN/LEFT; \ */
y += dyv - dw * dyh; x += dxv - dw * dxh;
dest += (dow - dw); y += dyv - dw * dyh;
dest += (dow - dw);
} }
} }
/*\ With antialiasing. /*\ With antialiasing.
@ -180,112 +197,148 @@ __imlib_RotateSample(DATA32 *src, DATA32 *dest, int sow, int sw, int sh,
|*| the bounding box. |*| the bounding box.
\*/ \*/
void void
__imlib_RotateAA(DATA32 *src, DATA32 *dest, int sow, int sw, int sh, __imlib_RotateAA(DATA32 * src, DATA32 * dest, int sow, int sw, int sh,
int dow, int dw, int dh, int x, int y, int dow, int dw, int dh, int x, int y,
int dxh, int dyh, int dxv, int dyv) int dxh, int dyh, int dxv, int dyv)
{ {
int i; int i;
if ((dw < 1) || (dh < 1)) return; if ((dw < 1) || (dh < 1))
if (__check_inside_coords(x, y, dxh, dyh, dxv, dyv, dw, dh, sw-1, sh-1)) {
__imlib_RotateAAInside(src, dest, sow, dow, dw, dh, x, y,
dxh, dyh, dxv, dyv);
return; return;
} if (__check_inside_coords(x, y, dxh, dyh, dxv, dyv, dw, dh, sw - 1, sh - 1))
{
__imlib_RotateAAInside(src, dest, sow, dow, dw, dh, x, y,
dxh, dyh, dxv, dyv);
return;
sw--; sh--; }
sw--;
sh--;
sw <<= _ROTATE_PREC; sw <<= _ROTATE_PREC;
sh <<= _ROTATE_PREC; sh <<= _ROTATE_PREC;
while (1) { while (1)
i = dw - 1; {
do { i = dw - 1;
DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) + do
((y >> _ROTATE_PREC) * sow)); {
if ((unsigned)x < sw) { DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) +
if ((unsigned)y < sh) { ((y >> _ROTATE_PREC) * sow));
/*\ 12 if ((unsigned)x < sw)
|*| 34 {
\*/ if ((unsigned)y < sh)
INTERP_ARGB(dest, src_x_y, sow, x, y); {
} else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX) { /*\ 12
/*\ 12 * |*| 34
|*| .. * \ */
\*/ INTERP_ARGB(dest, src_x_y, sow, x, y);
INTERP_RGB_A0(dest, src_x_y, src_x_y + 1, x, ~y); }
} else if ((unsigned)(~y) < _ROTATE_PREC_MAX) { else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX)
/*\ .. {
|*| 34 /*\ 12
\*/ * |*| ..
INTERP_RGB_A0(dest, src_x_y + sow, src_x_y + sow + 1, x, y); * \ */
} else *dest = 0; INTERP_RGB_A0(dest, src_x_y, src_x_y + 1, x, ~y);
} else if ((unsigned)(x - sw) < (_ROTATE_PREC_MAX)) { }
if ((unsigned)y < sh) { else if ((unsigned)(~y) < _ROTATE_PREC_MAX)
/*\ 1. {
|*| 3. /*\ ..
\*/ * |*| 34
INTERP_RGB_A0(dest, src_x_y, src_x_y + sow, y, ~x); * \ */
} else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX) { INTERP_RGB_A0(dest, src_x_y + sow, src_x_y + sow + 1, x,
/*\ 1. y);
|*| .. }
\*/ else
INTERP_A000(dest, src_x_y, ~x, ~y); *dest = 0;
} else if ((unsigned)(~y) < _ROTATE_PREC_MAX) { }
/*\ .. else if ((unsigned)(x - sw) < (_ROTATE_PREC_MAX))
|*| 3. {
\*/ if ((unsigned)y < sh)
INTERP_A000(dest, src_x_y + sow, ~x, y); {
} else *dest = 0; /*\ 1.
} else if ((unsigned)(~x) < _ROTATE_PREC_MAX) { * |*| 3.
if ((unsigned)y < sh) { * \ */
/*\ .2 INTERP_RGB_A0(dest, src_x_y, src_x_y + sow, y, ~x);
|*| .4 }
\*/ else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX)
INTERP_RGB_A0(dest, src_x_y + 1, src_x_y + sow + 1, y, x); {
} else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX) { /*\ 1.
/*\ .2 * |*| ..
|*| .. * \ */
\*/ INTERP_A000(dest, src_x_y, ~x, ~y);
INTERP_A000(dest, src_x_y + 1, x, ~y); }
} else if ((unsigned)(~y) < _ROTATE_PREC_MAX) { else if ((unsigned)(~y) < _ROTATE_PREC_MAX)
/*\ .. {
|*| .4 /*\ ..
\*/ * |*| 3.
INTERP_A000(dest, src_x_y + sow + 1, x, y); * \ */
} else *dest = 0; INTERP_A000(dest, src_x_y + sow, ~x, y);
} else *dest = 0; }
/*\ RIGHT; \*/ else
x += dxh; *dest = 0;
y += dyh; }
dest++; else if ((unsigned)(~x) < _ROTATE_PREC_MAX)
{
if ((unsigned)y < sh)
{
/*\ .2
* |*| .4
* \ */
INTERP_RGB_A0(dest, src_x_y + 1, src_x_y + sow + 1, y,
x);
}
else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX)
{
/*\ .2
* |*| ..
* \ */
INTERP_A000(dest, src_x_y + 1, x, ~y);
}
else if ((unsigned)(~y) < _ROTATE_PREC_MAX)
{
/*\ ..
* |*| .4
* \ */
INTERP_A000(dest, src_x_y + sow + 1, x, y);
}
else
*dest = 0;
}
else
*dest = 0;
/*\ RIGHT; \ */
x += dxh;
y += dyh;
dest++;
} while (--i >= 0); } while (--i >= 0);
if (--dh <= 0) break; if (--dh <= 0)
/*\ DOWN/LEFT; \*/ break;
x += dxv - dw * dxh; /*\ DOWN/LEFT; \ */
y += dyv - dw * dyh; x += dxv - dw * dxh;
dest += (dow - dw); y += dyv - dw * dyh;
dest += (dow - dw);
} }
} }
/*\ Should this be in blend.c ?? \*/ /*\ Should this be in blend.c ?? \*/
#define LINESIZE 16 #define LINESIZE 16
void void
__imlib_BlendImageToImageSkewed(ImlibImage *im_src, ImlibImage *im_dst, __imlib_BlendImageToImageSkewed(ImlibImage * im_src, ImlibImage * im_dst,
char aa, char blend, char merge_alpha, char aa, char blend, char merge_alpha,
int ssx, int ssy, int ssw, int ssh, int ssx, int ssy, int ssw, int ssh,
int ddx, int ddy, int ddx, int ddy,
int hsx, int hsy, int vsx, int vsy, int hsx, int hsy, int vsx, int vsy,
ImlibColorModifier *cm, ImlibOp op, ImlibColorModifier * cm, ImlibOp op,
int clx, int cly, int clw, int clh) int clx, int cly, int clw, int clh)
{ {
int x, y, dxh, dyh, dxv, dyv, i; int x, y, dxh, dyh, dxv, dyv, i;
double xy2; double xy2;
DATA32 *data, *src; DATA32 *data, *src;
int do_mmx; int do_mmx;
if ((ssw < 0) || (ssh < 0)) if ((ssw < 0) || (ssh < 0))
return; return;
@ -300,148 +353,190 @@ __imlib_BlendImageToImageSkewed(ImlibImage *im_src, ImlibImage *im_dst,
return; return;
/*\ Complicated gonio. Works on paper.. /*\ Complicated gonio. Works on paper..
|*| Too bad it doesn't all fit into integer math.. * |*| Too bad it doesn't all fit into integer math..
\*/ * \ */
if (vsx | vsy) { if (vsx | vsy)
xy2 = (double)(hsx * vsy - vsx * hsy) / _ROTATE_PREC_MAX; {
if (xy2 == 0.0) return; xy2 = (double)(hsx * vsy - vsx * hsy) / _ROTATE_PREC_MAX;
dxh = (double)(ssw * vsy) / xy2; if (xy2 == 0.0)
dxv = (double)-(ssw * vsx) / xy2; return;
dyh = (double)-(ssh * hsy) / xy2; dxh = (double)(ssw * vsy) / xy2;
dyv = (double)(ssh * hsx) / xy2; dxv = (double)-(ssw * vsx) / xy2;
} else { dyh = (double)-(ssh * hsy) / xy2;
xy2 = (double)(hsx * hsx + hsy * hsy) / _ROTATE_PREC_MAX; dyv = (double)(ssh * hsx) / xy2;
if (xy2 == 0.0) return; }
dxh = (double)(ssw * hsx) / xy2; else
dyh = (double)-(ssw * hsy) / xy2; {
dxv = -dyh; xy2 = (double)(hsx * hsx + hsy * hsy) / _ROTATE_PREC_MAX;
dyv = dxh; if (xy2 == 0.0)
} return;
x = - (ddx * dxh + ddy * dxv); dxh = (double)(ssw * hsx) / xy2;
y = - (ddx * dyh + ddy * dyv); dyh = (double)-(ssw * hsy) / xy2;
dxv = -dyh;
dyv = dxh;
}
x = -(ddx * dxh + ddy * dxv);
y = -(ddx * dyh + ddy * dyv);
if (ssx < 0) { if (ssx < 0)
x += ssx * _ROTATE_PREC_MAX; {
ssw += ssx; x += ssx * _ROTATE_PREC_MAX;
ssx = 0; ssw += ssx;
ssx = 0;
} }
if (ssy < 0) { if (ssy < 0)
y += ssy * _ROTATE_PREC_MAX; {
ssh += ssy; y += ssy * _ROTATE_PREC_MAX;
ssy = 0; ssh += ssy;
ssy = 0;
} }
if ((ssw + ssx) > im_src->w) ssw = im_src->w - ssx; if ((ssw + ssx) > im_src->w)
if ((ssh + ssy) > im_src->h) ssh = im_src->h - ssy; ssw = im_src->w - ssx;
if ((ssh + ssy) > im_src->h)
ssh = im_src->h - ssy;
src = im_src->data + ssx + ssy * im_src->w; src = im_src->data + ssx + ssy * im_src->w;
data = malloc(im_dst->w * LINESIZE * sizeof(DATA32)); data = malloc(im_dst->w * LINESIZE * sizeof(DATA32));
if (!data) if (!data)
return; return;
if (aa) { if (aa)
/*\ Account for virtual transparent border \*/ {
x += _ROTATE_PREC_MAX; /*\ Account for virtual transparent border \ */
y += _ROTATE_PREC_MAX; x += _ROTATE_PREC_MAX;
} y += _ROTATE_PREC_MAX;
}
#ifdef DO_MMX_ASM #ifdef DO_MMX_ASM
do_mmx = __imlib_get_cpuid() & CPUID_MMX; do_mmx = __imlib_get_cpuid() & CPUID_MMX;
#endif #endif
for (i = 0; i < im_dst->h; i += LINESIZE) { for (i = 0; i < im_dst->h; i += LINESIZE)
int x2, y2, w, h, l, r; {
int x2, y2, w, h, l, r;
h = MIN(LINESIZE, im_dst->h - i); h = MIN(LINESIZE, im_dst->h - i);
x2 = x + h * dxv; x2 = x + h * dxv;
y2 = y + h * dyv; y2 = y + h * dyv;
w = ssw << _ROTATE_PREC; w = ssw << _ROTATE_PREC;
h = ssh << _ROTATE_PREC; h = ssh << _ROTATE_PREC;
if (aa) { if (aa)
/*\ Account for virtual transparent border \*/ {
w += 2 << _ROTATE_PREC; /*\ Account for virtual transparent border \ */
h += 2 << _ROTATE_PREC; w += 2 << _ROTATE_PREC;
} h += 2 << _ROTATE_PREC;
/*\ Pretty similar code \*/ }
if (dxh > 0) { /*\ Pretty similar code \ */
if (dyh > 0) { if (dxh > 0)
l = MAX(-MAX(y, y2) / dyh, -MAX(x, x2) / dxh); {
r = MIN((h - MIN(y, y2)) / dyh, (w - MIN(x, x2)) / dxh); if (dyh > 0)
{
l = MAX(-MAX(y, y2) / dyh, -MAX(x, x2) / dxh);
r = MIN((h - MIN(y, y2)) / dyh, (w - MIN(x, x2)) / dxh);
} else if (dyh < 0) { }
l = MAX(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh); else if (dyh < 0)
r = MIN(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh); {
l = MAX(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh);
r = MIN(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh);
} else { }
l = -MAX(x, x2) / dxh; else
r = (w - MIN(x, x2)) / dxh; {
l = -MAX(x, x2) / dxh;
r = (w - MIN(x, x2)) / dxh;
} }
} else if (dxh < 0) { }
if (dyh > 0) { else if (dxh < 0)
l = MAX(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh); {
r = MIN(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh); if (dyh > 0)
{
l = MAX(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh);
r = MIN(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh);
} else if (dyh < 0) { }
l = MAX((h - MIN(y, y2)) / dyh, (w - MIN(x, x2)) / dxh); else if (dyh < 0)
r = MIN(-MAX(y, y2) / dyh, -MAX(x, x2) / dxh); {
l = MAX((h - MIN(y, y2)) / dyh, (w - MIN(x, x2)) / dxh);
r = MIN(-MAX(y, y2) / dyh, -MAX(x, x2) / dxh);
} else { }
l = (w - MIN(x, x2)) / dxh; else
r = -MAX(x, x2) / dxh; {
l = (w - MIN(x, x2)) / dxh;
r = -MAX(x, x2) / dxh;
} }
} else { }
if (dyh > 0) { else
l = -MAX(y, y2) / dyh; {
r = (h - MIN(y, y2)) / dyh; if (dyh > 0)
{
l = -MAX(y, y2) / dyh;
r = (h - MIN(y, y2)) / dyh;
} else if (dyh < 0) { }
l = (h - MIN(y, y2)) / dyh; else if (dyh < 0)
r = -MAX(y, y2) / dyh; {
l = (h - MIN(y, y2)) / dyh;
r = -MAX(y, y2) / dyh;
} else { }
l = 0; else
r = 0; {
l = 0;
r = 0;
} }
} }
l--; r += 2; /*\ Be paranoid about roundoff errors \*/ l--;
if (l < 0) l = 0; r += 2; /*\ Be paranoid about roundoff errors \ */
if (r > im_dst->w) r = im_dst->w; if (l < 0)
if (r <= l) { l = 0;
x = x2; y = y2; if (r > im_dst->w)
continue; r = im_dst->w;
if (r <= l)
{
x = x2;
y = y2;
continue;
} }
w = r - l; w = r - l;
h = MIN(LINESIZE, im_dst->h - i); h = MIN(LINESIZE, im_dst->h - i);
x += l * dxh; x += l * dxh;
y += l * dyh; y += l * dyh;
if (aa) { if (aa)
x -= _ROTATE_PREC_MAX; y -= _ROTATE_PREC_MAX; {
x -= _ROTATE_PREC_MAX;
y -= _ROTATE_PREC_MAX;
#ifdef DO_MMX_ASM #ifdef DO_MMX_ASM
if (do_mmx) if (do_mmx)
__imlib_mmx_RotateAA(src, data, im_src->w, ssw, ssh, w, w, h, __imlib_mmx_RotateAA(src, data, im_src->w, ssw, ssh, w, w, h,
x, y, dxh, dyh, dxv, dyv); x, y, dxh, dyh, dxv, dyv);
else else
#endif #endif
__imlib_RotateAA(src, data, im_src->w, ssw, ssh, w, w, h, __imlib_RotateAA(src, data, im_src->w, ssw, ssh, w, w, h,
x, y, dxh, dyh, dxv, dyv); x, y, dxh, dyh, dxv, dyv);
} else { }
__imlib_RotateSample(src, data, im_src->w, ssw, ssh, w, w, h, else
x, y, dxh, dyh, dxv, dyv); {
__imlib_RotateSample(src, data, im_src->w, ssw, ssh, w, w, h,
x, y, dxh, dyh, dxv, dyv);
} }
__imlib_BlendRGBAToData(data, w, h, im_dst->data, __imlib_BlendRGBAToData(data, w, h, im_dst->data,
im_dst->w, im_dst->h, 0, 0, l, i, w, h, im_dst->w, im_dst->h, 0, 0, l, i, w, h,
blend, merge_alpha, cm, op, 0); blend, merge_alpha, cm, op, 0);
x = x2; y = y2; x = x2;
y = y2;
} }
free(data); free(data);
} }

File diff suppressed because it is too large Load Diff

View File

@ -29,242 +29,269 @@
#define D( str ) #define D( str )
#endif #endif
IVariable *vars, *current_var, *curtail; IVariable *vars, *current_var, *curtail;
static int
static int __imlib_find_string( char *haystack, char *needle ) __imlib_find_string(char *haystack, char *needle)
{ {
if( strstr( haystack, needle ) != NULL ) if (strstr(haystack, needle) != NULL)
return ( strstr( haystack, needle ) - haystack ); return (strstr(haystack, needle) - haystack);
return 0; return 0;
} }
static char *__imlib_stripwhitespace( char *str ) static char *
__imlib_stripwhitespace(char *str)
{ {
int i, strt = 0, in_quote = 0; int i, strt = 0, in_quote = 0;
char *tmpstr = calloc( strlen(str)+1, sizeof(char) ); char *tmpstr = calloc(strlen(str) + 1, sizeof(char));
for( i = 0; i < strlen(str); i++ )
{ for (i = 0; i < strlen(str); i++)
if( str[i] == '\"' ) {
in_quote = (in_quote == 0 ? 1 : 0); if (str[i] == '\"')
if( in_quote || ! isspace(*(str+i)) ) in_quote = (in_quote == 0 ? 1 : 0);
tmpstr[strt++] = str[i]; if (in_quote || !isspace(*(str + i)))
} tmpstr[strt++] = str[i];
strcpy( str, tmpstr ); }
strcpy(str, tmpstr);
free(tmpstr); free(tmpstr);
return str; return str;
} }
static char *__imlib_copystr( char *str, int start, int end ) static char *
__imlib_copystr(char *str, int start, int end)
{ {
int i = 0; int i = 0;
char *rstr = calloc( 1024, sizeof( char ) ); char *rstr = calloc(1024, sizeof(char));
if( start <= end && end < strlen( str ) )
{ if (start <= end && end < strlen(str))
for( i = start; i <= end; i++ ) {
rstr[i-start] = str[i]; for (i = start; i <= end; i++)
return rstr; rstr[i - start] = str[i];
} return rstr;
}
return NULL; return NULL;
} }
static void __imlib_script_tidyup_params( IFunctionParam *param ) static void
__imlib_script_tidyup_params(IFunctionParam * param)
{ {
if( param->next ){ if (param->next)
__imlib_script_tidyup_params( param->next ); {
} __imlib_script_tidyup_params(param->next);
free( param->key ); }
if( param->type == VAR_CHAR ) free(param->key);
free( param->data ); if (param->type == VAR_CHAR)
free( param ); free(param->data);
free(param);
} }
static void __imlib_script_delete_variable( IVariable *var ) static void
__imlib_script_delete_variable(IVariable * var)
{ {
if( var->next != NULL ) if (var->next != NULL)
__imlib_script_delete_variable( var->next ); __imlib_script_delete_variable(var->next);
free( var ); free(var);
} }
void __imlib_script_tidyup(void) void
__imlib_script_tidyup(void)
{ {
__imlib_script_delete_variable( vars ); __imlib_script_delete_variable(vars);
} }
void *__imlib_script_get_next_var(void) void *
__imlib_script_get_next_var(void)
{ {
if( current_var != NULL ) if (current_var != NULL)
current_var = current_var->next; current_var = current_var->next;
if( current_var != NULL ) if (current_var != NULL)
return current_var->ptr; return current_var->ptr;
else else
return NULL; return NULL;
} }
void __imlib_script_add_var( void *ptr ) void
__imlib_script_add_var(void *ptr)
{ {
curtail->next = malloc( sizeof( IVariable ) ); curtail->next = malloc(sizeof(IVariable));
curtail = curtail->next; curtail = curtail->next;
curtail->ptr = ptr; curtail->ptr = ptr;
curtail->next = NULL; curtail->next = NULL;
} }
IFunctionParam *__imlib_script_parse_parameters( Imlib_Image im, char *parameters ) IFunctionParam *
__imlib_script_parse_parameters(Imlib_Image im, char *parameters)
{ {
int i = 0, in_quote = 0, depth=0, start=0, value_start=0; int i = 0, in_quote = 0, depth = 0, start = 0, value_start =
char *value = NULL; 0;
IFunctionParam *rootptr, *ptr; char *value = NULL;
IFunctionParam *rootptr, *ptr;
D( "(--) ===> Entering __imlib_script_parse_parameters()" ); D("(--) ===> Entering __imlib_script_parse_parameters()");
rootptr = malloc( sizeof( IFunctionParam ) ); rootptr = malloc(sizeof(IFunctionParam));
rootptr->key = strdup( "NO-KEY" ); rootptr->key = strdup("NO-KEY");
rootptr->type = VAR_CHAR; rootptr->type = VAR_CHAR;
rootptr->data = strdup( "NO-VALUE" ); rootptr->data = strdup("NO-VALUE");
rootptr->next = NULL; rootptr->next = NULL;
ptr = rootptr; ptr = rootptr;
for( i = 0; i <= strlen( parameters ); i++ ) for (i = 0; i <= strlen(parameters); i++)
{ {
if( parameters[i] == '\"' ) if (parameters[i] == '\"')
in_quote = (in_quote == 0 ? 1 : 0); in_quote = (in_quote == 0 ? 1 : 0);
if( !in_quote && parameters[i] == '(' ) depth++; if (!in_quote && parameters[i] == '(')
if( !in_quote && parameters[i] == ')' ) depth--; depth++;
if( !in_quote && parameters[i] == '=' && depth == 0) value_start=i+1; if (!in_quote && parameters[i] == ')')
if( !in_quote && (parameters[i] == ',' || i == (strlen(parameters))) && depth == 0 ) depth--;
{ if (!in_quote && parameters[i] == '=' && depth == 0)
ptr->next = malloc( sizeof( IFunctionParam ) ); value_start = i + 1;
ptr = ptr->next; if (!in_quote && (parameters[i] == ',' || i == (strlen(parameters)))
ptr->key = __imlib_copystr( parameters, start, value_start - 2 ); && depth == 0)
value = __imlib_copystr( parameters, value_start, i-1 ); {
ptr->next = malloc(sizeof(IFunctionParam));
ptr = ptr->next;
ptr->key = __imlib_copystr(parameters, start, value_start - 2);
value = __imlib_copystr(parameters, value_start, i - 1);
#ifdef FDEBUG #ifdef FDEBUG
printf( "DEBUG: (--) --> Variable \"%s\" = \"%s\"\n", ptr->key, value ); printf("DEBUG: (--) --> Variable \"%s\" = \"%s\"\n", ptr->key,
value);
#endif #endif
if( __imlib_find_string( value, "(" ) < __imlib_find_string( value, "\"" ) ) if (__imlib_find_string(value, "(") <
{ __imlib_find_string(value, "\""))
D( "(--) Found a function" ); {
ptr->data = __imlib_script_parse_function( im, value ); D("(--) Found a function");
ptr->type = VAR_PTR; ptr->data = __imlib_script_parse_function(im, value);
free( value ); ptr->type = VAR_PTR;
} free(value);
else }
{ else
if( strcmp( value, "[]" ) == 0 ) {
{ if (strcmp(value, "[]") == 0)
ptr->data = __imlib_script_get_next_var(); {
if( ptr->data == NULL ) ptr->data = __imlib_script_get_next_var();
D( "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEK" ); if (ptr->data == NULL)
/* printf( "Using pointer variable %p\n", ptr->data );*/ D("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEK");
ptr->type = VAR_PTR; /* printf( "Using pointer variable %p\n", ptr->data ); */
free(value); ptr->type = VAR_PTR;
} free(value);
else }
{ else
ptr->data = value; {
ptr->type = VAR_CHAR; ptr->data = value;
} ptr->type = VAR_CHAR;
} }
ptr->next = NULL; }
start = i+1; ptr->next = NULL;
} start = i + 1;
} }
D( "(--) <=== Leaving __imlib_script_parse_parameters()" ); }
D("(--) <=== Leaving __imlib_script_parse_parameters()");
return rootptr; return rootptr;
} }
Imlib_Image __imlib_script_parse_function( Imlib_Image im, char *function ) Imlib_Image
__imlib_script_parse_function(Imlib_Image im, char *function)
{ {
char *funcname, *funcparams; char *funcname, *funcparams;
IFunctionParam *params; IFunctionParam *params;
ImlibExternalFilter *filter = NULL; ImlibExternalFilter *filter = NULL;
Imlib_Image retval; Imlib_Image retval;
D( "(--) ===> Entering __imlib_script_parse_function()" ); D("(--) ===> Entering __imlib_script_parse_function()");
funcname = __imlib_copystr( function, 0, __imlib_find_string( function, "(" ) - 1 ); funcname =
funcparams = __imlib_copystr( function, __imlib_find_string( function, "(" ) + 1, strlen(function)-2 ); __imlib_copystr(function, 0, __imlib_find_string(function, "(") - 1);
funcparams =
__imlib_copystr(function, __imlib_find_string(function, "(") + 1,
strlen(function) - 2);
#ifdef FDEBUG #ifdef FDEBUG
printf( "DEBUG: (??) = function <%s>( \"%s\" )\n", funcname, funcparams ); printf("DEBUG: (??) = function <%s>( \"%s\" )\n", funcname, funcparams);
#endif #endif
params = __imlib_script_parse_parameters( im, funcparams ); params = __imlib_script_parse_parameters(im, funcparams);
/* excute the filter */ /* excute the filter */
filter = __imlib_get_dynamic_filter( funcname ); filter = __imlib_get_dynamic_filter(funcname);
if( filter != NULL ) if (filter != NULL)
{ {
#ifdef FDEBUG #ifdef FDEBUG
printf( "DEBUG: (--) Executing Filter \"%s\".\n", funcname ); printf("DEBUG: (--) Executing Filter \"%s\".\n", funcname);
#endif #endif
retval = filter->exec_filter( funcname, im, params ); retval = filter->exec_filter(funcname, im, params);
} }
else else
{ {
#ifdef FDEBUG #ifdef FDEBUG
printf( "DEBUG: (!!) Can't find filter \"%s\", returning given image.\n", funcname ); printf
("DEBUG: (!!) Can't find filter \"%s\", returning given image.\n",
funcname);
#endif #endif
retval = im; retval = im;
} }
D( "Get Here" ); D("Get Here");
/* clean up params */ /* clean up params */
free( funcname ); free(funcname);
free( funcparams ); free(funcparams);
__imlib_script_tidyup_params( params ); __imlib_script_tidyup_params(params);
D( "(--) <=== Leaving __imlib_script_parse_function()" ); D("(--) <=== Leaving __imlib_script_parse_function()");
return retval; return retval;
} }
Imlib_Image __imlib_script_parse( Imlib_Image im, char *script, va_list param_list ) Imlib_Image
__imlib_script_parse(Imlib_Image im, char *script, va_list param_list)
{ {
int i = 0, in_quote = 0, start = 0, depth = 0; int i = 0, in_quote = 0, start = 0, depth = 0;
char *scriptbuf = NULL, *function; char *scriptbuf = NULL, *function;
D( "(--) Script Parser Start." ); D("(--) Script Parser Start.");
if( script != NULL && strlen(script) > 0 ) if (script != NULL && strlen(script) > 0)
{ {
vars = malloc( sizeof( IVariable ) ); vars = malloc(sizeof(IVariable));
vars->ptr = NULL; vars->ptr = NULL;
vars->next = NULL; vars->next = NULL;
curtail = vars; curtail = vars;
current_var = vars; current_var = vars;
/* gather up variable from the command line */ /* gather up variable from the command line */
D( "(--) String Whitespace from script." ); D("(--) String Whitespace from script.");
scriptbuf = __imlib_stripwhitespace( strdup( script ) ); scriptbuf = __imlib_stripwhitespace(strdup(script));
i = __imlib_find_string( scriptbuf+start, "=[]") - 1; i = __imlib_find_string(scriptbuf + start, "=[]") - 1;
while( i > 0 ) while (i > 0)
{ {
__imlib_script_add_var( va_arg( param_list, void * ) ); __imlib_script_add_var(va_arg(param_list, void *));
start = start+i+2;
i = __imlib_find_string( scriptbuf+start, "=[]") - 1;
i = ( i == 0 ? 0 : i );
D( "(??) Found pointer variable" );
}
start = 0; start = start + i + 2;
i = 0; i = __imlib_find_string(scriptbuf + start, "=[]") - 1;
for( i = 0; i < strlen( scriptbuf ); i++ ) i = (i == 0 ? 0 : i);
{ D("(??) Found pointer variable");
if( script[i] == '\"' ) }
in_quote = (in_quote == 0 ? 1 : 0);
if( !in_quote && script[i] == '(' ) depth++; start = 0;
if( !in_quote && script[i] == ')' ) depth--; i = 0;
if( !in_quote && (script[i] == ';') && depth == 0 ) for (i = 0; i < strlen(scriptbuf); i++)
{ {
function = __imlib_copystr( scriptbuf, start, i-1 ); if (script[i] == '\"')
im = __imlib_script_parse_function( im, function ); in_quote = (in_quote == 0 ? 1 : 0);
imlib_context_set_image( im ); if (!in_quote && script[i] == '(')
start = i+1; depth++;
free( function ); if (!in_quote && script[i] == ')')
} depth--;
} if (!in_quote && (script[i] == ';') && depth == 0)
D( "(--) Cleaning up parameter list" ); {
__imlib_script_tidyup(); function = __imlib_copystr(scriptbuf, start, i - 1);
D( "(--) Script Parser Successful." ); im = __imlib_script_parse_function(im, function);
free( scriptbuf ); imlib_context_set_image(im);
return im; start = i + 1;
} free(function);
}
}
D("(--) Cleaning up parameter list");
__imlib_script_tidyup();
D("(--) Script Parser Successful.");
free(scriptbuf);
return im;
}
else else
{ {
D( "(!!) Script Parser Failed." ); D("(!!) Script Parser Failed.");
return NULL; return NULL;
} }
} }

View File

@ -1,15 +1,13 @@
#include "common.h" #include "common.h"
#include "updates.h" #include "updates.h"
enum _t_used enum _t_used {
{ T_UNUSED = 0,
T_UNUSED = 0,
T_USED = 1 T_USED = 1
}; };
struct _tile struct _tile {
{ enum _t_used used;
enum _t_used used;
}; };
#define TBITS 5 #define TBITS 5
@ -19,13 +17,13 @@ struct _tile
#define T(x, y) t[((y) * tw) + (x)] #define T(x, y) t[((y) * tw) + (x)]
ImlibUpdate * ImlibUpdate *
__imlib_MergeUpdate(ImlibUpdate *u, int w, int h, int hgapmax) __imlib_MergeUpdate(ImlibUpdate * u, int w, int h, int hgapmax)
{ {
ImlibUpdate *nu = NULL, *uu; ImlibUpdate *nu = NULL, *uu;
struct _tile *t; struct _tile *t;
int tw, th, x, y, i; int tw, th, x, y, i;
int *gaps = NULL; int *gaps = NULL;
/* if theres no rects to process.. return NULL */ /* if theres no rects to process.. return NULL */
if (!u) if (!u)
@ -40,115 +38,112 @@ __imlib_MergeUpdate(ImlibUpdate *u, int w, int h, int hgapmax)
/* fill in tiles to be all not used */ /* fill in tiles to be all not used */
for (i = 0, y = 0; y < th; y++) for (i = 0, y = 0; y < th; y++)
{ {
for (x = 0; x < tw; x++) for (x = 0; x < tw; x++)
t[i++].used = T_UNUSED; t[i++].used = T_UNUSED;
} }
/* fill in all tiles*/ /* fill in all tiles */
for (uu = u; uu; uu = uu->next) for (uu = u; uu; uu = uu->next)
{ {
CLIP(uu->x, uu->y, uu->w, uu->h, 0, 0, w, h); CLIP(uu->x, uu->y, uu->w, uu->h, 0, 0, w, h);
for (y = uu->y >> TB; y <= ((uu->y + uu->h - 1) >> TB); y++) for (y = uu->y >> TB; y <= ((uu->y + uu->h - 1) >> TB); y++)
{ {
for (x = uu->x >> TB; x <= ((uu->x + uu->w - 1) >> TB); x++) for (x = uu->x >> TB; x <= ((uu->x + uu->w - 1) >> TB); x++)
T(x, y).used = T_USED; T(x, y).used = T_USED;
} }
} }
/* scan each line - if > hgapmax gaps between tiles, then fill smallest */ /* scan each line - if > hgapmax gaps between tiles, then fill smallest */
gaps = malloc(tw *sizeof(int)); gaps = malloc(tw * sizeof(int));
for (y = 0; y < th; y++) for (y = 0; y < th; y++)
{ {
int hgaps = 0, start = -1, min; int hgaps = 0, start = -1, min;
char have = 1, gap = 0; char have = 1, gap = 0;
for (x = 0; x < tw; x++) for (x = 0; x < tw; x++)
gaps[x] = 0; gaps[x] = 0;
for (x = 0; x < tw; x++) for (x = 0; x < tw; x++)
{ {
if ((have) && (T(x, y).used == T_UNUSED)) if ((have) && (T(x, y).used == T_UNUSED))
{ {
start = x; start = x;
gap = 1; gap = 1;
have = 0; have = 0;
} }
else if ((!have) && (gap) && (T(x, y).used & T_USED)) else if ((!have) && (gap) && (T(x, y).used & T_USED))
{ {
gap = 0; gap = 0;
hgaps++; hgaps++;
have = 1; have = 1;
gaps[start] = x - start; gaps[start] = x - start;
} }
else if (T(x, y).used & T_USED) else if (T(x, y).used & T_USED)
have = 1; have = 1;
} }
while (hgaps > hgapmax) while (hgaps > hgapmax)
{ {
start = -1; start = -1;
min = tw; min = tw;
for (x = 0; x < tw; x++) for (x = 0; x < tw; x++)
{ {
if ((gaps[x] > 0) && (gaps[x] < min)) if ((gaps[x] > 0) && (gaps[x] < min))
{ {
start = x; start = x;
min = gaps[x]; min = gaps[x];
} }
} }
if (start >= 0) if (start >= 0)
{ {
gaps[start] = 0; gaps[start] = 0;
for (x = start; for (x = start;
T(x, y).used == T_UNUSED; T(x, y).used == T_UNUSED; T(x++, y).used = T_USED);
T(x++, y).used = T_USED); hgaps--;
hgaps--; }
} }
}
} }
free(gaps); free(gaps);
/* coalesce tiles into larger blocks and make new rect list */ /* coalesce tiles into larger blocks and make new rect list */
for (y = 0; y < th; y++) for (y = 0; y < th; y++)
{ {
for (x = 0; x < tw; x++) for (x = 0; x < tw; x++)
{ {
if (T(x, y).used & T_USED) if (T(x, y).used & T_USED)
{ {
int xx, yy, ww, hh, ok; int xx, yy, ww, hh, ok;
for (xx = x + 1, ww = 1; for (xx = x + 1, ww = 1;
(T(xx, y).used & T_USED) && (xx < tw); (T(xx, y).used & T_USED) && (xx < tw); xx++, ww++);
xx++, ww++); for (yy = y + 1, hh = 1, ok = 1;
for (yy = y + 1, hh = 1, ok = 1; (yy < th) && (ok); yy++, hh++)
(yy < th) && (ok); {
yy++, hh++) for (xx = x; xx < (x + ww); xx++)
{ {
for (xx = x; xx < (x + ww); xx++) if (!(T(xx, yy).used & T_USED))
{ {
if (!(T(xx, yy).used & T_USED)) ok = 0;
{ xx = x + ww;
ok = 0; hh--;
xx = x + ww; }
hh--; }
} }
} for (yy = y; yy < (y + hh); yy++)
} {
for (yy = y; yy < (y + hh); yy++) for (xx = x; xx < (x + ww); xx++)
{ T(xx, yy).used = T_UNUSED;
for (xx = x; xx < (x + ww); xx++) }
T(xx, yy).used = T_UNUSED; nu = __imlib_AddUpdate(nu, (x << TB), (y << TB),
} (ww << TB), (hh << TB));
nu = __imlib_AddUpdate(nu, (x << TB), (y << TB), }
(ww << TB), (hh << TB)); }
}
}
} }
free(t); free(t);
__imlib_FreeUpdates(u); __imlib_FreeUpdates(u);
return nu; return nu;
} }
ImlibUpdate * ImlibUpdate *
__imlib_AddUpdate(ImlibUpdate *u, int x, int y, int w, int h) __imlib_AddUpdate(ImlibUpdate * u, int x, int y, int w, int h)
{ {
ImlibUpdate *nu; ImlibUpdate *nu;
if ((w < 1) || (h < 1) || ((x + w) < 1) || ((y + h) < 1)) if ((w < 1) || (h < 1) || ((x + w) < 1) || ((y + h) < 1))
return u; return u;
@ -162,23 +157,23 @@ __imlib_AddUpdate(ImlibUpdate *u, int x, int y, int w, int h)
} }
void void
__imlib_FreeUpdates(ImlibUpdate *u) __imlib_FreeUpdates(ImlibUpdate * u)
{ {
ImlibUpdate *uu; ImlibUpdate *uu;
uu = u; uu = u;
while (uu) while (uu)
{ {
u = uu; u = uu;
uu = uu->next; uu = uu->next;
free(u); free(u);
} }
} }
ImlibUpdate * ImlibUpdate *
__imlib_DupUpdates(ImlibUpdate *u) __imlib_DupUpdates(ImlibUpdate * u)
{ {
ImlibUpdate *uu, *cu, *pu, *ru; ImlibUpdate *uu, *cu, *pu, *ru;
if (!u) if (!u)
return NULL; return NULL;
@ -190,11 +185,11 @@ __imlib_DupUpdates(ImlibUpdate *u)
ru = uu; ru = uu;
while (cu) while (cu)
{ {
uu = malloc(sizeof(ImlibUpdate)); uu = malloc(sizeof(ImlibUpdate));
memcpy(uu, u, sizeof(ImlibUpdate)); memcpy(uu, u, sizeof(ImlibUpdate));
pu->next = uu; pu->next = uu;
pu = cu; pu = cu;
cu = cu->next; cu = cu->next;
} }
return ru; return ru;
} }

View File

@ -7,18 +7,18 @@
#include "ximage.h" #include "ximage.h"
/* static private variables */ /* static private variables */
static signed char x_does_shm = -1; static signed char x_does_shm = -1;
static int list_num = 0; static int list_num = 0;
static XImage **list_xim = NULL; static XImage **list_xim = NULL;
static XShmSegmentInfo **list_si = NULL; static XShmSegmentInfo **list_si = NULL;
static Display **list_d = NULL; static Display **list_d = NULL;
static char *list_used = NULL; static char *list_used = NULL;
static int list_mem_use = 0; static int list_mem_use = 0;
static int list_max_mem = 1024 * 1024 * 1024; static int list_max_mem = 1024 * 1024 * 1024;
static int list_max_count = 0; static int list_max_count = 0;
/* temporary X error catcher we use later */ /* temporary X error catcher we use later */
static char _x_err = 0; static char _x_err = 0;
/* the fucntion we use for catching the error */ /* the fucntion we use for catching the error */
static void static void
@ -31,132 +31,140 @@ TmpXError(Display * d, XErrorEvent * ev)
} }
void void
__imlib_SetMaxXImageCount(Display *d, int num) __imlib_SetMaxXImageCount(Display * d, int num)
{ {
list_max_count = num; list_max_count = num;
__imlib_FlushXImage(d); __imlib_FlushXImage(d);
} }
int int
__imlib_GetMaxXImageCount(Display *d) __imlib_GetMaxXImageCount(Display * d)
{ {
return list_max_count; return list_max_count;
d = NULL; d = NULL;
} }
void void
__imlib_SetMaxXImageTotalSize(Display *d, int num) __imlib_SetMaxXImageTotalSize(Display * d, int num)
{ {
list_max_mem = num; list_max_mem = num;
__imlib_FlushXImage(d); __imlib_FlushXImage(d);
} }
int int
__imlib_GetMaxXImageTotalSize(Display *d) __imlib_GetMaxXImageTotalSize(Display * d)
{ {
return list_max_mem; return list_max_mem;
d = NULL; d = NULL;
} }
void void
__imlib_FlushXImage(Display *d) __imlib_FlushXImage(Display * d)
{ {
int i; int i;
XImage *xim; XImage *xim;
char did_free = 1; char did_free = 1;
while (((list_mem_use > list_max_mem) || (list_num > list_max_count)) && while (((list_mem_use > list_max_mem) || (list_num > list_max_count)) &&
(did_free)) (did_free))
{ {
did_free = 0; did_free = 0;
for (i = 0; i < list_num; i++) for (i = 0; i < list_num; i++)
{ {
if (list_used[i] == 0) if (list_used[i] == 0)
{ {
int j; int j;
xim = list_xim[i]; xim = list_xim[i];
list_mem_use -= xim->bytes_per_line * xim->height; list_mem_use -= xim->bytes_per_line * xim->height;
if (list_si[i]) if (list_si[i])
XShmDetach(d, list_si[i]); XShmDetach(d, list_si[i]);
XDestroyImage(xim); XDestroyImage(xim);
if (list_si[i]) if (list_si[i])
{ {
shmdt(list_si[i]->shmaddr); shmdt(list_si[i]->shmaddr);
shmctl(list_si[i]->shmid, IPC_RMID, 0); shmctl(list_si[i]->shmid, IPC_RMID, 0);
free(list_si[i]); free(list_si[i]);
} }
list_num--; list_num--;
for (j = i; j < list_num; j++) for (j = i; j < list_num; j++)
{ {
list_xim[j] = list_xim[j + 1]; list_xim[j] = list_xim[j + 1];
list_si[j] = list_si[j + 1]; list_si[j] = list_si[j + 1];
list_used[j] = list_used[j + 1]; list_used[j] = list_used[j + 1];
list_d[j] = list_d[j + 1]; list_d[j] = list_d[j + 1];
} }
if (list_num == 0) if (list_num == 0)
{ {
if (list_xim) free(list_xim); if (list_xim)
if (list_si) free(list_si); free(list_xim);
if (list_used) free(list_used); if (list_si)
if (list_d) free(list_d); free(list_si);
list_xim = NULL; if (list_used)
list_si = NULL; free(list_used);
list_used = NULL; if (list_d)
list_d = NULL; free(list_d);
} list_xim = NULL;
else list_si = NULL;
{ list_used = NULL;
list_xim = realloc(list_xim, sizeof(XImage *) * list_num); list_d = NULL;
list_si = realloc(list_si, sizeof(XShmSegmentInfo *) * list_num); }
list_used = realloc(list_used, sizeof(char) * list_num); else
list_d = realloc(list_d, sizeof(Display *) * list_num); {
} list_xim =
did_free = 1; realloc(list_xim, sizeof(XImage *) * list_num);
} list_si =
} realloc(list_si,
sizeof(XShmSegmentInfo *) * list_num);
list_used = realloc(list_used, sizeof(char) * list_num);
list_d = realloc(list_d, sizeof(Display *) * list_num);
}
did_free = 1;
}
}
} }
} }
/* free (consume == opposite of produce) the XImage (mark as unused) */ /* free (consume == opposite of produce) the XImage (mark as unused) */
void void
__imlib_ConsumeXImage(Display *d, XImage *xim) __imlib_ConsumeXImage(Display * d, XImage * xim)
{ {
int i; int i;
/* march through the XImage list */ /* march through the XImage list */
for (i = 0; i < list_num; i++) for (i = 0; i < list_num; i++)
{ {
/* find a match */ /* find a match */
if (list_xim[i] == xim) if (list_xim[i] == xim)
{ {
/* we have a match = mark as unused */ /* we have a match = mark as unused */
list_used[i] = 0; list_used[i] = 0;
/* flush the XImage list to get rud of stuff we dont want */ /* flush the XImage list to get rud of stuff we dont want */
__imlib_FlushXImage(d); __imlib_FlushXImage(d);
/* return */ /* return */
return; return;
} }
} }
} }
/* create a new XImage or find it on our list of currently available ones so */ /* create a new XImage or find it on our list of currently available ones so */
/* we dont need to create a new one */ /* we dont need to create a new one */
XImage * XImage *
__imlib_ProduceXImage(Display *d, Visual *v, int depth, int w, int h, char *shared) __imlib_ProduceXImage(Display * d, Visual * v, int depth, int w, int h,
char *shared)
{ {
XImage *xim; XImage *xim;
int i; int i;
/* if we havent check the shm extension before - see if its there */ /* if we havent check the shm extension before - see if its there */
if (x_does_shm < 0) if (x_does_shm < 0)
{ {
/* if its there set dose_xhm flag */ /* if its there set dose_xhm flag */
if (XShmQueryExtension(d)) if (XShmQueryExtension(d))
x_does_shm = 1; x_does_shm = 1;
/* clear the flag - no shm at all */ /* clear the flag - no shm at all */
else else
x_does_shm = 0; x_does_shm = 0;
} }
/* find a cached XImage (to avoid server to & fro) that is big enough */ /* find a cached XImage (to avoid server to & fro) that is big enough */
/* for our needs and the right depth */ /* for our needs and the right depth */
@ -164,39 +172,38 @@ __imlib_ProduceXImage(Display *d, Visual *v, int depth, int w, int h, char *shar
/* go thru the current image list */ /* go thru the current image list */
for (i = 0; i < list_num; i++) for (i = 0; i < list_num; i++)
{ {
/* if the image has the same depth, width and height - recycle it */ /* if the image has the same depth, width and height - recycle it */
/* as long as its not used */ /* as long as its not used */
if ((list_xim[i]->bits_per_pixel == depth) && if ((list_xim[i]->bits_per_pixel == depth) &&
(list_xim[i]->width >= w) && (list_xim[i]->width >= w) && (list_xim[i]->height >= h) &&
(list_xim[i]->height >= h) && /* (list_d[i] == d) && */
/* (list_d[i] == d) &&*/ (!list_used[i]))
(!list_used[i])) {
{ /* mark it as used */
/* mark it as used */ list_used[i] = 1;
list_used[i] = 1; /* if its shared set shared flag */
/* if its shared set shared flag */ if (list_si[i])
if (list_si[i]) *shared = 1;
*shared = 1; /* return it */
/* return it */ return list_xim[i];
return list_xim[i]; }
}
} }
/* can't find a usable XImage on the cache - create one */ /* can't find a usable XImage on the cache - create one */
/* add the new XImage to the XImage cache */ /* add the new XImage to the XImage cache */
list_num++; list_num++;
if (list_num == 1) if (list_num == 1)
{ {
list_xim = malloc(sizeof(XImage *) * list_num); list_xim = malloc(sizeof(XImage *) * list_num);
list_si = malloc(sizeof(XShmSegmentInfo *) * list_num); list_si = malloc(sizeof(XShmSegmentInfo *) * list_num);
list_used = malloc(sizeof(char) * list_num); list_used = malloc(sizeof(char) * list_num);
list_d = malloc(sizeof(Display *) * list_num); list_d = malloc(sizeof(Display *) * list_num);
} }
else else
{ {
list_xim = realloc(list_xim, sizeof(XImage *) * list_num); list_xim = realloc(list_xim, sizeof(XImage *) * list_num);
list_si = realloc(list_si, sizeof(XShmSegmentInfo *) * list_num); list_si = realloc(list_si, sizeof(XShmSegmentInfo *) * list_num);
list_used = realloc(list_used, sizeof(char) * list_num); list_used = realloc(list_used, sizeof(char) * list_num);
list_d = realloc(list_d, sizeof(Display *) * list_num); list_d = realloc(list_d, sizeof(Display *) * list_num);
} }
list_si[list_num - 1] = malloc(sizeof(XShmSegmentInfo)); list_si[list_num - 1] = malloc(sizeof(XShmSegmentInfo));
@ -205,104 +212,104 @@ __imlib_ProduceXImage(Display *d, Visual *v, int depth, int w, int h, char *shar
/* if the server does shm */ /* if the server does shm */
if (x_does_shm) if (x_does_shm)
{ {
/* try create an shm image */ /* try create an shm image */
xim = XShmCreateImage(d, v, depth, ZPixmap, NULL, xim = XShmCreateImage(d, v, depth, ZPixmap, NULL,
list_si[list_num - 1], w, h); list_si[list_num - 1], w, h);
/* if it succeeds */ /* if it succeeds */
if (xim) if (xim)
{ {
/* add to list */ /* add to list */
list_xim[list_num - 1] = xim; list_xim[list_num - 1] = xim;
/* get an shm id of this image */ /* get an shm id of this image */
list_si[list_num - 1]->shmid = list_si[list_num - 1]->shmid =
shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height, shmget(IPC_PRIVATE, xim->bytes_per_line * xim->height,
IPC_CREAT | 0777); IPC_CREAT | 0777);
/* if the get succeeds */ /* if the get succeeds */
if (list_si[list_num - 1]->shmid != -1) if (list_si[list_num - 1]->shmid != -1)
{ {
/* set the params for the shm segment */ /* set the params for the shm segment */
list_si[list_num - 1]->readOnly = False; list_si[list_num - 1]->readOnly = False;
list_si[list_num - 1]->shmaddr = xim->data = list_si[list_num - 1]->shmaddr = xim->data =
shmat(list_si[list_num - 1]->shmid, 0, 0); shmat(list_si[list_num - 1]->shmid, 0, 0);
/* get the shm addr for this data chunk */ /* get the shm addr for this data chunk */
if (xim->data != (char *)-1) if (xim->data != (char *)-1)
{ {
XErrorHandler ph; XErrorHandler ph;
/* setup a temporary error handler */ /* setup a temporary error handler */
_x_err = 0; _x_err = 0;
ph = XSetErrorHandler((XErrorHandler) TmpXError); ph = XSetErrorHandler((XErrorHandler) TmpXError);
/* ask X to attach to the shared mem segment */ /* ask X to attach to the shared mem segment */
XShmAttach(d, list_si[list_num - 1]); XShmAttach(d, list_si[list_num - 1]);
/* wait for X to reply and do this */ /* wait for X to reply and do this */
XSync(d, False); XSync(d, False);
/* reset the error handler */ /* reset the error handler */
XSetErrorHandler((XErrorHandler) ph); XSetErrorHandler((XErrorHandler) ph);
/* if we attached without an error we're set */ /* if we attached without an error we're set */
if (!_x_err) if (!_x_err)
{ {
/* mark the image as used */ /* mark the image as used */
list_used[list_num - 1] = 1; list_used[list_num - 1] = 1;
/* incrument our memory count */ /* incrument our memory count */
list_mem_use += xim->bytes_per_line * xim->height; list_mem_use += xim->bytes_per_line * xim->height;
/* set shared flag */ /* set shared flag */
*shared = 1; *shared = 1;
} }
/* attach by X failed... must be remote client */ /* attach by X failed... must be remote client */
else else
{ {
/* flag shm foevere to not work - remote */ /* flag shm foevere to not work - remote */
x_does_shm = 0; x_does_shm = 0;
/* destroy our previous image */ /* destroy our previous image */
XDestroyImage(xim); XDestroyImage(xim);
/* detach */ /* detach */
shmdt(list_si[list_num - 1]->shmaddr); shmdt(list_si[list_num - 1]->shmaddr);
/* remove the shm id */ /* remove the shm id */
shmctl(list_si[list_num - 1]->shmid, IPC_RMID, 0); shmctl(list_si[list_num - 1]->shmid, IPC_RMID, 0);
/* flag out xim as NULL */ /* flag out xim as NULL */
xim = NULL; xim = NULL;
} }
} }
/* get failed - out of shm id's or shm segment too big ? */ /* get failed - out of shm id's or shm segment too big ? */
else else
{ {
/* destroy previous image */ /* destroy previous image */
XDestroyImage(xim); XDestroyImage(xim);
/* remove the shm id we created */ /* remove the shm id we created */
shmctl(list_si[list_num - 1]->shmid, IPC_RMID, 0); shmctl(list_si[list_num - 1]->shmid, IPC_RMID, 0);
/* flag xim as NULL */ /* flag xim as NULL */
xim = NULL; xim = NULL;
} }
} }
/* couldnt create SHM image ? */ /* couldnt create SHM image ? */
else else
{ {
/* destroy previous image */ /* destroy previous image */
XDestroyImage(xim); XDestroyImage(xim);
/* flag xim as NULL */ /* flag xim as NULL */
xim = NULL; xim = NULL;
} }
} }
} }
/* ok if xim == NULL it all failed - fall back to XImages */ /* ok if xim == NULL it all failed - fall back to XImages */
if (!xim) if (!xim)
{ {
/* get rid of out shm info struct */ /* get rid of out shm info struct */
free(list_si[list_num - 1]); free(list_si[list_num - 1]);
/* flag it as NULL ot indicate a normal XImage */ /* flag it as NULL ot indicate a normal XImage */
list_si[list_num - 1] = NULL; list_si[list_num - 1] = NULL;
/* create a normal ximage */ /* create a normal ximage */
xim = XCreateImage(d, v, depth, ZPixmap, 0, NULL, w, h, 32, 0); xim = XCreateImage(d, v, depth, ZPixmap, 0, NULL, w, h, 32, 0);
/* allocate data for it */ /* allocate data for it */
xim->data = malloc(xim->bytes_per_line * xim->height); xim->data = malloc(xim->bytes_per_line * xim->height);
/* add xim to our list */ /* add xim to our list */
list_xim[list_num - 1] = xim; list_xim[list_num - 1] = xim;
/* incriment our memory count */ /* incriment our memory count */
list_mem_use += xim->bytes_per_line * xim->height; list_mem_use += xim->bytes_per_line * xim->height;
/* mark image as used */ /* mark image as used */
list_used[list_num - 1] = 1; list_used[list_num - 1] = 1;
/* remember what display that XImage was for */ /* remember what display that XImage was for */
list_d[list_num - 1] = d; list_d[list_num - 1] = d;
} }
/* flush unused images from the image list */ /* flush unused images from the image list */
__imlib_FlushXImage(d); __imlib_FlushXImage(d);

View File

@ -21,17 +21,18 @@
*/ */
#include "Imlib2.h" #include "Imlib2.h"
Display *disp; Display *disp;
Window win; Window win;
Visual *vis; Visual *vis;
Colormap cm; Colormap cm;
int depth; int depth;
int main (int argc, char **argv) int
main(int argc, char **argv)
{ {
int i, j, w, h, x, y; int i, j, w, h, x, y;
Imlib_Image im = NULL, im_bg = NULL; Imlib_Image im = NULL, im_bg = NULL;
XEvent ev; XEvent ev;
/** /**
* Initialization according to options * Initialization according to options
@ -41,13 +42,16 @@ int main (int argc, char **argv)
/** /**
* First tests to determine which rendering task to perform * First tests to determine which rendering task to perform
*/ */
disp = XOpenDisplay(NULL); disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp)); vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp));
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0, 0); win =
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
ButtonMotionMask | PointerMotionMask | ExposureMask); 0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask);
XMapWindow(disp, win); XMapWindow(disp, win);
/** /**
@ -68,54 +72,56 @@ int main (int argc, char **argv)
imlib_context_set_image(im_bg); imlib_context_set_image(im_bg);
w = imlib_image_get_width(); w = imlib_image_get_width();
h = imlib_image_get_height(); h = imlib_image_get_height();
printf( "Resizing Window to %d by %d\n", w, h ); printf("Resizing Window to %d by %d\n", w, h);
XResizeWindow(disp, win, w, h); XResizeWindow(disp, win, w, h);
XSync(disp, False); XSync(disp, False);
x = -9999; x = -9999;
y = -9999; y = -9999;
while (1) while (1)
{ {
Imlib_Image *temp, *temp2; Imlib_Image *temp, *temp2;
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
break;
case ButtonRelease:
exit(0);
break;
case MotionNotify:
x = ev.xmotion.x;
y = ev.xmotion.y;
default:
break;
} do
} {
while (XPending(disp)); XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
break;
case ButtonRelease:
exit(0);
break;
case MotionNotify:
x = ev.xmotion.x;
y = ev.xmotion.y;
default:
break;
imlib_context_set_blend( 0 ); }
imlib_context_set_image(im_bg); }
temp = imlib_clone_image(); while (XPending(disp));
imlib_context_set_image( temp );
/* imlib_blend_image_onto_image(im_bg, 0, imlib_context_set_blend(0);
0, 0, w, h, imlib_context_set_image(im_bg);
0, 0, w, h); temp = imlib_clone_image();
first = 0;*/ imlib_context_set_image(temp);
imlib_apply_filter("bump_map_point(x=[],y=[],map=test_images/imlib2.png);", &x, &y ); /* imlib_blend_image_onto_image(im_bg, 0,
* 0, 0, w, h,
* 0, 0, w, h);
* first = 0; */
temp2 = im_bg; imlib_apply_filter
im_bg = temp; ("bump_map_point(x=[],y=[],map=test_images/imlib2.png);", &x, &y);
imlib_context_set_image(im_bg);
imlib_render_image_on_drawable(0, 0 ); temp2 = im_bg;
im_bg = temp2; im_bg = temp;
imlib_context_set_image(temp); imlib_context_set_image(im_bg);
imlib_free_image(); imlib_render_image_on_drawable(0, 0);
} im_bg = temp2;
imlib_context_set_image(temp);
imlib_free_image();
}
return 0; return 0;
} }

View File

@ -12,22 +12,22 @@
#include "Imlib2.h" #include "Imlib2.h"
Display *disp; Display *disp;
Window win; Window win;
Visual *vis; Visual *vis;
Colormap cm; Colormap cm;
int depth; int depth;
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int w, h, tw, th; int w, h, tw, th;
Imlib_Image im_bg = NULL; Imlib_Image im_bg = NULL;
XEvent ev; XEvent ev;
KeySym keysym; KeySym keysym;
static char kbuf[20]; static char kbuf[20];
Imlib_Font font; Imlib_Font font;
Imlib_Color_Range range; Imlib_Color_Range range;
/** /**
* First tests to determine which rendering task to perform * First tests to determine which rendering task to perform
@ -37,8 +37,8 @@ main(int argc, char **argv)
depth = DefaultDepth(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp));
win = win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0, XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0); 0);
XSelectInput(disp, win, XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask); PointerMotionMask | ExposureMask | KeyPressMask);
@ -67,76 +67,76 @@ main(int argc, char **argv)
XSync(disp, False); XSync(disp, False);
while (1) while (1)
{ {
do do
{ {
XNextEvent(disp, &ev); XNextEvent(disp, &ev);
switch (ev.type) switch (ev.type)
{ {
case ButtonRelease: case ButtonRelease:
exit(0); exit(0);
break; break;
case KeyPress: case KeyPress:
XLookupString(&ev.xkey, (char *) kbuf, sizeof(kbuf), &keysym, XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
NULL); NULL);
switch (*kbuf) switch (*kbuf)
{ {
case 'q': case 'q':
exit(0); exit(0);
default: default:
break; break;
} }
break; break;
default: default:
break; break;
} }
} }
while (XPending(disp)); while (XPending(disp));
imlib_context_set_image(im_bg); imlib_context_set_image(im_bg);
imlib_context_set_color(128, 128, 255, 255); imlib_context_set_color(128, 128, 255, 255);
imlib_image_fill_rectangle(0, 0, w, h); imlib_image_fill_rectangle(0, 0, w, h);
imlib_context_set_color(0, 0, 0, 255); imlib_context_set_color(0, 0, 0, 255);
imlib_image_draw_rectangle(20, 20, 560, 140); imlib_image_draw_rectangle(20, 20, 560, 140);
imlib_image_draw_rectangle(20, 220, 560, 140); imlib_image_draw_rectangle(20, 220, 560, 140);
font = imlib_load_font("notepad/15"); font = imlib_load_font("notepad/15");
if (font) if (font)
{ {
char text[4096]; char text[4096];
imlib_context_set_font(font); imlib_context_set_font(font);
imlib_context_set_color(0, 0, 0, 255); imlib_context_set_color(0, 0, 0, 255);
sprintf(text,"RGBA range, 2 points, from red to magenta"); sprintf(text, "RGBA range, 2 points, from red to magenta");
imlib_get_text_size(text, &tw, &th); imlib_get_text_size(text, &tw, &th);
imlib_text_draw(300-tw/2, 180-th/2, text); imlib_text_draw(300 - tw / 2, 180 - th / 2, text);
sprintf(text,"HSVA range, 2 points, from red to magenta"); sprintf(text, "HSVA range, 2 points, from red to magenta");
imlib_get_text_size(text, &tw, &th); imlib_get_text_size(text, &tw, &th);
imlib_text_draw(300-tw/2, 380-th/2, text); imlib_text_draw(300 - tw / 2, 380 - th / 2, text);
imlib_free_font(); imlib_free_font();
} }
/* Draw rectangle w/ RGBA gradient */ /* Draw rectangle w/ RGBA gradient */
range = imlib_create_color_range(); range = imlib_create_color_range();
imlib_context_set_color_range(range); imlib_context_set_color_range(range);
imlib_context_set_color(255, 0, 0, 255); imlib_context_set_color(255, 0, 0, 255);
imlib_add_color_to_color_range(0); imlib_add_color_to_color_range(0);
imlib_context_set_color(255, 0, 255, 255); imlib_context_set_color(255, 0, 255, 255);
imlib_add_color_to_color_range(20); imlib_add_color_to_color_range(20);
imlib_image_fill_color_range_rectangle(21, 21, 558, 138, -90.0); imlib_image_fill_color_range_rectangle(21, 21, 558, 138, -90.0);
imlib_free_color_range(); imlib_free_color_range();
/* Draw rectangle w/ HSVA gradient */ /* Draw rectangle w/ HSVA gradient */
range = imlib_create_color_range(); range = imlib_create_color_range();
imlib_context_set_color_range(range); imlib_context_set_color_range(range);
imlib_context_set_color_hsva(0, 1, 1, 255); imlib_context_set_color_hsva(0, 1, 1, 255);
imlib_add_color_to_color_range(0); imlib_add_color_to_color_range(0);
imlib_context_set_color_hsva(300, 1, 1, 255); imlib_context_set_color_hsva(300, 1, 1, 255);
imlib_add_color_to_color_range(20); imlib_add_color_to_color_range(20);
imlib_image_fill_hsva_color_range_rectangle(21, 221, 558, 138, -90.0); imlib_image_fill_hsva_color_range_rectangle(21, 221, 558, 138, -90.0);
imlib_free_color_range(); imlib_free_color_range();
imlib_render_image_on_drawable(0, 0); imlib_render_image_on_drawable(0, 0);
} }
return 0; return 0;
} }

View File

@ -6,41 +6,47 @@
#include <stdio.h> #include <stdio.h>
/* some globals for our window & X display */ /* some globals for our window & X display */
Display *disp; Display *disp;
Window win; Window win;
Visual *vis; Visual *vis;
Colormap cm; Colormap cm;
int depth; int depth;
/* the program... */ /* the program... */
int main(int argc, char **argv) int
main(int argc, char **argv)
{ {
/* events we get from X */ /* events we get from X */
XEvent ev; XEvent ev;
/* areas to update */ /* areas to update */
Imlib_Updates updates, current_update; Imlib_Updates updates, current_update;
/* our virtual framebuffer image we draw into */ /* our virtual framebuffer image we draw into */
Imlib_Image buffer; Imlib_Image buffer;
/* a font */ /* a font */
Imlib_Font font; Imlib_Font font;
/* our color range */ /* our color range */
Imlib_Color_Range range; Imlib_Color_Range range;
/* our mouse x, y coordinates */ /* our mouse x, y coordinates */
int mouse_x = 0, mouse_y = 0; int mouse_x = 0, mouse_y = 0;
/* connect to X */ /* connect to X */
disp = XOpenDisplay(NULL); disp = XOpenDisplay(NULL);
/* get default visual , colormap etc. you could ask imlib2 for what it */ /* get default visual , colormap etc. you could ask imlib2 for what it */
/* thinks is the best, but this example is intended to be simple */ /* thinks is the best, but this example is intended to be simple */
vis = DefaultVisual(disp, DefaultScreen(disp)); vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp));
/* create a window 640x480 */ /* create a window 640x480 */
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
0, 0, 640, 480, 0, 0, 0); 0, 0, 640, 480, 0, 0, 0);
/* tell X what events we are interested in */ /* tell X what events we are interested in */
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask | XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | ExposureMask); PointerMotionMask | ExposureMask);
/* show the window */ /* show the window */
XMapWindow(disp, win); XMapWindow(disp, win);
/* set our cache to 2 Mb so it doesnt have to go hit the disk as long as */ /* set our cache to 2 Mb so it doesnt have to go hit the disk as long as */
@ -63,197 +69,205 @@ int main(int argc, char **argv)
/* infinite event loop */ /* infinite event loop */
for (;;) for (;;)
{ {
/* image variable */ /* image variable */
Imlib_Image image; Imlib_Image image;
/* width and height values */
int w, h, text_w, text_h;
/* init our updates to empty */ /* width and height values */
updates = imlib_updates_init(); int w, h, text_w, text_h;
/* while there are events form X - handle them */
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
/* window rectangle was exposed - add it to the list of */
/* rectangles we need to re-render */
updates = imlib_update_append_rect(updates,
ev.xexpose.x, ev.xexpose.y,
ev.xexpose.width, ev.xexpose.height);
break;
case ButtonPress:
/* if we click anywhere in the window, exit */
exit(0);
break;
case MotionNotify:
/* if the mouse moves - note it */
/* add a rectangle update for the new mouse position */
image = imlib_load_image("./test_images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(image);
imlib_free_image();
/* the old position - so we wipe over where it used to be */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2), mouse_y - (h / 2),
w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
imlib_context_set_font(font); /* init our updates to empty */
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y); updates = imlib_updates_init();
imlib_get_text_size(text, &text_w, &text_h); /* while there are events form X - handle them */
imlib_free_font(); do
updates = imlib_update_append_rect(updates, {
320 - (text_w / 2), 240 - (text_h / 2), XNextEvent(disp, &ev);
text_w, text_h); switch (ev.type)
} {
case Expose:
/* window rectangle was exposed - add it to the list of */
/* rectangles we need to re-render */
updates = imlib_update_append_rect(updates,
ev.xexpose.x,
ev.xexpose.y,
ev.xexpose.width,
ev.xexpose.height);
break;
case ButtonPress:
/* if we click anywhere in the window, exit */
exit(0);
break;
case MotionNotify:
/* if the mouse moves - note it */
/* add a rectangle update for the new mouse position */
image = imlib_load_image("./test_images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(image);
imlib_free_image();
/* the old position - so we wipe over where it used to be */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2),
mouse_y - (h / 2), w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
mouse_x = ev.xmotion.x; imlib_context_set_font(font);
mouse_y = ev.xmotion.y; sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
/* the new one */ imlib_get_text_size(text, &text_w, &text_h);
updates = imlib_update_append_rect(updates, imlib_free_font();
mouse_x - (w / 2), mouse_y - (h / 2), updates = imlib_update_append_rect(updates,
w, h); 320 - (text_w / 2),
font = imlib_load_font("notepad/30"); 240 - (text_h / 2),
if (font) text_w, text_h);
{ }
char text[4096];
imlib_context_set_font(font); mouse_x = ev.xmotion.x;
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y); mouse_y = ev.xmotion.y;
imlib_get_text_size(text, &text_w, &text_h); /* the new one */
imlib_free_font(); updates = imlib_update_append_rect(updates,
updates = imlib_update_append_rect(updates, mouse_x - (w / 2),
320 - (text_w / 2), 240 - (text_h / 2), mouse_y - (h / 2), w, h);
text_w, text_h); font = imlib_load_font("notepad/30");
} if (font)
default: {
/* any other events - do nothing */ char text[4096];
break;
}
}
while (XPending(disp));
/* no more events for now ? ok - idle time so lets draw stuff */ imlib_context_set_font(font);
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
imlib_get_text_size(text, &text_w, &text_h);
imlib_free_font();
updates = imlib_update_append_rect(updates,
320 - (text_w / 2),
240 - (text_h / 2),
text_w, text_h);
}
default:
/* any other events - do nothing */
break;
}
}
while (XPending(disp));
/* take all the little rectangles to redraw and merge them into */ /* no more events for now ? ok - idle time so lets draw stuff */
/* something sane for rendering */
updates = imlib_updates_merge_for_rendering(updates, 640, 480);
for (current_update = updates;
current_update;
current_update = imlib_updates_get_next(current_update))
{
int up_x, up_y, up_w, up_h;
/* find out where the first update is */ /* take all the little rectangles to redraw and merge them into */
imlib_updates_get_coordinates(current_update, /* something sane for rendering */
&up_x, &up_y, &up_w, &up_h); updates = imlib_updates_merge_for_rendering(updates, 640, 480);
for (current_update = updates;
current_update;
current_update = imlib_updates_get_next(current_update))
{
int up_x, up_y, up_w, up_h;
/* create our buffer image for renderign this update */ /* find out where the first update is */
buffer = imlib_create_image(up_w, up_h); imlib_updates_get_coordinates(current_update,
&up_x, &up_y, &up_w, &up_h);
/* we can blend stuff now */ /* create our buffer image for renderign this update */
imlib_context_set_blend(1); buffer = imlib_create_image(up_w, up_h);
/* fill the window background */ /* we can blend stuff now */
/* load the background image - you'll need to have some images */ imlib_context_set_blend(1);
/* in ./test_images lying around for this to actually work */
image = imlib_load_image("./test_images/bg.png");
/* we're working with this image now */
imlib_context_set_image(image);
/* get its size */
w = imlib_image_get_width();
h = imlib_image_get_height();
/* now we want to work with the buffer */
imlib_context_set_image(buffer);
/* if the iimage loaded */
if (image)
{
/* blend image onto the buffer and scale it to 640x480 */
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
- up_x, - up_y, 640, 480);
/* working with the loaded image */
imlib_context_set_image(image);
/* free it */
imlib_free_image();
}
/* draw an icon centered around the mouse position */ /* fill the window background */
image = imlib_load_image("./test_images/mush.png"); /* load the background image - you'll need to have some images */
imlib_context_set_image(image); /* in ./test_images lying around for this to actually work */
w = imlib_image_get_width(); image = imlib_load_image("./test_images/bg.png");
h = imlib_image_get_height(); /* we're working with this image now */
imlib_context_set_image(buffer); imlib_context_set_image(image);
if (image) /* get its size */
{ w = imlib_image_get_width();
imlib_blend_image_onto_image(image, 0, h = imlib_image_get_height();
0, 0, w, h, /* now we want to work with the buffer */
mouse_x - (w / 2) - up_x, mouse_y - (h / 2) - up_y, w, h); imlib_context_set_image(buffer);
imlib_context_set_image(image); /* if the iimage loaded */
imlib_free_image(); if (image)
} {
/* blend image onto the buffer and scale it to 640x480 */
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
-up_x, -up_y, 640, 480);
/* working with the loaded image */
imlib_context_set_image(image);
/* free it */
imlib_free_image();
}
/* draw a gradient on top of things at the top left of the window */ /* draw an icon centered around the mouse position */
/* create a range */ image = imlib_load_image("./test_images/mush.png");
range = imlib_create_color_range(); imlib_context_set_image(image);
imlib_context_set_color_range(range); w = imlib_image_get_width();
/* add white opaque as the first color */ h = imlib_image_get_height();
imlib_context_set_color(255, 255, 255, 255); imlib_context_set_image(buffer);
imlib_add_color_to_color_range(0); if (image)
/* add an orange color, semi-transparent 10 units from the first */ {
imlib_context_set_color(255, 200, 10, 100); imlib_blend_image_onto_image(image, 0,
imlib_add_color_to_color_range(10); 0, 0, w, h,
/* add black, fully transparent at the end 20 units away */ mouse_x - (w / 2) - up_x,
imlib_context_set_color(0, 0, 0, 0); mouse_y - (h / 2) - up_y, w, h);
imlib_add_color_to_color_range(20); imlib_context_set_image(image);
/* draw the range */ imlib_free_image();
imlib_context_set_image(buffer); }
imlib_image_fill_color_range_rectangle(- up_x, - up_y, 128, 128, -45.0);
/* free it */
imlib_free_color_range();
/* draw text - centered with the current mouse x, y */ /* draw a gradient on top of things at the top left of the window */
font = imlib_load_font("notepad/30"); /* create a range */
if (font) range = imlib_create_color_range();
{ imlib_context_set_color_range(range);
char text[4096]; /* add white opaque as the first color */
imlib_context_set_color(255, 255, 255, 255);
imlib_add_color_to_color_range(0);
/* add an orange color, semi-transparent 10 units from the first */
imlib_context_set_color(255, 200, 10, 100);
imlib_add_color_to_color_range(10);
/* add black, fully transparent at the end 20 units away */
imlib_context_set_color(0, 0, 0, 0);
imlib_add_color_to_color_range(20);
/* draw the range */
imlib_context_set_image(buffer);
imlib_image_fill_color_range_rectangle(-up_x, -up_y, 128, 128,
-45.0);
/* free it */
imlib_free_color_range();
/* set the current font */ /* draw text - centered with the current mouse x, y */
imlib_context_set_font(font); font = imlib_load_font("notepad/30");
/* set the image */ if (font)
imlib_context_set_image(buffer); {
/* set the color (black) */ char text[4096];
imlib_context_set_color(0, 0, 0, 255);
/* print text to display in the buffer */
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
/* query the size it will be */
imlib_get_text_size(text, &text_w, &text_h);
/* draw it */
imlib_text_draw(320 - (text_w / 2) - up_x, 240 - (text_h / 2) - up_y, text);
/* free the font */
imlib_free_font();
}
/* dont blend the image onto the drawable - slower */ /* set the current font */
imlib_context_set_blend(0); imlib_context_set_font(font);
/* set the buffer image as our current image */ /* set the image */
imlib_context_set_image(buffer); imlib_context_set_image(buffer);
/* render the image at 0, 0 */ /* set the color (black) */
imlib_render_image_on_drawable(up_x, up_y); imlib_context_set_color(0, 0, 0, 255);
/* don't need that temproary buffer image anymore */ /* print text to display in the buffer */
imlib_free_image(); sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
} /* query the size it will be */
/* if we had updates - free them */ imlib_get_text_size(text, &text_w, &text_h);
if (updates) /* draw it */
imlib_updates_free(updates); imlib_text_draw(320 - (text_w / 2) - up_x,
/* loop again waiting for events */ 240 - (text_h / 2) - up_y, text);
/* free the font */
imlib_free_font();
}
/* dont blend the image onto the drawable - slower */
imlib_context_set_blend(0);
/* set the buffer image as our current image */
imlib_context_set_image(buffer);
/* render the image at 0, 0 */
imlib_render_image_on_drawable(up_x, up_y);
/* don't need that temproary buffer image anymore */
imlib_free_image();
}
/* if we had updates - free them */
if (updates)
imlib_updates_free(updates);
/* loop again waiting for events */
} }
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -12,21 +12,21 @@
#include "Imlib2.h" #include "Imlib2.h"
Display *disp; Display *disp;
Window win; Window win;
Visual *vis; Visual *vis;
Colormap cm; Colormap cm;
int depth; int depth;
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int w, h; int w, h;
Imlib_Image im_bg = NULL; Imlib_Image im_bg = NULL;
XEvent ev; XEvent ev;
KeySym keysym; KeySym keysym;
static char kbuf[20]; static char kbuf[20];
ImlibPolygon poly, poly1, poly2; ImlibPolygon poly, poly1, poly2;
/** /**
* First tests to determine which rendering task to perform * First tests to determine which rendering task to perform
@ -36,8 +36,8 @@ main(int argc, char **argv)
depth = DefaultDepth(disp, DefaultScreen(disp)); depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp)); cm = DefaultColormap(disp, DefaultScreen(disp));
win = win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0, XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0); 0);
XSelectInput(disp, win, XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask | KeyPressMask); PointerMotionMask | ExposureMask | KeyPressMask);
@ -80,47 +80,47 @@ main(int argc, char **argv)
imlib_polygon_add_point(poly2, 270, 70); imlib_polygon_add_point(poly2, 270, 70);
while (1) while (1)
{ {
do do
{ {
XNextEvent(disp, &ev); XNextEvent(disp, &ev);
switch (ev.type) switch (ev.type)
{ {
case ButtonRelease: case ButtonRelease:
exit(0); exit(0);
break; break;
case KeyPress: case KeyPress:
XLookupString(&ev.xkey, (char *) kbuf, sizeof(kbuf), &keysym, XLookupString(&ev.xkey, (char *)kbuf, sizeof(kbuf), &keysym,
NULL); NULL);
switch (*kbuf) switch (*kbuf)
{ {
case ' ': case ' ':
imlib_context_set_anti_alias(!imlib_context_get_anti_alias imlib_context_set_anti_alias
()); (!imlib_context_get_anti_alias());
printf("AA is %s\n", printf("AA is %s\n",
imlib_context_get_anti_alias()? "on" : "off"); imlib_context_get_anti_alias()? "on" : "off");
break; break;
case 'q': case 'q':
exit(0); exit(0);
default: default:
break; break;
} }
break; break;
default: default:
break; break;
} }
} }
while (XPending(disp)); while (XPending(disp));
imlib_context_set_image(im_bg); imlib_context_set_image(im_bg);
imlib_context_set_color(0, 0, 0, 255); imlib_context_set_color(0, 0, 0, 255);
imlib_image_fill_rectangle(0, 0, w, h); imlib_image_fill_rectangle(0, 0, w, h);
imlib_context_set_color(255, 255, 255, 255); imlib_context_set_color(255, 255, 255, 255);
imlib_image_fill_polygon(poly); imlib_image_fill_polygon(poly);
imlib_image_fill_polygon(poly1); imlib_image_fill_polygon(poly1);
imlib_image_fill_polygon(poly2); imlib_image_fill_polygon(poly2);
imlib_render_image_on_drawable(0, 0); imlib_render_image_on_drawable(0, 0);
} }
return 0; return 0;
} }