• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KImgIO

  • sources
  • kde-4.14
  • kdelibs
  • kimgio
gimp.h
Go to the documentation of this file.
1 #ifndef GIMP_H
2 #define GIMP_H
3 /* -*- c++ -*-
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 typedef unsigned char uchar;
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 
72 // From GIMP "libgimp/gimpenums.h" v2.4
73 
75 
76 typedef enum
77 {
78  NORMAL_MODE,
79  DISSOLVE_MODE,
80  BEHIND_MODE,
81  MULTIPLY_MODE,
82  SCREEN_MODE,
83  OVERLAY_MODE,
84  DIFFERENCE_MODE,
85  ADDITION_MODE,
86  SUBTRACT_MODE,
87  DARKEN_ONLY_MODE,
88  LIGHTEN_ONLY_MODE,
89  HUE_MODE,
90  SATURATION_MODE,
91  COLOR_MODE,
92  VALUE_MODE,
93  DIVIDE_MODE,
94  DODGE_MODE,
95  BURN_MODE,
96  HARDLIGHT_MODE,
97  SOFTLIGHT_MODE,
98  GRAIN_EXTRACT_MODE,
99  GRAIN_MERGE_MODE
100 } LayerModeEffects;
101 
102 // From GIMP "xcf.c" v1.2
103 
105 
106 typedef enum
107 {
108  PROP_END = 0,
109  PROP_COLORMAP = 1,
110  PROP_ACTIVE_LAYER = 2,
111  PROP_ACTIVE_CHANNEL = 3,
112  PROP_SELECTION = 4,
113  PROP_FLOATING_SELECTION = 5,
114  PROP_OPACITY = 6,
115  PROP_MODE = 7,
116  PROP_VISIBLE = 8,
117  PROP_LINKED = 9,
118  PROP_PRESERVE_TRANSPARENCY = 10,
119  PROP_APPLY_MASK = 11,
120  PROP_EDIT_MASK = 12,
121  PROP_SHOW_MASK = 13,
122  PROP_SHOW_MASKED = 14,
123  PROP_OFFSETS = 15,
124  PROP_COLOR = 16,
125  PROP_COMPRESSION = 17,
126  PROP_GUIDES = 18,
127  PROP_RESOLUTION = 19,
128  PROP_TATTOO = 20,
129  PROP_PARASITES = 21,
130  PROP_UNIT = 22,
131  PROP_PATHS = 23,
132  PROP_USER_UNIT = 24
133 } PropType;
134 
135 // From GIMP "xcf.c" v1.2
136 
138 
139 typedef enum
140 {
141  COMPRESS_NONE = 0,
142  COMPRESS_RLE = 1,
143  COMPRESS_ZLIB = 2,
144  COMPRESS_FRACTAL = 3 /* Unused. */
145 } CompressionType;
146 
147 // From GIMP "paint_funcs.c" v1.2
148 
156 inline int INT_MULT ( int a, int b )
157 {
158  int c = a * b + 0x80;
159  return ( ( c >> 8 ) + c ) >> 8;
160 }
161 
173 inline int INT_BLEND ( int a, int b, int alpha )
174 {
175  return INT_MULT( a - b, alpha ) + b;
176 }
177 
178 // From GIMP "gimpcolorspace.c" v1.2
179 
186 static void RGBTOHSV ( uchar& red, uchar& green, uchar& blue )
187 {
188  int r, g, b;
189  double h, s, v;
190  int min, max;
191 
192  h = 0.;
193 
194  r = red;
195  g = green;
196  b = blue;
197 
198  if ( r > g ) {
199  max = qMax( r, b );
200  min = qMin( g, b );
201  }
202  else {
203  max = qMax( g, b );
204  min = qMin( r, b );
205  }
206 
207  v = max;
208 
209  if ( max != 0 )
210  s = ( ( max - min ) * 255 ) / (double)max;
211  else
212  s = 0;
213 
214  if ( s == 0 )
215  h = 0;
216  else {
217  int delta = max - min;
218  if ( r == max )
219  h = ( g - b ) / (double)delta;
220  else if ( g == max )
221  h = 2 + ( b - r ) / (double)delta;
222  else if ( b == max )
223  h = 4 + ( r - g ) / (double)delta;
224  h *= 42.5;
225 
226  if ( h < 0 )
227  h += 255;
228  if ( h > 255 )
229  h -= 255;
230  }
231 
232  red = (uchar)h;
233  green = (uchar)s;
234  blue = (uchar)v;
235 }
236 
243 static void HSVTORGB ( uchar& hue, uchar& saturation, uchar& value )
244 {
245  if ( saturation == 0 ) {
246  hue = value;
247  saturation = value;
248  //value = value;
249  }
250  else {
251  double h = hue * 6. / 255.;
252  double s = saturation / 255.;
253  double v = value / 255.;
254 
255  double f = h - (int)h;
256  double p = v * ( 1. - s );
257  double q = v * ( 1. - ( s * f ) );
258  double t = v * ( 1. - ( s * ( 1. - f ) ) );
259 
260  // Worth a note here that gcc 2.96 will generate different results
261  // depending on optimization mode on i386.
262 
263  switch ((int)h) {
264  case 0:
265  hue = (uchar)( v * 255 );
266  saturation = (uchar)( t * 255 );
267  value = (uchar)( p * 255 );
268  break;
269  case 1:
270  hue = (uchar)( q * 255 );
271  saturation = (uchar)( v * 255 );
272  value = (uchar)( p * 255 );
273  break;
274  case 2:
275  hue = (uchar)( p * 255 );
276  saturation = (uchar)( v * 255 );
277  value = (uchar)( t * 255 );
278  break;
279  case 3:
280  hue = (uchar)( p * 255 );
281  saturation = (uchar)( q * 255 );
282  value = (uchar)( v * 255 );
283  break;
284  case 4:
285  hue = (uchar)( t * 255 );
286  saturation = (uchar)( p * 255 );
287  value = (uchar)( v * 255 );
288  break;
289  case 5:
290  hue = (uchar)( v * 255 );
291  saturation = (uchar)( p * 255 );
292  value = (uchar)( q * 255 );
293  }
294  }
295 }
296 
303 static void RGBTOHLS ( uchar& red, uchar& green, uchar& blue )
304 {
305  int r = red;
306  int g = green;
307  int b = blue;
308 
309  int min, max;
310 
311  if ( r > g ) {
312  max = qMax( r, b );
313  min = qMin( g, b );
314  }
315  else {
316  max = qMax( g, b );
317  min = qMin( r, b );
318  }
319 
320  double h;
321  double l = ( max + min ) / 2.;
322  double s;
323 
324  if ( max == min ) {
325  s = 0.;
326  h = 0.;
327  }
328  else {
329  int delta = max - min;
330 
331  if ( l < 128 )
332  s = 255 * (double)delta / (double)( max + min );
333  else
334  s = 255 * (double)delta / (double)( 511 - max - min );
335 
336  if ( r == max )
337  h = ( g - b ) / (double)delta;
338  else if ( g == max )
339  h = 2 + ( b - r ) / (double)delta;
340  else
341  h = 4 + ( r - g ) / (double)delta;
342 
343  h *= 42.5;
344 
345  if ( h < 0 )
346  h += 255;
347  else if ( h > 255 )
348  h -= 255;
349  }
350 
351  red = (uchar)h;
352  green = (uchar)l;
353  blue = (uchar)s;
354 }
355 
363 static int HLSVALUE ( double n1, double n2, double hue )
364 {
365  double value;
366 
367  if ( hue > 255 )
368  hue -= 255;
369  else if ( hue < 0 )
370  hue += 255;
371 
372  if ( hue < 42.5 )
373  value = n1 + ( n2 - n1 ) * ( hue / 42.5 );
374  else if ( hue < 127.5 )
375  value = n2;
376  else if ( hue < 170 )
377  value = n1 + ( n2 - n1 ) * ( ( 170 - hue ) / 42.5 );
378  else
379  value = n1;
380 
381  return (int)( value * 255 );
382 }
383 
390 static void HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation )
391 {
392  double h = hue;
393  double l = lightness;
394  double s = saturation;
395 
396  if ( s == 0 ) {
397  hue = (uchar)l;
398  lightness = (uchar)l;
399  saturation = (uchar)l;
400  }
401  else {
402  double m1, m2;
403 
404  if ( l < 128 )
405  m2 = ( l * ( 255 + s ) ) / 65025.;
406  else
407  m2 = ( l + s - ( l * s ) / 255. ) / 255.;
408 
409  m1 = ( l / 127.5 ) - m2;
410 
411  hue = HLSVALUE( m1, m2, h + 85 );
412  lightness = HLSVALUE( m1, m2, h );
413  saturation = HLSVALUE( m1, m2, h - 85 );
414  }
415 }
416 #endif
GRAIN_EXTRACT_MODE
Definition: gimp.h:98
PROP_PRESERVE_TRANSPARENCY
Definition: gimp.h:118
LayerModeEffects
LayerModeEffects
Effect to apply when layers are merged together.
Definition: gimp.h:76
PROP_COLORMAP
Definition: gimp.h:109
RANDOM_TABLE_SIZE
const int RANDOM_TABLE_SIZE
Size of dissolve random number table.
Definition: gimp.h:39
NORMAL_MODE
Definition: gimp.h:78
DIFFERENCE_MODE
Definition: gimp.h:84
PROP_MODE
Definition: gimp.h:115
INT_BLEND
int INT_BLEND(int a, int b, int alpha)
Definition: gimp.h:173
PROP_VISIBLE
Definition: gimp.h:116
PropType
PropType
Properties which can be stored in an XCF file.
Definition: gimp.h:106
RGB_GIMAGE
Definition: gimp.h:64
COLOR_MODE
Definition: gimp.h:91
PROP_EDIT_MASK
Definition: gimp.h:120
SCREEN_MODE
Definition: gimp.h:82
PROP_TATTOO
Definition: gimp.h:128
COMPRESS_FRACTAL
Definition: gimp.h:144
COMPRESS_NONE
Definition: gimp.h:141
PROP_SHOW_MASK
Definition: gimp.h:121
DIVIDE_MODE
Definition: gimp.h:93
DODGE_MODE
Definition: gimp.h:94
PROP_RESOLUTION
Definition: gimp.h:127
PROP_ACTIVE_CHANNEL
Definition: gimp.h:111
HLSTORGB
static void HLSTORGB(uchar &hue, uchar &lightness, uchar &saturation)
Definition: gimp.h:390
EPSILON
const double EPSILON
Roundup in alpha blending.
Definition: gimp.h:41
GimpImageType
GimpImageType
Type of individual layers in an XCF file.
Definition: gimp.h:62
uchar
unsigned char uchar
Definition: gimp.h:24
GRAYA_GIMAGE
Definition: gimp.h:67
GRAY
Definition: gimp.h:56
GRAIN_MERGE_MODE
Definition: gimp.h:99
HLSVALUE
static int HLSVALUE(double n1, double n2, double hue)
Definition: gimp.h:363
HARDLIGHT_MODE
Definition: gimp.h:96
PROP_ACTIVE_LAYER
Definition: gimp.h:110
PROP_OFFSETS
Definition: gimp.h:123
PROP_USER_UNIT
Definition: gimp.h:132
SATURATION_MODE
Definition: gimp.h:90
PROP_OPACITY
Definition: gimp.h:114
BURN_MODE
Definition: gimp.h:95
RGB
Definition: gimp.h:55
LIGHTEN_ONLY_MODE
Definition: gimp.h:88
COMPRESS_ZLIB
Definition: gimp.h:143
TILE_HEIGHT
const uint TILE_HEIGHT
Height of a tile in the XCF file.
Definition: gimp.h:35
PROP_GUIDES
Definition: gimp.h:126
CompressionType
CompressionType
Compression type used in layer tiles.
Definition: gimp.h:139
PROP_FLOATING_SELECTION
Definition: gimp.h:113
uchar
quint8 uchar
Definition: dds.cpp:38
SOFTLIGHT_MODE
Definition: gimp.h:97
HSVTORGB
static void HSVTORGB(uchar &hue, uchar &saturation, uchar &value)
Definition: gimp.h:243
PROP_LINKED
Definition: gimp.h:117
DISSOLVE_MODE
Definition: gimp.h:79
PROP_PATHS
Definition: gimp.h:131
TILE_WIDTH
const uint TILE_WIDTH
Width of a tile in the XCF file.
Definition: gimp.h:34
RGBTOHSV
static void RGBTOHSV(uchar &red, uchar &green, uchar &blue)
Definition: gimp.h:186
PROP_UNIT
Definition: gimp.h:130
PROP_SELECTION
Definition: gimp.h:112
GimpImageBaseType
GimpImageBaseType
Basic GIMP image type.
Definition: gimp.h:53
DARKEN_ONLY_MODE
Definition: gimp.h:87
RGBA_GIMAGE
Definition: gimp.h:65
PROP_COLOR
Definition: gimp.h:124
PROP_COMPRESSION
Definition: gimp.h:125
HUE_MODE
Definition: gimp.h:89
PROP_SHOW_MASKED
Definition: gimp.h:122
COMPRESS_RLE
Definition: gimp.h:142
RANDOM_SEED
const int RANDOM_SEED
Seed for dissolve random number table.
Definition: gimp.h:40
ADDITION_MODE
Definition: gimp.h:85
SUBTRACT_MODE
Definition: gimp.h:86
BEHIND_MODE
Definition: gimp.h:80
uint
quint32 uint
Definition: dds.cpp:36
OVERLAY_MODE
Definition: gimp.h:83
PROP_END
Definition: gimp.h:108
PROP_APPLY_MASK
Definition: gimp.h:119
MULTIPLY_MODE
Definition: gimp.h:81
INDEXEDA_GIMAGE
Definition: gimp.h:69
OPAQUE_OPACITY
const uchar OPAQUE_OPACITY
Opaque value for 8-bit alpha component.
Definition: gimp.h:45
GRAY_GIMAGE
Definition: gimp.h:66
INT_MULT
int INT_MULT(int a, int b)
Definition: gimp.h:156
PROP_PARASITES
Definition: gimp.h:129
INDEXED
Definition: gimp.h:57
RGBTOHLS
static void RGBTOHLS(uchar &red, uchar &green, uchar &blue)
Definition: gimp.h:303
VALUE_MODE
Definition: gimp.h:92
INDEXED_GIMAGE
Definition: gimp.h:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KImgIO

Skip menu "KImgIO"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal