24 #include <tdeglobal.h>
34 const uint TILE_WIDTH = 64;
35 const uint TILE_HEIGHT = 64;
39 const int RANDOM_TABLE_SIZE = 4096;
40 const int RANDOM_SEED = 314159265;
41 const double EPSILON = 0.0001;
45 const uchar OPAQUE_OPACITY = 255;
105 PROP_ACTIVE_LAYER = 2,
106 PROP_ACTIVE_CHANNEL = 3,
108 PROP_FLOATING_SELECTION = 5,
113 PROP_PRESERVE_TRANSPARENCY = 10,
114 PROP_APPLY_MASK = 11,
117 PROP_SHOW_MASKED = 14,
120 PROP_COMPRESSION = 17,
122 PROP_RESOLUTION = 19,
151 inline int INT_MULT (
int a,
int b )
153 int c = a * b + 0x80;
154 return ( ( c >> 8 ) + c ) >> 8;
168 inline int INT_BLEND (
int a,
int b,
int alpha )
170 return INT_MULT( a - b, alpha ) + b;
181 void RGBTOHSV ( uchar& red, uchar& green, uchar& blue )
205 s = ( ( max - min ) * 255 ) / (double)max;
212 int delta = max - min;
214 h = ( g - b ) / (
double)delta;
216 h = 2 + ( b - r ) / (
double)delta;
218 h = 4 + ( r - g ) / (
double)delta;
238 void HSVTORGB ( uchar& hue, uchar& saturation, uchar& value )
240 if ( saturation == 0 ) {
246 double h = hue * 6. / 255.;
247 double s = saturation / 255.;
248 double v = value / 255.;
250 double f = h - (int)h;
251 double p = v * ( 1. - s );
252 double q = v * ( 1. - ( s * f ) );
253 double t = v * ( 1. - ( s * ( 1. - f ) ) );
260 hue = (uchar)( v * 255 );
261 saturation = (uchar)( t * 255 );
262 value = (uchar)( p * 255 );
265 hue = (uchar)( q * 255 );
266 saturation = (uchar)( v * 255 );
267 value = (uchar)( p * 255 );
270 hue = (uchar)( p * 255 );
271 saturation = (uchar)( v * 255 );
272 value = (uchar)( t * 255 );
275 hue = (uchar)( p * 255 );
276 saturation = (uchar)( q * 255 );
277 value = (uchar)( v * 255 );
280 hue = (uchar)( t * 255 );
281 saturation = (uchar)( p * 255 );
282 value = (uchar)( v * 255 );
285 hue = (uchar)( v * 255 );
286 saturation = (uchar)( p * 255 );
287 value = (uchar)( q * 255 );
298 void RGBTOHLS ( uchar& red, uchar& green, uchar& blue )
316 double l = ( max + min ) / 2.;
324 int delta = max - min;
327 s = 255 * (double)delta / (
double)( max + min );
329 s = 255 * (double)delta / (
double)( 511 - max - min );
332 h = ( g - b ) / (
double)delta;
334 h = 2 + ( b - r ) / (
double)delta;
336 h = 4 + ( r - g ) / (
double)delta;
358 int HLSVALUE (
double n1,
double n2,
double hue )
368 value = n1 + ( n2 - n1 ) * ( hue / 42.5 );
369 else if ( hue < 127.5 )
371 else if ( hue < 170 )
372 value = n1 + ( n2 - n1 ) * ( ( 170 - hue ) / 42.5 );
376 return (
int)( value * 255 );
385 void HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation )
388 double l = lightness;
389 double s = saturation;
393 lightness = (uchar)l;
394 saturation = (uchar)l;
400 m2 = ( l * ( 255 + s ) ) / 65025.;
402 m2 = ( l + s - ( l * s ) / 255. ) / 255.;
404 m1 = ( l / 127.5 ) - m2;
406 hue = HLSVALUE( m1, m2, h + 85 );
407 lightness = HLSVALUE( m1, m2, h );
408 saturation = HLSVALUE( m1, m2, h - 85 );