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

KImgIO

gimp.h

Go to the documentation of this file.
00001 #ifndef GIMP_H
00002 #define GIMP_H
00003 /* -*- c++ -*-
00004  * gimp.h: Header for a Qt 3 plug-in for reading GIMP XCF image files
00005  * Copyright (C) 2001 lignum Computing, Inc. <allen@lignumcomputing.com>
00006  * Copyright (C) 2004 Melchior FRANZ <mfranz@kde.org>
00007  *
00008  * This plug-in is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 #include <kglobal.h>
00025 
00026 /*
00027  * These are the constants and functions I extracted from The GIMP source
00028  * code. If the reader fails to work, this is probably the place to start
00029  * looking for discontinuities.
00030  */
00031 
00032 // From GIMP "tile.h" v1.2
00033 
00034 const uint TILE_WIDTH = 64; 
00035 const uint TILE_HEIGHT = 64;    
00036 
00037 // From GIMP "paint_funcs.c" v1.2
00038 
00039 const int RANDOM_TABLE_SIZE = 4096; 
00040 const int RANDOM_SEED = 314159265; 
00041 const double EPSILON = 0.0001;  
00042 
00043 // From GIMP "paint_funcs.h" v1.2
00044 
00045 const uchar OPAQUE_OPACITY = 255; 
00046 
00047 // From GIMP "apptypes.h" v1.2
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 
00072 // From GIMP "libgimp/gimpenums.h" v2.4
00073 
00075 
00076 typedef enum
00077 {
00078   NORMAL_MODE,
00079   DISSOLVE_MODE,
00080   BEHIND_MODE,
00081   MULTIPLY_MODE,
00082   SCREEN_MODE,
00083   OVERLAY_MODE,
00084   DIFFERENCE_MODE,
00085   ADDITION_MODE,
00086   SUBTRACT_MODE,
00087   DARKEN_ONLY_MODE,
00088   LIGHTEN_ONLY_MODE,
00089   HUE_MODE,
00090   SATURATION_MODE,
00091   COLOR_MODE,
00092   VALUE_MODE,
00093   DIVIDE_MODE,
00094   DODGE_MODE,
00095   BURN_MODE,
00096   HARDLIGHT_MODE,
00097   SOFTLIGHT_MODE,
00098   GRAIN_EXTRACT_MODE,
00099   GRAIN_MERGE_MODE
00100 } LayerModeEffects;
00101 
00102 // From GIMP "xcf.c" v1.2
00103 
00105 
00106 typedef enum
00107 {
00108   PROP_END = 0,
00109   PROP_COLORMAP = 1,
00110   PROP_ACTIVE_LAYER = 2,
00111   PROP_ACTIVE_CHANNEL = 3,
00112   PROP_SELECTION = 4,
00113   PROP_FLOATING_SELECTION = 5,
00114   PROP_OPACITY = 6,
00115   PROP_MODE = 7,
00116   PROP_VISIBLE = 8,
00117   PROP_LINKED = 9,
00118   PROP_PRESERVE_TRANSPARENCY = 10,
00119   PROP_APPLY_MASK = 11,
00120   PROP_EDIT_MASK = 12,
00121   PROP_SHOW_MASK = 13,
00122   PROP_SHOW_MASKED = 14,
00123   PROP_OFFSETS = 15,
00124   PROP_COLOR = 16,
00125   PROP_COMPRESSION = 17,
00126   PROP_GUIDES = 18,
00127   PROP_RESOLUTION = 19,
00128   PROP_TATTOO = 20,
00129   PROP_PARASITES = 21,
00130   PROP_UNIT = 22,
00131   PROP_PATHS = 23,
00132   PROP_USER_UNIT = 24
00133 } PropType;
00134 
00135 // From GIMP "xcf.c" v1.2
00136 
00138 
00139 typedef enum
00140 {
00141   COMPRESS_NONE = 0,
00142   COMPRESS_RLE = 1,
00143   COMPRESS_ZLIB = 2,
00144   COMPRESS_FRACTAL = 3  /* Unused. */
00145 } CompressionType;
00146 
00147 // From GIMP "paint_funcs.c" v1.2
00148 
00156 inline int INT_MULT ( int a, int b )
00157 {
00158   int c = a * b + 0x80;
00159   return ( ( c >> 8 ) + c ) >> 8;
00160 }
00161 
00173 inline int INT_BLEND ( int a, int b, int alpha )
00174 {
00175   return INT_MULT( a - b, alpha ) + b;
00176 }
00177 
00178 // From GIMP "gimpcolorspace.c" v1.2
00179 
00186 static void RGBTOHSV ( uchar& red, uchar& green, uchar& blue )
00187 {
00188   int r, g, b;
00189   double h, s, v;
00190   int min, max;
00191 
00192   h = 0.;
00193 
00194   r = red;
00195   g = green;
00196   b = blue;
00197 
00198   if ( r > g ) {
00199     max = qMax( r, b );
00200     min = qMin( g, b );
00201   }
00202   else {
00203     max = qMax( g, b );
00204     min = qMin( r, b );
00205   }
00206 
00207   v = max;
00208 
00209   if ( max != 0 )
00210     s = ( ( max - min ) * 255 ) / (double)max;
00211   else
00212     s = 0;
00213 
00214   if ( s == 0 )
00215     h = 0;
00216   else {
00217     int delta = max - min;
00218     if ( r == max )
00219       h = ( g - b ) / (double)delta;
00220     else if ( g == max )
00221       h = 2 + ( b - r ) / (double)delta;
00222     else if ( b == max )
00223       h = 4 + ( r - g ) / (double)delta;
00224     h *= 42.5;
00225 
00226     if ( h < 0 )
00227       h += 255;
00228     if ( h > 255 )
00229       h -= 255;
00230   }
00231 
00232   red   = (uchar)h;
00233   green = (uchar)s;
00234   blue  = (uchar)v;
00235 }
00236 
00243 static void HSVTORGB ( uchar& hue, uchar& saturation, uchar& value )
00244 {
00245   if ( saturation == 0 ) {
00246     hue        = value;
00247     saturation = value;
00248     value      = value;
00249   }
00250   else {
00251     double h = hue * 6. / 255.;
00252     double s = saturation / 255.;
00253     double v = value / 255.;
00254 
00255     double f = h - (int)h;
00256     double p = v * ( 1. - s );
00257     double q = v * ( 1. - ( s * f ) );
00258     double t = v * ( 1. - ( s * ( 1. - f ) ) );
00259 
00260     // Worth a note here that gcc 2.96 will generate different results
00261     // depending on optimization mode on i386.
00262 
00263     switch ((int)h) {
00264     case 0:
00265       hue        = (uchar)( v * 255 );
00266       saturation = (uchar)( t * 255 );
00267       value      = (uchar)( p * 255 );
00268       break;
00269     case 1:
00270       hue        = (uchar)( q * 255 );
00271       saturation = (uchar)( v * 255 );
00272       value      = (uchar)( p * 255 );
00273       break;
00274     case 2:
00275       hue        = (uchar)( p * 255 );
00276       saturation = (uchar)( v * 255 );
00277       value      = (uchar)( t * 255 );
00278       break;
00279     case 3:
00280       hue        = (uchar)( p * 255 );
00281       saturation = (uchar)( q * 255 );
00282       value      = (uchar)( v * 255 );
00283       break;
00284     case 4:
00285       hue        = (uchar)( t * 255 );
00286       saturation = (uchar)( p * 255 );
00287       value      = (uchar)( v * 255 );
00288       break;
00289     case 5:
00290       hue        = (uchar)( v * 255 );
00291       saturation = (uchar)( p * 255 );
00292       value      = (uchar)( q * 255 );
00293     }
00294   }
00295 }
00296 
00303 static void RGBTOHLS ( uchar& red, uchar& green, uchar& blue )
00304 {
00305   int r = red;
00306   int g = green;
00307   int b = blue;
00308 
00309   int min, max;
00310 
00311   if ( r > g ) {
00312     max = qMax( r, b );
00313     min = qMin( g, b );
00314   }
00315   else {
00316     max = qMax( g, b );
00317     min = qMin( r, b );
00318   }
00319 
00320   double h;
00321   double l = ( max + min ) / 2.;
00322   double s;
00323 
00324   if ( max == min ) {
00325     s = 0.;
00326     h = 0.;
00327   }
00328   else {
00329     int delta = max - min;
00330 
00331     if ( l < 128 )
00332       s = 255 * (double)delta / (double)( max + min );
00333     else
00334       s = 255 * (double)delta / (double)( 511 - max - min );
00335 
00336     if ( r == max )
00337       h = ( g - b ) / (double)delta;
00338     else if ( g == max )
00339       h = 2 + ( b - r ) / (double)delta;
00340     else
00341       h = 4 + ( r - g ) / (double)delta;
00342 
00343     h *= 42.5;
00344 
00345     if ( h < 0 )
00346       h += 255;
00347     else if ( h > 255 )
00348       h -= 255;
00349   }
00350 
00351   red   = (uchar)h;
00352   green = (uchar)l;
00353   blue  = (uchar)s;
00354 }
00355 
00363 static int HLSVALUE ( double n1, double n2, double hue )
00364 {
00365   double value;
00366 
00367   if ( hue > 255 )
00368     hue -= 255;
00369   else if ( hue < 0 )
00370     hue += 255;
00371 
00372   if ( hue < 42.5 )
00373     value = n1 + ( n2 - n1 ) * ( hue / 42.5 );
00374   else if ( hue < 127.5 )
00375     value = n2;
00376   else if ( hue < 170 )
00377     value = n1 + ( n2 - n1 ) * ( ( 170 - hue ) / 42.5 );
00378   else
00379     value = n1;
00380 
00381   return (int)( value * 255 );
00382 }
00383 
00390 static void HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation )
00391 {
00392   double h = hue;
00393   double l = lightness;
00394   double s = saturation;
00395 
00396   if ( s == 0 ) {
00397     hue        = (uchar)l;
00398     lightness  = (uchar)l;
00399     saturation = (uchar)l;
00400   }
00401   else {
00402     double m1, m2;
00403 
00404     if ( l < 128 )
00405       m2 = ( l * ( 255 + s ) ) / 65025.;
00406     else
00407       m2 = ( l + s - ( l * s ) / 255. ) / 255.;
00408 
00409     m1 = ( l / 127.5 ) - m2;
00410 
00411     hue        = HLSVALUE( m1, m2, h + 85 );
00412     lightness  = HLSVALUE( m1, m2, h );
00413     saturation = HLSVALUE( m1, m2, h - 85 );
00414   }
00415 }
00416 #endif

KImgIO

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal