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

@ -14,18 +14,18 @@
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);
if ((im = imlib_load_image(argv[1])) == NULL)
{ {
fprintf(stderr, PROG_NAME ": Error loading image: %s\n", argv[1]); fprintf(stderr, PROG_NAME ": Error loading image: %s\n", argv[1]);
exit(-1); exit(-1);
@ -60,7 +60,8 @@ main(int argc,
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++)
*q = tolower(*q);
imlib_image_set_format(p); imlib_image_set_format(p);
free(p); free(p);
} }
@ -74,18 +75,17 @@ main(int argc,
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

@ -23,7 +23,7 @@ int image_width = 0, image_height = 0;
Imlib_Image bg_im = NULL; Imlib_Image bg_im = NULL;
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 static int
@ -68,8 +68,9 @@ progress(Imlib_Image im, char percent, int update_x, int update_y,
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,
image_width, image_height);
XSetWindowBackgroundPixmap(disp, win, pm); XSetWindowBackgroundPixmap(disp, win, pm);
XResizeWindow(disp, win, image_width, image_height); XResizeWindow(disp, win, image_width, image_height);
XMapWindow(disp, win); XMapWindow(disp, win);
@ -81,8 +82,7 @@ progress(Imlib_Image im, char percent, int update_x, int update_y,
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,
@ -95,7 +95,7 @@ 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;
@ -135,7 +135,7 @@ main (int argc, char **argv)
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;
@ -226,7 +226,8 @@ main (int argc, char **argv)
} }
break; break;
case MotionNotify: case MotionNotify:
while (XCheckTypedWindowEvent(disp, win, MotionNotify, &ev)); while (XCheckTypedWindowEvent
(disp, win, MotionNotify, &ev));
x = ev.xmotion.x; x = ev.xmotion.x;
y = ev.xmotion.y; y = ev.xmotion.y;
if (zoom_mode) if (zoom_mode)
@ -291,7 +292,8 @@ main (int argc, char **argv)
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)
|| (errno == EBADF))
exit(1); exit(1);
} }
else else

View File

@ -31,17 +31,19 @@ bump_map(Imlib_Image im, pIFunctionParam par)
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_IMAGE("map", map);
ASSIGN_INT ("angle", an); ASSIGN_INT("angle", an);
ASSIGN_INT ("elevation", el); ASSIGN_INT("elevation", el);
ASSIGN_INT ("depth", d); ASSIGN_INT("depth", d);
ASSIGN_INT ("red", red); ASSIGN_INT("red", red);
ASSIGN_INT ("green", green); ASSIGN_INT("green", green);
ASSIGN_INT ("blue", blue); ASSIGN_INT("blue", blue);
ASSIGN_INT ("ambient", ambient); ASSIGN_INT("ambient", ambient);
} }
if (!map) return im; if (!map)
return im;
red /= 0x100; red /= 0x100;
green /= 0x100; green /= 0x100;
@ -71,16 +73,19 @@ bump_map(Imlib_Image im, pIFunctionParam par)
z_2 = z * z; z_2 = z * z;
my = h2; my = h2;
for (j = h; --j >= 0; ) { for (j = h; --j >= 0;)
{
mp = mpp; mp = mpp;
mpp += w2; mpp += w2;
if (--my <= 0) { if (--my <= 0)
{
mpp -= wh2; mpp -= wh2;
my = h2; my = h2;
} }
mpy = mpp; mpy = mpp;
mx = w2; mx = w2;
for (i = w; --i >= 0; ) { for (i = w; --i >= 0;)
{
double x1, y1, v; double x1, y1, v;
int r, g, b, gr; int r, g, b, gr;
@ -89,7 +94,8 @@ bump_map(Imlib_Image im, pIFunctionParam par)
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; mp -= w2;
mpy -= w2; mpy -= w2;
mx = w2; mx = w2;
@ -102,12 +108,18 @@ bump_map(Imlib_Image im, pIFunctionParam par)
r = v * R_VAL(src) * red; r = v * R_VAL(src) * red;
g = v * G_VAL(src) * green; g = v * G_VAL(src) * green;
b = v * B_VAL(src) * blue; b = v * B_VAL(src) * blue;
if (r < 0) r = 0; if (r < 0)
if (r > 255) r = 255; r = 0;
if (g < 0) g = 0; if (r > 255)
if (g > 255) g = 255; r = 255;
if (b < 0) b = 0; if (g < 0)
if (b > 255) b = 255; g = 0;
if (g > 255)
g = 255;
if (b < 0)
b = 0;
if (b > 255)
b = 255;
R_VAL(src) = r; R_VAL(src) = r;
G_VAL(src) = g; G_VAL(src) = g;
B_VAL(src) = b; B_VAL(src) = b;
@ -115,7 +127,8 @@ bump_map(Imlib_Image im, pIFunctionParam par)
src++; src++;
} }
} }
if (free_map) { if (free_map)
{
imlib_context_set_image(map); imlib_context_set_image(map);
imlib_free_image(); imlib_free_image();
} }
@ -137,18 +150,20 @@ bump_map_point(Imlib_Image im, pIFunctionParam par)
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_IMAGE("map", map);
ASSIGN_INT ("x", x); ASSIGN_INT("x", x);
ASSIGN_INT ("y", y); ASSIGN_INT("y", y);
ASSIGN_INT ("z", z); ASSIGN_INT("z", z);
ASSIGN_INT ("depth", d); ASSIGN_INT("depth", d);
ASSIGN_INT ("red", red); ASSIGN_INT("red", red);
ASSIGN_INT ("green", green); ASSIGN_INT("green", green);
ASSIGN_INT ("blue", blue); ASSIGN_INT("blue", blue);
ASSIGN_INT ("ambient", ambient); ASSIGN_INT("ambient", ambient);
} }
if (!map) return im; if (!map)
return im;
red /= 0x100; red /= 0x100;
green /= 0x100; green /= 0x100;
@ -172,17 +187,20 @@ bump_map_point(Imlib_Image im, pIFunctionParam par)
my = h2; my = h2;
y2 = -y; y2 = -y;
for (j = h; --j >= 0; ) { for (j = h; --j >= 0;)
{
mp = mpp; mp = mpp;
mpp += w2; mpp += w2;
if (--my <= 0) { if (--my <= 0)
{
mpp -= wh2; mpp -= wh2;
my = h2; my = h2;
} }
mpy = mpp; mpy = mpp;
mx = w2; mx = w2;
x2 = -x; x2 = -x;
for (i = w; --i >= 0; ) { for (i = w; --i >= 0;)
{
double x1, y1, v; double x1, y1, v;
int r, g, b, gr; int r, g, b, gr;
@ -191,7 +209,8 @@ bump_map_point(Imlib_Image im, pIFunctionParam par)
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; mp -= w2;
mpy -= w2; mpy -= w2;
mx = w2; mx = w2;
@ -205,12 +224,18 @@ bump_map_point(Imlib_Image im, pIFunctionParam par)
r = v * R_VAL(src) * red; r = v * R_VAL(src) * red;
g = v * G_VAL(src) * green; g = v * G_VAL(src) * green;
b = v * B_VAL(src) * blue; b = v * B_VAL(src) * blue;
if (r < 0) r = 0; if (r < 0)
if (r > 255) r = 255; r = 0;
if (g < 0) g = 0; if (r > 255)
if (g > 255) g = 255; r = 255;
if (b < 0) b = 0; if (g < 0)
if (b > 255) b = 255; g = 0;
if (g > 255)
g = 255;
if (b < 0)
b = 0;
if (b > 255)
b = 255;
R_VAL(src) = r; R_VAL(src) = r;
G_VAL(src) = g; G_VAL(src) = g;
B_VAL(src) = b; B_VAL(src) = b;
@ -220,7 +245,8 @@ bump_map_point(Imlib_Image im, pIFunctionParam par)
} }
y2++; y2++;
} }
if (free_map) { if (free_map)
{
imlib_context_set_image(map); imlib_context_set_image(map);
imlib_free_image(); imlib_free_image();
} }
@ -233,9 +259,11 @@ 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)
@ -253,8 +281,8 @@ 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

@ -28,7 +28,8 @@ 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; )
for (i = 256; --i >= 0;)
t[i] += v; t[i] += v;
} }
@ -36,7 +37,8 @@ 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; )
for (i = 256; --i >= 0;)
t[i] = ((t[i] - 0.5) * v) + 0.5; t[i] = ((t[i] - 0.5) * v) + 0.5;
} }
@ -44,7 +46,8 @@ 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; )
for (i = 256; --i >= 0;)
t[i] = pow(t[i], 1 / v); t[i] = pow(t[i], 1 / v);
} }
@ -52,7 +55,8 @@ 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; )
for (i = 256; --i >= 0;)
t[i] *= v; t[i] *= v;
} }
@ -63,102 +67,163 @@ colormod(Imlib_Image im, pIFunctionParam par)
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)) { {
if (!strcmp("x", ptr->key))
{
GET_INT(x, ptr); GET_INT(x, ptr);
} else if (!strcmp("y", ptr->key)) { }
else if (!strcmp("y", ptr->key))
{
GET_INT(y, ptr); GET_INT(y, ptr);
} else if (!strcmp("w", ptr->key)) { }
else if (!strcmp("w", ptr->key))
{
GET_INT(w, ptr); GET_INT(w, ptr);
} else if (!strcmp("h", ptr->key)) { }
else if (!strcmp("h", ptr->key))
{
GET_INT(h, ptr); GET_INT(h, ptr);
} else if (!memcmp("brightness", ptr->key, 10)) { }
else if (!memcmp("brightness", ptr->key, 10))
{
GET_DOUBLE(v, ptr); GET_DOUBLE(v, ptr);
if (!ptr->key[10]) { if (!ptr->key[10])
{
mod_brightness(r_d, v); mod_brightness(r_d, v);
mod_brightness(g_d, v); mod_brightness(g_d, v);
mod_brightness(b_d, v); mod_brightness(b_d, v);
mod_brightness(a_d, v); mod_brightness(a_d, v);
} else if (!strcmp("_r", ptr->key + 10)) { }
else if (!strcmp("_r", ptr->key + 10))
{
mod_brightness(r_d, v); mod_brightness(r_d, v);
} else if (!strcmp("_g", ptr->key + 10)) { }
else if (!strcmp("_g", ptr->key + 10))
{
mod_brightness(g_d, v); mod_brightness(g_d, v);
} else if (!strcmp("_b", ptr->key + 10)) { }
else if (!strcmp("_b", ptr->key + 10))
{
mod_brightness(b_d, v); mod_brightness(b_d, v);
} else if (!strcmp("_a", ptr->key + 10)) { }
else if (!strcmp("_a", ptr->key + 10))
{
mod_brightness(a_d, v); mod_brightness(a_d, v);
} }
} else if (!memcmp("contrast", ptr->key, 8)) { }
else if (!memcmp("contrast", ptr->key, 8))
{
GET_DOUBLE(v, ptr); GET_DOUBLE(v, ptr);
if (!ptr->key[8]) { if (!ptr->key[8])
{
mod_contrast(r_d, v); mod_contrast(r_d, v);
mod_contrast(g_d, v); mod_contrast(g_d, v);
mod_contrast(b_d, v); mod_contrast(b_d, v);
mod_contrast(a_d, v); mod_contrast(a_d, v);
} else if (!strcmp("_r", ptr->key + 8)) { }
else if (!strcmp("_r", ptr->key + 8))
{
mod_contrast(r_d, v); mod_contrast(r_d, v);
} else if (!strcmp("_g", ptr->key + 8)) { }
else if (!strcmp("_g", ptr->key + 8))
{
mod_contrast(g_d, v); mod_contrast(g_d, v);
} else if (!strcmp("_b", ptr->key + 8)) { }
else if (!strcmp("_b", ptr->key + 8))
{
mod_contrast(b_d, v); mod_contrast(b_d, v);
} else if (!strcmp("_a", ptr->key + 8)) { }
else if (!strcmp("_a", ptr->key + 8))
{
mod_contrast(a_d, v); mod_contrast(a_d, v);
} }
} else if (!memcmp("gamma", ptr->key, 5)) { }
else if (!memcmp("gamma", ptr->key, 5))
{
GET_DOUBLE(v, ptr); GET_DOUBLE(v, ptr);
if (!ptr->key[5]) { if (!ptr->key[5])
{
mod_gamma(r_d, v); mod_gamma(r_d, v);
mod_gamma(g_d, v); mod_gamma(g_d, v);
mod_gamma(b_d, v); mod_gamma(b_d, v);
mod_gamma(a_d, v); mod_gamma(a_d, v);
} else if (!strcmp("_r", ptr->key + 5)) { }
else if (!strcmp("_r", ptr->key + 5))
{
mod_gamma(r_d, v); mod_gamma(r_d, v);
} else if (!strcmp("_g", ptr->key + 5)) { }
else if (!strcmp("_g", ptr->key + 5))
{
mod_gamma(g_d, v); mod_gamma(g_d, v);
} else if (!strcmp("_b", ptr->key + 5)) { }
else if (!strcmp("_b", ptr->key + 5))
{
mod_gamma(b_d, v); mod_gamma(b_d, v);
} else if (!strcmp("_a", ptr->key + 5)) { }
else if (!strcmp("_a", ptr->key + 5))
{
mod_gamma(a_d, v); mod_gamma(a_d, v);
} }
} else if (!memcmp("tint", ptr->key, 4)) { }
else if (!memcmp("tint", ptr->key, 4))
{
GET_DOUBLE(v, ptr); GET_DOUBLE(v, ptr);
if (!ptr->key[4]) { if (!ptr->key[4])
{
mod_tint(r_d, v); mod_tint(r_d, v);
mod_tint(g_d, v); mod_tint(g_d, v);
mod_tint(b_d, v); mod_tint(b_d, v);
mod_tint(a_d, v); mod_tint(a_d, v);
} else if (!strcmp("_r", ptr->key + 4)) { }
else if (!strcmp("_r", ptr->key + 4))
{
mod_tint(r_d, v); mod_tint(r_d, v);
} else if (!strcmp("_g", ptr->key + 4)) { }
else if (!strcmp("_g", ptr->key + 4))
{
mod_tint(g_d, v); mod_tint(g_d, v);
} else if (!strcmp("_b", ptr->key + 4)) { }
else if (!strcmp("_b", ptr->key + 4))
{
mod_tint(b_d, v); mod_tint(b_d, v);
} else if (!strcmp("_a", ptr->key + 4)) { }
else if (!strcmp("_a", ptr->key + 4))
{
mod_tint(a_d, v); mod_tint(a_d, v);
} }
} }
} }
for (i = 256; --i >= 0; ) { for (i = 256; --i >= 0;)
if (a_d[i] < 0) a_d[i] = 0; {
if (a_d[i] > 1) a_d[i] = 1; 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; a_b[i] = a_d[i] * 255;
if (r_d[i] < 0) r_d[i] = 0; if (r_d[i] < 0)
if (r_d[i] > 1) r_d[i] = 1; r_d[i] = 0;
if (r_d[i] > 1)
r_d[i] = 1;
r_b[i] = r_d[i] * 255; r_b[i] = r_d[i] * 255;
if (g_d[i] < 0) g_d[i] = 0; if (g_d[i] < 0)
if (g_d[i] > 1) g_d[i] = 1; g_d[i] = 0;
if (g_d[i] > 1)
g_d[i] = 1;
g_b[i] = g_d[i] * 255; g_b[i] = g_d[i] * 255;
if (b_d[i] < 0) b_d[i] = 0; if (b_d[i] < 0)
if (b_d[i] > 1) b_d[i] = 1; b_d[i] = 0;
if (b_d[i] > 1)
b_d[i] = 1;
b_b[i] = b_d[i] * 255; b_b[i] = b_d[i] * 255;
} }
imlib_context_set_color_modifier(imlib_create_color_modifier()); imlib_context_set_color_modifier(imlib_create_color_modifier());
@ -174,9 +239,10 @@ 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)
@ -194,6 +260,6 @@ 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,65 +11,71 @@
#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 ) if (strcmp(filter, "tint") == 0)
{ {
Imlib_Color_Modifier cm; Imlib_Color_Modifier cm;
DATA8 atab[256]; DATA8 atab[256];
int x = 0, y = 0, w = 0, h = 0; int x = 0, y = 0, w = 0, h = 0;
DATA8 r = 255, b = 255, g = 255, a = 255; 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);
@ -83,8 +89,8 @@ void *exec( char *filter, void *im, pIFunctionParam params )
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);
@ -94,16 +100,17 @@ void *exec( char *filter, void *im, pIFunctionParam params )
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;
} }

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,7 +22,7 @@ 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;
@ -97,7 +97,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(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;
@ -113,13 +113,13 @@ 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;
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,8 +132,7 @@ 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++)
{ {
@ -156,11 +155,10 @@ save (ImlibImage *im, ImlibProgressFunction progress,
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)
@ -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]);
} }
} }

View File

@ -15,27 +15,26 @@
#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);
typedef struct tagRGBQUAD typedef struct tagRGBQUAD {
{
unsigned char rgbBlue; unsigned char rgbBlue;
unsigned char rgbGreen; unsigned char rgbGreen;
unsigned char rgbRed; unsigned char rgbRed;
unsigned char rgbReserved; unsigned char rgbReserved;
} } RGBQUAD;
RGBQUAD;
#define BI_RGB 0 #define BI_RGB 0
#define BI_RLE8 1 #define BI_RLE8 1
#define BI_RLE4 2 #define BI_RLE4 2
#define BI_BITFIELDS 3 #define BI_BITFIELDS 3
static int ReadleShort(FILE *file, unsigned short *ret) static int
ReadleShort(FILE * file, unsigned short *ret)
{ {
unsigned char b[2]; unsigned char b[2];
@ -46,7 +45,8 @@ static int ReadleShort(FILE *file, unsigned short *ret)
return 1; return 1;
} }
static int ReadleLong(FILE *file, unsigned long *ret) static int
ReadleLong(FILE * file, unsigned long *ret)
{ {
unsigned char b[4]; unsigned char b[4];
@ -58,7 +58,7 @@ static int ReadleLong(FILE *file, unsigned long *ret)
} }
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 *f; FILE *f;
@ -85,17 +85,21 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* header */ /* header */
{ {
struct stat statbuf; struct stat statbuf;
if (stat(im->real_file, &statbuf) == -1) {
if (stat(im->real_file, &statbuf) == -1)
{
fclose(f); fclose(f);
return 0; return 0;
} }
size = statbuf.st_size; size = statbuf.st_size;
if (fread(type, 1, 2, f) != 2) { if (fread(type, 1, 2, f) != 2)
{
fclose(f); fclose(f);
return 0; return 0;
} }
if (strncmp(type, "BM", 2)) { if (strncmp(type, "BM", 2))
{
fclose(f); fclose(f);
return 0; return 0;
} }
@ -103,7 +107,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
fseek(f, 8, SEEK_CUR); fseek(f, 8, SEEK_CUR);
ReadleLong(f, &offset); ReadleLong(f, &offset);
ReadleLong(f, &headSize); ReadleLong(f, &headSize);
if (headSize == 12) { if (headSize == 12)
{
ReadleShort(f, &tmpShort); ReadleShort(f, &tmpShort);
w = tmpShort; w = tmpShort;
ReadleShort(f, &tmpShort); ReadleShort(f, &tmpShort);
@ -113,7 +118,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
imgsize = size - offset; imgsize = size - offset;
comp = BI_RGB; comp = BI_RGB;
} }
else if (headSize == 40) { else if (headSize == 40)
{
ReadleLong(f, &w); ReadleLong(f, &w);
ReadleLong(f, &h); ReadleLong(f, &h);
ReadleShort(f, &planes); ReadleShort(f, &planes);
@ -124,30 +130,38 @@ load (ImlibImage *im, ImlibProgressFunction progress,
fseek(f, 16, SEEK_CUR); fseek(f, 16, SEEK_CUR);
} }
else { else
{
fclose(f); fclose(f);
return 0; return 0;
} }
if (bitcount < 16) { if (bitcount < 16)
{
ncols = (offset - headSize - 14); ncols = (offset - headSize - 14);
if (headSize == 12) { if (headSize == 12)
{
ncols /= 3; ncols /= 3;
for (i = 0; i < ncols; i++) for (i = 0; i < ncols; i++)
fread(&rgbQuads[i], 3, 1, f); fread(&rgbQuads[i], 3, 1, f);
} }
else { else
{
ncols /= 4; ncols /= 4;
fread(rgbQuads, 4, ncols, f); fread(rgbQuads, 4, ncols, f);
} }
} }
else if (bitcount == 16 || bitcount == 32) { else if (bitcount == 16 || bitcount == 32)
if (comp == BI_BITFIELDS) { {
if (comp == BI_BITFIELDS)
{
int bit; int bit;
ReadleLong(f, &bmask); ReadleLong(f, &bmask);
ReadleLong(f, &gmask); ReadleLong(f, &gmask);
ReadleLong(f, &rmask); ReadleLong(f, &rmask);
for (bit = bitcount - 1; bit >= 0; bit--) { for (bit = bitcount - 1; bit >= 0; bit--)
{
if (bmask & (1 << bit)) if (bmask & (1 << bit))
bshift = bit; bshift = bit;
if (gmask & (1 << bit)) if (gmask & (1 << bit))
@ -156,7 +170,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
rshift = bit; rshift = bit;
} }
} }
else if (bitcount == 16) { else if (bitcount == 16)
{
rmask = 0x7C00; rmask = 0x7C00;
gmask = 0x03E0; gmask = 0x03E0;
bmask = 0x001F; bmask = 0x001F;
@ -164,7 +179,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
gshift = 5; gshift = 5;
bshift = 0; bshift = 0;
} }
else if (bitcount == 32) { else if (bitcount == 32)
{
rmask = 0x00FF0000; rmask = 0x00FF0000;
gmask = 0x0000FF00; gmask = 0x0000FF00;
bmask = 0x000000FF; bmask = 0x000000FF;
@ -186,12 +202,14 @@ load (ImlibImage *im, ImlibProgressFunction progress,
{ {
fseek(f, offset, SEEK_SET); fseek(f, offset, SEEK_SET);
buffer = malloc(imgsize); buffer = malloc(imgsize);
if (!buffer) { if (!buffer)
{
fclose(f); fclose(f);
return 0; return 0;
} }
im->data = malloc(w * h * sizeof(DATA32)); im->data = malloc(w * h * sizeof(DATA32));
if (!im->data) { if (!im->data)
{
fclose(f); fclose(f);
free(buffer); free(buffer);
return 0; return 0;
@ -205,12 +223,17 @@ load (ImlibImage *im, ImlibProgressFunction progress,
data_end = im->data + w * h; data_end = im->data + w * h;
ptr = im->data + ((h - 1) * w); ptr = im->data + ((h - 1) * w);
if (bitcount == 1) { if (bitcount == 1)
if (comp == BI_RGB) { {
if (comp == BI_RGB)
{
skip = ((((w + 31) / 32) * 32) - w) / 8; skip = ((((w + 31) / 32) * 32) - w) / 8;
for (y = 0; y < h; y++) { for (y = 0; y < h; y++)
for (x = 0; x < w && buffer_ptr < buffer_end; x++) { {
if ((x & 7) == 0) byte = *(buffer_ptr++); for (x = 0; x < w && buffer_ptr < buffer_end; x++)
{
if ((x & 7) == 0)
byte = *(buffer_ptr++);
k = (byte >> 7) & 1; k = (byte >> 7) & 1;
*ptr++ = 0xff000000 | *ptr++ = 0xff000000 |
(rgbQuads[k].rgbRed << 16) | (rgbQuads[k].rgbRed << 16) |
@ -220,7 +243,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
buffer_ptr += skip; buffer_ptr += skip;
ptr -= w * 2; ptr -= w * 2;
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -229,7 +253,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -241,21 +267,27 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
} }
if (bitcount == 4) { if (bitcount == 4)
if (comp == BI_RLE4) { {
if (comp == BI_RLE4)
{
x = 0; x = 0;
y = 0; y = 0;
for (i = 0, g = 1; i < imgsize && g && buffer_ptr < buffer_end; i++) { for (i = 0, g = 1;
i < imgsize && g && buffer_ptr < buffer_end; i++)
{
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
if (byte) { if (byte)
{
unsigned char t1, t2; unsigned char t1, t2;
l = byte; l = byte;
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
t1 = byte & 0xF; t1 = byte & 0xF;
t2 = (byte >> 4) & 0xF; t2 = (byte >> 4) & 0xF;
for (j = 0; j < l; j++) { for (j = 0; j < l; j++)
{
k = (j & 1) ? t1 : t2; k = (j & 1) ? t1 : t2;
if (x >= w) if (x >= w)
@ -270,9 +302,11 @@ load (ImlibImage *im, ImlibProgressFunction progress,
ptr = data_end; ptr = data_end;
} }
} }
else { else
{
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
switch (byte) { switch (byte)
{
case 0: case 0:
x = 0; x = 0;
y++; y++;
@ -294,17 +328,21 @@ load (ImlibImage *im, ImlibProgressFunction progress,
break; break;
default: default:
l = byte; l = byte;
for (j = 0; j < l; j++) { for (j = 0; j < l; j++)
char t1 = '\0', t2 = '\0'; {
char t1 = '\0', t2 =
'\0';
if ((j & 1) == 0) { if ((j & 1) == 0)
{
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
t1 = byte & 0xF; t1 = byte & 0xF;
t2 = (byte >> 4) & 0xF; t2 = (byte >> 4) & 0xF;
} }
k = (j & 1) ? t1 : t2; k = (j & 1) ? t1 : t2;
if (x >= w) { if (x >= w)
{
buffer_ptr += (l - j) / 2; buffer_ptr += (l - j) / 2;
break; break;
} }
@ -320,7 +358,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
if ((l & 3) == 1) { if ((l & 3) == 1)
{
tempchar = *(buffer_ptr++); tempchar = *(buffer_ptr++);
tempchar = *(buffer_ptr++); tempchar = *(buffer_ptr++);
} }
@ -329,7 +368,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
break; break;
} }
} }
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -338,7 +378,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -350,10 +392,13 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
else if (comp == BI_RGB) { else if (comp == BI_RGB)
{
skip = ((((w + 7) / 8) * 8) - w) / 2; skip = ((((w + 7) / 8) * 8) - w) / 2;
for (y = 0; y < h; y++) { for (y = 0; y < h; y++)
for (x = 0; x < w && buffer_ptr < buffer_end; x++) { {
for (x = 0; x < w && buffer_ptr < buffer_end; x++)
{
if ((x & 1) == 0) if ((x & 1) == 0)
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
k = (byte & 0xF0) >> 4; k = (byte & 0xF0) >> 4;
@ -365,7 +410,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
buffer_ptr += skip; buffer_ptr += skip;
ptr -= w * 2; ptr -= w * 2;
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -374,7 +420,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -386,16 +434,22 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
} }
if (bitcount == 8) { if (bitcount == 8)
if (comp == BI_RLE8) { {
if (comp == BI_RLE8)
{
x = 0; x = 0;
y = 0; y = 0;
for (i = 0, g = 1; i < imgsize && buffer_ptr < buffer_end && g; i++) { for (i = 0, g = 1;
i < imgsize && buffer_ptr < buffer_end && g; i++)
{
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
if (byte) { if (byte)
{
l = byte; l = byte;
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
for (j = 0; j < l; j++) { for (j = 0; j < l; j++)
{
if (x >= w) if (x >= w)
break; break;
@ -409,9 +463,11 @@ load (ImlibImage *im, ImlibProgressFunction progress,
ptr = data_end; ptr = data_end;
} }
} }
else { else
{
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
switch (byte) { switch (byte)
{
case 0: case 0:
x = 0; x = 0;
y++; y++;
@ -428,16 +484,19 @@ load (ImlibImage *im, ImlibProgressFunction progress,
y += *(buffer_ptr++); y += *(buffer_ptr++);
ptr = im->data + ((h - y - 1) ptr = im->data + ((h - y - 1)
* w * * w *
sizeof(DATA32)) + (x * sizeof(DATA32)); sizeof(DATA32)) +
(x * sizeof(DATA32));
if (ptr > data_end) if (ptr > data_end)
ptr = data_end; ptr = data_end;
break; break;
default: default:
l = byte; l = byte;
for (j = 0; j < l; j++) { for (j = 0; j < l; j++)
{
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
if (x >= w) { if (x >= w)
{
buffer_ptr += l - j; buffer_ptr += l - j;
break; break;
} }
@ -457,7 +516,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
} }
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -466,7 +526,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -476,10 +538,13 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
} }
else if (comp == BI_RGB) { else if (comp == BI_RGB)
{
skip = (((w + 3) / 4) * 4) - w; skip = (((w + 3) / 4) * 4) - w;
for (y = 0; y < h; y++) { for (y = 0; y < h; y++)
for (x = 0; x < w && buffer_ptr < buffer_end; x++) { {
for (x = 0; x < w && buffer_ptr < buffer_end; x++)
{
byte = *(buffer_ptr++); byte = *(buffer_ptr++);
*ptr++ = 0xff000000 | *ptr++ = 0xff000000 |
(rgbQuads[byte].rgbRed << 16) | (rgbQuads[byte].rgbRed << 16) |
@ -488,7 +553,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
ptr -= w * 2; ptr -= w * 2;
buffer_ptr += skip; buffer_ptr += skip;
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -497,7 +563,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -510,18 +578,23 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
else if (bitcount == 16) { else if (bitcount == 16)
{
skip = (((w * 16 + 31) / 32) * 4) - (w * 2); skip = (((w * 16 + 31) / 32) * 4) - (w * 2);
for (y = 0; y < h; y++) { for (y = 0; y < h; y++)
for (x = 0; x < w && buffer_ptr < buffer_end; x++) { {
for (x = 0; x < w && buffer_ptr < buffer_end; x++)
{
r = ((unsigned short)(*buffer_ptr) & rmask) >> rshift; r = ((unsigned short)(*buffer_ptr) & rmask) >> rshift;
g = ((unsigned short)(*buffer_ptr) & gmask) >> gshift; g = ((unsigned short)(*buffer_ptr) & gmask) >> gshift;
b = ((unsigned short)(*(buffer_ptr++)) & bmask) >> bshift; b = ((unsigned short)(*(buffer_ptr++)) & bmask) >>
bshift;
*ptr++ = 0xff000000 | (r << 16) | (g << 8) | b; *ptr++ = 0xff000000 | (r << 16) | (g << 8) | b;
} }
ptr -= w * 2; ptr -= w * 2;
buffer_ptr += skip; buffer_ptr += skip;
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -530,7 +603,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -541,10 +616,13 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
} }
else if (bitcount == 24) { else if (bitcount == 24)
{
skip = (4 - ((w * 3) % 4)) & 3; skip = (4 - ((w * 3) % 4)) & 3;
for (y = 0; y < h; y++) { for (y = 0; y < h; y++)
for (x = 0; x < w && buffer_ptr < buffer_end; x++) { {
for (x = 0; x < w && buffer_ptr < buffer_end; x++)
{
b = *(buffer_ptr++); b = *(buffer_ptr++);
g = *(buffer_ptr++); g = *(buffer_ptr++);
r = *(buffer_ptr++); r = *(buffer_ptr++);
@ -552,7 +630,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
ptr -= w * 2; ptr -= w * 2;
buffer_ptr += skip; buffer_ptr += skip;
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -561,7 +640,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -572,10 +653,13 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
} }
else if (bitcount == 32) { else if (bitcount == 32)
{
skip = (((w * 32 + 31) / 32) * 4) - (w * 4); skip = (((w * 32 + 31) / 32) * 4) - (w * 4);
for (y = 0; y < h; y++) { for (y = 0; y < h; y++)
for (x = 0; x < w && buffer_ptr < buffer_end; x++) { {
for (x = 0; x < w && buffer_ptr < buffer_end; x++)
{
r = ((unsigned long)(*buffer_ptr) & rmask) >> rshift; r = ((unsigned long)(*buffer_ptr) & rmask) >> rshift;
g = ((unsigned long)(*buffer_ptr) & gmask) >> gshift; g = ((unsigned long)(*buffer_ptr) & gmask) >> gshift;
b = ((unsigned long)(*buffer_ptr) & bmask) >> bshift; b = ((unsigned long)(*buffer_ptr) & bmask) >> bshift;
@ -585,7 +669,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
ptr -= w * 2; ptr -= w * 2;
buffer_ptr += skip; buffer_ptr += skip;
if (progress) { if (progress)
{
char per; char per;
int l; int l;
@ -594,7 +679,9 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(y == (im->h - 1))) (y == (im->h - 1)))
{ {
l = y - pl; l = y - pl;
if(!progress(im, per, 0, im->h - y - 1, im->w, im->h - y + l)) if (!progress
(im, per, 0, im->h - y - 1, im->w,
im->h - y + l))
{ {
free(buffer); free(buffer);
return 2; return 2;
@ -611,26 +698,23 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
char char
save (ImlibImage *im, ImlibProgressFunction progress, save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
char progress_granularity)
{ {
/* TODO */ /* TODO */
return 0; return 0;
} }
void void
formats (ImlibLoader *l) formats(ImlibLoader * l)
{ {
char *list_formats[] = char *list_formats[] = { "bmp" };
{ "bmp" };
{ {
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

@ -14,12 +14,15 @@
#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;
@ -29,8 +32,8 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
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;
@ -50,36 +53,47 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
if (fd < 0) if (fd < 0)
return 0; return 0;
gif = DGifOpenFileHandle(fd); gif = DGifOpenFileHandle(fd);
if (!gif) { if (!gif)
{
close(fd); close(fd);
return 0; return 0;
} }
do { do
if (DGifGetRecordType(gif, &rec) == GIF_ERROR) { {
if (DGifGetRecordType(gif, &rec) == GIF_ERROR)
{
/* PrintGifError(); */ /* PrintGifError(); */
rec = TERMINATE_RECORD_TYPE; rec = TERMINATE_RECORD_TYPE;
} }
if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done)) { if ((rec == IMAGE_DESC_RECORD_TYPE) && (!done))
if (DGifGetImageDesc(gif) == GIF_ERROR) { {
if (DGifGetImageDesc(gif) == GIF_ERROR)
{
/* PrintGifError(); */ /* PrintGifError(); */
rec = TERMINATE_RECORD_TYPE; rec = TERMINATE_RECORD_TYPE;
} }
w = gif->Image.Width; w = gif->Image.Width;
h = gif->Image.Height; h = gif->Image.Height;
rows = malloc(h * sizeof(GifRowType *)); rows = malloc(h * sizeof(GifRowType *));
if (!rows) { if (!rows)
{
DGifCloseFile(gif); DGifCloseFile(gif);
return 0; return 0;
} }
for (i = 0; i < h; i++) { for (i = 0; i < h; i++)
{
rows[i] = NULL; rows[i] = NULL;
} }
for (i = 0; i < h; i++) { for (i = 0; i < h; i++)
{
rows[i] = malloc(w * sizeof(GifPixelType)); rows[i] = malloc(w * sizeof(GifPixelType));
if (!rows[i]) { if (!rows[i])
{
DGifCloseFile(gif); DGifCloseFile(gif);
for (i = 0; i < h; i++) { for (i = 0; i < h; i++)
if (rows[i]) { {
if (rows[i])
{
free(rows[i]); free(rows[i]);
} }
} }
@ -87,36 +101,49 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
return 0; return 0;
} }
} }
if (gif->Image.Interlace) { if (gif->Image.Interlace)
for (i = 0; i < 4; i++) { {
for (j = intoffset[i]; j < h; j += intjump[i]) { for (i = 0; i < 4; i++)
{
for (j = intoffset[i]; j < h; j += intjump[i])
{
DGifGetLine(gif, rows[j], w); DGifGetLine(gif, rows[j], w);
} }
} }
} else { }
for (i = 0; i < h; i++) { else
{
for (i = 0; i < h; i++)
{
DGifGetLine(gif, rows[i], w); DGifGetLine(gif, rows[i], w);
} }
} }
done = 1; done = 1;
} else if (rec == EXTENSION_RECORD_TYPE) { }
else if (rec == EXTENSION_RECORD_TYPE)
{
int ext_code; int ext_code;
GifByteType *ext; 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))
{
transp = (int)ext[4];
} }
ext = NULL; ext = NULL;
DGifGetExtensionNext(gif, &ext); DGifGetExtensionNext(gif, &ext);
} }
} }
} while (rec != TERMINATE_RECORD_TYPE); } while (rec != TERMINATE_RECORD_TYPE);
if (transp >= 0) { if (transp >= 0)
{
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 */
@ -126,36 +153,47 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
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; bg = gif->SBackGroundColor;
cmap = (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap); cmap = (gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap);
im->data = (DATA32 *) malloc(sizeof(DATA32) * w * h); im->data = (DATA32 *) malloc(sizeof(DATA32) * w * h);
if (!im->data) { if (!im->data)
{
DGifCloseFile(gif); DGifCloseFile(gif);
free(rows); free(rows);
return 0; return 0;
} }
ptr = im->data; ptr = im->data;
per_inc = 100.0 / (((float) w) * h); per_inc = 100.0 / (((float)w) * h);
for (i = 0; i < h; i++) { for (i = 0; i < h; i++)
for (j = 0; j < w; j++) { {
if (rows[i][j] == transp) { for (j = 0; j < w; j++)
{
if (rows[i][j] == transp)
{
r = cmap->Colors[bg].Red; r = cmap->Colors[bg].Red;
g = cmap->Colors[bg].Green; g = cmap->Colors[bg].Green;
b = cmap->Colors[bg].Blue; b = cmap->Colors[bg].Blue;
*ptr++ = 0x00ffffff & ((r << 16) | (g << 8) | b); *ptr++ = 0x00ffffff & ((r << 16) | (g << 8) | b);
} else { }
else
{
r = cmap->Colors[rows[i][j]].Red; r = cmap->Colors[rows[i][j]].Red;
g = cmap->Colors[rows[i][j]].Green; g = cmap->Colors[rows[i][j]].Green;
b = cmap->Colors[rows[i][j]].Blue; b = cmap->Colors[rows[i][j]].Blue;
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; *ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b;
} }
per += per_inc; per += per_inc;
if (progress && (((int) per) != last_per) && (((int) per) % progress_granularity == 0)) { if (progress && (((int)per) != last_per)
last_per = (int) per; && (((int)per) % progress_granularity == 0))
if (!(progress(im, (int) per, 0, last_y, w, i))) { {
last_per = (int)per;
if (!(progress(im, (int)per, 0, last_y, w, i)))
{
DGifCloseFile(gif); DGifCloseFile(gif);
for (i = 0; i < h; i++) { for (i = 0; i < h; i++)
{
free(rows[i]); free(rows[i]);
} }
free(rows); free(rows);
@ -166,11 +204,13 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
} }
} }
if (progress) { if (progress)
{
progress(im, 100, 0, last_y, w, h); progress(im, 100, 0, last_y, w, h);
} }
DGifCloseFile(gif); DGifCloseFile(gif);
for (i = 0; i < h; i++) { for (i = 0; i < h; i++)
{
free(rows[i]); free(rows[i]);
} }
free(rows); free(rows);
@ -178,7 +218,7 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
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

@ -11,8 +11,7 @@
#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;
}; };
@ -24,7 +23,6 @@ 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);
@ -148,7 +146,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
(0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) << 8) | (0xff000000) | ((ptr[0]) << 16) | ((ptr[1]) <<
8) |
(ptr[2]); (ptr[2]);
ptr += 3; ptr += 3;
ptr2++; ptr2++;
@ -163,7 +162,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
|| ((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); free(data);
jpeg_finish_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
@ -192,7 +192,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
(0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) << 8) | (0xff000000) | ((ptr[0]) << 16) | ((ptr[0]) <<
8) |
(ptr[0]); (ptr[0]);
ptr++; ptr++;
ptr2++; ptr2++;
@ -207,7 +208,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
|| ((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); free(data);
jpeg_finish_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
@ -229,8 +231,7 @@ 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;
@ -243,7 +244,6 @@ save(ImlibImage * im, ImlibProgressFunction progress,
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)
return 0; return 0;
@ -329,7 +329,7 @@ save(ImlibImage * im, ImlibProgressFunction 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;

View File

@ -18,11 +18,10 @@
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 void comment_free(ImlibImage *im, void *data); static void comment_free(ImlibImage * im, void *data);
static void static void
comment_free(ImlibImage * im, void *data) comment_free(ImlibImage * im, void *data)
{ {
@ -86,8 +85,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
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)
@ -149,7 +148,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
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)
{ {
@ -167,11 +166,11 @@ load(ImlibImage * im, ImlibProgressFunction progress,
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, nrows = 1; int y, count, prevy, pass, number_passes, per,
nrows = 1;
count = 0; count = 0;
number_passes = png_set_interlace_handling(png_ptr); number_passes = png_set_interlace_handling(png_ptr);
@ -223,10 +222,11 @@ load(ImlibImage * im, ImlibProgressFunction progress,
num = 0; num = 0;
png_get_text(png_ptr, info_ptr, &text, &num); png_get_text(png_ptr, info_ptr, &text, &num);
for(i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
if (!strcmp(text[i].key, "Imlib2-Comment")) if (!strcmp(text[i].key, "Imlib2-Comment"))
__imlib_AttachTag(im, "comment", 0, strdup(text[i].text), comment_free); __imlib_AttachTag(im, "comment", 0, strdup(text[i].text),
comment_free);
} }
} }
#endif #endif
@ -236,8 +236,7 @@ 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;
@ -270,8 +269,8 @@ save(ImlibImage * im, ImlibProgressFunction progress,
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);
@ -357,7 +356,7 @@ save(ImlibImage * im, ImlibProgressFunction 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;
@ -366,8 +365,10 @@ save(ImlibImage * im, ImlibProgressFunction progress,
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);
png_destroy_info_struct(png_ptr,
(png_infopp) & info_ptr);
fclose(f); fclose(f);
return 2; return 2;
} }
@ -380,8 +381,8 @@ save(ImlibImage * im, ImlibProgressFunction progress,
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;

View File

@ -13,7 +13,6 @@
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);
@ -111,9 +110,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
} }
} }
} }
if ((w <= 0) || (w > 8192) || if ((w <= 0) || (w > 8192) || (h <= 0) || (h > 8192) || (v < 0) || (v > 255))
(h <= 0) || (h > 8192) ||
(v < 0) || (v > 255))
{ {
fclose(f); fclose(f);
return 0; return 0;
@ -190,14 +187,14 @@ load(ImlibImage * im, ImlibProgressFunction 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;
/* fix off by one in case of the last line */ /* fix off by one in case of the last line */
if (y == (im->h -1)) if (y == (im->h - 1))
l++; l++;
if (!progress(im, per, 0, pl, im->w, l)) if (!progress(im, per, 0, pl, im->w, l))
@ -256,8 +253,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
0xff000000 | (iptr[0] << 16) | (iptr[0] << 8) | 0xff000000 | (iptr[0] << 16) | (iptr[0] << 8)
iptr[0]; | iptr[0];
ptr2++; ptr2++;
iptr++; iptr++;
} }
@ -268,7 +265,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{ {
*ptr2 = *ptr2 =
0xff000000 | (((iptr[0] * 255) / v) << 16) | 0xff000000 | (((iptr[0] * 255) / v) << 16) |
(((iptr[0] * 255) / v) << 8) | ((iptr[0] * 255) / v); (((iptr[0] * 255) / v) << 8) | ((iptr[0] *
255) / v);
ptr2++; ptr2++;
iptr++; iptr++;
} }
@ -278,7 +276,7 @@ load(ImlibImage * im, ImlibProgressFunction 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)))
{ {
@ -286,7 +284,7 @@ load(ImlibImage * im, ImlibProgressFunction progress,
l = y - pl; l = y - pl;
/* fix off by one in case of the last line */ /* fix off by one in case of the last line */
if (y == (im->h -1)) if (y == (im->h - 1))
l++; l++;
if (!progress(im, per, 0, pl, im->w, l)) if (!progress(im, per, 0, pl, im->w, l))
@ -349,8 +347,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
0xff000000 | (iptr[0] << 16) | (iptr[1] << 8) | 0xff000000 | (iptr[0] << 16) | (iptr[1] << 8)
iptr[2]; | iptr[2];
ptr2++; ptr2++;
iptr += 3; iptr += 3;
} }
@ -361,7 +359,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{ {
*ptr2 = *ptr2 =
0xff000000 | (((ptr[0] * 255) / v) << 16) | 0xff000000 | (((ptr[0] * 255) / v) << 16) |
(((iptr[1] * 255) / v) << 8) | ((iptr[2] * 255) / v); (((iptr[1] * 255) / v) << 8) | ((iptr[2] *
255) / v);
ptr2++; ptr2++;
iptr += 3; iptr += 3;
} }
@ -371,14 +370,14 @@ load(ImlibImage * im, ImlibProgressFunction 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;
/* fix off by one in case of the last line */ /* fix off by one in case of the last line */
if (y == (im->h -1)) if (y == (im->h - 1))
l++; l++;
if (!progress(im, per, 0, pl, im->w, l)) if (!progress(im, per, 0, pl, im->w, l))
@ -441,7 +440,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
0xff000000 | (ptr[0] << 16) | (ptr[0] << 8) | ptr[0]; 0xff000000 | (ptr[0] << 16) | (ptr[0] << 8) |
ptr[0];
ptr2++; ptr2++;
ptr++; ptr++;
} }
@ -452,7 +452,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{ {
*ptr2 = *ptr2 =
0xff000000 | (((ptr[0] * 255) / v) << 16) | 0xff000000 | (((ptr[0] * 255) / v) << 16) |
(((ptr[0] * 255) / v) << 8) | ((ptr[0] * 255) / v); (((ptr[0] * 255) / v) << 8) | ((ptr[0] *
255) / v);
ptr2++; ptr2++;
ptr++; ptr++;
} }
@ -462,14 +463,14 @@ load(ImlibImage * im, ImlibProgressFunction 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;
/* fix off by one in case of the last line */ /* fix off by one in case of the last line */
if (y == (im->h -1)) if (y == (im->h - 1))
l++; l++;
if (!progress(im, per, 0, pl, im->w, l)) if (!progress(im, per, 0, pl, im->w, l))
@ -507,7 +508,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
0xff000000 | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; 0xff000000 | (ptr[0] << 16) | (ptr[1] << 8) |
ptr[2];
ptr2++; ptr2++;
ptr += 3; ptr += 3;
} }
@ -518,7 +520,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
{ {
*ptr2 = *ptr2 =
0xff000000 | (((ptr[0] * 255) / v) << 16) | 0xff000000 | (((ptr[0] * 255) / v) << 16) |
(((ptr[1] * 255) / v) << 8) | ((ptr[2] * 255) / v); (((ptr[1] * 255) / v) << 8) | ((ptr[2] *
255) / v);
ptr2++; ptr2++;
ptr += 3; ptr += 3;
} }
@ -528,14 +531,14 @@ load(ImlibImage * im, ImlibProgressFunction 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;
/* fix off by one in case of the last line */ /* fix off by one in case of the last line */
if (y == (im->h -1)) if (y == (im->h - 1))
l++; l++;
if (!progress(im, per, 0, pl, im->w, l)) if (!progress(im, per, 0, pl, im->w, l))
@ -578,14 +581,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
*ptr2 = *ptr2 =
0xff000000 | (((r << 21) | (r << 18) | (r << 15)) & 0xff000000 | (((r << 21) | (r << 18) | (r << 15)) &
0xff0000) | (((g << 13) | (g << 10) | 0xff0000) | (((g << 13) | (g << 10) |
(g << 7)) & 0xff00) | ((b << (g << 7)) & 0xff00) |
6) | ((b << 6) | (b << 4) | (b << 2) | (b << 0));
(b <<
4) |
(b <<
2) |
(b <<
0));
ptr2++; ptr2++;
ptr++; ptr++;
} }
@ -594,12 +591,12 @@ load(ImlibImage * im, ImlibProgressFunction 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)))
{ {
/* fix off by one in case of the last line */ /* fix off by one in case of the last line */
if (y == (im->h -1)) if (y == (im->h - 1))
l++; l++;
if (!progress(im, per, 0, pl, im->w, l)) if (!progress(im, per, 0, pl, im->w, l))
@ -637,7 +634,8 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
(ptr[3] << 24) | (ptr[0] << 16) | (ptr[1] << 8) | (ptr[3] << 24) | (ptr[0] << 16) | (ptr[1] <<
8) |
ptr[2]; ptr[2];
ptr2++; ptr2++;
ptr += 4; ptr += 4;
@ -648,9 +646,11 @@ load(ImlibImage * im, ImlibProgressFunction progress,
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = *ptr2 =
(((ptr[3] * 255) / v) << 24) | (((ptr[0] * 255) / v) << (((ptr[3] * 255) /
16) | v) << 24) | (((ptr[0] * 255) /
(((ptr[1] * 255) / v) << 8) | ((ptr[2] * 255) / v); v) << 16) | (((ptr[1] * 255) /
v) << 8) |
((ptr[2] * 255) / v);
ptr2++; ptr2++;
ptr += 4; ptr += 4;
} }
@ -660,12 +660,12 @@ load(ImlibImage * im, ImlibProgressFunction 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)))
{ {
/* fix off by one in case of the last line */ /* fix off by one in case of the last line */
if (y == (im->h -1)) if (y == (im->h - 1))
l++; l++;
if (!progress(im, per, 0, pl, im->w, l)) if (!progress(im, per, 0, pl, im->w, l))
@ -696,8 +696,7 @@ 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;
DATA8 *buf, *bptr; DATA8 *buf, *bptr;
@ -742,8 +741,9 @@ save(ImlibImage * im, ImlibProgressFunction 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))
@ -787,8 +787,9 @@ save(ImlibImage * im, ImlibProgressFunction 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))

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
@ -72,15 +72,13 @@ typedef struct {
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;
@ -90,14 +88,13 @@ save (ImlibImage *im, ImlibProgressFunction progress,
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... */
@ -125,30 +122,36 @@ 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); fclose(f);
return 0; 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) { {
if (im->flags & F_HAS_ALPHA)
{
READ_RGBA(dataptr, r, g, b, a); READ_RGBA(dataptr, r, g, b, a);
*bufptr++ = b; *bufptr++ = b;
*bufptr++ = g; *bufptr++ = g;
*bufptr++ = r; *bufptr++ = r;
*bufptr++ = a; *bufptr++ = a;
} else { }
else
{
READ_RGB(dataptr, r, g, b); READ_RGB(dataptr, r, g, b);
*bufptr++ = b; *bufptr++ = b;
*bufptr++ = g; *bufptr++ = g;
@ -157,7 +160,6 @@ save (ImlibImage *im, ImlibProgressFunction progress,
dataptr++; dataptr++;
} /* end for (each pixel in row) */ } /* end for (each pixel in row) */
/* report progress every row */ /* report progress every row */
if (progress) if (progress)
{ {
@ -165,13 +167,12 @@ save (ImlibImage *im, ImlibProgressFunction progress,
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))
{ {
if(buf) if (buf)
free(buf); free(buf);
fclose(f); fclose(f);
return 2; return 2;
@ -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,7 +206,7 @@ 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;
@ -215,23 +216,23 @@ load (ImlibImage *im, ImlibProgressFunction progress,
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)
@ -241,14 +242,14 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
/* 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;
@ -279,7 +280,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* 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;
@ -296,7 +297,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
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);
@ -318,7 +319,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* 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);
@ -336,7 +337,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
(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);
@ -344,7 +345,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
/* 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;
@ -359,28 +360,27 @@ load (ImlibImage *im, ImlibProgressFunction progress,
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 */
for(x = 0; x < im->w; x++) /* for each pixel in the row */ {
switch (bpp)
{ {
switch(bpp) {
/* 32-bit BGRA pixels */ /* 32-bit BGRA pixels */
case 32: case 32:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 2), /* R */
*(bufptr + 1), /* G */ *(bufptr + 1), /* G */
*(bufptr + 0), /* B */ *(bufptr + 0), /* B */
*(bufptr + 3) /* A */ *(bufptr + 3) /* A */
@ -391,11 +391,10 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* 24-bit BGR pixels */ /* 24-bit BGR pixels */
case 24: 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 */ (char)0xff /* A */
); );
dataptr++; dataptr++;
bufptr += 3; bufptr += 3;
@ -403,12 +402,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* 8-bit grayscale */ /* 8-bit grayscale */
case 8: case 8:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *bufptr, /* grayscale */
*bufptr, /* grayscale */ *bufptr, *bufptr, (char)0xff);
*bufptr,
*bufptr,
(char) 0xff
);
dataptr++; dataptr++;
bufptr += 1; bufptr += 1;
break; break;
@ -417,17 +412,17 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} /* end for (each pixel) */ } /* end for (each pixel) */
/* report progress every row */ /* report progress every row */
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))
{ {
free(buf); free(buf);
fclose(fp); fclose(fp);
@ -449,39 +444,49 @@ load (ImlibImage *im, ImlibProgressFunction progress,
DATA32 *final_pixel = dataptr + im->w * im->h; DATA32 *final_pixel = dataptr + im->w * im->h;
/* loop until we've got all the pixels */ /* loop until we've got all the pixels */
while(dataptr < final_pixel) while (dataptr < final_pixel)
{ {
int count; int count;
curbyte = *bufptr++; curbyte = *bufptr++;
count = (curbyte & 0x7F) + 1; count = (curbyte & 0x7F) + 1;
if(curbyte & 0x80) /* RLE packet */ if (curbyte & 0x80) /* RLE packet */
{ {
int i; int i;
switch(bpp) { switch (bpp)
{
case 32: case 32:
blue = *bufptr++; green = *bufptr++; red = *bufptr++; blue = *bufptr++;
green = *bufptr++;
red = *bufptr++;
alpha = *bufptr++; alpha = *bufptr++;
for(i = 0; i < count; i++) { for (i = 0; i < count; i++)
{
WRITE_RGBA(dataptr, red, green, blue, alpha); WRITE_RGBA(dataptr, red, green, blue, alpha);
dataptr++; dataptr++;
} }
break; break;
case 24: case 24:
blue = *bufptr++; green = *bufptr++; red = *bufptr++; blue = *bufptr++;
for(i = 0; i < count; i++) { green = *bufptr++;
WRITE_RGBA(dataptr, red, green, blue, (char) 0xff); red = *bufptr++;
for (i = 0; i < count; i++)
{
WRITE_RGBA(dataptr, red, green, blue,
(char)0xff);
dataptr++; dataptr++;
} }
break; break;
case 8: case 8:
alpha = *bufptr++; alpha = *bufptr++;
for(i = 0; i < count; i++) { for (i = 0; i < count; i++)
WRITE_RGBA(dataptr, alpha, alpha, alpha, (char) 0xff); {
WRITE_RGBA(dataptr, alpha, alpha, alpha,
(char)0xff);
dataptr++; dataptr++;
} }
break; break;
@ -493,14 +498,14 @@ load (ImlibImage *im, ImlibProgressFunction progress,
{ {
int i; int i;
for(i = 0; i < count; i++) for (i = 0; i < count; i++)
{
switch (bpp)
{ {
switch(bpp) {
/* 32-bit BGRA pixels */ /* 32-bit BGRA pixels */
case 32: case 32:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *(bufptr + 2), /* R */
*(bufptr + 2), /* R */
*(bufptr + 1), /* G */ *(bufptr + 1), /* G */
*(bufptr + 0), /* B */ *(bufptr + 0), /* B */
*(bufptr + 3) /* A */ *(bufptr + 3) /* A */
@ -511,11 +516,10 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* 24-bit BGR pixels */ /* 24-bit BGR pixels */
case 24: 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 */ (char)0xff /* A */
); );
dataptr++; dataptr++;
bufptr += 3; bufptr += 3;
@ -523,12 +527,8 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* 8-bit grayscale */ /* 8-bit grayscale */
case 8: case 8:
WRITE_RGBA(dataptr, WRITE_RGBA(dataptr, *bufptr, /* pseudo-grayscale */
*bufptr, /* pseudo-grayscale */ *bufptr, *bufptr, (char)0xff);
*bufptr,
*bufptr,
(char) 0xff
);
dataptr++; dataptr++;
bufptr += 1; bufptr += 1;
break; break;
@ -537,7 +537,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} /* end if (raw packet) */ } /* end if (raw packet) */
/* report progress every packet */ /* report progress every packet */
if(progress) if (progress)
{ {
char per; char per;
int l; int l;
@ -547,13 +547,13 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* end at the end of a row */ /* end at the end of a row */
y = (dataptr - im->data) / im->w; y = (dataptr - im->data) / im->w;
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))
{ {
free(buf); free(buf);
fclose(fp); fclose(fp);
@ -575,9 +575,11 @@ load (ImlibImage *im, ImlibProgressFunction progress,
* above, but that would be messy to code. There's * above, but that would be messy to code. There's
* probably a better way... */ * probably a better way... */
if(vinverted) { if (vinverted)
{
im->data = flip(im->data, im->w, im->h); im->data = flip(im->data, im->w, im->h);
if(!im->data) { if (!im->data)
{
fclose(fp); fclose(fp);
free(buf); free(buf);
return 0; return 0;
@ -595,15 +597,14 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
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,19 +618,21 @@ 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; adv2 -= w;
memmove(out + adv, in + adv2, w * sizeof(DATA32)); memmove(out + adv, in + adv2, w * sizeof(DATA32));
adv += w; adv += w;
@ -638,4 +641,3 @@ flip(DATA32* in, int w, int h)
free(in); free(in);
return out; return out;
} }

View File

@ -19,9 +19,7 @@
/* 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; TIFFRGBAImage rgba;
tileContigRoutine put_contig; tileContigRoutine put_contig;
tileSeparateRoutine put_separate; tileSeparateRoutine put_separate;
@ -35,38 +33,42 @@ struct TIFFRGBAImage_Extra
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,
uint32 y, uint32 w, uint32 h);
static void error_handler(const char *module, const char *fmt,
va_list ap);
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 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);
} }
@ -74,7 +76,7 @@ put_separate_and_raster(TIFFRGBAImage* img, uint32* rast,
/* 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;
@ -114,12 +116,12 @@ raster(TIFFRGBAImage_Extra *img, uint32* rast,
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;
@ -131,15 +133,14 @@ raster(TIFFRGBAImage_Extra *img, uint32* rast,
/* 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;
@ -180,7 +181,7 @@ 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);
@ -218,7 +219,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
im->data = NULL; im->data = NULL;
} }
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image); TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif); TIFFClose(tif);
return 0; return 0;
@ -231,7 +232,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
_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;
@ -250,13 +251,13 @@ load (ImlibImage *im, ImlibProgressFunction progress,
} }
} }
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;
@ -265,7 +266,7 @@ load (ImlibImage *im, ImlibProgressFunction progress,
_TIFFfree(rast); _TIFFfree(rast);
} }
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image); TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif); TIFFClose(tif);
return 1; return 1;
@ -275,8 +276,7 @@ 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;
@ -287,8 +287,9 @@ save (ImlibImage *im, ImlibProgressFunction progress,
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;
@ -316,33 +317,59 @@ 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; compression_type = tag->val;
switch (compression_type) { switch (compression_type)
case COMPRESSION_NONE: break; {
case COMPRESSION_CCITTRLE: break; case COMPRESSION_NONE:
case COMPRESSION_CCITTFAX3: break; break;
case COMPRESSION_CCITTFAX4: break; case COMPRESSION_CCITTRLE:
case COMPRESSION_LZW: break; break;
case COMPRESSION_OJPEG: break; case COMPRESSION_CCITTFAX3:
case COMPRESSION_JPEG: break; break;
case COMPRESSION_NEXT: break; case COMPRESSION_CCITTFAX4:
case COMPRESSION_CCITTRLEW: break; break;
case COMPRESSION_PACKBITS: break; case COMPRESSION_LZW:
case COMPRESSION_THUNDERSCAN: break; break;
case COMPRESSION_IT8CTPAD: break; case COMPRESSION_OJPEG:
case COMPRESSION_IT8LW: break; break;
case COMPRESSION_IT8MP: break; case COMPRESSION_JPEG:
case COMPRESSION_IT8BL: break; break;
case COMPRESSION_PIXARFILM: break; case COMPRESSION_NEXT:
case COMPRESSION_PIXARLOG: break; break;
case COMPRESSION_DEFLATE: break; case COMPRESSION_CCITTRLEW:
case COMPRESSION_ADOBE_DEFLATE: break; break;
case COMPRESSION_DCS: break; case COMPRESSION_PACKBITS:
case COMPRESSION_JBIG: break; break;
case COMPRESSION_SGILOG: break; case COMPRESSION_THUNDERSCAN:
case COMPRESSION_SGILOG24: break; break;
default: compression_type = COMPRESSION_DEFLATE; 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;
} }
} }
@ -382,7 +409,7 @@ save (ImlibImage *im, ImlibProgressFunction progress,
{ {
/* 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;
@ -412,7 +439,7 @@ save (ImlibImage *im, ImlibProgressFunction progress,
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;
} }
@ -433,18 +460,17 @@ 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]);

View File

@ -13,9 +13,11 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "image.h" #include "image.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);
static FILE *rgb_txt = NULL; static FILE *rgb_txt = NULL;
@ -36,13 +38,16 @@ xpm_parse_color(char *color, int *r, int *g, int *b)
int i; int i;
len /= 3; len /= 3;
for (i = 0; i < len; i++) val[i] = color[1 + i + (0 * len)]; for (i = 0; i < len; i++)
val[i] = color[1 + i + (0 * len)];
val[i] = 0; val[i] = 0;
sscanf(val, "%x", r); sscanf(val, "%x", r);
for (i = 0; i < len; i++) val[i] = color[1 + i + (1 * len)]; for (i = 0; i < len; i++)
val[i] = color[1 + i + (1 * len)];
val[i] = 0; val[i] = 0;
sscanf(val, "%x", g); sscanf(val, "%x", g);
for (i = 0; i < len; i++) val[i] = color[1 + i + (2 * len)]; for (i = 0; i < len; i++)
val[i] = color[1 + i + (2 * len)];
val[i] = 0; val[i] = 0;
sscanf(val, "%x", b); sscanf(val, "%x", b);
if (len == 1) if (len == 1)
@ -98,17 +103,17 @@ xpm_parse_done(void)
} }
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, *end; DATA32 *ptr, *end;
FILE *f; FILE *f;
int pc, c, i, j, k, w, h, ncolors, cpp, comment, transp, quote, int pc, c, i, j, k, w, h, ncolors, cpp, comment, transp,
context, len, done, r, g, b; quote, context, len, done, r, g, b;
char *line, s[256], tok[128], col[256]; char *line, s[256], tok[128], col[256];
int lsz = 256; int lsz = 256;
struct _cmap struct _cmap {
{
unsigned char str[6]; unsigned char str[6];
unsigned char transp; unsigned char transp;
short r, g, b; short r, g, b;
@ -191,7 +196,8 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp); sscanf(line, "%i %i %i %i", &w, &h, &ncolors, &cpp);
if (ncolors > 32766) if (ncolors > 32766)
{ {
fprintf(stderr, "IMLIB ERROR: XPM files with colors > 32766 not supported\n"); fprintf(stderr,
"IMLIB ERROR: XPM files with colors > 32766 not supported\n");
free(line); free(line);
fclose(f); fclose(f);
xpm_parse_done(); xpm_parse_done();
@ -199,7 +205,8 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
if (cpp > 5) if (cpp > 5)
{ {
fprintf(stderr, "IMLIB ERROR: XPM files with characters per pixel > 5 not supported\n"); fprintf(stderr,
"IMLIB ERROR: XPM files with characters per pixel > 5 not supported\n");
free(line); free(line);
fclose(f); fclose(f);
xpm_parse_done(); xpm_parse_done();
@ -207,7 +214,8 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
if (w > 32767) if (w > 32767)
{ {
fprintf(stderr, "IMLIB ERROR: Image width > 32767 pixels for file\n"); fprintf(stderr,
"IMLIB ERROR: Image width > 32767 pixels for file\n");
free(line); free(line);
fclose(f); fclose(f);
xpm_parse_done(); xpm_parse_done();
@ -215,7 +223,8 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
if (h > 32767) if (h > 32767)
{ {
fprintf(stderr, "IMLIB ERROR: Image height > 32767 pixels for file\n"); fprintf(stderr,
"IMLIB ERROR: Image height > 32767 pixels for file\n");
free(line); free(line);
fclose(f); fclose(f);
xpm_parse_done(); xpm_parse_done();
@ -236,7 +245,7 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
return 0; return 0;
} }
per_inc = 100.0 / (((float) w) * h); per_inc = 100.0 / (((float)w) * h);
j = 0; j = 0;
context++; context++;
@ -269,15 +278,17 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
k += slen; k += slen;
if (!strcmp(s, "c")) if (!strcmp(s, "c"))
iscolor = 1; iscolor = 1;
if ((!strcmp(s, "m")) || (!strcmp(s, "s")) || if ((!strcmp(s, "m")) || (!strcmp(s, "s"))
(!strcmp(s, "g4")) || (!strcmp(s, "g")) || || (!strcmp(s, "g4"))
(!strcmp(s, "c")) || (k >= len)) || (!strcmp(s, "g"))
|| (!strcmp(s, "c")) || (k >= len))
{ {
if (k >= len) if (k >= len)
{ {
if (col[0]) if (col[0])
strcat(col, " "); strcat(col, " ");
if (strlen(col) + strlen(s) < sizeof(col)) if (strlen(col) + strlen(s) <
sizeof(col))
strcat(col, s); strcat(col, s);
} }
if (col[0]) if (col[0])
@ -290,11 +301,16 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
else else
{ {
if ((((cmap[j].r < 0) || if ((((cmap[j].r < 0) ||
(!strcmp(tok, "c"))) && (!strcmp(tok, "c")))
(!hascolor))) && (!hascolor)))
{ {
r = 0; g = 0; b = 0; r = 0;
xpm_parse_color(col, &r, &g, &b); g = 0;
b = 0;
xpm_parse_color(col,
&r,
&g,
&b);
cmap[j].r = r; cmap[j].r = r;
cmap[j].g = g; cmap[j].g = g;
cmap[j].b = b; cmap[j].b = b;
@ -323,19 +339,25 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
lookup[(int)cmap[i].str[0] - 32][0] = i; lookup[(int)cmap[i].str[0] - 32][0] = i;
if (cpp == 2) if (cpp == 2)
for (i = 0; i < ncolors; i++) for (i = 0; i < ncolors; i++)
lookup[(int)cmap[i].str[0] - 32][(int)cmap[i].str[1] - 32] = i; lookup[(int)cmap[i].str[0] -
32][(int)cmap[i].str[1] - 32] = i;
context++; context++;
} }
if (transp >= 0) { if (transp >= 0)
{
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);
} }
if (im->loader || immediate_load || progress) if (im->loader || immediate_load || progress)
{ {
im->data = (DATA32 *) malloc(sizeof(DATA32) * im->w * im->h); im->data =
(DATA32 *) malloc(sizeof(DATA32) * im->w *
im->h);
if (!im->data) if (!im->data)
{ {
free(cmap); free(cmap);
@ -369,36 +391,63 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
{ {
if (transp) if (transp)
{ {
for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) for (i = 0;
((i < 65536) && (ptr < end) && (line[i]));
i++)
{ {
col[0] = line[i]; col[0] = line[i];
if (cmap[lookup[(int)col[0] - 32][0]].transp) if (cmap[lookup[(int)col[0] - 32][0]].
transp)
{ {
r = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; r = (unsigned char)
g = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; cmap[lookup[(int)col[0] - 32]
b = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; [0]].r;
*ptr++ = 0x00ffffff & ((r << 16) | (g << 8) | b); g = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[0]].g;
b = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[0]].b;
*ptr++ =
0x00ffffff & ((r << 16) |
(g << 8) | b);
count++; count++;
} }
else else
{ {
r = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; r = (unsigned char)
g = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; cmap[lookup[(int)col[0] - 32]
b = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; [0]].r;
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; g = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[0]].g;
b = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[0]].b;
*ptr++ =
(0xff << 24) | (r << 16) | (g <<
8) |
b;
count++; count++;
} }
} }
} }
else else
{ {
for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) for (i = 0;
((i < 65536) && (ptr < end) && (line[i]));
i++)
{ {
col[0] = line[i]; col[0] = line[i];
r = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; r = (unsigned char)
g = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; cmap[lookup[(int)col[0] - 32][0]].r;
b = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; g = (unsigned char)
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; cmap[lookup[(int)col[0] - 32][0]].g;
b = (unsigned char)
cmap[lookup[(int)col[0] - 32][0]].b;
*ptr++ =
(0xff << 24) | (r << 16) | (g << 8) |
b;
count++; count++;
} }
} }
@ -407,38 +456,69 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
{ {
if (transp) if (transp)
{ {
for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) for (i = 0;
((i < 65536) && (ptr < end) && (line[i]));
i++)
{ {
col[0] = line[i++]; col[0] = line[i++];
col[1] = line[i]; col[1] = line[i];
if (cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].transp) if (cmap
[lookup[(int)col[0] - 32]
[(int)col[1] - 32]].transp)
{ {
r = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].r; r = (unsigned char)
g = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].g; cmap[lookup[(int)col[0] - 32]
b = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].b; [(int)col[1] - 32]].r;
*ptr++ = 0x00ffffff & ((r << 16) | (g << 8) | b); g = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[(int)col[1] - 32]].g;
b = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[(int)col[1] - 32]].b;
*ptr++ =
0x00ffffff & ((r << 16) |
(g << 8) | b);
count++; count++;
} }
else else
{ {
r = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].r; r = (unsigned char)
g = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].g; cmap[lookup[(int)col[0] - 32]
b = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].b; [(int)col[1] - 32]].r;
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; g = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[(int)col[1] - 32]].g;
b = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[(int)col[1] - 32]].b;
*ptr++ =
(0xff << 24) | (r << 16) | (g <<
8) |
b;
count++; count++;
} }
} }
} }
else else
{ {
for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) for (i = 0;
((i < 65536) && (ptr < end) && (line[i]));
i++)
{ {
col[0] = line[i++]; col[0] = line[i++];
col[1] = line[i]; col[1] = line[i];
r = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].r; r = (unsigned char)
g = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].g; cmap[lookup[(int)col[0] - 32]
b = (unsigned char)cmap[lookup[(int)col[0] - 32][(int)col[1] - 32]].b; [(int)col[1] - 32]].r;
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; g = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[(int)col[1] - 32]].g;
b = (unsigned char)
cmap[lookup[(int)col[0] - 32]
[(int)col[1] - 32]].b;
*ptr++ =
(0xff << 24) | (r << 16) | (g << 8) |
b;
count++; count++;
} }
} }
@ -447,7 +527,9 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
{ {
if (transp) if (transp)
{ {
for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) for (i = 0;
((i < 65536) && (ptr < end) && (line[i]));
i++)
{ {
for (j = 0; j < cpp; j++, i++) for (j = 0; j < cpp; j++, i++)
{ {
@ -461,18 +543,37 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
{ {
if (cmap[j].transp) if (cmap[j].transp)
{ {
r = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].r; r = (unsigned char)
g = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].g; cmap[lookup
b = (unsigned char)cmap[lookup[(int)col[0] - 32][0]].b; [(int)col[0] -
*ptr++ = 0x00ffffff & ((r << 16) | (g << 8) | b); 32][0]].r;
g = (unsigned char)
cmap[lookup
[(int)col[0] -
32][0]].g;
b = (unsigned char)
cmap[lookup
[(int)col[0] -
32][0]].b;
*ptr++ =
0x00ffffff & ((r << 16)
| (g <<
8) |
b);
count++; count++;
} }
else else
{ {
r = (unsigned char)cmap[j].r; r = (unsigned char)cmap[j].
g = (unsigned char)cmap[j].g; r;
b = (unsigned char)cmap[j].b; g = (unsigned char)cmap[j].
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; g;
b = (unsigned char)cmap[j].
b;
*ptr++ =
(0xff << 24) | (r <<
16) |
(g << 8) | b;
count++; count++;
} }
j = ncolors; j = ncolors;
@ -482,7 +583,9 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
else else
{ {
for (i = 0; ((i < 65536) && (ptr < end) && (line[i])); i++) for (i = 0;
((i < 65536) && (ptr < end) && (line[i]));
i++)
{ {
for (j = 0; j < cpp; j++, i++) for (j = 0; j < cpp; j++, i++)
{ {
@ -497,7 +600,9 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
r = (unsigned char)cmap[j].r; r = (unsigned char)cmap[j].r;
g = (unsigned char)cmap[j].g; g = (unsigned char)cmap[j].g;
b = (unsigned char)cmap[j].b; b = (unsigned char)cmap[j].b;
*ptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; *ptr++ =
(0xff << 24) | (r << 16) |
(g << 8) | b;
count++; count++;
j = ncolors; j = ncolors;
} }
@ -506,10 +611,11 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
} }
per += per_inc; per += per_inc;
if (progress && (((int) per) != last_per) && (((int) per) % progress_granularity == 0)) if (progress && (((int)per) != last_per)
&& (((int)per) % progress_granularity == 0))
{ {
last_per = (int) per; last_per = (int)per;
if (!(progress(im, (int) per, 0, last_y, w, i))) if (!(progress(im, (int)per, 0, last_y, w, i)))
{ {
fclose(f); fclose(f);
free(cmap); free(cmap);
@ -556,7 +662,7 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity,
} }
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;
@ -572,21 +678,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[] = { "xpm" };
{ "xpm" };
/* 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

@ -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

1523
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

@ -7,7 +7,7 @@ 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;
@ -27,13 +27,14 @@ __imlib_XActualDepth(Display *d, Visual *v)
} }
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;
@ -47,14 +48,12 @@ __imlib_BestVisual(Display *d, int screen, int *depth_return)
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) && else if ((xvir[i].depth > maxd) && (xvir[i].depth <= 24))
(xvir[i].depth <= 24))
{ {
maxd = xvir[i].depth; maxd = xvir[i].depth;
v = xvir[i].visual; v = xvir[i].visual;
@ -69,38 +68,45 @@ __imlib_BestVisual(Display *d, int screen, int *depth_return)
} }
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; *type_return = _pal_type;
return color_lut; return color_lut;
} }
if ((_max_colors >= 216) && (color_lut = __imlib_AllocColors666(d, cmap, v))) if ((_max_colors >= 216)
&& (color_lut = __imlib_AllocColors666(d, cmap, v)))
{ {
*type_return = _pal_type; *type_return = _pal_type;
return color_lut; return color_lut;
} }
if ((_max_colors >= 128) && (color_lut = __imlib_AllocColors232(d, cmap, v))) if ((_max_colors >= 128)
&& (color_lut = __imlib_AllocColors232(d, cmap, v)))
{ {
*type_return = _pal_type; *type_return = _pal_type;
return color_lut; return color_lut;
} }
if ((_max_colors >= 64) && (color_lut = __imlib_AllocColors222(d, cmap, v))) if ((_max_colors >= 64)
&& (color_lut = __imlib_AllocColors222(d, cmap, v)))
{ {
*type_return = _pal_type; *type_return = _pal_type;
return color_lut; return color_lut;
} }
if ((_max_colors >= 32) && (color_lut = __imlib_AllocColors221(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 >= 16) && (color_lut = __imlib_AllocColors121(d, cmap, v))) if ((_max_colors >= 16)
&& (color_lut = __imlib_AllocColors121(d, cmap, v)))
{ {
*type_return = _pal_type; *type_return = _pal_type;
return color_lut; return color_lut;
@ -117,13 +123,14 @@ __imlib_AllocColorTable(Display *d, Colormap cmap, DATA8 *type_return, Visual *v
} }
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));
@ -156,8 +163,8 @@ __imlib_AllocColors332(Display *d, Colormap cmap, Visual *v)
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);
@ -173,13 +180,14 @@ __imlib_AllocColors332(Display *d, Colormap cmap, Visual *v)
} }
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));
@ -212,8 +220,8 @@ __imlib_AllocColors666(Display *d, Colormap cmap, Visual *v)
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);
@ -229,13 +237,14 @@ __imlib_AllocColors666(Display *d, Colormap cmap, Visual *v)
} }
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));
@ -268,8 +277,8 @@ __imlib_AllocColors232(Display *d, Colormap cmap, Visual *v)
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);
@ -285,13 +294,14 @@ __imlib_AllocColors232(Display *d, Colormap cmap, Visual *v)
} }
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));
@ -324,8 +334,8 @@ __imlib_AllocColors222(Display *d, Colormap cmap, Visual *v)
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);
@ -341,13 +351,14 @@ __imlib_AllocColors222(Display *d, Colormap cmap, Visual *v)
} }
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));
@ -366,7 +377,11 @@ __imlib_AllocColors221(Display *d, Colormap cmap, Visual *v)
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 =
(b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
<<
2)
| (b << 1) | (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);
@ -380,8 +395,8 @@ __imlib_AllocColors221(Display *d, Colormap cmap, Visual *v)
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);
@ -397,13 +412,14 @@ __imlib_AllocColors221(Display *d, Colormap cmap, Visual *v)
} }
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));
@ -418,11 +434,19 @@ __imlib_AllocColors121(Display *d, Colormap cmap, Visual *v)
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 =
(r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r
<<
2)
| (r << 1) | (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 =
(b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
<<
2)
| (b << 1) | (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);
@ -436,8 +460,8 @@ __imlib_AllocColors121(Display *d, Colormap cmap, Visual *v)
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);
@ -453,13 +477,14 @@ __imlib_AllocColors121(Display *d, Colormap cmap, Visual *v)
} }
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));
@ -474,11 +499,23 @@ __imlib_AllocColors111(Display *d, Colormap cmap, Visual *v)
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 =
(r << 7) | (r << 6) | (r << 5) | (r << 4) | (r << 3) | (r
<<
2)
| (r << 1) | (r);
xcl.red = (unsigned short)((val << 8) | (val)); xcl.red = (unsigned short)((val << 8) | (val));
val = (g << 7) | (g << 6) | (g << 5) | (g << 4) | (g << 3) | (g << 2) | (g << 1) | (g); val =
(g << 7) | (g << 6) | (g << 5) | (g << 4) | (g << 3) | (g
<<
2)
| (g << 1) | (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 =
(b << 7) | (b << 6) | (b << 5) | (b << 4) | (b << 3) | (b
<<
2)
| (b << 1) | (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);
@ -492,8 +529,8 @@ __imlib_AllocColors111(Display *d, Colormap cmap, Visual *v)
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);
@ -509,7 +546,7 @@ __imlib_AllocColors111(Display *d, Colormap cmap, Visual *v)
} }
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;

View File

@ -5,57 +5,76 @@
*/ */
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;
hue = hue / 60.0;
h = (int)hue; h = (int)hue;
vs = value * saturation; vs = value * saturation;
vsf = vs * (hue - h); vsf = vs * (hue - h);
@ -99,90 +118,117 @@ __imlib_hsv_to_rgb(float hue, float saturation, float value, int *r, int *g, int
} }
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)
*saturation = d / (max + min);
else
*saturation = d / (2 - max - min);
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_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;
if (h < 60)
*r = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*r = (int)(255.0 * m2); *r = (int)(255.0 * m2);
else if (h<240) else if (h < 240)
*r = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0)); *r = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else else
*r = (int)(255.0 * m1); *r = (int)(255.0 * m1);
h = hue; h = hue;
if (h>360) h -= 360; else if (h<0) h += 360; if (h > 360)
if (h<60) h -= 360;
*g = (int)(255.0 * (m1 + m21 * h/60.0)); else if (h < 0)
else if (h<180) h += 360;
if (h < 60)
*g = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*g = (int)(255.0 * m2); *g = (int)(255.0 * m2);
else if (h<240) else if (h < 240)
*g = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0)); *g = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else else
*g = (int)(255.0 * m1); *g = (int)(255.0 * 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;
*b = (int)(255.0 * (m1 + m21 * h/60.0)); else if (h < 0)
else if (h<180) h += 360;
if (h < 60)
*b = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*b = (int)(255.0 * m2); *b = (int)(255.0 * m2);
else if (h<240) else if (h < 240)
*b = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0)); *b = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else else
*b = (int)(255.0 * m1); *b = (int)(255.0 * m1);
} }

View File

@ -18,30 +18,30 @@ __imlib_CreateCmod(void)
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;
@ -60,23 +60,23 @@ __imlib_CmodSetTables(ImlibColorModifier *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;
@ -119,8 +119,8 @@ __imlib_DataCmodApply(DATA32 *data, int w, int h, int 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,7 +133,7 @@ __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;
@ -141,50 +141,74 @@ __imlib_CmodModBrightness(ImlibColorModifier *cm, double v)
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;
@ -193,26 +217,38 @@ __imlib_CmodModGamma(ImlibColorModifier *cm, double v)
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

@ -70,7 +70,7 @@ __imlib_FlushContexts(void)
} }
void void
__imlib_FreeContextForDisplay(Display *d) __imlib_FreeContextForDisplay(Display * d)
{ {
Context *ct; Context *ct;
@ -78,14 +78,14 @@ __imlib_FreeContextForDisplay(Display *d)
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;
@ -93,14 +93,14 @@ __imlib_FreeContextForColormap(Display *d, Colormap cm)
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;
@ -108,14 +108,14 @@ __imlib_FreeContextForVisual(Display *d, Visual *v)
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;
@ -141,7 +141,7 @@ __imlib_FindContext(Display *d, Visual *v, Colormap c, int depth)
} }
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;
@ -188,7 +188,7 @@ __imlib_NewContext(Display *d, Visual *v, Colormap c, int depth)
} }
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;

View File

@ -8,12 +8,11 @@
#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;
@ -33,7 +32,8 @@ __imlib_CreatePixmapsForImage(Display *d, Drawable w, Visual *v, int depth,
*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,
"[Imlib2] Match found in cache. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n",
ip->references, ip->pixmap, ip->mask); ip->references, ip->pixmap, ip->mask);
#endif #endif
return 2; return 2;
@ -50,8 +50,7 @@ __imlib_CreatePixmapsForImage(Display *d, Drawable w, Visual *v, int depth,
*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,
"[Imlib2] Created pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n",
ip->references, ip->pixmap, ip->mask); ip->references, ip->pixmap, ip->mask);
#endif #endif
return 1; return 1;
} }

View File

@ -16,7 +16,6 @@
#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;
@ -26,115 +25,120 @@ 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; FREESHOW;
free( list[i] ); free(list[i]);
} }
} }
FREESHOW; FREESHOW;
if( list ) if (list)
free( 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;
} }
@ -144,14 +148,15 @@ pImlibExternalFilter __imlib_get_dynamic_filter( char *name )
} }
/* 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);
@ -164,7 +169,9 @@ char **__imlib_ListFilters(int *num_ret)
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,
sizeof(SYS_LOADERS_PATH) + 8 + strlen(l[i]) +
1);
sprintf(s, SYS_LOADERS_PATH "/filter/%s", l[i]); sprintf(s, SYS_LOADERS_PATH "/filter/%s", l[i]);
#ifndef __EMX__ #ifndef __EMX__
list[pi + i] = strdup(s); list[pi + i] = strdup(s);

View File

@ -21,7 +21,8 @@ __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;
@ -45,8 +46,10 @@ __imlib_FileKey(const char *file)
} }
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;
} }
@ -56,7 +59,8 @@ __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;
@ -98,7 +102,8 @@ __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)
{ {
@ -118,10 +123,14 @@ __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);
@ -137,10 +146,14 @@ __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);
@ -161,10 +174,14 @@ __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);
@ -185,10 +202,14 @@ __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);
@ -204,9 +225,12 @@ __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);
@ -228,12 +252,12 @@ __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++);
@ -241,12 +265,12 @@ __imlib_FileDir(char *dir, int *num)
{ {
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;)
@ -282,7 +306,7 @@ __imlib_FileDir(char *dir, int *num)
} }
} }
} }
return(names); return (names);
} }
void void
@ -310,6 +334,7 @@ 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,10 +344,14 @@ __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);
@ -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,7 +382,7 @@ __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)
@ -360,7 +390,7 @@ __imlib_FileHomeDir(int uid)
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)
{ {
@ -485,4 +504,3 @@ __imlib_FileFieldWord(char *s, int num, char *wd)
} }
return; return;
} }

View File

@ -11,7 +11,8 @@ __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->alpha.pixels = malloc(size * sizeof(ImlibFilterPixel));
fil->red.pixels = malloc(size * sizeof(ImlibFilterPixel)); fil->red.pixels = malloc(size * sizeof(ImlibFilterPixel));
fil->green.pixels = malloc(size * sizeof(ImlibFilterPixel)); fil->green.pixels = malloc(size * sizeof(ImlibFilterPixel));
@ -20,7 +21,9 @@ __imlib_CreateFilter(int size)
fil->red.size = size; fil->red.size = size;
fil->green.size = size; fil->green.size = size;
fil->blue.size = size; fil->blue.size = size;
} else { }
else
{
fil->alpha.pixels = 0; fil->alpha.pixels = 0;
fil->red.pixels = 0; fil->red.pixels = 0;
fil->green.pixels = 0; fil->green.pixels = 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)) if ((pix[i].xoff == x) && (pix[i].yoff == y))
break; break;
} }
/*\ If all zero, remove the found entry \*/ /*\ If all zero, remove the found entry \ */
if (!(a | r | g | b)) { if (!(a | r | g | b))
if (i >= 0) { {
while (i < fil->entries) { if (i >= 0)
{
while (i < fil->entries)
{
pix[i] = pix[i + 1]; pix[i] = pix[i + 1];
} }
fil->entries--; fil->entries--;
} }
return; return;
} }
/*\ No match, then make a new entry \*/ /*\ No match, then make a new entry \ */
if (i < 0) i = fil->entries; if (i < 0)
if (i >= fil->size) { i = fil->entries;
if (i >= fil->size)
{
fil->size += 4; fil->size += 4;
pix = realloc(pix, (fil->size * sizeof(ImlibFilterPixel))); pix = realloc(pix, (fil->size * sizeof(ImlibFilterPixel)));
if (!pix) return; if (!pix)
return;
fil->pixels = pix; fil->pixels = pix;
} }
if (i >= fil->entries) fil->entries = i + 1; 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,15 +127,17 @@ __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; ret += pix->a + pix->r + pix->g + pix->b;
pix++; pix++;
} }
@ -132,7 +145,7 @@ __imlib_FilterCalcDiv(ImlibFilterColor *fil)
} }
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;
@ -141,14 +154,19 @@ __imlib_FilterGet(ImlibFilterColor *fil, DATA32 *data,
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; off = x + pix->xoff;
if (off < 0) off = 0; if (off < 0)
if (off >= w) off = w - 1; off = 0;
if (off >= w)
off = w - 1;
p = data + off; p = data + off;
off = y + pix->yoff; off = y + pix->yoff;
if (off < 0) off = 0; if (off < 0)
if (off >= h) off = h - 1; off = 0;
if (off >= h)
off = h - 1;
p += off * w; p += off * w;
ret += A_VAL(p) * pix->a + R_VAL(p) * pix->r + ret += A_VAL(p) * pix->a + R_VAL(p) * pix->r +
G_VAL(p) * pix->g + B_VAL(p) * pix->b; G_VAL(p) * pix->g + B_VAL(p) * pix->b;
@ -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,26 +199,36 @@ __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++) { {
for (x = 0; x < im->w; x++)
{
*p2 = *p1; *p2 = *p1;
if (ad) { if (ad)
a = __imlib_FilterGet(&fil->alpha, im->data, im->w, im->h, x, y); {
a = __imlib_FilterGet(&fil->alpha, im->data, im->w, im->h, x,
y);
a /= ad; a /= ad;
A_VAL(p2) = SATURATE(a); A_VAL(p2) = SATURATE(a);
} }
if (rd) { if (rd)
r = __imlib_FilterGet(&fil->red, im->data, im->w, im->h, x, y); {
r = __imlib_FilterGet(&fil->red, im->data, im->w, im->h, x,
y);
r /= rd; r /= rd;
R_VAL(p2) = SATURATE(r); R_VAL(p2) = SATURATE(r);
} }
if (gd) { if (gd)
g = __imlib_FilterGet(&fil->green, im->data, im->w, im->h, x, y); {
g = __imlib_FilterGet(&fil->green, im->data, im->w, im->h, x,
y);
g /= gd; g /= gd;
G_VAL(p2) = SATURATE(g); G_VAL(p2) = SATURATE(g);
} }
if (bd) { if (bd)
b = __imlib_FilterGet(&fil->blue, im->data, im->w, im->h, x, y); {
b = __imlib_FilterGet(&fil->blue, im->data, im->w, im->h, x,
y);
b /= bd; b /= bd;
B_VAL(p2) = SATURATE(b); B_VAL(p2) = SATURATE(b);
} }

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; struct _Imlib_Hash_El
{
Imlib_Object_List _list_data;
char *key;
void *data;
};
struct _Imlib_Font
{
Imlib_Object_List _list_data;
char *name;
char *file;
int size; int size;
ImlibTTFHashElm **hash;
int mem_use;
};
#endif
struct _imlib_font_header struct
{ {
int type; FT_Face face;
}
ft;
ImlibFont *next; Imlib_Hash *glyphs;
char *name;
int references;
};
struct _imlib_ttffont int usage;
{
int type;
ImlibFont *next;
char *name;
int references; 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

View File

@ -19,10 +19,9 @@ Tmp_HandleXError(Display * d, XErrorEvent * ev)
} }
void void
__imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh, __imlib_GrabXImageToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
Display *d, XImage *xim, XImage *mxim, Visual *v, Display * d, XImage * xim, XImage * mxim, Visual * v,
int depth, int x, int y, int depth, int x, int y, int w, int h, char grab)
int w, int h, char grab)
{ {
int inx, iny; int inx, iny;
DATA32 *src, *ptr; DATA32 *src, *ptr;
@ -30,13 +29,16 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
int origx, origy; int origx, origy;
int bgr = 0; int bgr = 0;
if (!data) return; if (!data)
return;
if (grab) XGrabServer(d); /* This may prevent the image to be changed under our feet */ if (grab)
XGrabServer(d); /* This may prevent the image to be changed under our feet */
origx = x; origx = x;
origy = y; origy = y;
if (v->blue_mask > v->red_mask) bgr = 1; if (v->blue_mask > v->red_mask)
bgr = 1;
if (origx < 0) if (origx < 0)
inx = -origx; inx = -origx;
@ -47,8 +49,10 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
else else
iny = oy; iny = oy;
/* go thru the XImage and convert */ /* go thru the XImage and convert */
if (xim->bits_per_pixel == 32) depth = 32; if (xim->bits_per_pixel == 32)
switch (depth) { depth = 32;
switch (depth)
{
case 0: case 0:
case 1: case 1:
case 2: case 2:
@ -58,10 +62,13 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
case 6: case 6:
case 7: case 7:
case 8: case 8:
if (mxim) { if (mxim)
for (y = 0; y < h; y++) { {
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
mpixel = XGetPixel(mxim, x, y); mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) | *ptr++ = (0xff000000 >> (mpixel << 31)) |
@ -72,10 +79,13 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
} }
else { else
for (y = 0; y < h; y++) { {
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
*ptr++ = 0xff000000 | *ptr++ = 0xff000000 |
(btab[pixel & 0xff]) | (btab[pixel & 0xff]) |
@ -110,11 +120,14 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
#define B2SH(p) ((p) >> 13) #define B2SH(p) ((p) >> 13)
#define P1(p) (R1SH(p) & RMSK) | (G1SH(p) & GMSK) | (B1SH(p) & BMSK) #define P1(p) (R1SH(p) & RMSK) | (G1SH(p) & GMSK) | (B1SH(p) & BMSK)
#define P2(p) (R2SH(p) & RMSK) | (G2SH(p) & GMSK) | (B2SH(p) & BMSK) #define P2(p) (R2SH(p) & RMSK) | (G2SH(p) & GMSK) | (B2SH(p) & BMSK)
if (mxim) { if (mxim)
for (y = 0; y < h; y++) { {
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); for (y = 0; y < h; y++)
{
src = (DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < (w - 1); x += 2) { for (x = 0; x < (w - 1); x += 2)
{
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*ptr++ = MP(x + 1, y) | P2(*src); *ptr++ = MP(x + 1, y) | P2(*src);
*ptr++ = MP(x, y) | P1(*src); *ptr++ = MP(x, y) | P1(*src);
@ -124,7 +137,8 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
#endif #endif
src++; src++;
} }
if (x == (w - 1)) { if (x == (w - 1))
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
*ptr++ = MP(x, y) | P1(pixel); *ptr++ = MP(x, y) | P1(pixel);
} }
@ -132,11 +146,14 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
#undef MP #undef MP
#define MP(x, y) (0xff000000) #define MP(x, y) (0xff000000)
else { else
for (y = 0; y < h; y++) { {
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); for (y = 0; y < h; y++)
{
src = (DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < (w - 1); x += 2) { for (x = 0; x < (w - 1); x += 2)
{
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*ptr++ = MP(x + 1, y) | P2(*src); *ptr++ = MP(x + 1, y) | P2(*src);
*ptr++ = MP(x, y) | P1(*src); *ptr++ = MP(x, y) | P1(*src);
@ -146,7 +163,8 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
#endif #endif
src++; src++;
} }
if (x == (w - 1)) { if (x == (w - 1))
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
*ptr++ = MP(x, y) | P1(pixel); *ptr++ = MP(x, y) | P1(pixel);
} }
@ -178,11 +196,14 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
#define B2SH(p) ((p) >> 13) #define B2SH(p) ((p) >> 13)
#define P1(p) (R1SH(p) & RMSK) | (G1SH(p) & GMSK) | (B1SH(p) & BMSK) #define P1(p) (R1SH(p) & RMSK) | (G1SH(p) & GMSK) | (B1SH(p) & BMSK)
#define P2(p) (R2SH(p) & RMSK) | (G2SH(p) & GMSK) | (B2SH(p) & BMSK) #define P2(p) (R2SH(p) & RMSK) | (G2SH(p) & GMSK) | (B2SH(p) & BMSK)
if (mxim) { if (mxim)
for (y = 0; y < h; y++) { {
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); for (y = 0; y < h; y++)
{
src = (DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < (w - 1); x += 2) { for (x = 0; x < (w - 1); x += 2)
{
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*ptr++ = MP(x + 1, y) | P2(*src); *ptr++ = MP(x + 1, y) | P2(*src);
*ptr++ = MP(x, y) | P1(*src); *ptr++ = MP(x, y) | P1(*src);
@ -192,7 +213,8 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
#endif #endif
src++; src++;
} }
if (x == (w - 1)) { if (x == (w - 1))
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
*ptr++ = MP(x, y) | P1(pixel); *ptr++ = MP(x, y) | P1(pixel);
} }
@ -200,11 +222,14 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
#undef MP #undef MP
#define MP(x, y) (0xff000000) #define MP(x, y) (0xff000000)
else { else
for (y = 0; y < h; y++) { {
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); for (y = 0; y < h; y++)
{
src = (DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < (w - 1); x += 2) { for (x = 0; x < (w - 1); x += 2)
{
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*ptr++ = MP(x + 1, y) | P2(*src); *ptr++ = MP(x + 1, y) | P2(*src);
*ptr++ = MP(x, y) | P1(*src); *ptr++ = MP(x, y) | P1(*src);
@ -214,7 +239,8 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
#endif #endif
src++; src++;
} }
if (x == (w - 1)) { if (x == (w - 1))
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
*ptr++ = MP(x, y) | P1(pixel); *ptr++ = MP(x, y) | P1(pixel);
} }
@ -222,11 +248,15 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
break; break;
case 24: case 24:
if (bgr) { if (bgr)
if (mxim) { {
for (y = 0; y < h; y++) { if (mxim)
{
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
pixel = pixel =
((pixel << 16) & 0xff0000) | ((pixel << 16) & 0xff0000) |
@ -238,10 +268,13 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
} }
else { else
for (y = 0; y < h; y++) { {
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
*ptr++ = 0xff000000 | *ptr++ = 0xff000000 |
((pixel << 16) & 0xff0000) | ((pixel << 16) & 0xff0000) |
@ -251,11 +284,15 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
} }
else { else
if (mxim) { {
for (y = 0; y < h; y++) { if (mxim)
{
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
mpixel = XGetPixel(mxim, x, y); mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) | *ptr++ = (0xff000000 >> (mpixel << 31)) |
@ -263,25 +300,32 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
} }
else { else
for (y = 0; y < h; y++) { {
for (y = 0; y < h; y++)
{
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
pixel = XGetPixel(xim, x, y); pixel = XGetPixel(xim, x, y);
*ptr++ = 0xff000000 | *ptr++ = 0xff000000 | (pixel & 0x00ffffff);
(pixel & 0x00ffffff);
} }
} }
} }
} }
break; break;
case 32: case 32:
if (bgr) { if (bgr)
if (mxim) { {
for (y = 0; y < h; y++) { if (mxim)
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); {
for (y = 0; y < h; y++)
{
src =
(DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
mpixel = XGetPixel(mxim, x, y); mpixel = XGetPixel(mxim, x, y);
pixel = pixel =
((*src << 16) & 0xff0000) | ((*src << 16) & 0xff0000) |
@ -293,11 +337,15 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
} }
else { else
for (y = 0; y < h; y++) { {
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); for (y = 0; y < h; y++)
{
src =
(DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
*ptr++ = 0xff000000 | *ptr++ = 0xff000000 |
((*src << 16) & 0xff0000) | ((*src << 16) & 0xff0000) |
((*src) & 0x00ff00) | ((*src) & 0x00ff00) |
@ -307,12 +355,17 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
} }
else { else
if (mxim) { {
for (y = 0; y < h; y++) { if (mxim)
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); {
for (y = 0; y < h; y++)
{
src =
(DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
{
mpixel = XGetPixel(mxim, x, y); mpixel = XGetPixel(mxim, x, y);
*ptr++ = (0xff000000 >> (mpixel << 31)) | *ptr++ = (0xff000000 >> (mpixel << 31)) |
((*src) & 0x00ffffff); ((*src) & 0x00ffffff);
@ -320,13 +373,16 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
} }
else { else
for (y = 0; y < h; y++) { {
src = (DATA32 *)(xim->data + (xim->bytes_per_line * y)); for (y = 0; y < h; y++)
{
src =
(DATA32 *) (xim->data + (xim->bytes_per_line * y));
ptr = data + ((y + iny) * ow) + inx; ptr = data + ((y + iny) * ow) + inx;
for (x = 0; x < w; x++) { for (x = 0; x < w; x++)
*ptr++ = 0xff000000 | {
((*src) & 0x00ffffff); *ptr++ = 0xff000000 | ((*src) & 0x00ffffff);
src++; src++;
} }
} }
@ -340,8 +396,8 @@ __imlib_GrabXImageToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
char char
__imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh, __imlib_GrabDrawableToRGBA(DATA32 * data, int ox, int oy, int ow, int oh,
Display *d, Drawable p, Pixmap m, Visual *v, Display * d, Drawable p, Pixmap m, Visual * v,
Colormap cm, int depth, int x, int y, Colormap cm, int depth, int x, int y,
int w, int h, char domask, char grab) int w, int h, char domask, char grab)
{ {
@ -384,12 +440,12 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
else else
{ {
Window dw; Window dw;
XGetWindowAttributes(d, xatt.root, &ratt); XGetWindowAttributes(d, xatt.root, &ratt);
XTranslateCoordinates(d, p, xatt.root, 0, 0, &src_x, &src_y, &dw); XTranslateCoordinates(d, p, xatt.root, 0, 0, &src_x, &src_y, &dw);
src_w = xatt.width; src_w = xatt.width;
src_h = xatt.height; src_h = xatt.height;
if ((xatt.map_state != IsViewable) && if ((xatt.map_state != IsViewable) && (xatt.backing_store == NotUseful))
(xatt.backing_store == NotUseful))
{ {
if (grab) if (grab)
XUngrabServer(d); XUngrabServer(d);
@ -491,19 +547,16 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
_x_err = 0; _x_err = 0;
if (x_does_shm) if (x_does_shm)
{ {
xim = XShmCreateImage(d, v, xatt.depth, ZPixmap, NULL, xim = XShmCreateImage(d, v, xatt.depth, ZPixmap, NULL, &shminfo, w, h);
&shminfo, w, h);
if (!xim) if (!xim)
xim = XGetImage(d, p, x, y, w, h, xim = XGetImage(d, p, x, y, w, h, 0xffffffff, ZPixmap);
0xffffffff, ZPixmap);
else else
{ {
XSync(d, False); XSync(d, False);
if (_x_err) if (_x_err)
{ {
XDestroyImage(xim); XDestroyImage(xim);
xim = XGetImage(d, p, x, y, w, h, xim = XGetImage(d, p, x, y, w, h, 0xffffffff, ZPixmap);
0xffffffff, ZPixmap);
_x_err = 0; _x_err = 0;
} }
else else
@ -513,8 +566,7 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
if (shminfo.shmid < 0) if (shminfo.shmid < 0)
{ {
XDestroyImage(xim); XDestroyImage(xim);
xim = XGetImage(d, p, x, y, w, h, xim = XGetImage(d, p, x, y, w, h, 0xffffffff, ZPixmap);
0xffffffff, ZPixmap);
} }
else else
{ {
@ -547,8 +599,7 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
shmdt(shminfo.shmaddr); shmdt(shminfo.shmaddr);
shmctl(shminfo.shmid, IPC_RMID, 0); shmctl(shminfo.shmid, IPC_RMID, 0);
XDestroyImage(xim); XDestroyImage(xim);
xim = XGetImage(d, p, x, y, w, h, xim = XGetImage(d, p, x, y, w, h, 0xffffffff, ZPixmap);
0xffffffff, ZPixmap);
is_shm = 0; is_shm = 0;
} }
} }
@ -560,19 +611,16 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
_x_err = 0; _x_err = 0;
if (x_does_shm) if (x_does_shm)
{ {
mxim = XShmCreateImage(d, v, 1, ZPixmap, NULL, mxim = XShmCreateImage(d, v, 1, ZPixmap, NULL, &mshminfo, w, h);
&mshminfo, w, h);
if (!mxim) if (!mxim)
mxim = XGetImage(d, p, 0, 0, w, h, mxim = XGetImage(d, p, 0, 0, w, h, 0xffffffff, ZPixmap);
0xffffffff, ZPixmap);
else else
{ {
XSync(d, False); XSync(d, False);
if (_x_err) if (_x_err)
{ {
XDestroyImage(mxim); XDestroyImage(mxim);
xim = XGetImage(d, p, 0, 0, w, h, xim = XGetImage(d, p, 0, 0, w, h, 0xffffffff, ZPixmap);
0xffffffff, ZPixmap);
_x_err = 0; _x_err = 0;
} }
else else
@ -618,8 +666,7 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
shmdt(mshminfo.shmaddr); shmdt(mshminfo.shmaddr);
shmctl(mshminfo.shmid, IPC_RMID, 0); shmctl(mshminfo.shmid, IPC_RMID, 0);
XDestroyImage(mxim); XDestroyImage(mxim);
mxim = XGetImage(d, p, 0, 0, w, h, mxim = XGetImage(d, p, 0, 0, w, h, 0xffffffff, ZPixmap);
0xffffffff, ZPixmap);
is_mshm = 0; is_mshm = 0;
} }
XSetErrorHandler((XErrorHandler) prev_erh); XSetErrorHandler((XErrorHandler) prev_erh);
@ -669,9 +716,7 @@ __imlib_GrabDrawableToRGBA(DATA32 *data, int ox, int oy, int ow, int oh,
} }
} }
__imlib_GrabXImageToRGBA(data, ox, oy, ow, oh, __imlib_GrabXImageToRGBA(data, ox, oy, ow, oh,
d, xim, mxim, v, d, xim, mxim, v, depth, x, y, w, h, 0);
depth, x, y,
w, h, 0);
/* destroy the Ximage */ /* destroy the Ximage */
if (is_shm) if (is_shm)

View File

@ -19,12 +19,12 @@ __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;
@ -34,7 +34,7 @@ __imlib_FreeRange(ImlibRange *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;
@ -72,7 +72,7 @@ __imlib_AddRangeColor(ImlibRange *rg, DATA8 r, DATA8 g, DATA8 b, DATA8 a,
} }
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;
@ -123,12 +123,12 @@ __imlib_MapRange(ImlibRange *rg, int len)
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;
@ -143,7 +143,7 @@ __imlib_MapRange(ImlibRange *rg, int len)
} }
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;
@ -168,16 +168,20 @@ __imlib_MapHsvaRange(ImlibRange *rg, int len)
{ {
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;
gg = p->next->green;
b = p->blue;
bb = p->next->blue;
__imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1); __imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1);
__imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2); __imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2);
h = ((h1 * k2) + (h2 * k1)) / 65536.0; h = ((h1 * k2) + (h2 * k1)) / 65536.0;
s = ((s1 * k2) + (s2 * k1)) / 65536.0; s = ((s1 * k2) + (s2 * k1)) / 65536.0;
v = ((v1 * k2) + (v2 * k1)) / 65536.0; v = ((v1 * k2) + (v2 * k1)) / 65536.0;
__imlib_hsv_to_rgb(h, s, v, &r, &g, &b); __imlib_hsv_to_rgb(h, s, v, &r, &g, &b);
a = (unsigned long int)((p->alpha * k2) + (p->next->alpha * k1)) >> 16; a = (unsigned long int)((p->alpha * k2) +
(p->next->alpha * k1)) >> 16;
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b; pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
} }
} }
@ -201,12 +205,12 @@ __imlib_MapHsvaRange(ImlibRange *rg, int len)
kk = pmap[(l >> 16)]; kk = pmap[(l >> 16)];
k1 = l - (float)((l >> 16) << 16); k1 = l - (float)((l >> 16) << 16);
k2 = 65536 - k1; k2 = 65536 - k1;
b = ((k) ) & 0xff; b = ((k)) & 0xff;
g = ((k) >> 8 ) & 0xff; g = ((k) >> 8) & 0xff;
r = ((k) >> 16) & 0xff; r = ((k) >> 16) & 0xff;
a = ((k) >> 24) & 0xff; a = ((k) >> 24) & 0xff;
bb = ((kk) ) & 0xff; bb = ((kk)) & 0xff;
gg = ((kk) >> 8 ) & 0xff; gg = ((kk) >> 8) & 0xff;
rr = ((kk) >> 16) & 0xff; rr = ((kk) >> 16) & 0xff;
aa = ((kk) >> 24) & 0xff; aa = ((kk) >> 24) & 0xff;
__imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1); __imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1);
@ -224,12 +228,13 @@ __imlib_MapHsvaRange(ImlibRange *rg, int len)
} }
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 =
0, ww, hh, jump;
int tmp, i, divw, divh; int tmp, i, divw, divh;
DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na; DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na;
@ -267,7 +272,8 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int 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))
return;
xoff += (x - px); xoff += (x - px);
yoff += (y - py); yoff += (y - py);
} }
@ -279,14 +285,17 @@ __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++)
@ -412,12 +421,13 @@ __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 =
0, ww, hh, jump;
int tmp, i, divw, divh; int tmp, i, divw, divh;
DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na; DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na;
@ -455,7 +465,8 @@ __imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int 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))
return;
xoff += (x - px); xoff += (x - px);
yoff += (y - py); yoff += (y - py);
} }
@ -467,14 +478,17 @@ __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++)
@ -598,4 +612,3 @@ __imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int h,
free(hlut); free(hlut);
free(map); free(map);
} }

View File

@ -14,6 +14,7 @@
#include "loaderpath.h" #include "loaderpath.h"
static ImlibImage *images = NULL; static ImlibImage *images = NULL;
#ifndef X_DISPLAY_MISSING #ifndef X_DISPLAY_MISSING
static ImlibImagePixmap *pixmaps = NULL; static ImlibImagePixmap *pixmaps = NULL;
#endif #endif
@ -158,7 +159,7 @@ void
__imlib_ConsumeImage(ImlibImage * im) __imlib_ConsumeImage(ImlibImage * im)
{ {
#ifndef X_DISPLAY_MISSING #ifndef X_DISPLAY_MISSING
ImlibImagePixmap *ip; ImlibImagePixmap *ip;
#endif #endif
__imlib_FreeAllTags(im); __imlib_FreeAllTags(im);
@ -253,6 +254,7 @@ int
__imlib_CurrentCacheSize(void) __imlib_CurrentCacheSize(void)
{ {
ImlibImage *im; ImlibImage *im;
#ifndef X_DISPLAY_MISSING #ifndef X_DISPLAY_MISSING
ImlibImagePixmap *ip; ImlibImagePixmap *ip;
#endif #endif
@ -302,8 +304,7 @@ __imlib_CurrentCacheSize(void)
if (ip->references == 0) if (ip->references == 0)
{ {
/* if the image is invalid */ /* if the image is invalid */
if ((ip->dirty) || if ((ip->dirty) || ((ip->image) && (!(IMAGE_IS_VALID(ip->image)))))
((ip->image) && (!(IMAGE_IS_VALID(ip->image)))))
{ {
ImlibImagePixmap *tmp_ip; ImlibImagePixmap *tmp_ip;
@ -414,7 +415,8 @@ __imlib_ConsumeImagePixmap(ImlibImagePixmap * ip)
XFreePixmap(ip->display, ip->pixmap); XFreePixmap(ip->display, ip->pixmap);
if (ip->mask) if (ip->mask)
XFreePixmap(ip->display, ip->mask); XFreePixmap(ip->display, ip->mask);
if (ip->file) free(ip->file); if (ip->file)
free(ip->file);
free(ip); free(ip);
} }
@ -444,8 +446,7 @@ __imlib_FindCachedImagePixmap(ImlibImage * im, int w, int h, Display * d,
&& (ip->border.top == im->border.top) && (ip->border.top == im->border.top)
&& (ip->border.bottom == im->border.bottom) && && (ip->border.bottom == im->border.bottom) &&
(((im->file) && (ip->file) && !strcmp(im->file, ip->file)) || (((im->file) && (ip->file) && !strcmp(im->file, ip->file)) ||
((!im->file) && (!ip->file) && (im == ip->image))) ((!im->file) && (!ip->file) && (im == ip->image))))
)
{ {
/* move the pixmap to the head of the pixmap list */ /* move the pixmap to the head of the pixmap list */
if (previous_ip) if (previous_ip)
@ -634,7 +635,7 @@ __imlib_ListLoaders(int *num_ret)
*num_ret = 0; *num_ret = 0;
/* same for system loader path */ /* same for system loader path */
s = (char *) malloc(sizeof(SYS_LOADERS_PATH) + 6 + 1); s = (char *)malloc(sizeof(SYS_LOADERS_PATH) + 6 + 1);
sprintf(s, SYS_LOADERS_PATH "/image"); sprintf(s, SYS_LOADERS_PATH "/image");
#ifndef __EMX__ #ifndef __EMX__
l = __imlib_FileDir(s, &num); l = __imlib_FileDir(s, &num);
@ -648,7 +649,9 @@ __imlib_ListLoaders(int *num_ret)
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
s = (char *) realloc(s, sizeof(SYS_LOADERS_PATH) + 7 + strlen(l[i]) + 1); s = (char *)realloc(s,
sizeof(SYS_LOADERS_PATH) + 7 + strlen(l[i]) +
1);
sprintf(s, SYS_LOADERS_PATH "/image/%s", l[i]); sprintf(s, SYS_LOADERS_PATH "/image/%s", l[i]);
#ifndef __EMX__ #ifndef __EMX__
list[pi + i] = strdup(s); list[pi + i] = strdup(s);
@ -988,8 +991,10 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress,
ImlibLoader *best_loader; ImlibLoader *best_loader;
char loader_ret = 0; char loader_ret = 0;
if (!file) return NULL; if (!file)
if (file[0] == 0) return NULL; return NULL;
if (file[0] == 0)
return NULL;
/* see if we alreayd have the image cached */ /* see if we alreayd have the image cached */
im = __imlib_FindCachedImage(file); im = __imlib_FindCachedImage(file);
/* if we found a cached image and we shoudl always check that it is */ /* if we found a cached image and we shoudl always check that it is */
@ -1026,7 +1031,7 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress,
/* so produce a new one and load an image into that */ /* so produce a new one and load an image into that */
im = __imlib_ProduceImage(); im = __imlib_ProduceImage();
im->file = strdup(file); im->file = strdup(file);
if(__imlib_IsRealFile(file)) if (__imlib_IsRealFile(file))
{ {
im->real_file = strdup(im->file); im->real_file = strdup(im->file);
im->key = NULL; im->key = NULL;
@ -1044,8 +1049,7 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress,
errno = 0; errno = 0;
if (best_loader) if (best_loader)
loader_ret = loader_ret =
best_loader->load(im, progress, progress_granularity, best_loader->load(im, progress, progress_granularity, immediate_load);
immediate_load);
/* width is still 0 - the loader didnt manage to do anything */ /* width is still 0 - the loader didnt manage to do anything */
if (im->w == 0) if (im->w == 0)
{ {
@ -1077,7 +1081,8 @@ __imlib_LoadImage(const char *file, ImlibProgressFunction progress,
l->next = loaders; l->next = loaders;
loaders = l; loaders = l;
} }
if (im->w > 0) im->loader = l; if (im->w > 0)
im->loader = l;
} }
else else
im->loader = best_loader; im->loader = best_loader;
@ -1192,7 +1197,6 @@ __imlib_FreeImage(ImlibImage * im)
} }
} }
#ifndef X_DISPLAY_MISSING #ifndef X_DISPLAY_MISSING
/* free a cached pixmap */ /* free a cached pixmap */
void void

View File

@ -18,14 +18,16 @@
#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)
{ {
@ -33,43 +35,36 @@ __imlib_RenderGetPixel(Display *d, Drawable w, Visual *v, Colormap cm, int depth
{ {
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) | ((g >> 3) & 0x1b) | ((b >> 6) & 0x02)];
((b >> 6) & 0x02)];
break; break;
case 2: /* 222 */ case 2: /* 222 */
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 3: /* 221 */ case 3: /* 221 */
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 4: /* 121 */ case 4: /* 121 */
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 5: /* 111 */ 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 6: /* 1 */
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 7: /* 666 */ case 7: /* 666 */
return ct->palette[((int)(((double)r / 255) * 5.0) * 36) + return ct->palette[((int)(((double)r / 255) * 5.0) * 36) +
((int)(((double)g / 255) * 5.0) * 6 ) + ((int)(((double)g / 255) * 5.0) * 6) +
((int)(((double)b / 255) * 5.0) )]; ((int)(((double)b / 255) * 5.0))];
break; break;
default: default:
return 0; return 0;
@ -87,20 +82,17 @@ __imlib_RenderGetPixel(Display *d, Drawable w, Visual *v, Colormap cm, int depth
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) | ((g << 8) & 0x00ff00) | ((r) & 0x0000ff));
((r ) & 0x0000ff));
} }
if ((rm == 0x7c00) && (gm == 0x3e0) && (bm == 0x1f)) /* 555 */ if ((rm == 0x7c00) && (gm == 0x3e0) && (bm == 0x1f)) /* 555 */
{ {
return (((r << 7) & 0x7c00) | return (((r << 7) & 0x7c00) |
((g << 2) & 0x03e0) | ((g << 2) & 0x03e0) | ((b >> 3) & 0x001f));
((b >> 3) & 0x001f));
} }
for (i = 31; i >= 0; i--) for (i = 31; i >= 0; i--)
{ {
@ -126,38 +118,44 @@ __imlib_RenderGetPixel(Display *d, Drawable w, Visual *v, Colormap cm, int depth
break; break;
} }
} }
if (rshift >= 0) val = ((r << rshift) & rm); if (rshift >= 0)
else val = ((r >> (-rshift)) & rm); val = ((r << rshift) & rm);
if (gshift >= 0) val |= ((g << gshift) & gm); else
else val |= ((g >> (-gshift)) & gm); val = ((r >> (-rshift)) & rm);
if (bshift >= 0) val |= ((b << bshift) & bm); if (gshift >= 0)
else val |= ((b >> (-bshift)) & bm); val |= ((g << gshift) & gm);
else
val |= ((g >> (-gshift)) & gm);
if (bshift >= 0)
val |= ((b << bshift) & bm);
else
val |= ((b >> (-bshift)) & bm);
return val; 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)
@ -171,8 +169,10 @@ __imlib_generic_render(DATA32 *src, int jump, int w, int h, int dx, int dy,
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];
else
val = ct->palette[0];
XPutPixel(xim, x, y, val); XPutPixel(xim, x, y, val);
src++; src++;
} }
@ -236,13 +236,13 @@ __imlib_generic_render(DATA32 *src, int jump, int w, int h, int dx, int dy,
} }
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;
@ -301,10 +301,12 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
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)
@ -312,8 +314,9 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
__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); free(back);
back = NULL; back = NULL;
@ -324,7 +327,8 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
if (!xim) if (!xim)
{ {
__imlib_FreeScaleInfo(scaleinfo); __imlib_FreeScaleInfo(scaleinfo);
if (back) free(back); if (back)
free(back);
return; return;
} }
/* do a double check in 24/32bpp */ /* do a double check in 24/32bpp */
@ -337,7 +341,8 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
{ {
__imlib_ConsumeXImage(d, xim); __imlib_ConsumeXImage(d, xim);
__imlib_FreeScaleInfo(scaleinfo); __imlib_FreeScaleInfo(scaleinfo);
if (back) free(back); if (back)
free(back);
return; return;
} }
memset(mxim->data, 0, mxim->bytes_per_line * mxim->height); memset(mxim->data, 0, mxim->bytes_per_line * mxim->height);
@ -353,18 +358,20 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
if (m) if (m)
__imlib_ConsumeXImage(d, mxim); __imlib_ConsumeXImage(d, mxim);
__imlib_FreeScaleInfo(scaleinfo); __imlib_FreeScaleInfo(scaleinfo);
if (back) free(back); if (back)
free(back);
return; 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
@ -398,8 +405,7 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
} }
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)
@ -417,7 +423,8 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
if (m) if (m)
__imlib_ConsumeXImage(d, mxim); __imlib_ConsumeXImage(d, mxim);
__imlib_FreeScaleInfo(scaleinfo); __imlib_FreeScaleInfo(scaleinfo);
if (back) free(back); if (back)
free(back);
return; return;
} }
memcpy(buf, im->data + ((y + sy) * im->w) + sx, memcpy(buf, im->data + ((y + sy) * im->w) + sx,
@ -442,25 +449,30 @@ __imlib_RenderImage(Display *d, ImlibImage *im,
/* 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);
if (gcm)
XFreeGC(disp, gcm);
gc = 0; gc = 0;
gcm = 0; gcm = 0;
} }
@ -503,12 +515,12 @@ __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;
@ -518,32 +530,46 @@ __imlib_RenderImageSkewed(Display *d, ImlibImage *im, Drawable w, Drawable m,
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;
else
dy2 += hsy;
tsx = vsx;
tsy = vsy;
if (!tsx && !tsy)
{
tsy = (hsx * im->h) / im->w; tsy = (hsx * im->h) / im->w;
tsx = -(hsy * im->h) / im->w; tsx = -(hsy * im->h) / im->w;
} }
if (tsx < 0) dx1 += tsx; if (tsx < 0)
else dx2 += tsx; dx1 += tsx;
if (tsy < 0) dy1 += tsy; else
else dy2 += tsy; 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; dw += dx1;
dx1 = 0; dx1 = 0;
} }
if (dy1 < 0) { if (dy1 < 0)
{
dh += dy1; dh += dy1;
dy1 = 0; dy1 = 0;
} }

1760
src/rgba.c

File diff suppressed because it is too large Load Diff

View File

@ -274,26 +274,26 @@ __imlib_SharpenImage(ImlibImage * im, int rad)
p2 = data + 1 + (y * im->w); p2 = data + 1 + (y * im->w);
for (x = 1; x < (im->w - 1); x++) for (x = 1; x < (im->w - 1); x++)
{ {
b = (int) ((p1[0]) & 0xff) * 5; b = (int)((p1[0]) & 0xff) * 5;
g = (int) ((p1[0] >> 8) & 0xff) * 5; g = (int)((p1[0] >> 8) & 0xff) * 5;
r = (int) ((p1[0] >> 16) & 0xff) * 5; r = (int)((p1[0] >> 16) & 0xff) * 5;
a = (int) ((p1[0] >> 24) & 0xff) * 5; a = (int)((p1[0] >> 24) & 0xff) * 5;
b -= (int) ((p1[-1]) & 0xff); b -= (int)((p1[-1]) & 0xff);
g -= (int) ((p1[-1] >> 8) & 0xff); g -= (int)((p1[-1] >> 8) & 0xff);
r -= (int) ((p1[-1] >> 16) & 0xff); r -= (int)((p1[-1] >> 16) & 0xff);
a -= (int) ((p1[-1] >> 24) & 0xff); a -= (int)((p1[-1] >> 24) & 0xff);
b -= (int) ((p1[1]) & 0xff); b -= (int)((p1[1]) & 0xff);
g -= (int) ((p1[1] >> 8) & 0xff); g -= (int)((p1[1] >> 8) & 0xff);
r -= (int) ((p1[1] >> 16) & 0xff); r -= (int)((p1[1] >> 16) & 0xff);
a -= (int) ((p1[1] >> 24) & 0xff); a -= (int)((p1[1] >> 24) & 0xff);
b -= (int) ((p1[-im->w]) & 0xff); b -= (int)((p1[-im->w]) & 0xff);
g -= (int) ((p1[-im->w] >> 8) & 0xff); g -= (int)((p1[-im->w] >> 8) & 0xff);
r -= (int) ((p1[-im->w] >> 16) & 0xff); r -= (int)((p1[-im->w] >> 16) & 0xff);
a -= (int) ((p1[-im->w] >> 24) & 0xff); a -= (int)((p1[-im->w] >> 24) & 0xff);
b -= (int) ((p1[im->w]) & 0xff); b -= (int)((p1[im->w]) & 0xff);
g -= (int) ((p1[im->w] >> 8) & 0xff); g -= (int)((p1[im->w] >> 8) & 0xff);
r -= (int) ((p1[im->w] >> 16) & 0xff); r -= (int)((p1[im->w] >> 16) & 0xff);
a -= (int) ((p1[im->w] >> 24) & 0xff); a -= (int)((p1[im->w] >> 24) & 0xff);
a = (a & ((~a) >> 16)); a = (a & ((~a) >> 16));
a = ((a | ((a & 256) - ((a & 256) >> 8)))); a = ((a | ((a & 256) - ((a & 256) >> 8))));
@ -318,7 +318,8 @@ void
__imlib_TileImageHoriz(ImlibImage * im) __imlib_TileImageHoriz(ImlibImage * im)
{ {
DATA32 *p1, *p2, *p3, *p, *data; DATA32 *p1, *p2, *p3, *p, *data;
int x, y, per, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr, gg, bb; int x, y, per, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr,
gg, bb;
data = malloc(im->w * im->h * sizeof(DATA32)); data = malloc(im->w * im->h * sizeof(DATA32));
p1 = im->data; p1 = im->data;
@ -391,7 +392,8 @@ void
__imlib_TileImageVert(ImlibImage * im) __imlib_TileImageVert(ImlibImage * im)
{ {
DATA32 *p1, *p2, *p, *data; DATA32 *p1, *p2, *p, *data;
int x, y, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr, gg, bb; int x, y, tmp, na, nr, ng, nb, mix, a, r, g, b, aa, rr, gg,
bb;
data = malloc(im->w * im->h * sizeof(DATA32)); data = malloc(im->w * im->h * sizeof(DATA32));
p = data; p = data;
@ -1231,10 +1233,8 @@ __imlib_draw_box(ImlibImage * im, int x, int y, int w, int h, DATA8 r,
{ {
__imlib_draw_line(im, x, y, x + w - 1, y, r, g, b, a, op, 0); __imlib_draw_line(im, x, y, x + w - 1, y, r, g, b, a, op, 0);
__imlib_draw_line(im, x, y, x, y + h - 1, r, g, b, a, op, 0); __imlib_draw_line(im, x, y, x, y + h - 1, r, g, b, a, op, 0);
__imlib_draw_line(im, x, y + h - 1, x + w - 1, y + h - 1, r, g, b, a, op, __imlib_draw_line(im, x, y + h - 1, x + w - 1, y + h - 1, r, g, b, a, op, 0);
0); __imlib_draw_line(im, x + w - 1, y, x + w - 1, y + h - 1, r, g, b, a, op, 0);
__imlib_draw_line(im, x + w - 1, y, x + w - 1, y + h - 1, r, g, b, a, op,
0);
} }
void void
@ -1682,35 +1682,37 @@ imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
outcode_out = outcode0 ? outcode0 : outcode1; outcode_out = outcode0 ? outcode0 : outcode1;
if (outcode_out & TOP) if (outcode_out & TOP)
{ {
x = dx0 + (dx1 - dx0) * ((double) ymax - dy0) / (dy1 - dy0); x = dx0 + (dx1 - dx0) * ((double)ymax - dy0) / (dy1 - dy0);
y = ymax; y = ymax;
} }
else if (outcode_out & BOTTOM) else if (outcode_out & BOTTOM)
{ {
x = dx0 + (dx1 - dx0) * ((double) ymin - dy0) / (dy1 - dy0); x = dx0 + (dx1 - dx0) * ((double)ymin - dy0) / (dy1 - dy0);
y = ymin; y = ymin;
} }
else if (outcode_out & RIGHT) else if (outcode_out & RIGHT)
{ {
y = dy0 + (dy1 - dy0) * ((double) xmax - dx0) / (dx1 - dx0); y = dy0 + (dy1 - dy0) * ((double)xmax - dx0) / (dx1 - dx0);
x = xmax; x = xmax;
} }
else else
{ {
y = dy0 + (dy1 - dy0) * ((double) xmin - dx0) / (dx1 - dx0); y = dy0 + (dy1 - dy0) * ((double)xmin - dx0) / (dx1 - dx0);
x = xmin; x = xmin;
} }
if (outcode_out == outcode0) if (outcode_out == outcode0)
{ {
dx0 = x; dx0 = x;
dy0 = y; dy0 = y;
outcode0 = __imlib_comp_outcode(dx0, dy0, xmin, xmax, ymin, ymax); outcode0 =
__imlib_comp_outcode(dx0, dy0, xmin, xmax, ymin, ymax);
} }
else else
{ {
dx1 = x; dx1 = x;
dy1 = y; dy1 = y;
outcode1 = __imlib_comp_outcode(dx1, dy1, xmin, xmax, ymin, ymax); outcode1 =
__imlib_comp_outcode(dx1, dy1, xmin, xmax, ymin, ymax);
} }
} }
} }
@ -1730,7 +1732,8 @@ imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin,
return accept; return accept;
} }
ImlibOutCode __imlib_comp_outcode(double x, double y, double xmin, ImlibOutCode
__imlib_comp_outcode(double x, double y, double xmin,
double xmax, double ymin, double ymax) double xmax, double ymin, double ymax)
{ {
ImlibOutCode code = 0; ImlibOutCode code = 0;
@ -1779,7 +1782,6 @@ __imlib_polygon_free(ImlibPoly poly)
free(poly); free(poly);
} }
void void
__imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, unsigned char closed, __imlib_draw_polygon(ImlibImage * im, ImlibPoly poly, unsigned char closed,
DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op) DATA8 r, DATA8 g, DATA8 b, DATA8 a, ImlibOp op)
@ -1840,10 +1842,10 @@ __imlib_polygon_get_bounds(ImlibPoly poly, int *px1, int *py1, int *px2,
int x1 = 0, y1 = 0, x2 = 0, y2 = 0; int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
int i; int i;
*px1=0; *px1 = 0;
*py1=0; *py1 = 0;
*px2=0; *px2 = 0;
*py2=0; *py2 = 0;
if (!poly || !poly->points || (poly->pointcount < 1)) if (!poly || !poly->points || (poly->pointcount < 1))
return; return;
@ -1869,8 +1871,7 @@ __imlib_draw_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb, DATA8 r,
int x, y, dec; int x, y, dec;
for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; x++)
x++)
{ {
__imlib_draw_set_point(im, xc + x, yc + y, r, g, b, a, op); __imlib_draw_set_point(im, xc + x, yc + y, r, g, b, a, op);
__imlib_draw_set_point(im, xc - x, yc + y, r, g, b, a, op); __imlib_draw_set_point(im, xc - x, yc + y, r, g, b, a, op);
@ -1882,8 +1883,7 @@ __imlib_draw_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb, DATA8 r,
dec += b2 * (4 * x + 6); dec += b2 * (4 * x + 6);
} }
for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x; for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x; y++)
y++)
{ {
__imlib_draw_set_point(im, xc + x, yc + y, r, g, b, a, op); __imlib_draw_set_point(im, xc + x, yc + y, r, g, b, a, op);
__imlib_draw_set_point(im, xc - x, yc + y, r, g, b, a, op); __imlib_draw_set_point(im, xc - x, yc + y, r, g, b, a, op);
@ -1911,7 +1911,8 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
edgeRec *table1, *table2; edgeRec *table1, *table2;
if((clip_xmin != 0) && (clip_ymin != 0) && (clip_xmax != -1) && (clip_ymax != -1)) if ((clip_xmin != 0) && (clip_ymin != 0) && (clip_xmax != -1)
&& (clip_ymax != -1))
clip = 1; clip = 1;
table1 = malloc(sizeof(edgeRec) * (im->h + 1)); table1 = malloc(sizeof(edgeRec) * (im->h + 1));
@ -1922,8 +1923,7 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
miny = yc - bb - 1; miny = yc - bb - 1;
maxy = yc + bb + 1; maxy = yc + bb + 1;
for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; x++)
x++)
{ {
if (((yc - y) >= 0) && ((yc - y) < im->h)) if (((yc - y) >= 0) && ((yc - y) < im->h))
{ {
@ -1942,8 +1942,7 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
dec += b2 * (4 * x + 6); dec += b2 * (4 * x + 6);
} }
for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x; for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x; y++)
y++)
{ {
if (((yc - y) >= 0) && ((yc - y) < im->h)) if (((yc - y) >= 0) && ((yc - y) < im->h))
{ {
@ -1970,7 +1969,8 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
__spanlist_clip(table1, table2, &miny, &maxy, clip_xmin, clip_xmax, __spanlist_clip(table1, table2, &miny, &maxy, clip_xmin, clip_xmax,
clip_ymin, clip_ymax); clip_ymin, clip_ymax);
if (miny < 0) miny = 0; if (miny < 0)
miny = 0;
if (miny >= im->h) if (miny >= im->h)
{ {
free(table1); free(table1);
@ -1992,12 +1992,14 @@ __imlib_fill_ellipse(ImlibImage * im, int xc, int yc, int aa, int bb,
x1 = table1[miny].x; x1 = table1[miny].x;
x2 = table2[miny].x; x2 = table2[miny].x;
if(clip) if (clip)
{ {
if (x1 < clip_xmin) x1 = clip_xmin; if (x1 < clip_xmin)
if (x2 > clip_xmax) x2 = clip_xmax; x1 = clip_xmin;
if (x2 > clip_xmax)
x2 = clip_xmax;
} }
if((x1 != x2) && (x1 < im->w)) if ((x1 != x2) && (x1 < im->w))
span(im, miny, x1, x2, r, g, b, a, op); span(im, miny, x1, x2, r, g, b, a, op);
miny++; miny++;
} }
@ -2018,8 +2020,7 @@ __imlib_draw_ellipse_clipped(ImlibImage * im, int xc, int yc, int aa, int bb,
int x, y, dec; int x, y, dec;
for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; for (x = 0, y = bb, dec = 2 * b2 + a2 * (1 - 2 * bb); b2 * x <= a2 * y; x++)
x++)
{ {
__imlib_draw_set_point_clipped(im, xc + x, yc + y, clip_xmin, clip_xmax, __imlib_draw_set_point_clipped(im, xc + x, yc + y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op); clip_ymin, clip_ymax, r, g, b, a, op);
@ -2035,8 +2036,7 @@ __imlib_draw_ellipse_clipped(ImlibImage * im, int xc, int yc, int aa, int bb,
dec += b2 * (4 * x + 6); dec += b2 * (4 * x + 6);
} }
for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x; for (x = aa, y = 0, dec = 2 * a2 + b2 * (1 - 2 * aa); a2 * y <= b2 * x; y++)
y++)
{ {
__imlib_draw_set_point_clipped(im, xc + x, yc + y, clip_xmin, clip_xmax, __imlib_draw_set_point_clipped(im, xc + x, yc + y, clip_xmin, clip_xmax,
clip_ymin, clip_ymax, r, g, b, a, op); clip_ymin, clip_ymax, r, g, b, a, op);
@ -2053,7 +2053,6 @@ __imlib_draw_ellipse_clipped(ImlibImage * im, int xc, int yc, int aa, int bb,
} }
} }
static void static void
edge(edgeRec * table, ImlibPoint * pt1, ImlibPoint * pt2) edge(edgeRec * table, ImlibPoint * pt1, ImlibPoint * pt2)
{ {
@ -2069,7 +2068,7 @@ edge(edgeRec * table, ImlibPoint * pt1, ImlibPoint * pt2)
return; return;
idy = MAX(2, idy - 1); idy = MAX(2, idy - 1);
x = pt1->x; x = pt1->x;
dx = (pt2->x - pt1->x) / (double) idy; dx = (pt2->x - pt1->x) / (double)idy;
do do
{ {
table[iy1].x = x; table[iy1].x = x;
@ -2143,8 +2142,7 @@ span(ImlibImage * im, int y, int x1, int x2, DATA8 r, DATA8 g,
} }
typedef struct _span Span; typedef struct _span Span;
struct _span struct _span {
{
int x, xstart, ystart, vert, xend, yend; int x, xstart, ystart, vert, xend, yend;
int pol, point; int pol, point;
double gradient; double gradient;
@ -2163,19 +2161,28 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
int i, h, j, top, right, left, pol, ppol, dir; int i, h, j, top, right, left, pol, ppol, dir;
/* less than 3 points - not even a tirangle - abort */ /* less than 3 points - not even a tirangle - abort */
if (poly->pointcount < 3) return; if (poly->pointcount < 3)
return;
/* if no clip is set or clip is outside image, clip it to the image */ /* if no clip is set or clip is outside image, clip it to the image */
if (clip_xmin < clip_xmax) if (clip_xmin < clip_xmax)
{ {
if (clip_xmax < 0) return; if (clip_xmax < 0)
if (clip_xmin >= im->w) return; return;
if (clip_ymax < 0) return; if (clip_xmin >= im->w)
if (clip_ymin >= im->h) return; return;
if (clip_xmin < 0) clip_xmin = 0; if (clip_ymax < 0)
if (clip_xmax >= im->w) clip_xmax = im->w - 1; return;
if (clip_ymin < 0) clip_ymin = 0; if (clip_ymin >= im->h)
if (clip_ymax >= im->h) clip_ymax = im->h - 1; return;
if (clip_xmin < 0)
clip_xmin = 0;
if (clip_xmax >= im->w)
clip_xmax = im->w - 1;
if (clip_ymin < 0)
clip_ymin = 0;
if (clip_ymax >= im->h)
clip_ymax = im->h - 1;
} }
/* set clip to image size */ /* set clip to image size */
else else
@ -2186,14 +2193,18 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
clip_ymax = im->h - 1; clip_ymax = im->h - 1;
} }
/* clip is invalid - ie 0 or less than size - abort */ /* clip is invalid - ie 0 or less than size - abort */
if (clip_ymax < clip_ymin) return; if (clip_ymax < clip_ymin)
if (clip_xmax < clip_xmin) return; return;
if (clip_xmax < clip_xmin)
return;
/* allocate spanlist for the output image */ /* allocate spanlist for the output image */
h = clip_ymax - clip_ymin + 1; h = clip_ymax - clip_ymin + 1;
if (h < 1) return; if (h < 1)
return;
spans = malloc(h * sizeof(Span *)); spans = malloc(h * sizeof(Span *));
if (!spans) return; if (!spans)
return;
memset(spans, 0, h * sizeof(Span *)); memset(spans, 0, h * sizeof(Span *));
/* find top most poly pont */ /* find top most poly pont */
@ -2229,13 +2240,17 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
pol = 0; pol = 0;
ppol = 0; ppol = 0;
dir = 1; dir = 1;
if (right > top) dir = 1; if (right > top)
dir = 1;
else if (right == top) else if (right == top)
{ {
if (left < top) dir = 1; if (left < top)
else dir = -1; dir = 1;
else
dir = -1;
} }
else dir = -1; else
dir = -1;
for (j = 0; (j != poly->pointcount) && (j != -poly->pointcount); j += dir) for (j = 0; (j != poly->pointcount) && (j != -poly->pointcount); j += dir)
{ {
int pt1, pt2, x1, y1, x2, y2, vert, step; int pt1, pt2, x1, y1, x2, y2, vert, step;
@ -2244,25 +2259,32 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
/* current point and next point - line connecting the 2 */ /* current point and next point - line connecting the 2 */
pt1 = ((j + top) % poly->pointcount); pt1 = ((j + top) % poly->pointcount);
pt2 = ((j + top + 1) % poly->pointcount); pt2 = ((j + top + 1) % poly->pointcount);
while (pt1 < 0) pt1 += poly->pointcount; while (pt1 < 0)
while (pt2 < 0) pt2 += poly->pointcount; pt1 += poly->pointcount;
while (pt2 < 0)
pt2 += poly->pointcount;
/* conveneince for 2 points */ /* conveneince for 2 points */
x1 = poly->points[pt1].x; x1 = poly->points[pt1].x;
y1 = poly->points[pt1].y; y1 = poly->points[pt1].y;
x2 = poly->points[pt2].x; x2 = poly->points[pt2].x;
y2 = poly->points[pt2].y; y2 = poly->points[pt2].y;
ppol = pol; ppol = pol;
if (y2 > y1) pol = 1; if (y2 > y1)
else pol = -1; pol = 1;
else
pol = -1;
vert = 0; vert = 0;
grad = 0; grad = 0;
/* vertical ? */ /* vertical ? */
if (x2 == x1) vert = 1; if (x2 == x1)
vert = 1;
/* gradient */ /* gradient */
else grad = (double)(y2 - y1) / (double)(x2 - x1); else
grad = (double)(y2 - y1) / (double)(x2 - x1);
/* go thru the line span by span */ /* go thru the line span by span */
step = 1; step = 1;
if (y1 >= y2) step = -1; if (y1 >= y2)
step = -1;
for (i = y1;;) for (i = y1;;)
{ {
Span *s; Span *s;
@ -2282,16 +2304,21 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
dbx = ((double)x1 + ((double)(i - y1) / grad)); dbx = ((double)x1 + ((double)(i - y1) / grad));
x = (int)dbx; x = (int)dbx;
if ((dbx - ((double)x)) >= 0.5) x += 1; if ((dbx - ((double)x)) >= 0.5)
x += 1;
} }
else if (vert) x = x1; else if (vert)
else x = x1; x = x1;
else
x = x1;
if ((i >= clip_ymin) && (i <= clip_ymax)) if ((i >= clip_ymin) && (i <= clip_ymax))
{ {
/* for every scanline this line spans add a span point */ /* for every scanline this line spans add a span point */
s = malloc(sizeof(Span)); s = malloc(sizeof(Span));
if (pol == 1) s->x = x + 1; if (pol == 1)
else s->x = x; s->x = x + 1;
else
s->x = x;
s->pol = pol; s->pol = pol;
s->xstart = x1; s->xstart = x1;
s->ystart = y1; s->ystart = y1;
@ -2301,35 +2328,40 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
s->gradient = grad; s->gradient = grad;
s->next = NULL; s->next = NULL;
if ((i == y1) || (i == y2)) s->point = 1; if ((i == y1) || (i == y2))
else s->point = 0; s->point = 1;
else
s->point = 0;
/* actually add the scan point to the scan list array */ /* actually add the scan point to the scan list array */
if (!(spans[i - clip_ymin])) spans[i - clip_ymin] = s; if (!(spans[i - clip_ymin]))
spans[i - clip_ymin] = s;
else else
{ {
Span *ps, *ss; Span *ps, *ss;
ps = NULL; ps = NULL;
for (ss = spans[i - clip_ymin]; for (ss = spans[i - clip_ymin]; ss; ss = ss->next)
ss;
ss = ss->next)
{ {
if (s->x <= ss->x) if (s->x <= ss->x)
{ {
if (!ps) spans[i - clip_ymin] = s; if (!ps)
else ps->next = s; spans[i - clip_ymin] = s;
else
ps->next = s;
s->next = ss; s->next = ss;
goto nospans; goto nospans;
} }
ps = ss; ps = ss;
} }
/* last span on line and still not < ss->x */ /* last span on line and still not < ss->x */
if (ps) ps->next = s; if (ps)
ps->next = s;
nospans: nospans:
} }
} }
if (i == y2) goto nolines; if (i == y2)
goto nolines;
i += step; i += step;
} }
nolines: nolines:
@ -2343,9 +2375,7 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
for (s = spans[i]; s; s = s->next) for (s = spans[i]; s; s = s->next)
{ {
if ((s->next) && if ((s->next) &&
(s->next->x == s->x) && (s->next->x == s->x) && (s->next->pol == s->pol))
(s->next->pol == s->pol)
)
{ {
Span *ss; Span *ss;
@ -2375,8 +2405,10 @@ __imlib_draw_polygon_filled(ImlibImage * im, ImlibPoly poly, int clip_xmin,
} }
if ((x1 <= clip_xmax) && (x2 > clip_xmin) && (x1 < x2)) if ((x1 <= clip_xmax) && (x2 > clip_xmin) && (x1 < x2))
{ {
if (x1 < clip_xmin) x1 = clip_xmin; if (x1 < clip_xmin)
if (x2 > (clip_xmax + 1)) x2 = clip_xmax + 1; x1 = clip_xmin;
if (x2 > (clip_xmax + 1))
x2 = clip_xmax + 1;
span(im, i + clip_ymin, x1, x2 - 1, r, g, b, a, op); span(im, i + clip_ymin, x1, x2 - 1, r, g, b, a, op);
} }
} }
@ -2423,7 +2455,9 @@ __spanlist_clip(edgeRec * table1, edgeRec * table2, int *sy, int *ey,
if (pt2->x < pt1->x) if (pt2->x < pt1->x)
exchange(double, pt2->x, pt1->x); exchange(double, pt2->x, pt1->x);
if(pt1->x < xmax) {
if (pt1->x < xmax)
{
pt1->x = MAX(pt1->x, xmin); pt1->x = MAX(pt1->x, xmin);
pt2->x = MIN(pt2->x, xmax); pt2->x = MIN(pt2->x, xmax);
} }
@ -2445,7 +2479,7 @@ __imlib_polygon_contains_point(ImlibPoly poly, int x, int y)
while (start < poly->pointcount && poly->points[start].y == y) while (start < poly->pointcount && poly->points[start].y == y)
start++; start++;
/* if one doesn't exist we will use point on segment test /* if one doesn't exist we will use point on segment test
and can start with vertex 0 anyway */ * and can start with vertex 0 anyway */
cx = start % poly->pointcount; cx = start % poly->pointcount;
out_x = poly->points[0].x; out_x = poly->points[0].x;
@ -2477,19 +2511,21 @@ __imlib_polygon_contains_point(ImlibPoly poly, int x, int y)
{ {
count++; count++;
if (__imlib_point_on_segment(next_x, next_y, x, y, out_x, out_y)) if (__imlib_point_on_segment
(next_x, next_y, x, y, out_x, out_y))
{ {
/* current seg intersects test seg @ 2nd vtx /* current seg intersects test seg @ 2nd vtx
reset ysave */ * reset ysave */
ysave = curr_y; ysave = curr_y;
} }
if (__imlib_point_on_segment(curr_x, curr_y, x, y, out_x, out_y) if (__imlib_point_on_segment
(curr_x, curr_y, x, y, out_x, out_y)
&& (ysave < y != next_y < y)) && (ysave < y != next_y < y))
{ {
/* current seg xsects test seg @ 1st vtx and /* current seg xsects test seg @ 1st vtx and
ysave on opposite side of test line from * ysave on opposite side of test line from
curr seg 2nd vtx; * curr seg 2nd vtx;
decrement hits (2-1) for odd parity */ * decrement hits (2-1) for odd parity */
count--; count--;
} }
} }
@ -2499,7 +2535,6 @@ __imlib_polygon_contains_point(ImlibPoly poly, int x, int y)
return (count % 2 == 1); return (count % 2 == 1);
} }
unsigned char unsigned char
__imlib_segments_intersect(int r1_x, int r1_y, int r2_x, int r2_y, int s1_x, __imlib_segments_intersect(int r1_x, int r1_y, int r2_x, int r2_y, int s1_x,
int s1_y, int s2_x, int s2_y) int s1_y, int s2_x, int s2_y)
@ -2539,8 +2574,8 @@ __imlib_point_delta_from_line(int p_x, int p_y, int s1_x, int s1_y, int s2_x,
return p_x - s1_x; return p_x - s1_x;
else else
{ {
double m = (double) (s2_y - s1_y) / (double) (s2_x - s1_x); double m = (double)(s2_y - s1_y) / (double)(s2_x - s1_x);
return (p_y - s1_y - (double) (p_x - s1_x) * m); return (p_y - s1_y - (double)(p_x - s1_x) * m);
} }
} }

View File

@ -50,25 +50,29 @@
/*\ 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; i = dw - 1;
do { do
{
*dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)]; *dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)];
/*\ RIGHT; \*/ /*\ RIGHT; \ */
x += dxh; x += dxh;
y += dyh; y += dyh;
dest++; dest++;
} while (--i >= 0); } while (--i >= 0);
if (--dh <= 0) break; if (--dh <= 0)
/*\ DOWN/LEFT; \*/ break;
/*\ DOWN/LEFT; \ */
x += dxv - dw * dxh; x += dxv - dw * dxh;
y += dyv - dw * dyh; y += dyv - dw * dyh;
dest += (dow - dw); dest += (dow - dw);
@ -77,27 +81,31 @@ __imlib_RotateSampleInside(DATA32 *src, DATA32 *dest, int sow, int dow,
/*\ 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; i = dw - 1;
do { do
{
DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) + DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) +
((y >> _ROTATE_PREC) * sow)); ((y >> _ROTATE_PREC) * sow));
INTERP_ARGB(dest, src_x_y, sow, x, y); INTERP_ARGB(dest, src_x_y, sow, x, y);
/*\ RIGHT; \*/ /*\ RIGHT; \ */
x += dxh; x += dxh;
y += dyh; y += dyh;
dest++; dest++;
} while (--i >= 0); } while (--i >= 0);
if (--dh <= 0) break; if (--dh <= 0)
/*\ DOWN/LEFT; \*/ break;
/*\ DOWN/LEFT; \ */
x += dxv - dw * dxh; x += dxv - dw * dxh;
y += dyv - dw * dyh; y += dyv - dw * dyh;
dest += (dow - dw); dest += (dow - dw);
@ -120,13 +128,16 @@ __check_inside_coords(int x, int y, int dxh, int dyh, int dxv, int dyv,
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,15 +146,17 @@ __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))
return;
if (__check_inside_coords(x, y, dxh, dyh, dxv, dyv, dw, dh, sw, sh)) { if (__check_inside_coords(x, y, dxh, dyh, dxv, dyv, dw, dh, sw, sh))
{
__imlib_RotateSampleInside(src, dest, sow, dow, dw, dh, x, y, __imlib_RotateSampleInside(src, dest, sow, dow, dw, dh, x, y,
dxh, dyh, dxv, dyv); dxh, dyh, dxv, dyv);
return; return;
@ -152,20 +165,24 @@ __imlib_RotateSample(DATA32 *src, DATA32 *dest, int sow, int sw, int sh,
sw <<= _ROTATE_PREC; sw <<= _ROTATE_PREC;
sh <<= _ROTATE_PREC; sh <<= _ROTATE_PREC;
while (1) { while (1)
{
i = dw - 1; i = dw - 1;
do { do
{
if (((unsigned)x < sw) && ((unsigned)y < sh)) if (((unsigned)x < sw) && ((unsigned)y < sh))
*dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)]; *dest = src[(x >> _ROTATE_PREC) + ((y >> _ROTATE_PREC) * sow)];
else *dest = 0; else
/*\ RIGHT; \*/ *dest = 0;
/*\ RIGHT; \ */
x += dxh; x += dxh;
y += dyh; y += dyh;
dest++; dest++;
} while (--i >= 0); } while (--i >= 0);
if (--dh <= 0) break; if (--dh <= 0)
/*\ DOWN/LEFT; \*/ break;
/*\ DOWN/LEFT; \ */
x += dxv - dw * dxh; x += dxv - dw * dxh;
y += dyv - dw * dyh; y += dyv - dw * dyh;
dest += (dow - dw); dest += (dow - dw);
@ -180,89 +197,125 @@ __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))
return;
if (__check_inside_coords(x, y, dxh, dyh, dxv, dyv, dw, dh, sw-1, sh-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, __imlib_RotateAAInside(src, dest, sow, dow, dw, dh, x, y,
dxh, dyh, dxv, dyv); dxh, dyh, dxv, dyv);
return; return;
} }
sw--; sh--; sw--;
sh--;
sw <<= _ROTATE_PREC; sw <<= _ROTATE_PREC;
sh <<= _ROTATE_PREC; sh <<= _ROTATE_PREC;
while (1) { while (1)
{
i = dw - 1; i = dw - 1;
do { do
{
DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) + DATA32 *src_x_y = (src + (x >> _ROTATE_PREC) +
((y >> _ROTATE_PREC) * sow)); ((y >> _ROTATE_PREC) * sow));
if ((unsigned)x < sw) { if ((unsigned)x < sw)
if ((unsigned)y < sh) { {
if ((unsigned)y < sh)
{
/*\ 12 /*\ 12
|*| 34 * |*| 34
\*/ * \ */
INTERP_ARGB(dest, src_x_y, sow, x, y); INTERP_ARGB(dest, src_x_y, sow, x, y);
} else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX) { }
else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX)
{
/*\ 12 /*\ 12
|*| .. * |*| ..
\*/ * \ */
INTERP_RGB_A0(dest, src_x_y, src_x_y + 1, 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) < _ROTATE_PREC_MAX)
{
/*\ .. /*\ ..
|*| 34 * |*| 34
\*/ * \ */
INTERP_RGB_A0(dest, src_x_y + sow, src_x_y + sow + 1, x, y); INTERP_RGB_A0(dest, src_x_y + sow, src_x_y + sow + 1, x,
} else *dest = 0; y);
} else if ((unsigned)(x - sw) < (_ROTATE_PREC_MAX)) { }
if ((unsigned)y < sh) { else
*dest = 0;
}
else if ((unsigned)(x - sw) < (_ROTATE_PREC_MAX))
{
if ((unsigned)y < sh)
{
/*\ 1. /*\ 1.
|*| 3. * |*| 3.
\*/ * \ */
INTERP_RGB_A0(dest, src_x_y, src_x_y + sow, y, ~x); INTERP_RGB_A0(dest, src_x_y, src_x_y + sow, y, ~x);
} else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX) { }
else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX)
{
/*\ 1. /*\ 1.
|*| .. * |*| ..
\*/ * \ */
INTERP_A000(dest, src_x_y, ~x, ~y); INTERP_A000(dest, src_x_y, ~x, ~y);
} else if ((unsigned)(~y) < _ROTATE_PREC_MAX) { }
else if ((unsigned)(~y) < _ROTATE_PREC_MAX)
{
/*\ .. /*\ ..
|*| 3. * |*| 3.
\*/ * \ */
INTERP_A000(dest, src_x_y + sow, ~x, y); INTERP_A000(dest, src_x_y + sow, ~x, y);
} else *dest = 0; }
} else if ((unsigned)(~x) < _ROTATE_PREC_MAX) { else
if ((unsigned)y < sh) { *dest = 0;
}
else if ((unsigned)(~x) < _ROTATE_PREC_MAX)
{
if ((unsigned)y < sh)
{
/*\ .2 /*\ .2
|*| .4 * |*| .4
\*/ * \ */
INTERP_RGB_A0(dest, src_x_y + 1, src_x_y + sow + 1, y, x); INTERP_RGB_A0(dest, src_x_y + 1, src_x_y + sow + 1, y,
} else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX) { x);
}
else if ((unsigned)(y - sh) < _ROTATE_PREC_MAX)
{
/*\ .2 /*\ .2
|*| .. * |*| ..
\*/ * \ */
INTERP_A000(dest, src_x_y + 1, 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 * |*| .4
\*/ * \ */
INTERP_A000(dest, src_x_y + sow + 1, x, y); INTERP_A000(dest, src_x_y + sow + 1, x, y);
} else *dest = 0; }
} else *dest = 0; else
/*\ RIGHT; \*/ *dest = 0;
}
else
*dest = 0;
/*\ RIGHT; \ */
x += dxh; x += dxh;
y += dyh; y += dyh;
dest++; dest++;
} while (--i >= 0); } while (--i >= 0);
if (--dh <= 0) break; if (--dh <= 0)
/*\ DOWN/LEFT; \*/ break;
/*\ DOWN/LEFT; \ */
x += dxv - dw * dxh; x += dxv - dw * dxh;
y += dyv - dw * dyh; y += dyv - dw * dyh;
dest += (dow - dw); dest += (dow - dw);
@ -274,12 +327,12 @@ __imlib_RotateAA(DATA32 *src, DATA32 *dest, int sow, int sw, int sh,
#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;
@ -300,54 +353,65 @@ __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; xy2 = (double)(hsx * vsy - vsx * hsy) / _ROTATE_PREC_MAX;
if (xy2 == 0.0) return; if (xy2 == 0.0)
return;
dxh = (double)(ssw * vsy) / xy2; dxh = (double)(ssw * vsy) / xy2;
dxv = (double)-(ssw * vsx) / xy2; dxv = (double)-(ssw * vsx) / xy2;
dyh = (double)-(ssh * hsy) / xy2; dyh = (double)-(ssh * hsy) / xy2;
dyv = (double)(ssh * hsx) / xy2; dyv = (double)(ssh * hsx) / xy2;
} else { }
else
{
xy2 = (double)(hsx * hsx + hsy * hsy) / _ROTATE_PREC_MAX; xy2 = (double)(hsx * hsx + hsy * hsy) / _ROTATE_PREC_MAX;
if (xy2 == 0.0) return; if (xy2 == 0.0)
return;
dxh = (double)(ssw * hsx) / xy2; dxh = (double)(ssw * hsx) / xy2;
dyh = (double)-(ssw * hsy) / xy2; dyh = (double)-(ssw * hsy) / xy2;
dxv = -dyh; dxv = -dyh;
dyv = dxh; dyv = dxh;
} }
x = - (ddx * dxh + ddy * dxv); x = -(ddx * dxh + ddy * dxv);
y = - (ddx * dyh + ddy * dyv); y = -(ddx * dyh + ddy * dyv);
if (ssx < 0) { if (ssx < 0)
{
x += ssx * _ROTATE_PREC_MAX; x += ssx * _ROTATE_PREC_MAX;
ssw += ssx; ssw += ssx;
ssx = 0; ssx = 0;
} }
if (ssy < 0) { if (ssy < 0)
{
y += ssy * _ROTATE_PREC_MAX; y += ssy * _ROTATE_PREC_MAX;
ssh += ssy; ssh += ssy;
ssy = 0; 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 \*/ {
/*\ Account for virtual transparent border \ */
x += _ROTATE_PREC_MAX; x += _ROTATE_PREC_MAX;
y += _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);
@ -357,62 +421,88 @@ __imlib_BlendImageToImageSkewed(ImlibImage *im_src, ImlibImage *im_dst,
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 \*/ {
/*\ Account for virtual transparent border \ */
w += 2 << _ROTATE_PREC; w += 2 << _ROTATE_PREC;
h += 2 << _ROTATE_PREC; h += 2 << _ROTATE_PREC;
} }
/*\ Pretty similar code \*/ /*\ Pretty similar code \ */
if (dxh > 0) { if (dxh > 0)
if (dyh > 0) { {
if (dyh > 0)
{
l = MAX(-MAX(y, y2) / dyh, -MAX(x, x2) / dxh); l = MAX(-MAX(y, y2) / dyh, -MAX(x, x2) / dxh);
r = MIN((h - MIN(y, y2)) / dyh, (w - MIN(x, x2)) / dxh); r = MIN((h - MIN(y, y2)) / dyh, (w - MIN(x, x2)) / dxh);
} else if (dyh < 0) { }
else if (dyh < 0)
{
l = MAX(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh); l = MAX(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh);
r = MIN(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh); r = MIN(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh);
} else { }
else
{
l = -MAX(x, x2) / dxh; l = -MAX(x, x2) / dxh;
r = (w - MIN(x, x2)) / dxh; r = (w - MIN(x, x2)) / dxh;
} }
} else if (dxh < 0) { }
if (dyh > 0) { else if (dxh < 0)
{
if (dyh > 0)
{
l = MAX(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh); l = MAX(-MAX(y, y2) / dyh, (w - MIN(x, x2)) / dxh);
r = MIN(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh); r = MIN(-MAX(x, x2) / dxh, (h - MIN(y, y2)) / dyh);
} else if (dyh < 0) { }
else if (dyh < 0)
{
l = MAX((h - MIN(y, y2)) / dyh, (w - MIN(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); r = MIN(-MAX(y, y2) / dyh, -MAX(x, x2) / dxh);
} else { }
else
{
l = (w - MIN(x, x2)) / dxh; l = (w - MIN(x, x2)) / dxh;
r = -MAX(x, x2) / dxh; r = -MAX(x, x2) / dxh;
} }
} else { }
if (dyh > 0) { else
{
if (dyh > 0)
{
l = -MAX(y, y2) / dyh; l = -MAX(y, y2) / dyh;
r = (h - MIN(y, y2)) / dyh; r = (h - MIN(y, y2)) / dyh;
} else if (dyh < 0) { }
else if (dyh < 0)
{
l = (h - MIN(y, y2)) / dyh; l = (h - MIN(y, y2)) / dyh;
r = -MAX(y, y2) / dyh; r = -MAX(y, y2) / dyh;
} else { }
else
{
l = 0; l = 0;
r = 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)
r = im_dst->w;
if (r <= l)
{
x = x2;
y = y2;
continue; continue;
} }
@ -421,8 +511,10 @@ __imlib_BlendImageToImageSkewed(ImlibImage *im_src, ImlibImage *im_dst,
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,
@ -432,7 +524,9 @@ __imlib_BlendImageToImageSkewed(ImlibImage *im_src, ImlibImage *im_dst,
__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 { }
else
{
__imlib_RotateSample(src, data, im_src->w, ssw, ssh, w, w, h, __imlib_RotateSample(src, data, im_src->w, ssw, ssh, w, w, h,
x, y, dxh, dyh, dxv, dyv); x, y, dxh, dyh, dxv, dyv);
@ -440,7 +534,8 @@ __imlib_BlendImageToImageSkewed(ImlibImage *im_src, ImlibImage *im_dst,
__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);

View File

@ -7,8 +7,7 @@
#include <assert.h> #include <assert.h>
/*\ NB: If you change this, don't forget asm_scale.S \*/ /*\ NB: If you change this, don't forget asm_scale.S \*/
struct _imlib_scale_info struct _imlib_scale_info {
{
int *xpoints; int *xpoints;
DATA32 **ypoints; DATA32 **ypoints;
int *xapoints, *yapoints; int *xapoints, *yapoints;
@ -23,13 +22,14 @@ struct _imlib_scale_info
#define YAP (yapoints[dyy + y]) #define YAP (yapoints[dyy + y])
static DATA32 ** static DATA32 **
__imlib_CalcYPoints(DATA32 *src, int sw, int sh, int dh, int b1, int b2) __imlib_CalcYPoints(DATA32 * src, int sw, int sh, int dh, int b1, int b2)
{ {
DATA32 **p; DATA32 **p;
int i, j = 0; int i, j = 0;
int val, inc, rv = 0; int val, inc, rv = 0;
if (dh < 0) { if (dh < 0)
{
dh = -dh; dh = -dh;
rv = 1; rv = 1;
} }
@ -69,9 +69,10 @@ __imlib_CalcYPoints(DATA32 *src, int sw, int sh, int dh, int b1, int b2)
val += inc; val += inc;
} }
if (rv) if (rv)
for (i = dh / 2; --i >= 0; ) for (i = dh / 2; --i >= 0;)
{ {
DATA32 *tmp = p[i]; DATA32 *tmp = p[i];
p[i] = p[dh - i - 1]; p[i] = p[dh - i - 1];
p[dh - i - 1] = tmp; p[dh - i - 1] = tmp;
} }
@ -84,7 +85,8 @@ __imlib_CalcXPoints(int sw, int dw, int b1, int b2)
int *p, i, j = 0; int *p, i, j = 0;
int val, inc, rv = 0; int val, inc, rv = 0;
if (dw < 0) { if (dw < 0)
{
dw = -dw; dw = -dw;
rv = 1; rv = 1;
} }
@ -124,9 +126,10 @@ __imlib_CalcXPoints(int sw, int dw, int b1, int b2)
val += inc; val += inc;
} }
if (rv) if (rv)
for (i = dw / 2; --i >= 0; ) for (i = dw / 2; --i >= 0;)
{ {
int tmp = p[i]; int tmp = p[i];
p[i] = p[dw - i - 1]; p[i] = p[dw - i - 1];
p[dw - i - 1] = tmp; p[dw - i - 1] = tmp;
} }
@ -138,7 +141,8 @@ __imlib_CalcApoints(int s, int d, int b1, int b2, int up)
{ {
int *p, i, j = 0, rv = 0; int *p, i, j = 0, rv = 0;
if (d < 0) { if (d < 0)
{
rv = 1; rv = 1;
d = -d; d = -d;
} }
@ -208,9 +212,10 @@ __imlib_CalcApoints(int s, int d, int b1, int b2, int up)
} }
if (rv) if (rv)
{ {
for (i = d / 2; --i >= 0; ) for (i = d / 2; --i >= 0;)
{ {
int tmp = p[i]; int tmp = p[i];
p[i] = p[d - i - 1]; p[i] = p[d - i - 1];
p[d - i - 1] = tmp; p[d - i - 1] = tmp;
} }
@ -219,9 +224,10 @@ __imlib_CalcApoints(int s, int d, int b1, int b2, int up)
} }
ImlibScaleInfo * ImlibScaleInfo *
__imlib_FreeScaleInfo(ImlibScaleInfo *isi) __imlib_FreeScaleInfo(ImlibScaleInfo * isi)
{ {
if (isi) { if (isi)
{
free(isi->xpoints); free(isi->xpoints);
free(isi->ypoints); free(isi->ypoints);
free(isi->xapoints); free(isi->xapoints);
@ -232,7 +238,7 @@ __imlib_FreeScaleInfo(ImlibScaleInfo *isi)
} }
ImlibScaleInfo * ImlibScaleInfo *
__imlib_CalcScaleInfo(ImlibImage *im, int sw, int sh, int dw, int dh, char aa) __imlib_CalcScaleInfo(ImlibImage * im, int sw, int sh, int dw, int dh, char aa)
{ {
ImlibScaleInfo *isi; ImlibScaleInfo *isi;
int scw, sch; int scw, sch;
@ -241,7 +247,8 @@ __imlib_CalcScaleInfo(ImlibImage *im, int sw, int sh, int dw, int dh, char aa)
sch = dh * im->h / sh; sch = dh * im->h / sh;
isi = malloc(sizeof(ImlibScaleInfo)); isi = malloc(sizeof(ImlibScaleInfo));
if (!isi) return NULL; if (!isi)
return NULL;
memset(isi, 0, sizeof(ImlibScaleInfo)); memset(isi, 0, sizeof(ImlibScaleInfo));
isi->pix_assert = im->data + im->w * im->h; isi->pix_assert = im->data + im->w * im->h;
@ -256,13 +263,15 @@ __imlib_CalcScaleInfo(ImlibImage *im, int sw, int sh, int dw, int dh, char aa)
im->border.top, im->border.bottom); im->border.top, im->border.bottom);
if (!isi->ypoints) if (!isi->ypoints)
return __imlib_FreeScaleInfo(isi); return __imlib_FreeScaleInfo(isi);
if (aa) { if (aa)
{
isi->xapoints = __imlib_CalcApoints(im->w, scw, im->border.left, isi->xapoints = __imlib_CalcApoints(im->w, scw, im->border.left,
im->border.right, isi->xup_yup & 1); im->border.right, isi->xup_yup & 1);
if (!isi->xapoints) if (!isi->xapoints)
return __imlib_FreeScaleInfo(isi); return __imlib_FreeScaleInfo(isi);
isi->yapoints = __imlib_CalcApoints(im->h, sch, im->border.top, isi->yapoints = __imlib_CalcApoints(im->h, sch, im->border.top,
im->border.bottom, isi->xup_yup & 2); im->border.bottom,
isi->xup_yup & 2);
if (!isi->yapoints) if (!isi->yapoints)
return __imlib_FreeScaleInfo(isi); return __imlib_FreeScaleInfo(isi);
} }
@ -271,7 +280,7 @@ __imlib_CalcScaleInfo(ImlibImage *im, int sw, int sh, int dw, int dh, char aa)
/* scale by pixel sampling only */ /* scale by pixel sampling only */
void void
__imlib_ScaleSampleRGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy, __imlib_ScaleSampleRGBA(ImlibScaleInfo * isi, DATA32 * dest, int dxx, int dyy,
int dx, int dy, int dw, int dh, int dow) int dx, int dy, int dw, int dh, int dow)
{ {
DATA32 *sptr, *dptr; DATA32 *sptr, *dptr;
@ -298,7 +307,7 @@ __imlib_ScaleSampleRGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
/* scale by area sampling */ /* scale by area sampling */
void void
__imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy, __imlib_ScaleAARGBA(ImlibScaleInfo * isi, DATA32 * dest, int dxx, int dyy,
int dx, int dy, int dw, int dh, int dow, int sow) int dx, int dy, int dw, int dh, int dow, int sow)
{ {
DATA32 *sptr, *dptr; DATA32 *sptr, *dptr;
@ -400,7 +409,7 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
*dptr++ = RGBA_COMPOSE(r, g, b, a); *dptr++ = RGBA_COMPOSE(r, g, b, a);
} }
else else
*dptr++ = sptr[xpoints[x] ]; *dptr++ = sptr[xpoints[x]];
} }
} }
} }
@ -409,7 +418,7 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
else if (isi->xup_yup == 1) else if (isi->xup_yup == 1)
#ifndef OLD_SCALE_DOWN #ifndef OLD_SCALE_DOWN
{ {
/*\ 'Correct' version, with math units prepared for MMXification \*/ /*\ 'Correct' version, with math units prepared for MMXification \ */
int Cy, j; int Cy, j;
DATA32 *pix; DATA32 *pix;
int r, g, b, a, rr, gg, bb, aa; int r, g, b, a, rr, gg, bb, aa;
@ -497,6 +506,7 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
for (y = 0; y < dh; y++) for (y = 0; y < dh; y++)
{ {
int yap; int yap;
/* calculate the source line we'll scan from */ /* calculate the source line we'll scan from */
dptr = dest + dx + ((y + dy) * dow); dptr = dest + dx + ((y + dy) * dow);
sptr = ypoints[dyy + y]; sptr = ypoints[dyy + y];
@ -591,7 +601,7 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
else if (isi->xup_yup == 2) else if (isi->xup_yup == 2)
#ifndef OLD_SCALE_DOWN #ifndef OLD_SCALE_DOWN
{ {
/*\ 'Correct' version, with math units prepared for MMXification \*/ /*\ 'Correct' version, with math units prepared for MMXification \ */
int Cx, j; int Cx, j;
DATA32 *pix; DATA32 *pix;
int r, g, b, a, rr, gg, bb, aa; int r, g, b, a, rr, gg, bb, aa;
@ -776,10 +786,10 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
#ifndef OLD_SCALE_DOWN #ifndef OLD_SCALE_DOWN
{ {
/*\ 'Correct' version, with math units prepared for MMXification: /*\ 'Correct' version, with math units prepared for MMXification:
|*| The operation 'b = (b * c) >> 16' translates to pmulhw, * |*| The operation 'b = (b * c) >> 16' translates to pmulhw,
|*| so the operation 'b = (b * c) >> d' would translate to * |*| so the operation 'b = (b * c) >> d' would translate to
|*| psllw (16 - d), %mmb; pmulh %mmc, %mmb * |*| psllw (16 - d), %mmb; pmulh %mmc, %mmb
\*/ * \ */
int Cx, Cy, i, j; int Cx, Cy, i, j;
DATA32 *pix; DATA32 *pix;
int a, r, g, b, ax, rx, gx, bx; int a, r, g, b, ax, rx, gx, bx;
@ -903,20 +913,24 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
/* go through every scanline in the output buffer */ /* go through every scanline in the output buffer */
for (y = 0; y < dh; y++) for (y = 0; y < dh; y++)
{ {
int yap = (ypoints[dyy + y + 1] - ypoints[dyy + y]) / sow; int yap =
(ypoints[dyy + y + 1] - ypoints[dyy + y]) / sow;
/* calculate the source line we'll scan from */ /* calculate the source line we'll scan from */
dptr = dest + dx + ((y + dy) * dow); dptr = dest + dx + ((y + dy) * dow);
sptr = ypoints[dyy + y]; sptr = ypoints[dyy + y];
for (x = dxx; x < end; x++) for (x = dxx; x < end; x++)
{ {
int xap = xpoints[x + 1] - xpoints[x]; int xap = xpoints[x + 1] - xpoints[x];
if ((xap > 1) || (yap > 1)) if ((xap > 1) || (yap > 1))
{ {
r = 0; g = 0; b = 0; r = 0;
g = 0;
b = 0;
pix = ypoints[dyy + y] + xpoints[x]; pix = ypoints[dyy + y] + xpoints[x];
for (j = yap; --j >= 0; ) for (j = yap; --j >= 0;)
{ {
for (i = xap; --i >= 0; ) for (i = xap; --i >= 0;)
{ {
r += R_VAL(pix + i); r += R_VAL(pix + i);
g += G_VAL(pix + i); g += G_VAL(pix + i);
@ -942,7 +956,7 @@ __imlib_ScaleAARGBA(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
/* scale by area sampling - IGNORE the ALPHA byte*/ /* scale by area sampling - IGNORE the ALPHA byte*/
void void
__imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy, __imlib_ScaleAARGB(ImlibScaleInfo * isi, DATA32 * dest, int dxx, int dyy,
int dx, int dy, int dw, int dh, int dow, int sow) int dx, int dy, int dw, int dh, int dow, int sow)
{ {
DATA32 *sptr, *dptr; DATA32 *sptr, *dptr;
@ -984,7 +998,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
rr = R_VAL(pix) * XAP; rr = R_VAL(pix) * XAP;
gg = G_VAL(pix) * XAP; gg = G_VAL(pix) * XAP;
bb = B_VAL(pix) * XAP; bb = B_VAL(pix) * XAP;
pix --; pix--;
rr += R_VAL(pix) * INV_XAP; rr += R_VAL(pix) * INV_XAP;
gg += G_VAL(pix) * INV_XAP; gg += G_VAL(pix) * INV_XAP;
bb += B_VAL(pix) * INV_XAP; bb += B_VAL(pix) * INV_XAP;
@ -1033,7 +1047,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
*dptr++ = RGBA_COMPOSE(r, g, b, 0xff); *dptr++ = RGBA_COMPOSE(r, g, b, 0xff);
} }
else else
*dptr++ = sptr[xpoints[x] ]; *dptr++ = sptr[xpoints[x]];
} }
} }
} }
@ -1042,7 +1056,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
else if (isi->xup_yup == 1) else if (isi->xup_yup == 1)
#ifndef OLD_SCALE_DOWN #ifndef OLD_SCALE_DOWN
{ {
/*\ 'Correct' version, with math units prepared for MMXification \*/ /*\ 'Correct' version, with math units prepared for MMXification \ */
int Cy, j; int Cy, j;
DATA32 *pix; DATA32 *pix;
int r, g, b, rr, gg, bb; int r, g, b, rr, gg, bb;
@ -1119,6 +1133,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
for (y = 0; y < dh; y++) for (y = 0; y < dh; y++)
{ {
int yap; int yap;
/* calculate the source line we'll scan from */ /* calculate the source line we'll scan from */
dptr = dest + dx + ((y + dy) * dow); dptr = dest + dx + ((y + dy) * dow);
sptr = ypoints[dyy + y]; sptr = ypoints[dyy + y];
@ -1203,7 +1218,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
else if (isi->xup_yup == 2) else if (isi->xup_yup == 2)
#ifndef OLD_SCALE_DOWN #ifndef OLD_SCALE_DOWN
{ {
/*\ 'Correct' version, with math units prepared for MMXification \*/ /*\ 'Correct' version, with math units prepared for MMXification \ */
int Cx, j; int Cx, j;
DATA32 *pix; DATA32 *pix;
int r, g, b, rr, gg, bb; int r, g, b, rr, gg, bb;
@ -1368,7 +1383,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
else else
#ifndef OLD_SCALE_DOWN #ifndef OLD_SCALE_DOWN
{ {
/*\ 'Correct' version, with math units prepared for MMXification \*/ /*\ 'Correct' version, with math units prepared for MMXification \ */
int Cx, Cy, i, j; int Cx, Cy, i, j;
DATA32 *pix; DATA32 *pix;
int r, g, b, rx, gx, bx; int r, g, b, rx, gx, bx;
@ -1479,20 +1494,24 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
/* go through every scanline in the output buffer */ /* go through every scanline in the output buffer */
for (y = 0; y < dh; y++) for (y = 0; y < dh; y++)
{ {
int yap = (ypoints[dyy + y + 1] - ypoints[dyy + y]) / sow; int yap =
(ypoints[dyy + y + 1] - ypoints[dyy + y]) / sow;
/* calculate the source line we'll scan from */ /* calculate the source line we'll scan from */
dptr = dest + dx + ((y + dy) * dow); dptr = dest + dx + ((y + dy) * dow);
sptr = ypoints[dyy + y]; sptr = ypoints[dyy + y];
for (x = dxx; x < end; x++) for (x = dxx; x < end; x++)
{ {
int xap = xpoints[x + 1] - xpoints[x]; int xap = xpoints[x + 1] - xpoints[x];
if ((xap > 1) || (yap > 1)) if ((xap > 1) || (yap > 1))
{ {
r = 0; g = 0; b = 0; r = 0;
g = 0;
b = 0;
pix = sptr + xpoints[x]; pix = sptr + xpoints[x];
for (j = yap; --j >= 0; ) for (j = yap; --j >= 0;)
{ {
for (i = xap; --i >= 0; ) for (i = xap; --i >= 0;)
{ {
r += R_VAL(pix + i); r += R_VAL(pix + i);
g += G_VAL(pix + i); g += G_VAL(pix + i);
@ -1513,4 +1532,3 @@ __imlib_ScaleAARGB(ImlibScaleInfo *isi, DATA32 *dest, int dxx, int dyy,
} }
#endif #endif
} }

View File

@ -31,130 +31,148 @@
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] == '\"' ) if (str[i] == '\"')
in_quote = (in_quote == 0 ? 1 : 0); in_quote = (in_quote == 0 ? 1 : 0);
if( in_quote || ! isspace(*(str+i)) ) if (in_quote || !isspace(*(str + i)))
tmpstr[strt++] = 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++ ) for (i = start; i <= end; i++)
rstr[i-start] = str[i]; rstr[i - start] = str[i];
return rstr; 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 ); free(param->key);
if( param->type == VAR_CHAR ) if (param->type == VAR_CHAR)
free( param->data ); free(param->data);
free( param ); 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 =
0;
char *value = NULL; char *value = NULL;
IFunctionParam *rootptr, *ptr; 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)
value_start = i + 1;
if (!in_quote && (parameters[i] == ',' || i == (strlen(parameters)))
&& depth == 0)
{ {
ptr->next = malloc( sizeof( IFunctionParam ) ); ptr->next = malloc(sizeof(IFunctionParam));
ptr = ptr->next; ptr = ptr->next;
ptr->key = __imlib_copystr( parameters, start, value_start - 2 ); ptr->key = __imlib_copystr(parameters, start, value_start - 2);
value = __imlib_copystr( parameters, value_start, i-1 ); 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" ); D("(--) Found a function");
ptr->data = __imlib_script_parse_function( im, value ); ptr->data = __imlib_script_parse_function(im, value);
ptr->type = VAR_PTR; ptr->type = VAR_PTR;
free( value ); free(value);
} }
else else
{ {
if( strcmp( value, "[]" ) == 0 ) if (strcmp(value, "[]") == 0)
{ {
ptr->data = __imlib_script_get_next_var(); ptr->data = __imlib_script_get_next_var();
if( ptr->data == NULL ) if (ptr->data == NULL)
D( "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEK" ); D("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEK");
/* printf( "Using pointer variable %p\n", ptr->data );*/ /* printf( "Using pointer variable %p\n", ptr->data ); */
ptr->type = VAR_PTR; ptr->type = VAR_PTR;
free(value); free(value);
} }
@ -165,106 +183,115 @@ IFunctionParam *__imlib_script_parse_parameters( Imlib_Image im, char *parameter
} }
} }
ptr->next = NULL; ptr->next = NULL;
start = i+1; 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; start = start + i + 2;
i = ( i == 0 ? 0 : i ); i = __imlib_find_string(scriptbuf + start, "=[]") - 1;
D( "(??) Found pointer variable" ); i = (i == 0 ? 0 : i);
D("(??) Found pointer variable");
} }
start = 0; start = 0;
i = 0; i = 0;
for( i = 0; i < strlen( scriptbuf ); i++ ) for (i = 0; i < strlen(scriptbuf); i++)
{ {
if( script[i] == '\"' ) if (script[i] == '\"')
in_quote = (in_quote == 0 ? 1 : 0); in_quote = (in_quote == 0 ? 1 : 0);
if( !in_quote && script[i] == '(' ) depth++; if (!in_quote && script[i] == '(')
if( !in_quote && script[i] == ')' ) depth--; depth++;
if( !in_quote && (script[i] == ';') && depth == 0 ) if (!in_quote && script[i] == ')')
depth--;
if (!in_quote && (script[i] == ';') && depth == 0)
{ {
function = __imlib_copystr( scriptbuf, start, i-1 ); function = __imlib_copystr(scriptbuf, start, i - 1);
im = __imlib_script_parse_function( im, function ); im = __imlib_script_parse_function(im, function);
imlib_context_set_image( im ); imlib_context_set_image(im);
start = i+1; start = i + 1;
free( function ); free(function);
} }
} }
D( "(--) Cleaning up parameter list" ); D("(--) Cleaning up parameter list");
__imlib_script_tidyup(); __imlib_script_tidyup();
D( "(--) Script Parser Successful." ); D("(--) Script Parser Successful.");
free( scriptbuf ); free(scriptbuf);
return im; return im;
} }
else else
{ {
D( "(!!) Script Parser Failed." ); D("(!!) Script Parser Failed.");
return NULL; return NULL;
} }
} }

View File

@ -1,14 +1,12 @@
#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;
}; };
@ -20,7 +18,7 @@ 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;
@ -43,7 +41,7 @@ __imlib_MergeUpdate(ImlibUpdate *u, int w, int h, int hgapmax)
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);
@ -54,7 +52,7 @@ __imlib_MergeUpdate(ImlibUpdate *u, int w, int h, int hgapmax)
} }
} }
/* 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;
@ -97,8 +95,7 @@ __imlib_MergeUpdate(ImlibUpdate *u, int w, int h, int hgapmax)
{ {
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--;
} }
} }
@ -114,11 +111,9 @@ __imlib_MergeUpdate(ImlibUpdate *u, int w, int h, int hgapmax)
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 < th) && (ok); yy++, hh++)
yy++, hh++)
{ {
for (xx = x; xx < (x + ww); xx++) for (xx = x; xx < (x + ww); xx++)
{ {
@ -146,7 +141,7 @@ __imlib_MergeUpdate(ImlibUpdate *u, int w, int h, int hgapmax)
} }
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;
@ -162,7 +157,7 @@ __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;
@ -176,7 +171,7 @@ __imlib_FreeUpdates(ImlibUpdate *u)
} }
ImlibUpdate * ImlibUpdate *
__imlib_DupUpdates(ImlibUpdate *u) __imlib_DupUpdates(ImlibUpdate * u)
{ {
ImlibUpdate *uu, *cu, *pu, *ru; ImlibUpdate *uu, *cu, *pu, *ru;

View File

@ -31,35 +31,35 @@ 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;
@ -96,10 +96,14 @@ __imlib_FlushXImage(Display *d)
} }
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);
if (list_used)
free(list_used);
if (list_d)
free(list_d);
list_xim = NULL; list_xim = NULL;
list_si = NULL; list_si = NULL;
list_used = NULL; list_used = NULL;
@ -107,8 +111,11 @@ __imlib_FlushXImage(Display *d)
} }
else else
{ {
list_xim = realloc(list_xim, sizeof(XImage *) * list_num); list_xim =
list_si = realloc(list_si, sizeof(XShmSegmentInfo *) * list_num); 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_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);
} }
@ -120,7 +127,7 @@ __imlib_FlushXImage(Display *d)
/* 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;
@ -143,7 +150,8 @@ __imlib_ConsumeXImage(Display *d, XImage *xim)
/* 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;
@ -167,9 +175,8 @@ __imlib_ProduceXImage(Display *d, Visual *v, int depth, int w, int h, char *shar
/* 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 */

View File

@ -27,7 +27,8 @@ 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;
@ -45,9 +46,12 @@ int main (int argc, char **argv)
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,7 +72,7 @@ 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;
@ -76,6 +80,7 @@ int main (int argc, char **argv)
while (1) while (1)
{ {
Imlib_Image *temp, *temp2; Imlib_Image *temp, *temp2;
do do
{ {
XNextEvent(disp, &ev); XNextEvent(disp, &ev);
@ -96,22 +101,23 @@ int main (int argc, char **argv)
} }
while (XPending(disp)); while (XPending(disp));
imlib_context_set_blend( 0 ); imlib_context_set_blend(0);
imlib_context_set_image(im_bg); imlib_context_set_image(im_bg);
temp = imlib_clone_image(); temp = imlib_clone_image();
imlib_context_set_image( temp ); imlib_context_set_image(temp);
/* imlib_blend_image_onto_image(im_bg, 0, /* imlib_blend_image_onto_image(im_bg, 0,
0, 0, w, h, * 0, 0, w, h,
0, 0, w, h); * 0, 0, w, h);
first = 0;*/ * first = 0; */
imlib_apply_filter("bump_map_point(x=[],y=[],map=test_images/imlib2.png);", &x, &y ); imlib_apply_filter
("bump_map_point(x=[],y=[],map=test_images/imlib2.png);", &x, &y);
temp2 = im_bg; temp2 = im_bg;
im_bg = temp; im_bg = temp;
imlib_context_set_image(im_bg); imlib_context_set_image(im_bg);
imlib_render_image_on_drawable(0, 0 ); imlib_render_image_on_drawable(0, 0);
im_bg = temp2; im_bg = temp2;
imlib_context_set_image(temp); imlib_context_set_image(temp);
imlib_free_image(); imlib_free_image();

View File

@ -77,7 +77,7 @@ main(int argc, char **argv)
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)
{ {
@ -107,12 +107,12 @@ main(int argc, char **argv)
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();
} }

View File

@ -13,18 +13,24 @@ 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;
@ -65,6 +71,7 @@ int main(int argc, char **argv)
{ {
/* image variable */ /* image variable */
Imlib_Image image; Imlib_Image image;
/* width and height values */ /* width and height values */
int w, h, text_w, text_h; int w, h, text_w, text_h;
@ -80,8 +87,10 @@ int main(int argc, char **argv)
/* window rectangle was exposed - add it to the list of */ /* window rectangle was exposed - add it to the list of */
/* rectangles we need to re-render */ /* rectangles we need to re-render */
updates = imlib_update_append_rect(updates, updates = imlib_update_append_rect(updates,
ev.xexpose.x, ev.xexpose.y, ev.xexpose.x,
ev.xexpose.width, ev.xexpose.height); ev.xexpose.y,
ev.xexpose.width,
ev.xexpose.height);
break; break;
case ButtonPress: case ButtonPress:
/* if we click anywhere in the window, exit */ /* if we click anywhere in the window, exit */
@ -98,8 +107,8 @@ int main(int argc, char **argv)
imlib_free_image(); imlib_free_image();
/* the old position - so we wipe over where it used to be */ /* the old position - so we wipe over where it used to be */
updates = imlib_update_append_rect(updates, updates = imlib_update_append_rect(updates,
mouse_x - (w / 2), mouse_y - (h / 2), mouse_x - (w / 2),
w, h); mouse_y - (h / 2), w, h);
font = imlib_load_font("notepad/30"); font = imlib_load_font("notepad/30");
if (font) if (font)
{ {
@ -110,7 +119,8 @@ int main(int argc, char **argv)
imlib_get_text_size(text, &text_w, &text_h); imlib_get_text_size(text, &text_w, &text_h);
imlib_free_font(); imlib_free_font();
updates = imlib_update_append_rect(updates, updates = imlib_update_append_rect(updates,
320 - (text_w / 2), 240 - (text_h / 2), 320 - (text_w / 2),
240 - (text_h / 2),
text_w, text_h); text_w, text_h);
} }
@ -118,8 +128,8 @@ int main(int argc, char **argv)
mouse_y = ev.xmotion.y; mouse_y = ev.xmotion.y;
/* the new one */ /* the new one */
updates = imlib_update_append_rect(updates, updates = imlib_update_append_rect(updates,
mouse_x - (w / 2), mouse_y - (h / 2), mouse_x - (w / 2),
w, h); mouse_y - (h / 2), w, h);
font = imlib_load_font("notepad/30"); font = imlib_load_font("notepad/30");
if (font) if (font)
{ {
@ -130,7 +140,8 @@ int main(int argc, char **argv)
imlib_get_text_size(text, &text_w, &text_h); imlib_get_text_size(text, &text_w, &text_h);
imlib_free_font(); imlib_free_font();
updates = imlib_update_append_rect(updates, updates = imlib_update_append_rect(updates,
320 - (text_w / 2), 240 - (text_h / 2), 320 - (text_w / 2),
240 - (text_h / 2),
text_w, text_h); text_w, text_h);
} }
default: default:
@ -178,7 +189,7 @@ int main(int argc, char **argv)
/* blend image onto the buffer and scale it to 640x480 */ /* blend image onto the buffer and scale it to 640x480 */
imlib_blend_image_onto_image(image, 0, imlib_blend_image_onto_image(image, 0,
0, 0, w, h, 0, 0, w, h,
- up_x, - up_y, 640, 480); -up_x, -up_y, 640, 480);
/* working with the loaded image */ /* working with the loaded image */
imlib_context_set_image(image); imlib_context_set_image(image);
/* free it */ /* free it */
@ -195,7 +206,8 @@ int main(int argc, char **argv)
{ {
imlib_blend_image_onto_image(image, 0, imlib_blend_image_onto_image(image, 0,
0, 0, w, h, 0, 0, w, h,
mouse_x - (w / 2) - up_x, mouse_y - (h / 2) - up_y, w, h); mouse_x - (w / 2) - up_x,
mouse_y - (h / 2) - up_y, w, h);
imlib_context_set_image(image); imlib_context_set_image(image);
imlib_free_image(); imlib_free_image();
} }
@ -215,7 +227,8 @@ int main(int argc, char **argv)
imlib_add_color_to_color_range(20); imlib_add_color_to_color_range(20);
/* draw the range */ /* draw the range */
imlib_context_set_image(buffer); imlib_context_set_image(buffer);
imlib_image_fill_color_range_rectangle(- up_x, - up_y, 128, 128, -45.0); imlib_image_fill_color_range_rectangle(-up_x, -up_y, 128, 128,
-45.0);
/* free it */ /* free it */
imlib_free_color_range(); imlib_free_color_range();
@ -236,7 +249,8 @@ int main(int argc, char **argv)
/* query the size it will be */ /* query the size it will be */
imlib_get_text_size(text, &text_w, &text_h); imlib_get_text_size(text, &text_w, &text_h);
/* draw it */ /* draw it */
imlib_text_draw(320 - (text_w / 2) - up_x, 240 - (text_h / 2) - up_y, text); imlib_text_draw(320 - (text_w / 2) - up_x,
240 - (text_h / 2) - up_y, text);
/* free the font */ /* free the font */
imlib_free_font(); imlib_free_font();
} }

File diff suppressed because it is too large Load Diff

View File

@ -90,13 +90,13 @@ main(int argc, char **argv)
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;