summaryrefslogtreecommitdiff
path: root/filters
diff options
context:
space:
mode:
Diffstat (limited to 'filters')
-rw-r--r--filters/filter_bumpmap.c424
-rw-r--r--filters/filter_colormod.c332
-rw-r--r--filters/filter_test.c159
3 files changed, 508 insertions, 407 deletions
diff --git a/filters/filter_bumpmap.c b/filters/filter_bumpmap.c
index be3204f..b08c151 100644
--- a/filters/filter_bumpmap.c
+++ b/filters/filter_bumpmap.c
@@ -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;
}
diff --git a/filters/filter_colormod.c b/filters/filter_colormod.c
index dbc49c8..c106f2c 100644
--- a/filters/filter_colormod.c
+++ b/filters/filter_colormod.c
@@ -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;
-
- 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 (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;
+ 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();
+
+ 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;
}
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;
}
diff --git a/filters/filter_test.c b/filters/filter_test.c
index 50e76b8..4d3f11a 100644
--- a/filters/filter_test.c
+++ b/filters/filter_test.c
@@ -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;
}