4
4
* Functions to blend pixels with or without alpha, in various formats
7
* $Id: pixelblending.c,v 1.17 2006/12/05 16:43:00 ton Exp $
7
* $Id: pixelblending.c,v 1.18 2007/04/04 13:18:30 campbellbarton Exp $
9
9
* ***** BEGIN GPL LICENSE BLOCK *****
52
52
/* ------------------------------------------------------------------------- */
53
53
/* Debug/behaviour defines */
54
/* if defined: alpha blending with floats clips colour, as with shorts */
55
/* #define RE_FLOAT_COLOUR_CLIPPING */
54
/* if defined: alpha blending with floats clips color, as with shorts */
55
/* #define RE_FLOAT_COLOR_CLIPPING */
56
56
/* if defined: alpha values are clipped */
57
57
/* For now, we just keep alpha clipping. We run into thresholding and */
58
58
/* blending difficulties otherwise. Be careful here. */
63
63
/* Threshold for a 'full' pixel: pixels with alpha above this level are */
64
64
/* considered opaque This is the decimal value for 0xFFF0 / 0xFFFF */
65
#define RE_FULL_COLOUR_FLOAT 0.9998
65
#define RE_FULL_COLOR_FLOAT 0.9998
66
66
/* Threshold for an 'empty' pixel: pixels with alpha above this level are */
67
67
/* considered completely transparent. This is the decimal value */
68
68
/* for 0x000F / 0xFFFF */
69
#define RE_EMPTY_COLOUR_FLOAT 0.0002
69
#define RE_EMPTY_COLOR_FLOAT 0.0002
72
72
/* ------------------------------------------------------------------------- */
114
114
void addalphaAddfacFloat(float *dest, float *source, char addfac)
116
116
float m; /* weiging factor of destination */
117
float c; /* intermediate colour */
117
float c; /* intermediate color */
119
119
/* Addfac is a number between 0 and 1: rescale */
120
120
/* final target is to diminish the influence of dest when addfac rises */
121
121
m = 1.0 - ( source[3] * ((255.0 - addfac) / 255.0));
124
124
c= (m * dest[0]) + source[0];
125
#ifdef RE_FLOAT_COLOUR_CLIPPING
126
if(c >= RE_FULL_COLOUR_FLOAT) dest[0] = RE_FULL_COLOUR_FLOAT;
125
#ifdef RE_FLOAT_COLOR_CLIPPING
126
if(c >= RE_FULL_COLOR_FLOAT) dest[0] = RE_FULL_COLOR_FLOAT;
131
131
c= (m * dest[1]) + source[1];
132
#ifdef RE_FLOAT_COLOUR_CLIPPING
133
if(c >= RE_FULL_COLOUR_FLOAT) dest[1] = RE_FULL_COLOUR_FLOAT;
132
#ifdef RE_FLOAT_COLOR_CLIPPING
133
if(c >= RE_FULL_COLOR_FLOAT) dest[1] = RE_FULL_COLOR_FLOAT;
138
138
c= (m * dest[2]) + source[2];
139
#ifdef RE_FLOAT_COLOUR_CLIPPING
140
if(c >= RE_FULL_COLOUR_FLOAT) dest[2] = RE_FULL_COLOUR_FLOAT;
139
#ifdef RE_FLOAT_COLOR_CLIPPING
140
if(c >= RE_FULL_COLOR_FLOAT) dest[2] = RE_FULL_COLOR_FLOAT;
145
145
c= (m * dest[3]) + source[3];
146
146
#ifdef RE_ALPHA_CLIPPING
147
if(c >= RE_FULL_COLOUR_FLOAT) dest[3] = RE_FULL_COLOUR_FLOAT;
147
if(c >= RE_FULL_COLOR_FLOAT) dest[3] = RE_FULL_COLOR_FLOAT;