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>
Brian Lindholm <lindholm@aol.com>
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.
_______________________________________________
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
* 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).

View File

@ -7,14 +7,30 @@ AM_INIT_AUTOMAKE(imlib2, 1.0.7)
AM_CONFIG_HEADER(config.h)
freetype_libs=-lttf
AC_ARG_WITH(ttf,
[ --with-ttf=DIR use freetype rooted at <DIR>],
[freetype_libs="$freetype_libs -L$withval/lib"
freetype_includes="-I$withval/include"
CPPFLAGS="$CPPFLAGS $freetype_includes"
LIBS="$LIBS $freetype_libs"
])
dnl here was freetype stuff (1)
# check for freetype
AC_ARG_WITH(freetype-config,
[ --with-freetype-config=FREETYPE_CONFIG use freetype-config specified ],
[
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
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,'`
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 "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)
dnl here was freetype headers checking
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
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
dnl /here was freetype headers checking
AC_CHECK_LIB(dl, dlopen, dlopen_libs=-ldl)
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_libs)
AC_SUBST(dlopen_libs)
AC_SUBST(freetype_cflags)
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 \
filters/Makefile demo/Makefile doc/Makefile \

View File

@ -6,14 +6,28 @@ AM_INIT_AUTOMAKE(imlib2, 1.0.7)
AM_CONFIG_HEADER(config.h)
freetype_libs=-lttf
AC_ARG_WITH(ttf,
[ --with-ttf=DIR use freetype rooted at <DIR>],
[freetype_libs="$freetype_libs -L$withval/lib"
freetype_includes="-I$withval/include"
CPPFLAGS="$CPPFLAGS $freetype_includes"
LIBS="$LIBS $freetype_libs"
dnl here was freetype stuff (1)
AC_ARG_WITH(freetype-config,
[ --with-freetype-config=FREETYPE_CONFIG use freetype-config specified ],
[
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
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,'`
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])
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
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)
EXTRA_LIBS="-L/usr/local/lib -L/usr/X11R6/lib"
@ -304,7 +288,10 @@ AC_SUBST(x_ldflags)
AC_SUBST(x_libs)
AC_SUBST(dlopen_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 \
filters/Makefile demo/Makefile doc/Makefile \

View File

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

View File

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

View File

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

View File

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

View File

@ -11,101 +11,108 @@
#include "script.h"
#include "dynamic_filters.h"
void init( struct imlib_filter_info *info );
void deinit(void);
void *exec( char *filter, void *im, pIFunctionParam params );
void init(struct imlib_filter_info *info);
void deinit(void);
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" };
int i = 0;
char *filters[] = { "tint", "cool_text", "gradient" };
int i = 0;
info->name = strdup( "Test Filter" );
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->name = strdup("Test Filter");
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->num_filters = 3;
info->filters = malloc(sizeof(char *)*3);
info->filters = malloc(sizeof(char *) * 3);
for (i = 0; i < info->num_filters; i++)
info->filters[i] = strdup(filters[i]);
}
void deinit(void)
void
deinit(void)
{
return;
}
void *exec( char *filter, void *im, pIFunctionParam params )
void *
exec(char *filter, void *im, pIFunctionParam params)
{
Imlib_Image imge = im;
Imlib_Image anoim;
IFunctionParam *ptr;
if( strcmp( filter, "tint" ) == 0 )
{
Imlib_Color_Modifier cm;
DATA8 atab[256];
int x = 0, y = 0, w = 0, h = 0;
DATA8 r = 255, b = 255, g = 255, a = 255;
Imlib_Image imge = im;
Imlib_Image anoim;
IFunctionParam *ptr;
if (strcmp(filter, "tint") == 0)
{
Imlib_Color_Modifier cm;
DATA8 atab[256];
int x = 0, y = 0, w = 0, h = 0;
DATA8 r = 255, b = 255, g = 255, a = 255;
/*
printf( "filter_test.c: tint called\n" );
*/
/* Set friendly defaults */
imlib_context_set_image( imge );
w = imlib_image_get_width();
h = imlib_image_get_height();
for( ptr = params; ptr != NULL; ptr = ptr->next )
{
ASSIGN_DATA8( "red", r );
ASSIGN_DATA8( "blue", b );
ASSIGN_DATA8( "green", g );
ASSIGN_INT( "x", x );
ASSIGN_INT( "y", y );
ASSIGN_INT( "w", w );
ASSIGN_INT( "h", h );
ASSIGN_DATA8( "alpha", a );
}
/* Set friendly defaults */
imlib_context_set_image(imge);
w = imlib_image_get_width();
h = imlib_image_get_height();
for (ptr = params; ptr != NULL; ptr = ptr->next)
{
ASSIGN_DATA8("red", r);
ASSIGN_DATA8("blue", b);
ASSIGN_DATA8("green", g);
ASSIGN_INT("x", x);
ASSIGN_INT("y", y);
ASSIGN_INT("w", w);
ASSIGN_INT("h", h);
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 );
*/
anoim = imlib_create_image( w, h );
cm = imlib_create_color_modifier();
imlib_context_set_color_modifier(cm);
imlib_context_set_image(anoim);
imlib_context_set_color(r, g, b, 255);
imlib_image_fill_rectangle(0, 0, w, h);
imlib_context_set_blend(1);
imlib_image_set_has_alpha(1);
memset(atab, a, sizeof(atab));
imlib_set_color_modifier_tables(NULL, NULL, NULL, atab);
imlib_apply_color_modifier_to_rectangle(0, 0, w, h);
imlib_context_set_image( imge );
imlib_blend_image_onto_image( anoim, 0, 0, 0, w, h, x, y, w, h);
imlib_free_color_modifier();
imlib_context_set_image(anoim);
imlib_free_image_and_decache();
imlib_context_set_image(imge);
return imge;
}
if( strcmp( filter, "cool_text" ) == 0 )
{
return imge;
}
if( strcmp( filter, "gradient" ) == 0 )
{
int angle = 0;
for( ptr = params; ptr != NULL; ptr = ptr->next )
{
ASSIGN_INT( "angle", angle );
}
return imge;
}
anoim = imlib_create_image(w, h);
cm = imlib_create_color_modifier();
imlib_context_set_color_modifier(cm);
imlib_context_set_image(anoim);
imlib_context_set_color(r, g, b, 255);
imlib_image_fill_rectangle(0, 0, w, h);
imlib_context_set_blend(1);
imlib_image_set_has_alpha(1);
memset(atab, a, sizeof(atab));
imlib_set_color_modifier_tables(NULL, NULL, NULL, atab);
imlib_apply_color_modifier_to_rectangle(0, 0, w, h);
imlib_context_set_image(imge);
imlib_blend_image_onto_image(anoim, 0, 0, 0, w, h, x, y, w, h);
imlib_free_color_modifier();
imlib_context_set_image(anoim);
imlib_free_image_and_decache();
imlib_context_set_image(imge);
return imge;
}
if (strcmp(filter, "cool_text") == 0)
{
return imge;
}
if (strcmp(filter, "gradient") == 0)
{
int angle = 0;
for (ptr = params; ptr != NULL; ptr = ptr->next)
{
ASSIGN_INT("angle", angle);
}
return imge;
}
return imge;
}

View File

@ -8,5 +8,5 @@ Description: Powerful image loading and rendering library
Version: @VERSION@
Requires: @REQUIREMENTS@
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 "image.h"
char load (ImlibImage *im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load);
char save (ImlibImage *im, ImlibProgressFunction progress,
char progress_granularity);
void formats (ImlibLoader *l);
char load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load);
char save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity);
void formats(ImlibLoader * l);
#define SWAP32(x) (x) = \
((((x) & 0x000000ff ) << 24) |\
@ -21,13 +21,13 @@ void formats (ImlibLoader *l);
(((x) & 0x00ff0000 ) >> 8) |\
(((x) & 0xff000000 ) >> 24))
char
load (ImlibImage *im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
char
load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
int w, h, alpha;
int w, h, alpha;
FILE *f;
if (im->data)
return 0;
f = fopen(im->real_file, "rb");
@ -35,95 +35,95 @@ load (ImlibImage *im, ImlibProgressFunction progress,
return 0;
/* header */
{
char buf[256], buf2[256];
{
char buf[256], buf2[256];
if (!fgets(buf, 255, f))
{
fclose(f);
return 0;
}
sscanf(buf, "%s %i %i %i", buf2, &w, &h, &alpha);
if (strcmp(buf2, "ARGB"))
{
fclose(f);
return 0;
}
im->w = w;
im->h = h;
if (!im->format)
{
if (alpha)
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("argb");
}
}
if (!fgets(buf, 255, f))
{
fclose(f);
return 0;
}
sscanf(buf, "%s %i %i %i", buf2, &w, &h, &alpha);
if (strcmp(buf2, "ARGB"))
{
fclose(f);
return 0;
}
im->w = w;
im->h = h;
if (!im->format)
{
if (alpha)
SET_FLAG(im->flags, F_HAS_ALPHA);
else
UNSET_FLAG(im->flags, F_HAS_ALPHA);
im->format = strdup("argb");
}
}
if (((!im->data) && (im->loader)) || (immediate_load) || (progress))
{
DATA32 *ptr;
int y, pl = 0;
char pper = 0;
DATA32 *ptr;
int y, pl = 0;
char pper = 0;
/* must set the im->data member before callign progress function */
ptr = im->data = malloc(w * h * sizeof(DATA32));
if (!im->data)
{
fclose(f);
return 0;
}
for (y = 0; y < h; y++)
{
/* must set the im->data member before callign progress function */
ptr = im->data = malloc(w * h * sizeof(DATA32));
if (!im->data)
{
fclose(f);
return 0;
}
for (y = 0; y < h; y++)
{
#ifdef WORDS_BIGENDIAN
{
int x;
fread(ptr, im->w, 4, f);
for (x = 0; x < im->w; x++)
SWAP32(ptr[x]);
}
{
int x;
fread(ptr, im->w, 4, f);
for (x = 0; x < im->w; x++)
SWAP32(ptr[x]);
}
#else
fread(ptr, im->w, 4, f);
#endif
ptr += im->w;
if (progress)
{
char per;
int l;
per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) ||
(y == (im->h - 1)))
{
l = y - pl;
if(!progress(im, per, 0, (y - l), im->w, l))
{
fclose(f);
return 2;
}
pper = per;
pl = y;
}
}
}
fread(ptr, im->w, 4, f);
#endif
ptr += im->w;
if (progress)
{
char per;
int l;
per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) ||
(y == (im->h - 1)))
{
l = y - pl;
if (!progress(im, per, 0, (y - l), im->w, l))
{
fclose(f);
return 2;
}
pper = per;
pl = y;
}
}
}
}
fclose(f);
return 1;
}
char
save (ImlibImage *im, ImlibProgressFunction progress,
char progress_granularity)
char
save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
{
FILE *f;
DATA32 *ptr;
int y, pl = 0, alpha = 0;
char pper = 0;
#ifdef WORDS_BIGENDIAN
DATA32 *buf = (DATA32 *) malloc(im->w * 4);
#endif
/* no image data? abort */
if (!im->data)
return 0;
@ -132,47 +132,45 @@ save (ImlibImage *im, ImlibProgressFunction progress,
return 0;
if (im->flags & F_HAS_ALPHA)
alpha = 1;
fprintf(f, "ARGB %i %i %i\n",
im->w, im->h, alpha);
fprintf(f, "ARGB %i %i %i\n", im->w, im->h, alpha);
ptr = im->data;
for (y = 0; y < im->h; y++)
{
#ifdef WORDS_BIGENDIAN
{
int x;
memcpy(buf, ptr, im->w * 4);
for (x = 0; x < im->w; x++)
SWAP32(buf[x]);
fwrite(buf, im->w, 4, f);
}
{
int x;
memcpy(buf, ptr, im->w * 4);
for (x = 0; x < im->w; x++)
SWAP32(buf[x]);
fwrite(buf, im->w, 4, f);
}
#else
fwrite(ptr, im->w, 4, f);
fwrite(ptr, im->w, 4, f);
#endif
ptr += im->w;
if (progress)
{
char per;
int l;
per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) ||
(y == (im->h - 1)))
{
ptr += im->w;
if (progress)
{
char per;
int l;
per = (char)((100 * y) / im->h);
if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
{
l = y - pl;
if(!progress(im, per, 0, (y - l), im->w, l))
{
if (!progress(im, per, 0, (y - l), im->w, l))
{
#ifdef WORDS_BIGENDIAN
if (buf)
free(buf);
if (buf)
free(buf);
#endif
fclose(f);
return 2;
}
pper = per;
pl = y;
}
}
fclose(f);
return 2;
}
pper = per;
pl = y;
}
}
}
/* finish off */
#ifdef WORDS_BIGENDIAN
@ -183,19 +181,17 @@ save (ImlibImage *im, ImlibProgressFunction progress,
return 1;
}
void
formats (ImlibLoader *l)
{
char *list_formats[] =
{ "argb", "arg" };
void
formats(ImlibLoader * l)
{
char *list_formats[] = { "argb", "arg" };
{
int i;
l->num_formats = (sizeof(list_formats) / sizeof (char *));
l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]);
}
{
int i;
l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]);
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -19,174 +19,175 @@
/* 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 */
struct TIFFRGBAImage_Extra
{
TIFFRGBAImage rgba;
tileContigRoutine put_contig;
tileSeparateRoutine put_separate;
ImlibImage *image;
ImlibProgressFunction progress;
char pper;
char progress_granularity;
uint32 num_pixels;
uint32 py;
struct TIFFRGBAImage_Extra {
TIFFRGBAImage rgba;
tileContigRoutine put_contig;
tileSeparateRoutine put_separate;
ImlibImage *image;
ImlibProgressFunction progress;
char pper;
char progress_granularity;
uint32 num_pixels;
uint32 py;
};
typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
static void put_contig_and_raster(TIFFRGBAImage*, uint32*,
uint32, uint32, uint32, uint32, int32, int32, unsigned char*);
static void put_separate_and_raster(TIFFRGBAImage*, uint32*,
uint32, uint32, uint32, uint32, int32, int32,
unsigned char*, unsigned char*, unsigned char*, unsigned char*);
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 save (ImlibImage *im, ImlibProgressFunction progress,
char progress_granularity);
void formats (ImlibLoader *l);
static void put_contig_and_raster(TIFFRGBAImage *, uint32 *,
uint32, uint32, uint32, uint32, int32,
int32, unsigned char *);
static void put_separate_and_raster(TIFFRGBAImage *, uint32 *, uint32,
uint32, uint32, uint32, int32,
int32, unsigned char *,
unsigned char *, unsigned char *,
unsigned char *);
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 save(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity);
void formats(ImlibLoader * l);
static void
put_contig_and_raster(TIFFRGBAImage* img, uint32* rast,
uint32 x, uint32 y, uint32 w, uint32 h,
int32 fromskew, int32 toskew,
unsigned char* cp)
put_contig_and_raster(TIFFRGBAImage * img, uint32 * rast,
uint32 x, uint32 y, uint32 w, uint32 h,
int32 fromskew, int32 toskew, unsigned char *cp)
{
(*(((TIFFRGBAImage_Extra *)img)->put_contig))(img, rast, x, y, w, h,
fromskew, toskew, cp);
raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
(*(((TIFFRGBAImage_Extra *) img)->put_contig)) (img, rast, x, y, w, h,
fromskew, toskew, cp);
raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
}
static void
put_separate_and_raster(TIFFRGBAImage* img, uint32* rast,
uint32 x, uint32 y, uint32 w, uint32 h,
int32 fromskew, int32 toskew,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a)
put_separate_and_raster(TIFFRGBAImage * img, uint32 * rast,
uint32 x, uint32 y, uint32 w, uint32 h,
int32 fromskew, int32 toskew,
unsigned char *r, unsigned char *g, unsigned char *b,
unsigned char *a)
{
(*(((TIFFRGBAImage_Extra *)img)->put_separate))
(img, rast, x, y, w, h, fromskew, toskew, r, g, b, a);
raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
(*(((TIFFRGBAImage_Extra *) img)->put_separate))
(img, rast, x, y, w, h, fromskew, toskew, r, g, b, a);
raster((TIFFRGBAImage_Extra *) img, rast, x, y, w, h);
}
/* needs orientation code */
static void
raster(TIFFRGBAImage_Extra *img, uint32* rast,
raster(TIFFRGBAImage_Extra * img, uint32 * rast,
uint32 x, uint32 y, uint32 w, uint32 h)
{
uint32 image_width, image_height;
uint32 *pixel, pixel_value;
int i, j, dy, rast_offset;
DATA32 *buffer_pixel, *buffer = img->image->data;
uint32 image_width, image_height;
uint32 *pixel, pixel_value;
int i, j, dy, rast_offset;
DATA32 *buffer_pixel, *buffer = img->image->data;
image_width = img->image->w;
image_height = img->image->h;
dy = h > y ? -1 : y - h;
dy = h > y ? -1 : y - h;
/* rast seems to point to the beginning of the last strip processed */
/* so you need use negative offsets. Bizzare. Someone please check this */
/* I don't understand why, but that seems to be what's going on. */
/* libtiff needs better docs! */
for (i = y, rast_offset = 0; i > dy; i--, rast_offset--)
{
pixel = rast + (rast_offset * image_width);
buffer_pixel = buffer + ((((image_height - 1) - i) * image_width) + x);
for (j = 0; j < w; j++)
{
pixel_value = (*(pixel++));
(*(buffer_pixel++)) =
(TIFFGetA(pixel_value) << 24) |
(TIFFGetR(pixel_value) << 16) | (TIFFGetG(pixel_value) << 8) |
TIFFGetB(pixel_value);
}
pixel = rast + (rast_offset * image_width);
buffer_pixel = buffer + ((((image_height - 1) - i) * image_width) + x);
for (j = 0; j < w; j++)
{
pixel_value = (*(pixel++));
(*(buffer_pixel++)) =
(TIFFGetA(pixel_value) << 24) |
(TIFFGetR(pixel_value) << 16) | (TIFFGetG(pixel_value) << 8) |
TIFFGetB(pixel_value);
}
}
if (img->progress)
{
char per;
uint32 real_y = (image_height - 1) - y;
if (w >= image_width)
{
per = (char)(((real_y + h - 1) * 100)/image_height);
if (((per - img->pper) >= img->progress_granularity) ||
(real_y + h) >= image_height)
{
(*img->progress)(img->image, per, 0, img->py, w,
(real_y + h) - img->py);
img->py = real_y + h;
img->pper = per;
}
}
else
{
/* for tile based images, we just progress each tile because */
/* of laziness. Couldn't think of a good way to do this */
per = (char)((w * h * 100) / img->num_pixels);
img->pper += per;
(*img->progress)(img->image, img->pper, x,
(image_height - 1) - y, w, h);
}
char per;
uint32 real_y = (image_height - 1) - y;
if (w >= image_width)
{
per = (char)(((real_y + h - 1) * 100) / image_height);
if (((per - img->pper) >= img->progress_granularity) ||
(real_y + h) >= image_height)
{
(*img->progress) (img->image, per, 0, img->py, w,
(real_y + h) - img->py);
img->py = real_y + h;
img->pper = per;
}
}
else
{
/* for tile based images, we just progress each tile because */
/* of laziness. Couldn't think of a good way to do this */
per = (char)((w * h * 100) / img->num_pixels);
img->pper += per;
(*img->progress) (img->image, img->pper, x,
(image_height - 1) - y, w, h);
}
}
}
char
load (ImlibImage *im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
char
load(ImlibImage * im, ImlibProgressFunction progress,
char progress_granularity, char immediate_load)
{
TIFF *tif = NULL;
FILE *file;
int fd;
uint16 magic_number;
TIFFRGBAImage_Extra rgba_image;
uint32 *rast = NULL;
uint32 width, height, num_pixels;
TIFF *tif = NULL;
FILE *file;
int fd;
uint16 magic_number;
TIFFRGBAImage_Extra rgba_image;
uint32 *rast = NULL;
uint32 width, height, num_pixels;
if (im->data)
return 0;
file = fopen(im->real_file, "rb");
if (!file)
return 0;
fread(&magic_number, sizeof(uint16), 1, file);
/* Apparently rewind(f) isn't sufficient */
fseek(file, (long)0, SEEK_SET);
if ((magic_number != TIFF_BIGENDIAN) /* Checks if actually tiff file */
&& (magic_number != TIFF_LITTLEENDIAN))
{
fclose(file);
return 0;
fclose(file);
return 0;
}
fd = fileno(file);
fd = dup(fd);
lseek(fd, (long)0, SEEK_SET);
fclose(file);
tif = TIFFFdOpen(fd, im->real_file, "r");
if (!tif)
return 0;
if ((!TIFFRGBAImageOK(tif, "Cannot be processed by libtiff"))
|| (!TIFFRGBAImageBegin((TIFFRGBAImage *) &rgba_image, tif, 0,
"Error reading tiff")))
if ((!TIFFRGBAImageOK(tif, "Cannot be processed by libtiff"))
|| (!TIFFRGBAImageBegin((TIFFRGBAImage *) & rgba_image, tif, 0,
"Error reading tiff")))
{
TIFFClose(tif);
return 0;
TIFFClose(tif);
return 0;
}
rgba_image.image = im;
im->w = width = rgba_image.rgba.width;
im->h = height = rgba_image.rgba.height;
@ -197,77 +198,77 @@ load (ImlibImage *im, ImlibProgressFunction progress,
UNSET_FLAG(im->flags, F_HAS_ALPHA);
if (!im->format)
im->format = strdup("tiff");
if ((im->loader) || (immediate_load) || (progress))
{
rgba_image.progress = progress;
rgba_image.pper = rgba_image.py = 0;
rgba_image.progress_granularity = progress_granularity;
rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels);
im->data = (DATA32 *) malloc(sizeof(DATA32) * num_pixels);
if ((!rast) || (!im->data)) /* Error checking */
{
fprintf(stderr, "imlib2-tiffloader: Out of memory\n");
if (!rast)
_TIFFfree(rast);
if (!im->data)
{
free(im->data);
im->data = NULL;
}
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image);
TIFFClose(tif);
return 0;
}
if (rgba_image.rgba.put.any == NULL)
{
fprintf(stderr, "imlib2-tiffloader: No put function");
_TIFFfree(rast);
free(im->data);
im->data = NULL;
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image);
TIFFClose(tif);
return 0;
}
else
{
if (rgba_image.rgba.isContig)
{
rgba_image.put_contig = rgba_image.rgba.put.contig;
rgba_image.rgba.put.contig = put_contig_and_raster;
}
else
{
rgba_image.put_separate = rgba_image.rgba.put.separate;
rgba_image.rgba.put.separate = put_separate_and_raster;
}
}
if (!TIFFRGBAImageGet((TIFFRGBAImage *) &rgba_image,
rast, width, height))
{
_TIFFfree(rast);
free(im->data);
im->data = NULL;
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image);
TIFFClose(tif);
return 0;
}
_TIFFfree(rast);
{
rgba_image.progress = progress;
rgba_image.pper = rgba_image.py = 0;
rgba_image.progress_granularity = progress_granularity;
rast = (uint32 *) _TIFFmalloc(sizeof(uint32) * num_pixels);
im->data = (DATA32 *) malloc(sizeof(DATA32) * num_pixels);
if ((!rast) || (!im->data)) /* Error checking */
{
fprintf(stderr, "imlib2-tiffloader: Out of memory\n");
if (!rast)
_TIFFfree(rast);
if (!im->data)
{
free(im->data);
im->data = NULL;
}
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif);
return 0;
}
if (rgba_image.rgba.put.any == NULL)
{
fprintf(stderr, "imlib2-tiffloader: No put function");
_TIFFfree(rast);
free(im->data);
im->data = NULL;
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif);
return 0;
}
else
{
if (rgba_image.rgba.isContig)
{
rgba_image.put_contig = rgba_image.rgba.put.contig;
rgba_image.rgba.put.contig = put_contig_and_raster;
}
else
{
rgba_image.put_separate = rgba_image.rgba.put.separate;
rgba_image.rgba.put.separate = put_separate_and_raster;
}
}
if (!TIFFRGBAImageGet((TIFFRGBAImage *) & rgba_image,
rast, width, height))
{
_TIFFfree(rast);
free(im->data);
im->data = NULL;
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif);
return 0;
}
_TIFFfree(rast);
}
TIFFRGBAImageEnd((TIFFRGBAImage *) &rgba_image);
TIFFRGBAImageEnd((TIFFRGBAImage *) & rgba_image);
TIFFClose(tif);
return 1;
}
@ -275,34 +276,34 @@ load (ImlibImage *im, ImlibProgressFunction progress,
/* this is a problem in libtiff */
char
save (ImlibImage *im, ImlibProgressFunction progress,
char progress_granularity)
save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
{
TIFF *tif = NULL;
uint8 *buf = NULL;
DATA32 pixel, *data = im->data;
double alpha_factor;
uint32 x, y;
uint8 r, g, b, a;
int has_alpha = IMAGE_HAS_ALPHA(im);
int i = 0, pl = 0;
char pper = 0;
TIFF *tif = NULL;
uint8 *buf = NULL;
DATA32 pixel, *data = im->data;
double alpha_factor;
uint32 x, y;
uint8 r, g, b, a;
int has_alpha = IMAGE_HAS_ALPHA(im);
int i = 0, pl = 0;
char pper = 0;
/* By default uses patent-free use COMPRESSION_DEFLATE,
another lossless compression technique */
ImlibImageTag *tag;
int compression_type = COMPRESSION_DEFLATE;
* another lossless compression technique */
ImlibImageTag *tag;
int compression_type = COMPRESSION_DEFLATE;
if (!im->data)
return 0;
tif = TIFFOpen(im->real_file, "w");
if (!tif)
return 0;
/* None of the TIFFSetFields are checked for errors, but since they */
/* shouldn't fail, this shouldn't be a problem */
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, im->h);
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, im->w);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
@ -316,112 +317,138 @@ save (ImlibImage *im, ImlibProgressFunction progress,
/* compression */
tag = __imlib_GetTag(im, "compression_type");
if (tag) {
compression_type = tag->val;
switch (compression_type) {
case COMPRESSION_NONE: break;
case COMPRESSION_CCITTRLE: break;
case COMPRESSION_CCITTFAX3: break;
case COMPRESSION_CCITTFAX4: break;
case COMPRESSION_LZW: break;
case COMPRESSION_OJPEG: break;
case COMPRESSION_JPEG: break;
case COMPRESSION_NEXT: break;
case COMPRESSION_CCITTRLEW: break;
case COMPRESSION_PACKBITS: break;
case COMPRESSION_THUNDERSCAN: break;
case COMPRESSION_IT8CTPAD: break;
case COMPRESSION_IT8LW: break;
case COMPRESSION_IT8MP: break;
case COMPRESSION_IT8BL: break;
case COMPRESSION_PIXARFILM: break;
case COMPRESSION_PIXARLOG: break;
case COMPRESSION_DEFLATE: break;
case COMPRESSION_ADOBE_DEFLATE: break;
case COMPRESSION_DCS: break;
case COMPRESSION_JBIG: break;
case COMPRESSION_SGILOG: break;
case COMPRESSION_SGILOG24: break;
default: compression_type = COMPRESSION_DEFLATE;
}
if (tag)
{
compression_type = tag->val;
switch (compression_type)
{
case COMPRESSION_NONE:
break;
case COMPRESSION_CCITTRLE:
break;
case COMPRESSION_CCITTFAX3:
break;
case COMPRESSION_CCITTFAX4:
break;
case COMPRESSION_LZW:
break;
case COMPRESSION_OJPEG:
break;
case COMPRESSION_JPEG:
break;
case COMPRESSION_NEXT:
break;
case COMPRESSION_CCITTRLEW:
break;
case COMPRESSION_PACKBITS:
break;
case COMPRESSION_THUNDERSCAN:
break;
case COMPRESSION_IT8CTPAD:
break;
case COMPRESSION_IT8LW:
break;
case COMPRESSION_IT8MP:
break;
case COMPRESSION_IT8BL:
break;
case COMPRESSION_PIXARFILM:
break;
case COMPRESSION_PIXARLOG:
break;
case COMPRESSION_DEFLATE:
break;
case COMPRESSION_ADOBE_DEFLATE:
break;
case COMPRESSION_DCS:
break;
case COMPRESSION_JBIG:
break;
case COMPRESSION_SGILOG:
break;
case COMPRESSION_SGILOG24:
break;
default:
compression_type = COMPRESSION_DEFLATE;
}
}
}
TIFFSetField(tif, TIFFTAG_COMPRESSION, compression_type);
if (has_alpha)
{
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, EXTRASAMPLE_ASSOCALPHA);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField(tif, TIFFTAG_EXTRASAMPLES, EXTRASAMPLE_ASSOCALPHA);
}
else
{
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
}
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(tif, 0));
buf = (uint8 *) _TIFFmalloc(TIFFScanlineSize(tif));
if (!buf)
{
TIFFClose(tif);
return 0;
TIFFClose(tif);
return 0;
}
for (y = 0; y < im->h; y++)
{
i = 0;
for (x = 0; x < im->w; x++)
{
pixel = data[(y * im->w) + x];
r = (pixel >> 16) & 0xff;
g = (pixel >> 8) & 0xff;
b = pixel & 0xff;
if (has_alpha)
{
/* TIFF makes you pre-mutiply the rgb components by alpha */
a = (pixel >> 24) & 0xff;
alpha_factor = ((double) a / 255.0);
r *= alpha_factor;
g *= alpha_factor;
b *= alpha_factor;
}
/* This might be endian dependent */
buf[i++] = r;
buf[i++] = g;
buf[i++] = b;
if (has_alpha)
buf[i++] = a;
}
if (!TIFFWriteScanline(tif, buf, y, 0))
{
_TIFFfree(buf);
TIFFClose(tif);
return 0;
}
if (progress)
{
char per;
int l;
per = (char)((100 * y) / im->h);
if ((per - pper) >= progress_granularity)
{
l = y - pl;
(*progress)(im, per, 0, (y - l), im->w, l);
pper = per;
pl = y;
}
}
i = 0;
for (x = 0; x < im->w; x++)
{
pixel = data[(y * im->w) + x];
r = (pixel >> 16) & 0xff;
g = (pixel >> 8) & 0xff;
b = pixel & 0xff;
if (has_alpha)
{
/* TIFF makes you pre-mutiply the rgb components by alpha */
a = (pixel >> 24) & 0xff;
alpha_factor = ((double)a / 255.0);
r *= alpha_factor;
g *= alpha_factor;
b *= alpha_factor;
}
/* This might be endian dependent */
buf[i++] = r;
buf[i++] = g;
buf[i++] = b;
if (has_alpha)
buf[i++] = a;
}
if (!TIFFWriteScanline(tif, buf, y, 0))
{
_TIFFfree(buf);
TIFFClose(tif);
return 0;
}
if (progress)
{
char per;
int l;
per = (char)((100 * y) / im->h);
if ((per - pper) >= progress_granularity)
{
l = y - pl;
(*progress) (im, per, 0, (y - l), im->w, l);
pper = per;
pl = y;
}
}
}
_TIFFfree(buf);
TIFFClose(tif);
return 1;
}
@ -432,21 +459,20 @@ save (ImlibImage *im, ImlibProgressFunction progress,
/* your laoder CAN load more than one format if it likes - like: */
/* loader->formats = { "gif", "png", "jpeg", "jpg"} */
/* if it can load those formats. */
void
formats (ImlibLoader *l)
{
void
formats(ImlibLoader * l)
{
/* this is the only bit you have to change... */
char *list_formats[] =
{ "tiff", "tif" };
char *list_formats[] = { "tiff", "tif" };
/* don't bother changing any of this - it just reads this in and sets */
/* the struct values and makes copies */
{
int i;
l->num_formats = (sizeof(list_formats) / sizeof (char *));
l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]);
}
{
int i;
l->num_formats = (sizeof(list_formats) / sizeof(char *));
l->formats = malloc(sizeof(char *) * l->num_formats);
for (i = 0; i < l->num_formats; i++)
l->formats[i] = strdup(list_formats[i]);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,8 @@ LDFLAGS = -L/usr/X11R6/lib
INCLUDES = -I. -I$(top_srcdir) -I$(top_srcdir)/src \
-I$(top_srcdir)/loaders -I$(top_srcdir)/libltdl \
-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 \
asm_blend_cmod.S
MMX_OBJS = $(MMX_SRCS:.S=.lo)
@ -17,12 +18,13 @@ MMX_OBJS = $(MMX_SRCS:.S=.lo)
lib_LTLIBRARIES = libImlib2.la
include_HEADERS = Imlib2.h
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 \
font_main.c font_load.c font_query.c font_draw.c \
Imlib2.h image.h scale.h blend.h updates.h colormod.h \
file.h common.h rgbadraw.h font.h format.h \
rotate.h grad.h filter.h script.h dynamic_filters.h \
color_helpers.h
color_helpers.h
EXTRA_libImlib2_la_SOURCES = rend.c ximage.c rgba.c color.c grab.c draw.c \
context.c color.h context.h draw.h grab.h rend.h \
@ -32,12 +34,12 @@ libImlib2_la_LDFLAGS = -version-info 1:4:0
if HAVE_MMX
libImlib2_la_LIBADD = $(X_OBJS) @DLLDFLAGS@ $(MMX_OBJS) \
$(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)
else
libImlib2_la_LIBADD = $(X_OBJS) @DLLDFLAGS@ \
$(top_builddir)/libltdl/libltdlc.la \
$(x_libs) -lttf $(LDFLAGS)
$(x_libs) $(freetype_libs) $(LDFLAGS)
libImlib2_la_DEPENDENCIES = $(top_builddir)/config.h $(X_OBJS)
endif

3311
src/api.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -3,187 +3,233 @@
* Color space conversion helper routines
* Convert between rgb and hsv adn between rgb and hls
*/
void
__imlib_rgb_to_hsv(int r, int g, int b, float *hue, float *saturation, float *value)
{
int f;
float i,j,k,max,min,d;
i = ((float)r)/255.0;
j = ((float)g)/255.0;
k = ((float)b)/255.0;
void
__imlib_rgb_to_hsv(int r, int g, int b, float *hue, float *saturation,
float *value)
{
int f;
float i, j, k, max, min, d;
i = ((float)r) / 255.0;
j = ((float)g) / 255.0;
k = ((float)b) / 255.0;
f = 0;
max = min = i;
if (j>max) { max = j; f = 1; } else min = j;
if (k>max) { max = k; f = 2; } else if (k<min) min = k;
if (j > max)
{
max = j;
f = 1;
}
else
min = j;
if (k > max)
{
max = k;
f = 2;
}
else if (k < min)
min = k;
d = max - min;
*value = max;
if (max!=0) *saturation = d/max; else *saturation = 0;
if (*saturation==0)
if (max != 0)
*saturation = d / max;
else
*saturation = 0;
if (*saturation == 0)
*hue = 0;
else
{
switch (f)
{
case 0:
*hue = (j - k)/d;
break;
case 1:
*hue = 2 + (k - i)/d;
break;
case 2:
*hue = 4 + (i - j)/d;
break;
}
*hue *= 60.0;
if (*hue<0) *hue += 360.0;
}
{
switch (f)
{
case 0:
*hue = (j - k) / d;
break;
case 1:
*hue = 2 + (k - i) / d;
break;
case 2:
*hue = 4 + (i - j) / d;
break;
}
*hue *= 60.0;
if (*hue < 0)
*hue += 360.0;
}
}
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;
float vs,vsf;
int i, p, q, t, h;
float vs, vsf;
i = (int)(value*255.0);
if (saturation==0)
i = (int)(value * 255.0);
if (saturation == 0)
*r = *g = *b = i;
else
{
if (hue==360) hue = 0;
hue = hue/60.0;
h = (int)hue;
vs = value * saturation;
vsf = vs * (hue - h);
p = (int)(255.0 * (value - vs));
q = (int)(255.0 * (value - vsf));
t = (int)(255.0 * (value - vs + vsf));
switch (h)
{
case 0:
*r = i;
*g = t;
*b = p;
break;
case 1:
*r = q;
*g = i;
*b = p;
break;
case 2:
*r = p;
*g = i;
*b = t;
break;
case 3:
*r = p;
*g = q;
*b = i;
break;
case 4:
*r = t;
*g = p;
*b = i;
break;
case 5:
*r = i;
*g = p;
*b = q;
break;
}
}
{
if (hue == 360)
hue = 0;
hue = hue / 60.0;
h = (int)hue;
vs = value * saturation;
vsf = vs * (hue - h);
p = (int)(255.0 * (value - vs));
q = (int)(255.0 * (value - vsf));
t = (int)(255.0 * (value - vs + vsf));
switch (h)
{
case 0:
*r = i;
*g = t;
*b = p;
break;
case 1:
*r = q;
*g = i;
*b = p;
break;
case 2:
*r = p;
*g = i;
*b = t;
break;
case 3:
*r = p;
*g = q;
*b = i;
break;
case 4:
*r = t;
*g = p;
*b = i;
break;
case 5:
*r = i;
*g = p;
*b = q;
break;
}
}
}
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;
float i,j,k,max,min,d;
int f;
float i, j, k, max, min, d;
i = ((float)r)/255.0;
j = ((float)g)/255.0;
k = ((float)b)/255.0;
i = ((float)r) / 255.0;
j = ((float)g) / 255.0;
k = ((float)b) / 255.0;
f = 0;
max = min = i;
if (j>max) { max = j; f = 1; } else min = j;
if (k>max) { max = k; f = 2; } else if (k<min) min = k;
if (j > max)
{
max = j;
f = 1;
}
else
min = j;
if (k > max)
{
max = k;
f = 2;
}
else if (k < min)
min = k;
d = max - min;
*lightness = (max + min)/2.0;
if (d==0)
{
*saturation = 0;
*hue = 0;
}
*lightness = (max + min) / 2.0;
if (d == 0)
{
*saturation = 0;
*hue = 0;
}
else
{
if (*lightness < 0.5) *saturation = d/(max + min); else *saturation = d/(2 - max - min);
switch (f)
{
case 0:
*hue = (j - k)/d;
break;
case 1:
*hue = 2 + (k - i)/d;
break;
case 2:
*hue = 4 + (i - j)/d;
break;
}
*hue *= 60.0;
if (*hue<0) *hue += 360.0;
}
{
if (*lightness < 0.5)
*saturation = d / (max + min);
else
*saturation = d / (2 - max - min);
switch (f)
{
case 0:
*hue = (j - k) / d;
break;
case 1:
*hue = 2 + (k - i) / d;
break;
case 2:
*hue = 4 + (i - j) / d;
break;
}
*hue *= 60.0;
if (*hue < 0)
*hue += 360.0;
}
}
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);
else
{
if (lightness<=0.5)
m2 = lightness * (1 + saturation);
else
m2 = lightness + saturation + lightness * saturation;
m1 = 2 * lightness - m2;
m21 = m2 - m1;
h = hue + 120;
if (h>360) h -= 360; else if (h<0) h += 360;
if (h<60)
*r = (int)(255.0 * (m1 + m21 * h/60.0));
else if (h<180)
*r = (int)(255.0 * m2);
else if (h<240)
*r = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0));
else
*r = (int)(255.0 * m1);
h = hue;
if (h>360) h -= 360; else if (h<0) h += 360;
if (h<60)
*g = (int)(255.0 * (m1 + m21 * h/60.0));
else if (h<180)
*g = (int)(255.0 * m2);
else if (h<240)
*g = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0));
else
*g = (int)(255.0 * m1);
h = hue - 120;
if (h>360) h -= 360; else if (h<0) h += 360;
if (h<60)
*b = (int)(255.0 * (m1 + m21 * h/60.0));
else if (h<180)
*b = (int)(255.0 * m2);
else if (h<240)
*b = (int)(255.0 * (m1 + m21 * (240.0 - h)/60.0));
else
*b = (int)(255.0 * m1);
}
{
if (lightness <= 0.5)
m2 = lightness * (1 + saturation);
else
m2 = lightness + saturation + lightness * saturation;
m1 = 2 * lightness - m2;
m21 = m2 - m1;
h = hue + 120;
if (h > 360)
h -= 360;
else if (h < 0)
h += 360;
if (h < 60)
*r = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*r = (int)(255.0 * m2);
else if (h < 240)
*r = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else
*r = (int)(255.0 * m1);
h = hue;
if (h > 360)
h -= 360;
else if (h < 0)
h += 360;
if (h < 60)
*g = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*g = (int)(255.0 * m2);
else if (h < 240)
*g = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else
*g = (int)(255.0 * m1);
h = hue - 120;
if (h > 360)
h -= 360;
else if (h < 0)
h += 360;
if (h < 60)
*b = (int)(255.0 * (m1 + m21 * h / 60.0));
else if (h < 180)
*b = (int)(255.0 * m2);
else if (h < 240)
*b = (int)(255.0 * (m1 + m21 * (240.0 - h) / 60.0));
else
*b = (int)(255.0 * m1);
}
}

View File

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

View File

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

View File

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

View File

@ -16,164 +16,171 @@
#include "script.h"
#include "loaderpath.h"
pImlibExternalFilter filters = NULL;
int dyn_initialised = 0;
pImlibExternalFilter filters = NULL;
int dyn_initialised = 0;
#define MALLOCSHOW
#define FREESHOW
#define FREESHOW
/*
#define FDEBUG
*/
pImlibExternalFilter __imlib_LoadFilter( char *file )
pImlibExternalFilter
__imlib_LoadFilter(char *file)
{
ImlibExternalFilter *ptr;
struct imlib_filter_info *info;
/* printf( "Loading filter %s\n", file ); */
MALLOCSHOW;
ptr = malloc( sizeof( ImlibExternalFilter ) );
ptr = malloc(sizeof(ImlibExternalFilter));
ptr->filename = strdup(file);
ptr->handle = lt_dlopenext(file);
if( !ptr->handle )
{
FREESHOW;
free( ptr->filename );
FREESHOW;
free( ptr );
return NULL;
}
ptr->init_filter = lt_dlsym( ptr->handle, "init" );
ptr->deinit_filter = lt_dlsym( ptr->handle, "deinit" );
ptr->exec_filter = lt_dlsym( ptr->handle, "exec" );
if( !ptr->init_filter || !ptr->deinit_filter || !ptr->exec_filter )
{
lt_dlclose( ptr->handle );
FREESHOW;
free( ptr->filename );
FREESHOW;
free( ptr );
return NULL;
}
info = malloc( sizeof( struct imlib_filter_info ) );
ptr->init_filter( info );
if (!ptr->handle)
{
FREESHOW;
free(ptr->filename);
FREESHOW;
free(ptr);
return NULL;
}
ptr->init_filter = lt_dlsym(ptr->handle, "init");
ptr->deinit_filter = lt_dlsym(ptr->handle, "deinit");
ptr->exec_filter = lt_dlsym(ptr->handle, "exec");
if (!ptr->init_filter || !ptr->deinit_filter || !ptr->exec_filter)
{
lt_dlclose(ptr->handle);
FREESHOW;
free(ptr->filename);
FREESHOW;
free(ptr);
return NULL;
}
info = malloc(sizeof(struct imlib_filter_info));
ptr->init_filter(info);
ptr->num_filters = info->num_filters;
ptr->filters = info->filters;
ptr->name = info->name;
ptr->author = info->author;
ptr->description = info->description;
free( info );
#ifdef FDEBUG
printf( "Filter has %d filters in it.\n", ptr->num_filters );
for( i = 0; i < ptr->num_filters; i++ )
printf( " -> \"%s\"\n", ptr->filters[i] );
free(info);
#ifdef FDEBUG
printf("Filter has %d filters in it.\n", ptr->num_filters);
for (i = 0; i < ptr->num_filters; i++)
printf(" -> \"%s\"\n", ptr->filters[i]);
#endif
ptr->next = NULL;
return ptr;
}
void __imlib_dynamic_filters_init()
void
__imlib_dynamic_filters_init()
{
char **list;
int num_filters, i = 0;
char **list;
int num_filters, i = 0;
ImlibExternalFilter *ptr, *tptr;
if( ! dyn_initialised )
{
MALLOCSHOW;
filters = malloc( sizeof( ImlibExternalFilter ) );
filters->filename = "";
filters->next = NULL;
ptr = filters;
if (!dyn_initialised)
{
MALLOCSHOW;
filters = malloc(sizeof(ImlibExternalFilter));
filters->filename = "";
filters->next = NULL;
ptr = filters;
#ifdef FDEBUG
printf( "DEBUG: Dynamic filters Initisialising\n" );
printf("DEBUG: Dynamic filters Initisialising\n");
#endif
dyn_initialised = 1;
dyn_initialised = 1;
#ifdef FDEBUG
printf( "DEBUG: Loading Filters\n" );
printf("DEBUG: Loading Filters\n");
#endif
list = __imlib_ListFilters( &num_filters );
for( i = num_filters - 1; i >= 0; i -- )
{
tptr = NULL;
if((tptr = __imlib_LoadFilter( list[i] )) != NULL )
{
ptr->next = tptr;
ptr = ptr->next;
}
if( list[i] ){
FREESHOW;
free( list[i] );
}
}
FREESHOW;
if( list )
free( list );
}
list = __imlib_ListFilters(&num_filters);
for (i = num_filters - 1; i >= 0; i--)
{
tptr = NULL;
if ((tptr = __imlib_LoadFilter(list[i])) != NULL)
{
ptr->next = tptr;
ptr = ptr->next;
}
if (list[i])
{
FREESHOW;
free(list[i]);
}
}
FREESHOW;
if (list)
free(list);
}
}
void __imlib_dynamic_filters_deinit()
void
__imlib_dynamic_filters_deinit()
{
}
pImlibExternalFilter __imlib_get_dynamic_filter( char *name )
pImlibExternalFilter
__imlib_get_dynamic_filter(char *name)
{
pImlibExternalFilter f_ptr;
int i = 0;
int i = 0;
/* scan the filters */
for( f_ptr = filters->next; f_ptr != NULL; f_ptr = f_ptr->next )
{
/* scan the methods provided */
for( i = 0; i < f_ptr->num_filters; i++ )
{
if( strcmp( f_ptr->filters[i], name ) == 0 )
{
for (f_ptr = filters->next; f_ptr != NULL; f_ptr = f_ptr->next)
{
/* scan the methods provided */
for (i = 0; i < f_ptr->num_filters; i++)
{
if (strcmp(f_ptr->filters[i], name) == 0)
{
#ifdef FDEBUG
printf( "DEBUG: Found filter \"%s\"\n", name );
printf("DEBUG: Found filter \"%s\"\n", name);
#endif
return f_ptr;
}
}
}
return f_ptr;
}
}
}
return NULL;
}
/* loader dir */
char **__imlib_ListFilters(int *num_ret)
char **
__imlib_ListFilters(int *num_ret)
{
char **list = NULL, **l, *s;
int num, i, pi = 0;
char **list = NULL, **l, *s;
int num, i, pi = 0;
*num_ret = 0;
/* 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");
#ifndef __EMX__
#ifndef __EMX__
l = __imlib_FileDir(s, &num);
#else
#else
l = __imlib_FileDir(__XOS2RedirRoot(s), &num);
#endif
#endif
if (num > 0)
{
*num_ret += num;
list = realloc(list, sizeof(char *) * *num_ret);
for (i = 0; i < num; i++)
{
s = (char *) realloc(s, sizeof(SYS_LOADERS_PATH) + 8 + strlen(l[i]) + 1);
sprintf(s, SYS_LOADERS_PATH "/filter/%s", l[i]);
#ifndef __EMX__
list[pi + i] = strdup(s);
#else
list[pi + i] = strdup(__XOS2RedirRoot(s));
#endif
}
__imlib_FileFreeDirList(l, num);
}
{
*num_ret += num;
list = realloc(list, sizeof(char *) * *num_ret);
for (i = 0; i < num; i++)
{
s = (char *)realloc(s,
sizeof(SYS_LOADERS_PATH) + 8 + strlen(l[i]) +
1);
sprintf(s, SYS_LOADERS_PATH "/filter/%s", l[i]);
#ifndef __EMX__
list[pi + i] = strdup(s);
#else
list[pi + i] = strdup(__XOS2RedirRoot(s));
#endif
}
__imlib_FileFreeDirList(l, num);
}
free(s);
/* List currently contains *everything in there* we need to weed out
@ -181,6 +188,6 @@ char **__imlib_ListFilters(int *num_ret)
* lt_dlopen can take an extension-less name and do the Right Thing
* with it, so that's what we'll give it. */
list = __imlib_TrimLoaderList(list, num_ret);
return list;
}

View File

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

View File

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

View File

@ -1,229 +1,130 @@
#ifndef __FONT
#define __FONT 1
typedef struct _imlib_font_header ImlibFontHeader;
typedef struct _imlib_ttffont ImlibTtfFont;
typedef struct _imlib_xfont ImlibXFontSet;
typedef union _imlib_font ImlibFont;
typedef struct _imlib_encoding_map ImlibEncodingMap;
typedef unsigned short ImlibWideChar;
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#define TTF_FONT_CACHE 1
#define TTF_HASH_SIZE (256*1)
/* TODO separate fonts and data stuff */
#ifdef TTF_FONT_CACHE
typedef struct _imlib_ttf_hash ImlibTTFHash;
typedef struct _imlib_ttf_hash_elm ImlibTTFHashElm;
typedef struct _Imlib_Font ImlibFont;
typedef struct _Imlib_Font_Glyph Imlib_Font_Glyph;
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;
TT_Glyph *glyph;
TT_Raster_Map *glyph_raster;
Imlib_Object_List *next, *prev;
Imlib_Object_List *last;
};
struct _imlib_ttf_hash
struct _Imlib_Hash
{
ImlibTTFHash *next;
char *name;
int references;
int type;
int size;
ImlibTTFHashElm **hash;
int mem_use;
int population;
Imlib_Object_List *buckets[256];
};
#endif
struct _imlib_font_header
struct _Imlib_Hash_El
{
int type;
ImlibFont *next;
char *name;
int references;
Imlib_Object_List _list_data;
char *key;
void *data;
};
struct _imlib_ttffont
struct _Imlib_Font
{
int type;
Imlib_Object_List _list_data;
char *name;
char *file;
int size;
struct
{
FT_Face face;
}
ft;
Imlib_Hash *glyphs;
int usage;
int references;
ImlibFont *next;
char *name;
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 {
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
struct _Imlib_Font_Glyph
{
ImlibXmbHashElm *next;
wchar_t wc;
int w, h;
DATA32 *im;
FT_Glyph glyph;
FT_BitmapGlyph glyph_out;
};
struct _imlib_xfd_hash
{
ImlibXmbHash *next;
char *name;
int references;
/* functions */
int type;
int size;
ImlibXmbHashElm **hash;
int hash_count;
int collision_count;
int mem_use;
};
#endif
void imlib_font_init(void);
int imlib_font_ascent_get(ImlibFont * fn);
int imlib_font_descent_get(ImlibFont * fn);
int imlib_font_max_ascent_get(ImlibFont * fn);
int imlib_font_max_descent_get(ImlibFont * fn);
int imlib_font_get_line_advance(ImlibFont * fn);
int imlib_font_utf8_get_next(unsigned char *buf, int *iindex);
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
{
int type;
ImlibFont *imlib_font_load_joined(const char *name);
ImlibFont *imlib_font_load(const char *name, int size);
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;
char *name;
int references;
void imlib_font_query_size(ImlibFont * fn, const char *text,
int *w, int *h);
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;
int font_count;
XFontStruct **font_struct;
char **font_name;
int ascent;
int descent;
int max_ascent;
int max_descent;
int max_width;
ImlibFont *ttffont;
int total_ascent;
int total_descent;
Imlib_Font_Glyph *imlib_font_cache_glyph_get(ImlibFont * fn, FT_UInt index);
void imlib_render_str(ImlibImage * im, ImlibFont * f, 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 clx, int cly, int clw,
int clh);
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);
#ifdef XMB_FONT_CACHE
ImlibXmbHash *hash;
#endif
};
/* data manipulation */
union _imlib_font
{
int type;
ImlibFontHeader hdr;
ImlibTtfFont ttf;
ImlibXFontSet xf;
};
/* 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
void *imlib_object_list_prepend(void *in_list, void *in_item);
void *imlib_object_list_remove(void *in_list, void *in_item);
Imlib_Hash *imlib_hash_add(Imlib_Hash * hash, const char *key,
const void *data);
void *imlib_hash_find(Imlib_Hash * hash, const char *key);
void imlib_hash_free(Imlib_Hash * hash);
void imlib_hash_foreach(Imlib_Hash * hash,
int (*func) (Imlib_Hash * hash,
const char *key, void *data,
void *fdata),
const void *fdata);

1059
src/grab.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

5782
src/rgba.c

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@ -21,35 +21,39 @@
*/
#include "Imlib2.h"
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
int main (int argc, char **argv)
int
main(int argc, char **argv)
{
int i, j, w, h, x, y;
Imlib_Image im = NULL, im_bg = NULL;
XEvent ev;
int i, j, w, h, x, y;
Imlib_Image im = NULL, im_bg = NULL;
XEvent ev;
/**
* Initialization according to options
*/
printf("Initialising\n");
/**
* First tests to determine which rendering task to perform
*/
disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0, 0);
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
ButtonMotionMask | PointerMotionMask | ExposureMask);
disp = XOpenDisplay(NULL);
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
win =
XCreateSimpleWindow(disp, DefaultRootWindow(disp), 0, 0, 100, 100, 0, 0,
0);
XSelectInput(disp, win,
ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
PointerMotionMask | ExposureMask);
XMapWindow(disp, win);
/**
* Start rendering
*/
@ -61,61 +65,63 @@ int main (int argc, char **argv)
imlib_context_set_dither(1);
imlib_context_set_blend(0);
imlib_context_set_color_modifier(NULL);
im_bg = imlib_load_image("test_images/imlib2.png");
im = imlib_load_image("test_images/imlib2.png");
imlib_context_set_image(im_bg);
w = imlib_image_get_width();
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);
XSync(disp, False);
x = -9999;
y = -9999;
while (1)
{
Imlib_Image *temp, *temp2;
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
break;
case ButtonRelease:
exit(0);
break;
case MotionNotify:
x = ev.xmotion.x;
y = ev.xmotion.y;
default:
break;
}
}
while (XPending(disp));
imlib_context_set_blend( 0 );
imlib_context_set_image(im_bg);
temp = imlib_clone_image();
imlib_context_set_image( temp );
/* imlib_blend_image_onto_image(im_bg, 0,
0, 0, w, h,
0, 0, w, h);
first = 0;*/
imlib_apply_filter("bump_map_point(x=[],y=[],map=test_images/imlib2.png);", &x, &y );
{
Imlib_Image *temp, *temp2;
temp2 = im_bg;
im_bg = temp;
imlib_context_set_image(im_bg);
imlib_render_image_on_drawable(0, 0 );
im_bg = temp2;
imlib_context_set_image(temp);
imlib_free_image();
}
do
{
XNextEvent(disp, &ev);
switch (ev.type)
{
case Expose:
break;
case ButtonRelease:
exit(0);
break;
case MotionNotify:
x = ev.xmotion.x;
y = ev.xmotion.y;
default:
break;
}
}
while (XPending(disp));
imlib_context_set_blend(0);
imlib_context_set_image(im_bg);
temp = imlib_clone_image();
imlib_context_set_image(temp);
/* imlib_blend_image_onto_image(im_bg, 0,
* 0, 0, w, h,
* 0, 0, w, h);
* first = 0; */
imlib_apply_filter
("bump_map_point(x=[],y=[],map=test_images/imlib2.png);", &x, &y);
temp2 = im_bg;
im_bg = temp;
imlib_context_set_image(im_bg);
imlib_render_image_on_drawable(0, 0);
im_bg = temp2;
imlib_context_set_image(temp);
imlib_free_image();
}
return 0;
}

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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