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 static bool random_table_initialized; 00163 00167 static QVector<QRgb> grayTable; 00168 00170 //static int add_lut[256][256]; - this is so lame waste of 256k of memory 00171 static int add_lut( int, int ); 00172 00175 typedef void (*PixelCopyOperation)(Layer& layer, uint i, uint j, int k, int l, 00176 QImage& image, int m, int n); 00177 00179 typedef void (*PixelMergeOperation)(Layer& layer, uint i, uint j, int k, int l, 00180 QImage& image, int m, int n); 00181 00183 typedef struct { 00184 bool affect_alpha; 00185 } LayerModes; 00186 00189 static const LayerModes layer_modes[]; 00190 00191 bool loadImageProperties(QDataStream& xcf_io, XCFImage& image); 00192 bool loadProperty(QDataStream& xcf_io, PropType& type, QByteArray& bytes); 00193 bool loadLayer(QDataStream& xcf_io, XCFImage& xcf_image); 00194 bool loadLayerProperties(QDataStream& xcf_io, Layer& layer); 00195 bool composeTiles(XCFImage& xcf_image); 00196 void setGrayPalette(QImage& image); 00197 void setPalette(XCFImage& xcf_image, QImage& image); 00198 static void assignImageBytes(Layer& layer, uint i, uint j); 00199 bool loadHierarchy(QDataStream& xcf_io, Layer& layer); 00200 bool loadLevel(QDataStream& xcf_io, Layer& layer, qint32 bpp); 00201 static void assignMaskBytes(Layer& layer, uint i, uint j); 00202 bool loadMask(QDataStream& xcf_io, Layer& layer); 00203 bool loadChannelProperties(QDataStream& xcf_io, Layer& layer); 00204 bool initializeImage(XCFImage& xcf_image); 00205 bool loadTileRLE(QDataStream& xcf_io, uchar* tile, int size, 00206 int data_length, qint32 bpp); 00207 00208 static void copyLayerToImage(XCFImage& xcf_image); 00209 static void copyRGBToRGB(Layer& layer, uint i, uint j, int k, int l, 00210 QImage& image, int m, int n); 00211 static void copyGrayToGray(Layer& layer, uint i, uint j, int k, int l, 00212 QImage& image, int m, int n); 00213 static void copyGrayToRGB(Layer& layer, uint i, uint j, int k, int l, 00214 QImage& image, int m, int n); 00215 static void copyGrayAToRGB(Layer& layer, uint i, uint j, int k, int l, 00216 QImage& image, int m, int n); 00217 static void copyIndexedToIndexed(Layer& layer, uint i, uint j, int k, int l, 00218 QImage& image, int m, int n); 00219 static void copyIndexedAToIndexed(Layer& layer, uint i, uint j, int k, int l, 00220 QImage& image, int m, int n); 00221 static void copyIndexedAToRGB(Layer& layer, uint i, uint j, int k, int l, 00222 QImage& image, int m, int n); 00223 00224 static void mergeLayerIntoImage(XCFImage& xcf_image); 00225 static void mergeRGBToRGB(Layer& layer, uint i, uint j, int k, int l, 00226 QImage& image, int m, int n); 00227 static void mergeGrayToGray(Layer& layer, uint i, uint j, int k, int l, 00228 QImage& image, int m, int n); 00229 static void mergeGrayAToGray(Layer& layer, uint i, uint j, int k, int l, 00230 QImage& image, int m, int n); 00231 static void mergeGrayToRGB(Layer& layer, uint i, uint j, int k, int l, 00232 QImage& image, int m, int n); 00233 static void mergeGrayAToRGB(Layer& layer, uint i, uint j, int k, int l, 00234 QImage& image, int m, int n); 00235 static void mergeIndexedToIndexed(Layer& layer, uint i, uint j, int k, int l, 00236 QImage& image, int m, int n); 00237 static void mergeIndexedAToIndexed(Layer& layer, uint i, uint j, int k, int l, 00238 QImage& image, int m, int n); 00239 static void mergeIndexedAToRGB(Layer& layer, uint i, uint j, int k, int l, 00240 QImage& image, int m, int n); 00241 00242 static void initializeRandomTable(); 00243 static void dissolveRGBPixels(QImage& image, int x, int y); 00244 static void dissolveAlphaPixels(QImage& image, int x, int y); 00245 }; 00246 00247 #endif
KDE 4.6 API Reference