* 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:
Chris Ross 2000-05-20 22:33:14 +00:00
parent caa073ee7b
commit 2e5728f366
6 changed files with 188 additions and 21 deletions

View File

@ -9,3 +9,4 @@ gilbertt (Tom Gilbert) <gilbertt@btinternet.com>
Takis <takis@lumumba.luc.ac.be>
Dan Maas <dmaas@dcine.com>
pla@cland.ru
boris (Chris Ross) <chris@darkrock.co.uk>

View File

@ -12,8 +12,12 @@ INCLUDES = -I/usr/X11R6/include -I$(top_srcdir)/libltdl \
-I$(top_srcdir)/loaders
pkgdir = $(libdir)/loaders/filter
pkg_LTLIBRARIES = testfilter.la
pkg_LTLIBRARIES = testfilter.la bump_map.la
testfilter_la_SOURCES = filter_test.c
testfilter_la_LDFLAGS = -no-undefined -module -avoid-version
testfilter_la_LIBADD =
bump_map_la_SOURCES = filter_bumpmap.c
bump_map_la_LDFLAGS = -no-undefined -module -avoid-version
bump_map_la_LIBADD =

160
filters/filter_bumpmap.c Normal file
View File

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

View File

@ -19,7 +19,7 @@
#define FDEBUG 1
*/
int find_string( char *haystack, char *needle )
int __imlib_find_string( char *haystack, char *needle )
{
if( strstr( haystack, needle ) != NULL )
return ( strstr( haystack, needle ) - haystack );
@ -42,7 +42,7 @@ char *stripwhitespace( char *str )
return str;
}
char *copystr( char *str, int start, int end )
char *__imlib_copystr( char *str, int start, int end )
{
int i = 0;
char *rstr = calloc( 1024, sizeof( char ) );
@ -55,7 +55,7 @@ char *copystr( char *str, int start, int end )
return NULL;
}
pIFunctionParam parse_param( char *param )
pIFunctionParam __imlib_parse_param( char *param )
{
int i;
@ -63,15 +63,15 @@ pIFunctionParam parse_param( char *param )
if( param != NULL )
{
ptr = malloc( sizeof( IFunctionParam ) );
i = find_string(param,"=");
i = __imlib_find_string(param,"=");
if( i > 0 )
{
ptr->key = copystr(param, 0, i-1);
ptr->key = __imlib_copystr(param, 0, i-1);
ptr->type = 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
ptr->data = (void *)copystr(param, i+1, strlen(param)-1);
ptr->data = (void *)__imlib_copystr(param, i+1, strlen(param)-1);
#ifdef FDEBUG
printf( "DEBUG: -> param [%s]=\"%s\"\n", ptr->key, (char *)ptr->data );
#endif /* FDEBUG */
@ -90,7 +90,7 @@ pIFunctionParam parse_param( char *param )
return NULL;
}
pIFunction parse_function( char *func )
pIFunction __imlib_parse_function( char *func )
{
int i = 0, in_quote=0, start=0;
IFunction *ptrfunc = malloc( sizeof( IFunction ) );
@ -100,7 +100,7 @@ pIFunction parse_function( char *func )
if( func != NULL )
{
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
printf( "DEBUG: Function name: \"%s\"\n", ptrfunc->name );
#endif /* FDEBUG */
@ -112,15 +112,15 @@ pIFunction parse_function( char *func )
ptrfunc->params->next = NULL;
ptrparam = ptrfunc->params;
start = find_string( func, "(" ) + 1;
start = __imlib_find_string( func, "(" ) + 1;
for( i = start; i < strlen(func); i++ )
{
if( func[i] == '\"' )
in_quote = (in_quote == 0 ? 1 : 0);
if( !in_quote && (func[i] == ',' || func[i] == ')') )
{
tmpbuf = copystr( func, start, i-1 );
ptrparam->next = parse_param( tmpbuf );
tmpbuf = __imlib_copystr( func, start, i-1 );
ptrparam->next = __imlib_parse_param( tmpbuf );
if( ptrparam->next != NULL )
ptrparam = ptrparam->next;
start = i+1;
@ -138,13 +138,12 @@ pIFunction parse_function( char *func )
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;
IFunction *ptr = parse_function( NULL ), *tmp_fptr = NULL;
IFunction *ptr = __imlib_parse_function( NULL ), *tmp_fptr = NULL;
IFunction *rptr = ptr;
IFunctionParam *tmp_pptr;
va_list param_list;
void *tmpptr;
#ifdef FDEBUG
@ -160,7 +159,7 @@ pIFunction __imlib_script_parse( char *script, ... )
in_quote = (in_quote == 0 ? 1 : 0);
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;
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
* any [], if we have replace it with the next var off the list update the pointer, luverly
* jubly */
va_start( param_list, script );
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 )
@ -198,7 +196,6 @@ pIFunction __imlib_script_parse( char *script, ... )
}
}
}
va_end( param_list );
#ifdef FDEBUG
printf( "DEBUG: Imlib Script Parser End.\n" );
#endif

View File

@ -2,6 +2,7 @@
#define _DYN_FUNCTION_H_
#include "ltdl.h"
#include <stdarg.h>
#define VAR_CHAR 1
#define VAR_PTR 2
@ -25,6 +26,6 @@ struct _imlib_function
pIFunction next;
};
pIFunction __imlib_script_parse( char *script, ... );
pIFunction __imlib_script_parse( char *script, va_list );
void __imlib_script_tidyup( IFunction *func );
#endif /* _FUNCTION_H_ */

View File

@ -741,7 +741,11 @@ int main (int argc, char **argv)
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_context_set_color(255, 255, 255, 255);