xcf.h
#ifndef XCF_H
#define XCF_H
/*
* qxcfi.cpp: A Qt 3 plug-in for reading GIMP XCF image files
* Copyright (C) 2001 lignum Computing, Inc. <allen@lignumcomputing.com>
* Copyright (C) 2004 Melchior FRANZ <mfranz@kde.org>
*
* This plug-in is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <qimage.h>
#include <qiodevice.h>
#include <qvaluestack.h>
#include <qvaluevector.h>
#include "gimp.h"
extern "C" {
void kimgio_xcf_read(QImageIO *);
void kimgio_xcf_write(QImageIO *);
}
const float INCHESPERMETER = (100.0 / 2.54);
typedef QValueVector<QValueVector<QImage> > Tiles;
class XCFImageFormat {
public:
XCFImageFormat();
void readXCF(QImageIO* image_io);
private:
class Layer {
public:
Q_UINT32 width;
Q_UINT32 height;
Q_INT32 type;
char* name;
Q_UINT32 hierarchy_offset;
Q_UINT32 mask_offset;
uint nrows;
uint ncols;
Tiles image_tiles;
Tiles alpha_tiles;
Tiles mask_tiles;
struct {
Q_UINT32 opacity;
Q_UINT32 visible;
Q_UINT32 show_masked;
uchar red, green, blue;
Q_UINT32 tattoo;
} mask_channel;
bool active;
Q_UINT32 opacity;
Q_UINT32 visible;
Q_UINT32 linked;
Q_UINT32 preserve_transparency;
Q_UINT32 apply_mask;
Q_UINT32 edit_mask;
Q_UINT32 show_mask;
Q_INT32 x_offset;
Q_INT32 y_offset;
Q_UINT32 mode;
Q_UINT32 tattoo;
uchar tile[TILE_WIDTH * TILE_HEIGHT * sizeof(QRgb)];
void (*assignBytes)(Layer& layer, uint i, uint j);
Layer(void) : name(0) {}
~Layer(void) { delete[] name; }
};
class XCFImage {
public:
Q_UINT32 width;
Q_UINT32 height;
Q_INT32 type;
Q_UINT8 compression;
float x_resolution;
float y_resolution;
Q_INT32 tattoo;
Q_UINT32 unit;
Q_INT32 num_colors;
QValueVector<QRgb> palette;
int num_layers;
Layer layer;
bool initialized;
QImage image;
XCFImage(void) : initialized(false) {}
};
static int random_table[RANDOM_TABLE_SIZE];
//static int add_lut[256][256]; - this is so lame waste of 256k of memory
static int add_lut( int, int );
typedef void (*PixelCopyOperation)(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
typedef void (*PixelMergeOperation)(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
typedef struct {
bool affect_alpha;
} LayerModes;
static const LayerModes layer_modes[];
bool loadImageProperties(QDataStream& xcf_io, XCFImage& image);
bool loadProperty(QDataStream& xcf_io, PropType& type, QByteArray& bytes);
bool loadLayer(QDataStream& xcf_io, XCFImage& xcf_image);
bool loadLayerProperties(QDataStream& xcf_io, Layer& layer);
bool composeTiles(XCFImage& xcf_image);
void setGrayPalette(QImage& image);
void setPalette(XCFImage& xcf_image, QImage& image);
static void assignImageBytes(Layer& layer, uint i, uint j);
bool loadHierarchy(QDataStream& xcf_io, Layer& layer);
bool loadLevel(QDataStream& xcf_io, Layer& layer, Q_INT32 bpp);
static void assignMaskBytes(Layer& layer, uint i, uint j);
bool loadMask(QDataStream& xcf_io, Layer& layer);
bool loadChannelProperties(QDataStream& xcf_io, Layer& layer);
bool initializeImage(XCFImage& xcf_image);
bool loadTileRLE(QDataStream& xcf_io, uchar* tile, int size,
int data_length, Q_INT32 bpp);
static void copyLayerToImage(XCFImage& xcf_image);
static void copyRGBToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void copyGrayToGray(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void copyGrayToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void copyGrayAToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void copyIndexedToIndexed(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void copyIndexedAToIndexed(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void copyIndexedAToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeLayerIntoImage(XCFImage& xcf_image);
static void mergeRGBToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeGrayToGray(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeGrayAToGray(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeGrayToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeGrayAToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeIndexedToIndexed(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeIndexedAToIndexed(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void mergeIndexedAToRGB(Layer& layer, uint i, uint j, int k, int l,
QImage& image, int m, int n);
static void dissolveRGBPixels(QImage& image, int x, int y);
static void dissolveAlphaPixels(QImage& image, int x, int y);
};
#endif

KDE Home | KDE Accessibility Home | Description of Access Keys