• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kimgio
 

kimgio

  • kimgio
gimp.h
1 #ifndef GIMP_H
2 #define GIMP_H
3 /*
4  * gimp.h: Header for a Qt 3 plug-in for reading GIMP XCF image files
5  * Copyright (C) 2001 lignum Computing, Inc. <allen@lignumcomputing.com>
6  * Copyright (C) 2004 Melchior FRANZ <mfranz@kde.org>
7  *
8  * This plug-in is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 #include <tdeglobal.h>
25 
26 /*
27  * These are the constants and functions I extracted from The GIMP source
28  * code. If the reader fails to work, this is probably the place to start
29  * looking for discontinuities.
30  */
31 
32 // From GIMP "tile.h" v1.2
33 
34 const uint TILE_WIDTH = 64;
35 const uint TILE_HEIGHT = 64;
36 
37 // From GIMP "paint_funcs.c" v1.2
38 
39 const int RANDOM_TABLE_SIZE = 4096;
40 const int RANDOM_SEED = 314159265;
41 const double EPSILON = 0.0001;
42 
43 // From GIMP "paint_funcs.h" v1.2
44 
45 const uchar OPAQUE_OPACITY = 255;
46 
47 // From GIMP "apptypes.h" v1.2
48 
52 
53 typedef enum
54 {
55  RGB,
56  GRAY,
57  INDEXED
58 } GimpImageBaseType;
59 
61 
62 typedef enum
63 {
64  RGB_GIMAGE,
65  RGBA_GIMAGE,
66  GRAY_GIMAGE,
67  GRAYA_GIMAGE,
68  INDEXED_GIMAGE,
69  INDEXEDA_GIMAGE
70 } GimpImageType;
71 
73 
74 typedef enum
75 {
76  NORMAL_MODE,
77  DISSOLVE_MODE,
78  BEHIND_MODE,
79  MULTIPLY_MODE,
80  SCREEN_MODE,
81  OVERLAY_MODE,
82  DIFFERENCE_MODE,
83  ADDITION_MODE,
84  SUBTRACT_MODE,
85  DARKEN_ONLY_MODE,
86  LIGHTEN_ONLY_MODE,
87  HUE_MODE,
88  SATURATION_MODE,
89  COLOR_MODE,
90  VALUE_MODE,
91  DIVIDE_MODE,
92  ERASE_MODE,
93  REPLACE_MODE,
94  ANTI_ERASE_MODE
95 } LayerModeEffects;
96 
97 // From GIMP "xcf.c" v1.2
98 
100 
101 typedef enum
102 {
103  PROP_END = 0,
104  PROP_COLORMAP = 1,
105  PROP_ACTIVE_LAYER = 2,
106  PROP_ACTIVE_CHANNEL = 3,
107  PROP_SELECTION = 4,
108  PROP_FLOATING_SELECTION = 5,
109  PROP_OPACITY = 6,
110  PROP_MODE = 7,
111  PROP_VISIBLE = 8,
112  PROP_LINKED = 9,
113  PROP_PRESERVE_TRANSPARENCY = 10,
114  PROP_APPLY_MASK = 11,
115  PROP_EDIT_MASK = 12,
116  PROP_SHOW_MASK = 13,
117  PROP_SHOW_MASKED = 14,
118  PROP_OFFSETS = 15,
119  PROP_COLOR = 16,
120  PROP_COMPRESSION = 17,
121  PROP_GUIDES = 18,
122  PROP_RESOLUTION = 19,
123  PROP_TATTOO = 20,
124  PROP_PARASITES = 21,
125  PROP_UNIT = 22,
126  PROP_PATHS = 23,
127  PROP_USER_UNIT = 24
128 } PropType;
129 
130 // From GIMP "xcf.c" v1.2
131 
133 
134 typedef enum
135 {
136  COMPRESS_NONE = 0,
137  COMPRESS_RLE = 1,
138  COMPRESS_ZLIB = 2,
139  COMPRESS_FRACTAL = 3 /* Unused. */
140 } CompressionType;
141 
142 // From GIMP "paint_funcs.c" v1.2
143 
151 inline int INT_MULT ( int a, int b )
152 {
153  int c = a * b + 0x80;
154  return ( ( c >> 8 ) + c ) >> 8;
155 }
156 
168 inline int INT_BLEND ( int a, int b, int alpha )
169 {
170  return INT_MULT( a - b, alpha ) + b;
171 }
172 
173 // From GIMP "gimpcolorspace.c" v1.2
174 
181 void RGBTOHSV ( uchar& red, uchar& green, uchar& blue )
182 {
183  int r, g, b;
184  double h, s, v;
185  int min, max;
186 
187  h = 0.;
188 
189  r = red;
190  g = green;
191  b = blue;
192 
193  if ( r > g ) {
194  max = KMAX( r, b );
195  min = KMIN( g, b );
196  }
197  else {
198  max = KMAX( g, b );
199  min = KMIN( r, b );
200  }
201 
202  v = max;
203 
204  if ( max != 0 )
205  s = ( ( max - min ) * 255 ) / (double)max;
206  else
207  s = 0;
208 
209  if ( s == 0 )
210  h = 0;
211  else {
212  int delta = max - min;
213  if ( r == max )
214  h = ( g - b ) / (double)delta;
215  else if ( g == max )
216  h = 2 + ( b - r ) / (double)delta;
217  else if ( b == max )
218  h = 4 + ( r - g ) / (double)delta;
219  h *= 42.5;
220 
221  if ( h < 0 )
222  h += 255;
223  if ( h > 255 )
224  h -= 255;
225  }
226 
227  red = (uchar)h;
228  green = (uchar)s;
229  blue = (uchar)v;
230 }
231 
238 void HSVTORGB ( uchar& hue, uchar& saturation, uchar& value )
239 {
240  if ( saturation == 0 ) {
241  hue = value;
242  saturation = value;
243  value = value;
244  }
245  else {
246  double h = hue * 6. / 255.;
247  double s = saturation / 255.;
248  double v = value / 255.;
249 
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 ) ) );
254 
255  // Worth a note here that gcc 2.96 will generate different results
256  // depending on optimization mode on i386.
257 
258  switch ((int)h) {
259  case 0:
260  hue = (uchar)( v * 255 );
261  saturation = (uchar)( t * 255 );
262  value = (uchar)( p * 255 );
263  break;
264  case 1:
265  hue = (uchar)( q * 255 );
266  saturation = (uchar)( v * 255 );
267  value = (uchar)( p * 255 );
268  break;
269  case 2:
270  hue = (uchar)( p * 255 );
271  saturation = (uchar)( v * 255 );
272  value = (uchar)( t * 255 );
273  break;
274  case 3:
275  hue = (uchar)( p * 255 );
276  saturation = (uchar)( q * 255 );
277  value = (uchar)( v * 255 );
278  break;
279  case 4:
280  hue = (uchar)( t * 255 );
281  saturation = (uchar)( p * 255 );
282  value = (uchar)( v * 255 );
283  break;
284  case 5:
285  hue = (uchar)( v * 255 );
286  saturation = (uchar)( p * 255 );
287  value = (uchar)( q * 255 );
288  }
289  }
290 }
291 
298 void RGBTOHLS ( uchar& red, uchar& green, uchar& blue )
299 {
300  int r = red;
301  int g = green;
302  int b = blue;
303 
304  int min, max;
305 
306  if ( r > g ) {
307  max = KMAX( r, b );
308  min = KMIN( g, b );
309  }
310  else {
311  max = KMAX( g, b );
312  min = KMIN( r, b );
313  }
314 
315  double h;
316  double l = ( max + min ) / 2.;
317  double s;
318 
319  if ( max == min ) {
320  s = 0.;
321  h = 0.;
322  }
323  else {
324  int delta = max - min;
325 
326  if ( l < 128 )
327  s = 255 * (double)delta / (double)( max + min );
328  else
329  s = 255 * (double)delta / (double)( 511 - max - min );
330 
331  if ( r == max )
332  h = ( g - b ) / (double)delta;
333  else if ( g == max )
334  h = 2 + ( b - r ) / (double)delta;
335  else
336  h = 4 + ( r - g ) / (double)delta;
337 
338  h *= 42.5;
339 
340  if ( h < 0 )
341  h += 255;
342  else if ( h > 255 )
343  h -= 255;
344  }
345 
346  red = (uchar)h;
347  green = (uchar)l;
348  blue = (uchar)s;
349 }
350 
358 int HLSVALUE ( double n1, double n2, double hue )
359 {
360  double value;
361 
362  if ( hue > 255 )
363  hue -= 255;
364  else if ( hue < 0 )
365  hue += 255;
366 
367  if ( hue < 42.5 )
368  value = n1 + ( n2 - n1 ) * ( hue / 42.5 );
369  else if ( hue < 127.5 )
370  value = n2;
371  else if ( hue < 170 )
372  value = n1 + ( n2 - n1 ) * ( ( 170 - hue ) / 42.5 );
373  else
374  value = n1;
375 
376  return (int)( value * 255 );
377 }
378 
385 void HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation )
386 {
387  double h = hue;
388  double l = lightness;
389  double s = saturation;
390 
391  if ( s == 0 ) {
392  hue = (uchar)l;
393  lightness = (uchar)l;
394  saturation = (uchar)l;
395  }
396  else {
397  double m1, m2;
398 
399  if ( l < 128 )
400  m2 = ( l * ( 255 + s ) ) / 65025.;
401  else
402  m2 = ( l + s - ( l * s ) / 255. ) / 255.;
403 
404  m1 = ( l / 127.5 ) - m2;
405 
406  hue = HLSVALUE( m1, m2, h + 85 );
407  lightness = HLSVALUE( m1, m2, h );
408  saturation = HLSVALUE( m1, m2, h - 85 );
409  }
410 }
411 #endif

kimgio

Skip menu "kimgio"
  • Main Page
  • File List
  • Related Pages

kimgio

Skip menu "kimgio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kimgio by doxygen 1.9.1
This website is maintained by Timothy Pearson.