color modifiers in imlib2 now done.. cleaned up soem code...

SVN revision: 936
This commit is contained in:
Carsten Haitzler 1999-10-21 17:07:21 +00:00
parent a82425db17
commit 910a509458
25 changed files with 3133 additions and 2188 deletions

78
api.c
View File

@ -3,6 +3,7 @@
#include <X11/extensions/shape.h>
#include <string.h>
#include "common.h"
#include "colormod.h"
#include "scale.h"
#include "image.h"
#include "context.h"
@ -528,7 +529,7 @@ imlib_create_scaled_image_from_drawable(Display *display,
char domask = 0, tmpmask = 0;
int x, xx;
XGCValues gcv;
GC gc, mgc;
GC gc = 0, mgc = 0;
Pixmap p, m;
if ((mask) || (get_mask_from_shape))
@ -1157,3 +1158,78 @@ imlib_flush_font_cache(void)
{
__imlib_purge_font_cache();
}
Imlib_Color_Modifier
imlib_create_color_modifier(void)
{
return (Imlib_Color_Modifier)__imlib_CreateCmod();
}
void
imlib_free_color_modifier(Imlib_Color_Modifier color_modifier)
{
__imlib_FreeCmod((ImlibColorModifier *)color_modifier);
}
void
imlib_modify_color_modifier_gamma(Imlib_Color_Modifier color_modifier,
double gamma_value)
{
__imlib_CmodModGamma((ImlibColorModifier *)color_modifier,
gamma_value);
}
void
imlib_modify_color_modifier_brightness(Imlib_Color_Modifier color_modifier,
double brightness_value)
{
__imlib_CmodModBrightness((ImlibColorModifier *)color_modifier,
brightness_value);
}
void
imlib_modify_color_modifier_contrast(Imlib_Color_Modifier color_modifier,
double contrast_value)
{
__imlib_CmodModContrast((ImlibColorModifier *)color_modifier,
contrast_value);
}
void
imlib_set_color_modifier_tables(Imlib_Color_Modifier color_modifier,
DATA8 *red_table,
DATA8 *green_table,
DATA8 *blue_table,
DATA8 *alpha_table)
{
__imlib_CmodSetTables((ImlibColorModifier *)color_modifier,
red_table, green_table, blue_table, alpha_table);
}
void
imlib_get_color_modifier_tables(Imlib_Color_Modifier color_modifier,
DATA8 *red_table,
DATA8 *green_table,
DATA8 *blue_table,
DATA8 *alpha_table)
{
__imlib_CmodGetTables((ImlibColorModifier *)color_modifier,
red_table, green_table, blue_table, alpha_table);
}
void
imlib_rset_color_modifier(Imlib_Color_Modifier color_modifier)
{
__imlib_CmodReset((ImlibColorModifier *)color_modifier);
}
void
imlib_apply_color_modifier(Imlib_Image image,
Imlib_Color_Modifier color_modifier)
{
ImlibImage *im;
CAST_IMAGE(im, image);
__imlib_DataCmodApply(im->data, im->w, im->h, 0,
(ImlibColorModifier *)color_modifier);
}

82
api.h
View File

@ -16,25 +16,6 @@ typedef void * Imlib_Font;
typedef struct _imlib_border Imlib_Border;
typedef struct _imlib_color Imlib_Color;
typedef struct _imlib_rectangle Imlib_Rectangle;
typedef enum _imlib_operation Imlib_Operation;
typedef enum _imlib_load_error Imlib_Load_Error;
typedef enum _imlib_text_direction Imlib_Text_Direction;
struct _imlib_border
{
int left, right, top, bottom;
};
struct _imlib_color
{
int alpha, red, green, blue;
};
struct _imlib_rectangle
{
int x, y, width, height;
};
enum _imlib_operation
{
@ -69,6 +50,25 @@ enum _imlib_load_error
IMLIB_LOAD_ERROR_UNKNOWN
};
typedef enum _imlib_operation Imlib_Operation;
typedef enum _imlib_load_error Imlib_Load_Error;
typedef enum _imlib_text_direction Imlib_Text_Direction;
struct _imlib_border
{
int left, right, top, bottom;
};
struct _imlib_color
{
int alpha, red, green, blue;
};
struct _imlib_rectangle
{
int x, y, width, height;
};
typedef void (*Imlib_Progress_Function)(Imlib_Image *im, char percent,
int update_x, int update_y,
int update_w, int update_h);
@ -289,6 +289,30 @@ int imlib_get_font_cache_size(void);
void imlib_set_font_cache_size(int bytes);
void imlib_flush_font_cache(void);
/* image modification - color */
Imlib_Color_Modifier imlib_create_color_modifier(void);
void imlib_free_color_modifier(Imlib_Color_Modifier color_modifier);
void imlib_modify_color_modifier_gamma(Imlib_Color_Modifier color_modifier,
double gamma_value);
void imlib_modify_color_modifier_brightness(Imlib_Color_Modifier color_modifier,
double brightness_value);
void imlib_modify_color_modifier_contrast(Imlib_Color_Modifier color_modifier,
double contrast_value);
void imlib_set_color_modifier_tables(Imlib_Color_Modifier color_modifier,
DATA8 *red_table,
DATA8 *green_table,
DATA8 *blue_table,
DATA8 *alpha_table);
void imlib_get_color_modifier_tables(Imlib_Color_Modifier color_modifier,
DATA8 *red_table,
DATA8 *green_table,
DATA8 *blue_table,
DATA8 *alpha_table);
void imlib_rset_color_modifier(Imlib_Color_Modifier color_modifier);
void imlib_apply_color_modifier(Imlib_Image image,
Imlib_Color_Modifier color_modifier);
#if 0
void imlib_image_copy_alpha_to_image(Imlib_Image image_source,
Imlib_Image image_destination,
@ -337,24 +361,4 @@ int imlib_get_character_index_and_location_in_text(Imlib_font font,
void imlib_save_image(Imlib_Image image, char *filename);
#endif
#if 0
/* do this later as none of the color lookup code is in the rendering */
/* backend yet */
/* image modification - color */
Imlib_Color_Modifier imlib_create_color_modifier(void);
void imlib_free_color_modifier(Imlib_Color_Modifier color_modifier);
void imlib_set_color_modifier_gamma(Imlib_Color_Modifier color_modifier,
double gamma_value);
void imlib_set_color_modifier_brightness(Imlib_Color_Modifier color_modifier,
double brightness_value);
void imlib_set_color_modifier_contrast(Imlib_Color_Modifier color_modifier,
double contrast_value);
void imlib_set_color_modifier_tables(Imlib_Color_Modifier color_modifier,
DATA8 *red_table,
DATA8 *green_table,
DATA8 *blue_table);
void imlib_apply_color_modifier(Imlib_Image image,
Imlib_Color_Modifier color_modifier);
#endif
#endif

869
blend.c
View File

@ -1,5 +1,6 @@
#include "common.h"
#include <X11/Xlib.h>
#include "colormod.h"
#include "image.h"
#include "blend.h"
#include "scale.h"
@ -46,66 +47,133 @@ __imlib_BlendRGBAToData(DATA32 *src, int src_w, int src_h, DATA32 *dst,
h = dst_h - dy;
if ((w <= 0) || (h <= 0))
return;
switch(op)
if (cm)
{
case OP_COPY:
if (dalpha == 0)
__imlib_BlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_BlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_CopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 3)
__imlib_CopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
case OP_ADD:
if (dalpha == 0)
__imlib_AddBlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_AddBlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
switch(op)
{
case OP_COPY:
if (dalpha == 0)
__imlib_BlendRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 1)
__imlib_BlendRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 2)
__imlib_CopyRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 3)
__imlib_CopyRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
break;
case OP_ADD:
if (dalpha == 0)
__imlib_AddBlendRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 1)
__imlib_AddBlendRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 2)
__imlib_AddCopyRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 3)
__imlib_AddCopyRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
break;
case OP_SUBTRACT:
if (dalpha == 0)
__imlib_SubBlendRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 1)
__imlib_SubBlendRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 2)
__imlib_SubCopyRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 3)
__imlib_SubCopyRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
break;
case OP_RESHADE:
if (dalpha == 0)
__imlib_ReBlendRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 1)
__imlib_ReBlendRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 2)
__imlib_ReCopyRGBAToRGBCmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
else if (dalpha == 3)
__imlib_ReCopyRGBAToRGBACmod(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h, cm);
break;
default:
break;
}
}
else
{
switch(op)
{
case OP_COPY:
if (dalpha == 0)
__imlib_BlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_BlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_CopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_AddCopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 3)
__imlib_AddCopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
case OP_SUBTRACT:
if (dalpha == 0)
__imlib_SubBlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_SubBlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_SubCopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 3)
__imlib_SubCopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
case OP_RESHADE:
if (dalpha == 0)
__imlib_ReBlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_ReBlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_ReCopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 3)
__imlib_ReCopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
default:
break;
else if (dalpha == 3)
__imlib_CopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
case OP_ADD:
if (dalpha == 0)
__imlib_AddBlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_AddBlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_AddCopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 3)
__imlib_AddCopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
case OP_SUBTRACT:
if (dalpha == 0)
__imlib_SubBlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_SubBlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_SubCopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 3)
__imlib_SubCopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
case OP_RESHADE:
if (dalpha == 0)
__imlib_ReBlendRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 1)
__imlib_ReBlendRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 2)
__imlib_ReCopyRGBAToRGB(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
else if (dalpha == 3)
__imlib_ReCopyRGBAToRGBA(src + (sy * src_w) + sx, src_w - w,
dst + (dy * dst_w) + dx, dst_w - w, w, h);
break;
default:
break;
}
}
}
@ -705,6 +773,691 @@ __imlib_ReCopyRGBAToRGBA(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
}
}
}
/* COLORMOD COPY OPS */
void
__imlib_BlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
if (a == 255)
*p2 = *p1;
else if (a > 0)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = (r - rr) * a;
nr = rr + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (g - gg) * a;
ng = gg + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (b - bb) * a;
nb = bb + ((tmp + (tmp >> 8) + 0x80) >> 8);
*p2 = (nr << 16) | (ng << 8) | nb;
}
p1++;
p2++;
}
}
}
void
__imlib_BlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb, aa, na;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
if (a == 255)
*p2 = *p1;
else if (a > 0)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
aa = (*p2 >> 24) & 0xff;
tmp = (r - rr) * a;
nr = rr + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (g - gg) * a;
ng = gg + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = (b - bb) * a;
nb = bb + ((tmp + (tmp >> 8) + 0x80) >> 8);
tmp = a + aa;
na = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
*p2 = (na << 24) | (nr << 16) |
(ng << 8) | nb;
}
p1++;
p2++;
}
}
}
void
__imlib_CopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
DATA8 r, g, b, a;
for (y = 0; y < h; y++)
{
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
a = (*p2 >> 24) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
*p2 = (a << 24) | (r << 16) | (g << 8) | b;
p2++;
p1++;
}
}
}
void
__imlib_CopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
DATA8 r, g, b, a;
for (y = 0; y < h; y++)
{
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
a = (*p1 >> 24) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
*p2 = (a << 24) | (r << 16) | (g << 8) | b;
p2++;
p1++;
}
}
}
/* COLORMOD ADD OPS */
void
__imlib_AddBlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr + ((r * a) >> 8);
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = gg + ((g * a) >> 8);
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = bb + ((b * a) >> 8);
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
*p2 = (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_AddBlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb, aa, na;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
aa = (*p2 >> 24) & 0xff;
tmp = rr + ((r * a) >> 8);
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = gg + ((g * a) >> 8);
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = bb + ((b * a) >> 8);
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = a + aa;
na = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
*p2 = (na << 24) | (nr << 16) |
(ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_AddCopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr + r;
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = gg + g;
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = bb + b;
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
*p2 = (*p2 & 0xff000000) | (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_AddCopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr + r;
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = gg + g;
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
tmp = bb + b;
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
*p2 = (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
/* COLORMOD SUBTRACT OPS */
void
__imlib_SubBlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr - ((r * a) >> 8);
nr = tmp & (~(tmp >> 8));
tmp = gg - ((g * a) >> 8);
ng = tmp & (~(tmp >> 8));
tmp = bb - ((b * a) >> 8);
nb = tmp & (~(tmp >> 8));
*p2 = (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_SubBlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb, aa, na;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
aa = (*p2 >> 24) & 0xff;
tmp = rr - ((r * a) >> 8);
nr = tmp & (~(tmp >> 8));
tmp = gg - ((g * a) >> 8);
ng = tmp & (~(tmp >> 8));
tmp = bb - ((b * a) >> 8);
nb = tmp & (~(tmp >> 8));
tmp = a + aa;
na = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
*p2 = (na << 24) | (nr << 16) |
(ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_SubCopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr - r;
nr = tmp & (~(tmp >> 8));
tmp = gg - g;
ng = tmp & (~(tmp >> 8));
tmp = bb - b;
nb = tmp & (~(tmp >> 8));
*p2 = (*p2 & 0xff000000) | (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_SubCopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr - r;
nr = tmp & (~(tmp >> 8));
tmp = gg - g;
ng = tmp & (~(tmp >> 8));
tmp = bb - b;
nb = tmp & (~(tmp >> 8));
*p2 = (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
/* COLORMOD RESHADE OPS */
void
__imlib_ReBlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr + (((r - 127) * a) >> 7);
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = gg + (((g - 127) * a) >> 7);
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = bb + (((b - 127) * a) >> 7);
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
*p2 = (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_ReBlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 a, nr, ng, nb, r, g, b, rr, gg, bb, aa, na;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
a = (*p1 >> 24) & 0xff;
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
aa = (*p2 >> 24) & 0xff;
tmp = rr + (((r - 127) * a) >> 7);
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = gg + (((g - 127) * a) >> 7);
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = bb + (((b - 127) * a) >> 7);
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = a + aa;
na = (tmp | ((tmp & 256) - ((tmp & 256) >> 8)));
*p2 = (na << 24) | (nr << 16) |
(ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_ReCopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr + ((r - 127) << 1);
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = gg + ((g - 127) << 1);
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = bb + ((b - 127) << 1);
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
*p2 = (*p2 & 0xff000000) | (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
void
__imlib_ReCopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm)
{
int x, y;
DATA32 *p1, *p2;
for (y = 0; y < h; y++)
{
DATA8 nr, ng, nb, r, g, b, rr, gg, bb;
int tmp;
p1 = src + (y * (w + src_jump));
p2 = dst + (y * (w + dst_jump));
for (x = 0; x < w; x++)
{
b = (*p1 ) & 0xff;
g = (*p1 >> 8 ) & 0xff;
r = (*p1 >> 16) & 0xff;
CMOD_APPLY_RGB(cm, r, g, b);
bb = (*p2 ) & 0xff;
gg = (*p2 >> 8 ) & 0xff;
rr = (*p2 >> 16) & 0xff;
tmp = rr + ((r - 127) << 1);
nr = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = gg + ((g - 127) << 1);
ng = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
tmp = bb + ((b - 127) << 1);
nb = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 8));
*p2 = (nr << 16) | (ng << 8) | nb;
p1++;
p2++;
}
}
}
#define LINESIZE 16
#define CLIP(x, y, w, h, xx, yy, ww, hh) \

58
blend.h
View File

@ -1,8 +1,6 @@
#ifndef __BLEND
#define __BLEND 1
typedef enum _imlibop ImlibOp;
enum _imlibop
{
OP_COPY,
@ -11,6 +9,8 @@ enum _imlibop
OP_RESHADE
};
typedef enum _imlibop ImlibOp;
void
__imlib_BlendImageToImage(ImlibImage *im_src, ImlibImage *im_dst,
char aa, char blend, char merge_alpha,
@ -70,4 +70,58 @@ __imlib_ReCopyRGBAToRGB(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
void
__imlib_ReCopyRGBAToRGBA(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h);
void
__imlib_BlendRGBAToRGB(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h);
void
__imlib_BlendRGBAToRGBA(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h);
void
__imlib_BlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_BlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_CopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_CopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_AddBlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_AddBlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_AddCopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_AddCopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_SubBlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_SubBlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_SubCopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_SubCopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_ReBlendRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_ReBlendRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_ReCopyRGBAToRGBCmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
void
__imlib_ReCopyRGBAToRGBACmod(DATA32 *src, int src_jump, DATA32 *dst, int dst_jump,
int w, int h, ImlibColorModifier *cm);
#endif

View File

@ -1 +1,202 @@
#include "common.h"
#include "colormod.h"
#include "file.h"
#include "loaderpath.h"
#include <X11/Xlib.h>
#include <math.h>
#include "image.h"
static DATABIG mod_count = 0;
ImlibColorModifier *
__imlib_CreateCmod(void)
{
ImlibColorModifier *cm;
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;
}
return cm;
}
void
__imlib_FreeCmod(ImlibColorModifier *cm)
{
free(cm);
}
void
__imlib_CmodChanged(ImlibColorModifier *cm)
{
mod_count++;
cm->modification_count = mod_count;
}
void
__imlib_CmodSetTables(ImlibColorModifier *cm,
DATA8 *r, DATA8 *g, DATA8 *b, DATA8 *a)
{
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];
}
__imlib_CmodChanged(cm);
}
void
__imlib_CmodReset(ImlibColorModifier *cm)
{
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;
}
__imlib_CmodChanged(cm);
}
void
__imlib_DataCmodApply(DATA32 *data, int w, int h, int jump,
ImlibColorModifier *cm)
{
int x, y;
DATA32 *p;
DATA8 r, g, b, a;
p = data;
for (y = 0; y < h; y++)
{
for (x = 0; x < w; x++)
{
b = (*p ) & 0xff;
g = (*p >> 8 ) & 0xff;
r = (*p >> 16) & 0xff;
a = (*p >> 24) & 0xff;
CMOD_APPLY_RGBA(cm, r, g, b, a);
*p = (a << 24) | (r << 16) | (g << 8) | b;
p++;
}
p += jump;
}
}
void
__imlib_CmodGetTables(ImlibColorModifier *cm, DATA8 *r, DATA8 *g,
DATA8 *b, DATA8 *a)
{
if (r)
memcpy(r, cm->red_mapping, (256 * sizeof(DATA8)));
if (g)
memcpy(g, cm->green_mapping, (256 * sizeof(DATA8)));
if (b)
memcpy(b, cm->blue_mapping, (256 * sizeof(DATA8)));
if (a)
memcpy(a, cm->alpha_mapping, (256 * sizeof(DATA8)));
}
void
__imlib_CmodModBrightness(ImlibColorModifier *cm, double v)
{
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->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->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)
{
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->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)
{
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->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_DataCmodApply(im->data, im->w, im->h, 0, cm);
}
#endif

View File

@ -1,3 +1,44 @@
#ifndef __COLORMOD
#define __COLORMOD 1