00001 #ifndef GIMP_H
00002 #define GIMP_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <kglobal.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 const uint TILE_WIDTH = 64;
00035 const uint TILE_HEIGHT = 64;
00036
00037
00038
00039 const int RANDOM_TABLE_SIZE = 4096;
00040 const int RANDOM_SEED = 314159265;
00041 const double EPSILON = 0.0001;
00042
00043
00044
00045 const uchar OPAQUE_OPACITY = 255;
00046
00047
00048
00052
00053 typedef enum
00054 {
00055 RGB,
00056 GRAY,
00057 INDEXED
00058 } GimpImageBaseType;
00059
00061
00062 typedef enum
00063 {
00064 RGB_GIMAGE,
00065 RGBA_GIMAGE,
00066 GRAY_GIMAGE,
00067 GRAYA_GIMAGE,
00068 INDEXED_GIMAGE,
00069 INDEXEDA_GIMAGE
00070 } GimpImageType;
00071
00073
00074 typedef enum
00075 {
00076 NORMAL_MODE,
00077 DISSOLVE_MODE,
00078 BEHIND_MODE,
00079 MULTIPLY_MODE,
00080 SCREEN_MODE,
00081 OVERLAY_MODE,
00082 DIFFERENCE_MODE,
00083 ADDITION_MODE,
00084 SUBTRACT_MODE,
00085 DARKEN_ONLY_MODE,
00086 LIGHTEN_ONLY_MODE,
00087 HUE_MODE,
00088 SATURATION_MODE,
00089 COLOR_MODE,
00090 VALUE_MODE,
00091 DIVIDE_MODE,
00092 ERASE_MODE,
00093 REPLACE_MODE,
00094 ANTI_ERASE_MODE
00095 } LayerModeEffects;
00096
00097
00098
00100
00101 typedef enum
00102 {
00103 PROP_END = 0,
00104 PROP_COLORMAP = 1,
00105 PROP_ACTIVE_LAYER = 2,
00106 PROP_ACTIVE_CHANNEL = 3,
00107 PROP_SELECTION = 4,
00108 PROP_FLOATING_SELECTION = 5,
00109 PROP_OPACITY = 6,
00110 PROP_MODE = 7,
00111 PROP_VISIBLE = 8,
00112 PROP_LINKED = 9,
00113 PROP_PRESERVE_TRANSPARENCY = 10,
00114 PROP_APPLY_MASK = 11,
00115 PROP_EDIT_MASK = 12,
00116 PROP_SHOW_MASK = 13,
00117 PROP_SHOW_MASKED = 14,
00118 PROP_OFFSETS = 15,
00119 PROP_COLOR = 16,
00120 PROP_COMPRESSION = 17,
00121 PROP_GUIDES = 18,
00122 PROP_RESOLUTION = 19,
00123 PROP_TATTOO = 20,
00124 PROP_PARASITES = 21,
00125 PROP_UNIT = 22,
00126 PROP_PATHS = 23,
00127 PROP_USER_UNIT = 24
00128 } PropType;
00129
00130
00131
00133
00134 typedef enum
00135 {
00136 COMPRESS_NONE = 0,
00137 COMPRESS_RLE = 1,
00138 COMPRESS_ZLIB = 2,
00139 COMPRESS_FRACTAL = 3
00140 } CompressionType;
00141
00142
00143
00151 inline int INT_MULT ( int a, int b )
00152 {
00153 int c = a * b + 0x80;
00154 return ( ( c >> 8 ) + c ) >> 8;
00155 }
00156
00168 inline int INT_BLEND ( int a, int b, int alpha )
00169 {
00170 return INT_MULT( a - b, alpha ) + b;
00171 }
00172
00173
00174
00181 void RGBTOHSV ( uchar& red, uchar& green, uchar& blue )
00182 {
00183 int r, g, b;
00184 double h, s, v;
00185 int min, max;
00186
00187 h = 0.;
00188
00189 r = red;
00190 g = green;
00191 b = blue;
00192
00193 if ( r > g ) {
00194 max = KMAX( r, b );
00195 min = KMIN( g, b );
00196 }
00197 else {
00198 max = KMAX( g, b );
00199 min = KMIN( r, b );
00200 }
00201
00202 v = max;
00203
00204 if ( max != 0 )
00205 s = ( ( max - min ) * 255 ) / (double)max;
00206 else
00207 s = 0;
00208
00209 if ( s == 0 )
00210 h = 0;
00211 else {
00212 int delta = max - min;
00213 if ( r == max )
00214 h = ( g - b ) / (double)delta;
00215 else if ( g == max )
00216 h = 2 + ( b - r ) / (double)delta;
00217 else if ( b == max )
00218 h = 4 + ( r - g ) / (double)delta;
00219 h *= 42.5;
00220
00221 if ( h < 0 )
00222 h += 255;
00223 if ( h > 255 )
00224 h -= 255;
00225 }
00226
00227 red = (uchar)h;
00228 green = (uchar)s;
00229 blue = (uchar)v;
00230 }
00231
00238 void HSVTORGB ( uchar& hue, uchar& saturation, uchar& value )
00239 {
00240 if ( saturation == 0 ) {
00241 hue = value;
00242 saturation = value;
00243 value = value;
00244 }
00245 else {
00246 double h = hue * 6. / 255.;
00247 double s = saturation / 255.;
00248 double v = value / 255.;
00249
00250 double f = h - (int)h;
00251 double p = v * ( 1. - s );
00252 double q = v * ( 1. - ( s * f ) );
00253 double t = v * ( 1. - ( s * ( 1. - f ) ) );
00254
00255
00256
00257
00258 switch ((int)h) {
00259 case 0:
00260 hue = (uchar)( v * 255 );
00261 saturation = (uchar)( t * 255 );
00262 value = (uchar)( p * 255 );
00263 break;
00264 case 1:
00265 hue = (uchar)( q * 255 );
00266 saturation = (uchar)( v * 255 );
00267 value = (uchar)( p * 255 );
00268 break;
00269 case 2:
00270 hue = (uchar)( p * 255 );
00271 saturation = (uchar)( v * 255 );
00272 value = (uchar)( t * 255 );
00273 break;
00274 case 3:
00275 hue = (uchar)( p * 255 );
00276 saturation = (uchar)( q * 255 );
00277 value = (uchar)( v * 255 );
00278 break;
00279 case 4:
00280 hue = (uchar)( t * 255 );
00281 saturation = (uchar)( p * 255 );
00282 value = (uchar)( v * 255 );
00283 break;
00284 case 5:
00285 hue = (uchar)( v * 255 );
00286 saturation = (uchar)( p * 255 );
00287 value = (uchar)( q * 255 );
00288 }
00289 }
00290 }
00291
00298 void RGBTOHLS ( uchar& red, uchar& green, uchar& blue )
00299 {
00300 int r = red;
00301 int g = green;
00302 int b = blue;
00303
00304 int min, max;
00305
00306 if ( r > g ) {
00307 max = KMAX( r, b );
00308 min = KMIN( g, b );
00309 }
00310 else {
00311 max = KMAX( g, b );
00312 min = KMIN( r, b );
00313 }
00314
00315 double h;
00316 double l = ( max + min ) / 2.;
00317 double s;
00318
00319 if ( max == min ) {
00320 s = 0.;
00321 h = 0.;
00322 }
00323 else {
00324 int delta = max - min;
00325
00326 if ( l < 128 )
00327 s = 255 * (double)delta / (double)( max + min );
00328 else
00329 s = 255 * (double)delta / (double)( 511 - max - min );
00330
00331 if ( r == max )
00332 h = ( g - b ) / (double)delta;
00333 else if ( g == max )
00334 h = 2 + ( b - r ) / (double)delta;
00335 else
00336 h = 4 + ( r - g ) / (double)delta;
00337
00338 h *= 42.5;
00339
00340 if ( h < 0 )
00341 h += 255;
00342 else if ( h > 255 )
00343 h -= 255;
00344 }
00345
00346 red = (uchar)h;
00347 green = (uchar)l;
00348 blue = (uchar)s;
00349 }
00350
00358 int HLSVALUE ( double n1, double n2, double hue )
00359 {
00360 double value;
00361
00362 if ( hue > 255 )
00363 hue -= 255;
00364 else if ( hue < 0 )
00365 hue += 255;
00366
00367 if ( hue < 42.5 )
00368 value = n1 + ( n2 - n1 ) * ( hue / 42.5 );
00369 else if ( hue < 127.5 )
00370 value = n2;
00371 else if ( hue < 170 )
00372 value = n1 + ( n2 - n1 ) * ( ( 170 - hue ) / 42.5 );
00373 else
00374 value = n1;
00375
00376 return (int)( value * 255 );
00377 }
00378
00385 void HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation )
00386 {
00387 double h = hue;
00388 double l = lightness;
00389 double s = saturation;
00390
00391 if ( s == 0 ) {
00392 hue = (uchar)l;
00393 lightness = (uchar)l;
00394 saturation = (uchar)l;
00395 }
00396 else {
00397 double m1, m2;
00398
00399 if ( l < 128 )
00400 m2 = ( l * ( 255 + s ) ) / 65025.;
00401 else
00402 m2 = ( l + s - ( l * s ) / 255. ) / 255.;
00403
00404 m1 = ( l / 127.5 ) - m2;
00405
00406 hue = HLSVALUE( m1, m2, h + 85 );
00407 lightness = HLSVALUE( m1, m2, h );
00408 saturation = HLSVALUE( m1, m2, h - 85 );
00409 }
00410 }
00411 #endif