forked from old/legacy-imlib2
* Changed some of the methods to stop furutre name conflicts
* Added Willems patch for bump mapping -very vey cool, check out test/imllib2 * Died due to excess excitement over bump mapping SVN revision: 2674
This commit is contained in:
parent
caa073ee7b
commit
2e5728f366
1
AUTHORS
1
AUTHORS
|
@ -9,3 +9,4 @@ gilbertt (Tom Gilbert) <gilbertt@btinternet.com>
|
||||||
Takis <takis@lumumba.luc.ac.be>
|
Takis <takis@lumumba.luc.ac.be>
|
||||||
Dan Maas <dmaas@dcine.com>
|
Dan Maas <dmaas@dcine.com>
|
||||||
pla@cland.ru
|
pla@cland.ru
|
||||||
|
boris (Chris Ross) <chris@darkrock.co.uk>
|
||||||
|
|
|
@ -12,8 +12,12 @@ INCLUDES = -I/usr/X11R6/include -I$(top_srcdir)/libltdl \
|
||||||
-I$(top_srcdir)/loaders
|
-I$(top_srcdir)/loaders
|
||||||
|
|
||||||
pkgdir = $(libdir)/loaders/filter
|
pkgdir = $(libdir)/loaders/filter
|
||||||
pkg_LTLIBRARIES = testfilter.la
|
pkg_LTLIBRARIES = testfilter.la bump_map.la
|
||||||
|
|
||||||
testfilter_la_SOURCES = filter_test.c
|
testfilter_la_SOURCES = filter_test.c
|
||||||
testfilter_la_LDFLAGS = -no-undefined -module -avoid-version
|
testfilter_la_LDFLAGS = -no-undefined -module -avoid-version
|
||||||
testfilter_la_LIBADD =
|
testfilter_la_LIBADD =
|
||||||
|
|
||||||
|
bump_map_la_SOURCES = filter_bumpmap.c
|
||||||
|
bump_map_la_LDFLAGS = -no-undefined -module -avoid-version
|
||||||
|
bump_map_la_LIBADD =
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/extensions/XShm.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "Imlib2.h"
|
||||||
|
#include "image.h"
|
||||||
|
#include "script.h"
|
||||||
|
#include "dynamic_filters.h"
|
||||||
|
#include "colormod.h"
|
||||||
|
#include "blend.h"
|
||||||
|
|
||||||
|
#define ASSIGN_IMAGE(k, v) \
|
||||||
|
if (!strcmp((k), par->key)) { \
|
||||||
|
if (par->type == VAR_PTR) { \
|
||||||
|
(v) = (Imlib_Image)(par->data); \
|
||||||
|
} else if (par->type == VAR_CHAR) { \
|
||||||
|
(v) = imlib_load_image(par->data); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ASSIGN_DOUBLE(k, v) \
|
||||||
|
if (!strcmp((k), par->key)) { \
|
||||||
|
if (par->type == VAR_PTR) { \
|
||||||
|
(v) = (double)(*(int *)par->data); \
|
||||||
|
} else if (par->type == VAR_CHAR) { \
|
||||||
|
(v) = strtod(par->data, 0); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
static Imlib_Image
|
||||||
|
bump_map(Imlib_Image im, pIFunctionParam par)
|
||||||
|
{
|
||||||
|
return im;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Imlib_Image
|
||||||
|
bump_map_point(Imlib_Image im, pIFunctionParam par)
|
||||||
|
{
|
||||||
|
Imlib_Image map = im;
|
||||||
|
double x = 0, y = 0, z = 30, d = 2;
|
||||||
|
double red = 2, green = 2, blue = 2;
|
||||||
|
|
||||||
|
DATA32 *src;
|
||||||
|
DATA32 *mp, *mpy, *mpp;
|
||||||
|
double z_2, x2, y2;
|
||||||
|
int w, h, i, j, w2, h2, wh2, mx, my;
|
||||||
|
|
||||||
|
for (; par; par = par->next) {
|
||||||
|
ASSIGN_IMAGE ("map", map);
|
||||||
|
ASSIGN_DOUBLE("x", x);
|
||||||
|
ASSIGN_DOUBLE("y", y);
|
||||||
|
ASSIGN_DOUBLE("z", z);
|
||||||
|
ASSIGN_DOUBLE("depth", d);
|
||||||
|
ASSIGN_DOUBLE("red", red);
|
||||||
|
ASSIGN_DOUBLE("green", green);
|
||||||
|
ASSIGN_DOUBLE("blue", blue);
|
||||||
|
}
|
||||||
|
if (!map) return im;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
return im;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init(struct imlib_filter_info *info)
|
||||||
|
{
|
||||||
|
char *filters[] = { "bump_map_point", "bump_map" };
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = (sizeof(filters) / sizeof(*filters));
|
||||||
|
info->num_filters = i;
|
||||||
|
info->filters = malloc(sizeof(char *) * i);
|
||||||
|
while (--i >= 0)
|
||||||
|
info->filters[i] = strdup(filters[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
deinit()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
33
src/script.c
33
src/script.c
|
@ -19,7 +19,7 @@
|
||||||
#define FDEBUG 1
|
#define FDEBUG 1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int find_string( char *haystack, char *needle )
|
int __imlib_find_string( char *haystack, char *needle )
|
||||||
{
|
{
|
||||||
if( strstr( haystack, needle ) != NULL )
|
if( strstr( haystack, needle ) != NULL )
|
||||||
return ( strstr( haystack, needle ) - haystack );
|
return ( strstr( haystack, needle ) - haystack );
|
||||||
|
@ -42,7 +42,7 @@ char *stripwhitespace( char *str )
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *copystr( char *str, int start, int end )
|
char *__imlib_copystr( char *str, int start, int end )
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *rstr = calloc( 1024, sizeof( char ) );
|
char *rstr = calloc( 1024, sizeof( char ) );
|
||||||
|
@ -55,7 +55,7 @@ char *copystr( char *str, int start, int end )
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pIFunctionParam parse_param( char *param )
|
pIFunctionParam __imlib_parse_param( char *param )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -63,15 +63,15 @@ pIFunctionParam parse_param( char *param )
|
||||||
if( param != NULL )
|
if( param != NULL )
|
||||||
{
|
{
|
||||||
ptr = malloc( sizeof( IFunctionParam ) );
|
ptr = malloc( sizeof( IFunctionParam ) );
|
||||||
i = find_string(param,"=");
|
i = __imlib_find_string(param,"=");
|
||||||
if( i > 0 )
|
if( i > 0 )
|
||||||
{
|
{
|
||||||
ptr->key = copystr(param, 0, i-1);
|
ptr->key = __imlib_copystr(param, 0, i-1);
|
||||||
ptr->type = 1;
|
ptr->type = 1;
|
||||||
if( param[i+1] == '\"' )
|
if( param[i+1] == '\"' )
|
||||||
ptr->data = (void *)copystr(param, i+2, strlen(param)-2);
|
ptr->data = (void *)__imlib_copystr(param, i+2, strlen(param)-2);
|
||||||
else
|
else
|
||||||
ptr->data = (void *)copystr(param, i+1, strlen(param)-1);
|
ptr->data = (void *)__imlib_copystr(param, i+1, strlen(param)-1);
|
||||||
#ifdef FDEBUG
|
#ifdef FDEBUG
|
||||||
printf( "DEBUG: -> param [%s]=\"%s\"\n", ptr->key, (char *)ptr->data );
|
printf( "DEBUG: -> param [%s]=\"%s\"\n", ptr->key, (char *)ptr->data );
|
||||||
#endif /* FDEBUG */
|
#endif /* FDEBUG */
|
||||||
|
@ -90,7 +90,7 @@ pIFunctionParam parse_param( char *param )
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pIFunction parse_function( char *func )
|
pIFunction __imlib_parse_function( char *func )
|
||||||
{
|
{
|
||||||
int i = 0, in_quote=0, start=0;
|
int i = 0, in_quote=0, start=0;
|
||||||
IFunction *ptrfunc = malloc( sizeof( IFunction ) );
|
IFunction *ptrfunc = malloc( sizeof( IFunction ) );
|
||||||
|
@ -100,7 +100,7 @@ pIFunction parse_function( char *func )
|
||||||
if( func != NULL )
|
if( func != NULL )
|
||||||
{
|
{
|
||||||
func = stripwhitespace( func );
|
func = stripwhitespace( func );
|
||||||
ptrfunc->name = copystr( func, 0, find_string( func, "(" ) - 1 );
|
ptrfunc->name = __imlib_copystr( func, 0, __imlib_find_string( func, "(" ) - 1 );
|
||||||
#ifdef FDEBUG
|
#ifdef FDEBUG
|
||||||
printf( "DEBUG: Function name: \"%s\"\n", ptrfunc->name );
|
printf( "DEBUG: Function name: \"%s\"\n", ptrfunc->name );
|
||||||
#endif /* FDEBUG */
|
#endif /* FDEBUG */
|
||||||
|
@ -112,15 +112,15 @@ pIFunction parse_function( char *func )
|
||||||
ptrfunc->params->next = NULL;
|
ptrfunc->params->next = NULL;
|
||||||
ptrparam = ptrfunc->params;
|
ptrparam = ptrfunc->params;
|
||||||
|
|
||||||
start = find_string( func, "(" ) + 1;
|
start = __imlib_find_string( func, "(" ) + 1;
|
||||||
for( i = start; i < strlen(func); i++ )
|
for( i = start; i < strlen(func); i++ )
|
||||||
{
|
{
|
||||||
if( func[i] == '\"' )
|
if( func[i] == '\"' )
|
||||||
in_quote = (in_quote == 0 ? 1 : 0);
|
in_quote = (in_quote == 0 ? 1 : 0);
|
||||||
if( !in_quote && (func[i] == ',' || func[i] == ')') )
|
if( !in_quote && (func[i] == ',' || func[i] == ')') )
|
||||||
{
|
{
|
||||||
tmpbuf = copystr( func, start, i-1 );
|
tmpbuf = __imlib_copystr( func, start, i-1 );
|
||||||
ptrparam->next = parse_param( tmpbuf );
|
ptrparam->next = __imlib_parse_param( tmpbuf );
|
||||||
if( ptrparam->next != NULL )
|
if( ptrparam->next != NULL )
|
||||||
ptrparam = ptrparam->next;
|
ptrparam = ptrparam->next;
|
||||||
start = i+1;
|
start = i+1;
|
||||||
|
@ -138,13 +138,12 @@ pIFunction parse_function( char *func )
|
||||||
return ptrfunc;
|
return ptrfunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
pIFunction __imlib_script_parse( char *script, ... )
|
pIFunction __imlib_script_parse( char *script, va_list param_list )
|
||||||
{
|
{
|
||||||
int i = 0, in_quote = 0, start = 0, hit_null = 0;
|
int i = 0, in_quote = 0, start = 0, hit_null = 0;
|
||||||
IFunction *ptr = parse_function( NULL ), *tmp_fptr = NULL;
|
IFunction *ptr = __imlib_parse_function( NULL ), *tmp_fptr = NULL;
|
||||||
IFunction *rptr = ptr;
|
IFunction *rptr = ptr;
|
||||||
IFunctionParam *tmp_pptr;
|
IFunctionParam *tmp_pptr;
|
||||||
va_list param_list;
|
|
||||||
void *tmpptr;
|
void *tmpptr;
|
||||||
|
|
||||||
#ifdef FDEBUG
|
#ifdef FDEBUG
|
||||||
|
@ -160,7 +159,7 @@ pIFunction __imlib_script_parse( char *script, ... )
|
||||||
in_quote = (in_quote == 0 ? 1 : 0);
|
in_quote = (in_quote == 0 ? 1 : 0);
|
||||||
if( ! in_quote && script[i] == ';' )
|
if( ! in_quote && script[i] == ';' )
|
||||||
{
|
{
|
||||||
ptr->next = parse_function( copystr( script, start, i-1 ) );
|
ptr->next = __imlib_parse_function( __imlib_copystr( script, start, i-1 ) );
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
start = i+1;
|
start = i+1;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +167,6 @@ pIFunction __imlib_script_parse( char *script, ... )
|
||||||
/* righty now we need to traverse the whole of the function tree and see if we have hit
|
/* righty now we need to traverse the whole of the function tree and see if we have hit
|
||||||
* any [], if we have replace it with the next var off the list update the pointer, luverly
|
* any [], if we have replace it with the next var off the list update the pointer, luverly
|
||||||
* jubly */
|
* jubly */
|
||||||
va_start( param_list, script );
|
|
||||||
for( tmp_fptr = rptr->next; tmp_fptr != NULL; tmp_fptr = tmp_fptr->next )
|
for( tmp_fptr = rptr->next; tmp_fptr != NULL; tmp_fptr = tmp_fptr->next )
|
||||||
{
|
{
|
||||||
for( tmp_pptr = tmp_fptr->params; tmp_pptr != NULL; tmp_pptr = tmp_pptr->next )
|
for( tmp_pptr = tmp_fptr->params; tmp_pptr != NULL; tmp_pptr = tmp_pptr->next )
|
||||||
|
@ -198,7 +196,6 @@ pIFunction __imlib_script_parse( char *script, ... )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
va_end( param_list );
|
|
||||||
#ifdef FDEBUG
|
#ifdef FDEBUG
|
||||||
printf( "DEBUG: Imlib Script Parser End.\n" );
|
printf( "DEBUG: Imlib Script Parser End.\n" );
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _DYN_FUNCTION_H_
|
#define _DYN_FUNCTION_H_
|
||||||
|
|
||||||
#include "ltdl.h"
|
#include "ltdl.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define VAR_CHAR 1
|
#define VAR_CHAR 1
|
||||||
#define VAR_PTR 2
|
#define VAR_PTR 2
|
||||||
|
@ -25,6 +26,6 @@ struct _imlib_function
|
||||||
pIFunction next;
|
pIFunction next;
|
||||||
};
|
};
|
||||||
|
|
||||||
pIFunction __imlib_script_parse( char *script, ... );
|
pIFunction __imlib_script_parse( char *script, va_list );
|
||||||
void __imlib_script_tidyup( IFunction *func );
|
void __imlib_script_tidyup( IFunction *func );
|
||||||
#endif /* _FUNCTION_H_ */
|
#endif /* _FUNCTION_H_ */
|
||||||
|
|
|
@ -741,7 +741,11 @@ int main (int argc, char **argv)
|
||||||
imlib_image_get_height());
|
imlib_image_get_height());
|
||||||
|
|
||||||
}
|
}
|
||||||
{
|
imlib_apply_filter("bump_map_point(x=[],y=[],map=test_images/bulb.png);", &x, &y, NULL);
|
||||||
|
up = imlib_update_append_rect(up, 0, 0,
|
||||||
|
imlib_image_get_width(),
|
||||||
|
imlib_image_get_height());
|
||||||
|
{
|
||||||
Imlib_Updates uu;
|
Imlib_Updates uu;
|
||||||
|
|
||||||
imlib_context_set_color(255, 255, 255, 255);
|
imlib_context_set_color(255, 255, 255, 255);
|
||||||
|
|
Loading…
Reference in New Issue