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

KImgIO

xcf.h

Go to the documentation of this file.
00001 #ifndef XCF_H
00002 #define XCF_H
00003 /*
00004  * qxcfi.cpp: 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 
00025 #include <QtGui/QImageIOPlugin>
00026 #include <QtGui/QImage>
00027 #include <QtCore/QIODevice>
00028 #include <QtCore/QVector>
00029 
00030 #include "gimp.h"
00031 
00032 class XCFHandler : public QImageIOHandler
00033 {
00034 public:
00035     XCFHandler();
00036 
00037     bool canRead() const;
00038     bool read(QImage *image);
00039     bool write(const QImage &image);
00040 
00041     QByteArray name() const;
00042 
00043     static bool canRead(QIODevice *device);
00044 };
00045 
00046 const float INCHESPERMETER = (100.0f / 2.54f);
00047 
00055 typedef QVector<QVector<QImage> > Tiles;
00056 
00057 
00058 
00059 class XCFImageFormat {
00060 public:
00061     XCFImageFormat();
00062     bool readXCF(QIODevice *device, QImage *image);
00063 
00064 
00065 private:
00074     class Layer {
00075     public:
00076         quint32 width;          
00077         quint32 height;     
00078         qint32 type;            
00079         char* name;         
00080         quint32 hierarchy_offset;   
00081         quint32 mask_offset;        
00082 
00083         uint nrows;         
00084         uint ncols;         
00085 
00086         Tiles image_tiles;      
00087 
00088 
00089         Tiles alpha_tiles;
00090         Tiles mask_tiles;       
00091 
00093         struct {
00094             quint32 opacity;
00095             quint32 visible;
00096             quint32 show_masked;
00097             uchar red, green, blue;
00098             quint32 tattoo;
00099         } mask_channel;
00100 
00101         bool active;            
00102         quint32 opacity;        
00103         quint32 visible;        
00104         quint32 linked;     
00105         quint32 preserve_transparency; 
00106         quint32 apply_mask;     
00107         quint32 edit_mask;      
00108         quint32 show_mask;      
00109         qint32 x_offset;        
00110         qint32 y_offset;        
00111         quint32 mode;           
00112         quint32 tattoo;     
00113 
00115         uchar tile[TILE_WIDTH * TILE_HEIGHT * sizeof(QRgb)];
00116 
00121         void (*assignBytes)(Layer& layer, uint i, uint j);
00122 
00123         Layer(void) : name(0) {}
00124         ~Layer(void) { delete[] name; }
00125     };
00126 
00127 
00132     class XCFImage {
00133     public:
00134         quint32 width;          
00135         quint32 height;     
00136         qint32 type;            
00137 
00138         quint8 compression;     
00139         float x_resolution;     
00140         float y_resolution;     
00141         qint32 tattoo;          
00142         quint32 unit;           
00143         qint32 num_colors;      
00144         QVector<QRgb> palette;          
00145 
00146         int num_layers;         
00147         Layer layer;            
00148 
00149         bool initialized;       
00150         QImage image;           
00151 
00152         XCFImage(void) : initialized(false) {}
00153     };
00154 
00155 
00161     static int random_table[RANDOM_TABLE_SIZE];
00162 
00164     //static int add_lut[256][256]; - this is so lame waste of 256k of memory
00165     static int add_lut( int, int );
00166 
00169     typedef void (*PixelCopyOperation)(Layer& layer, uint i, uint j, int k, int l,
00170             QImage& image, int m, int n);
00171 
00173     typedef void (*PixelMergeOperation)(Layer& layer, uint i, uint j, int k, int l,
00174             QImage& image, int m, int n);
00175 
00177     typedef struct {
00178         bool affect_alpha;      
00179     } LayerModes;
00180 
00183     static const LayerModes layer_modes[];
00184 
00185     bool loadImageProperties(QDataStream& xcf_io, XCFImage& image);
00186     bool loadProperty(QDataStream& xcf_io, PropType& type, QByteArray& bytes);
00187     bool loadLayer(QDataStream& xcf_io, XCFImage& xcf_image);
00188     bool loadLayerProperties(QDataStream& xcf_io, Layer& layer);
00189     bool composeTiles(XCFImage& xcf_image);
00190     void setGrayPalette(QImage& image);
00191     void setPalette(XCFImage& xcf_image, QImage& image);
00192     static void assignImageBytes(Layer& layer, uint i, uint j);
00193     bool loadHierarchy(QDataStream& xcf_io, Layer& layer);
00194     bool loadLevel(QDataStream& xcf_io, Layer& layer, qint32 bpp);
00195     static void assignMaskBytes(Layer& layer, uint i, uint j);
00196     bool loadMask(QDataStream& xcf_io, Layer& layer);
00197     bool loadChannelProperties(QDataStream& xcf_io, Layer& layer);
00198     bool initializeImage(XCFImage& xcf_image);
00199     bool loadTileRLE(QDataStream& xcf_io, uchar* tile, int size,
00200             int data_length, qint32 bpp);
00201     static void copyLayerToImage(XCFImage& xcf_image);
00202     static void copyRGBToRGB(Layer& layer, uint i, uint j, int k, int l,
00203             QImage& image, int m, int n);
00204 
00205     static void copyGrayToGray(Layer& layer, uint i, uint j, int k, int l,
00206             QImage& image, int m, int n);
00207     static void copyGrayToRGB(Layer& layer, uint i, uint j, int k, int l,
00208             QImage& image, int m, int n);
00209     static void copyGrayAToRGB(Layer& layer, uint i, uint j, int k, int l,
00210             QImage& image, int m, int n);
00211     static void copyIndexedToIndexed(Layer& layer, uint i, uint j, int k, int l,
00212             QImage& image, int m, int n);
00213     static void copyIndexedAToIndexed(Layer& layer, uint i, uint j, int k, int l,
00214             QImage& image, int m, int n);
00215     static void copyIndexedAToRGB(Layer& layer, uint i, uint j, int k, int l,
00216             QImage& image, int m, int n);
00217 
00218     static void mergeLayerIntoImage(XCFImage& xcf_image);
00219     static void mergeRGBToRGB(Layer& layer, uint i, uint j, int k, int l,
00220             QImage& image, int m, int n);
00221     static void mergeGrayToGray(Layer& layer, uint i, uint j, int k, int l,
00222             QImage& image, int m, int n);
00223     static void mergeGrayAToGray(Layer& layer, uint i, uint j, int k, int l,
00224             QImage& image, int m, int n);
00225     static void mergeGrayToRGB(Layer& layer, uint i, uint j, int k, int l,
00226             QImage& image, int m, int n);
00227     static void mergeGrayAToRGB(Layer& layer, uint i, uint j, int k, int l,
00228             QImage& image, int m, int n);
00229     static void mergeIndexedToIndexed(Layer& layer, uint i, uint j, int k, int l,
00230             QImage& image, int m, int n);
00231     static void mergeIndexedAToIndexed(Layer& layer, uint i, uint j, int k, int l,
00232             QImage& image, int m, int n);
00233     static void mergeIndexedAToRGB(Layer& layer, uint i, uint j, int k, int l,
00234             QImage& image, int m, int n);
00235 
00236     static void dissolveRGBPixels(QImage& image, int x, int y);
00237     static void dissolveAlphaPixels(QImage& image, int x, int y);
00238 };
00239 
00240 #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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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