KImgIO
rgb.h
Go to the documentation of this file.00001 // kimgio module for SGI images 00002 // 00003 // Copyright (C) 2004 Melchior FRANZ <mfranz@kde.org> 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the Lesser GNU General Public License as 00007 // published by the Free Software Foundation; either version 2 of the 00008 // License, or (at your option) any later version. 00009 00010 #ifndef KIMG_RGB_H 00011 #define KIMG_RGB_H 00012 00013 00014 #include <QtGui/QImageIOPlugin> 00015 #include <QtCore/QMap> 00016 #include <QtCore/QVector> 00017 00018 00019 class RGBHandler : public QImageIOHandler 00020 { 00021 public: 00022 RGBHandler(); 00023 00024 bool canRead() const; 00025 bool read(QImage *image); 00026 bool write(const QImage &image); 00027 QByteArray name() const; 00028 static bool canRead(QIODevice *device); 00029 }; 00030 00031 00032 class RLEData : public QVector<uchar> { 00033 public: 00034 RLEData() {} 00035 RLEData(const uchar *d, uint l, uint o) : _offset(o) { 00036 for (uint i = 0; i < l; i++) 00037 append(d[i]); 00038 } 00039 bool operator<(const RLEData&) const; 00040 void write(QDataStream& s); 00041 uint offset() const { return _offset; } 00042 00043 private: 00044 uint _offset; 00045 }; 00046 00047 00048 class RLEMap : public QMap<RLEData, uint> { 00049 public: 00050 RLEMap() : _counter(0), _offset(0) {} 00051 uint insert(const uchar *d, uint l); 00052 QVector<const RLEData*> vector(); 00053 void setBaseOffset(uint o) { _offset = o; } 00054 00055 private: 00056 uint _counter; 00057 uint _offset; 00058 }; 00059 00060 00061 class SGIImage { 00062 public: 00063 SGIImage(QIODevice *device); 00064 ~SGIImage(); 00065 00066 bool readImage(QImage&); 00067 bool writeImage(const QImage&); 00068 00069 private: 00070 enum { NORMAL, DITHERED, SCREEN, COLORMAP }; // colormap 00071 QIODevice *_dev; 00072 QDataStream _stream; 00073 00074 quint8 _rle; 00075 quint8 _bpc; 00076 quint16 _dim; 00077 quint16 _xsize; 00078 quint16 _ysize; 00079 quint16 _zsize; 00080 quint32 _pixmin; 00081 quint32 _pixmax; 00082 char _imagename[80]; 00083 quint32 _colormap; 00084 00085 quint32 *_starttab; 00086 quint32 *_lengthtab; 00087 QByteArray _data; 00088 QByteArray::Iterator _pos; 00089 RLEMap _rlemap; 00090 QVector<const RLEData*> _rlevector; 00091 uint _numrows; 00092 00093 bool readData(QImage&); 00094 bool getRow(uchar *dest); 00095 00096 void writeHeader(); 00097 void writeRle(); 00098 void writeVerbatim(const QImage&); 00099 bool scanData(const QImage&); 00100 uint compact(uchar *, uchar *); 00101 uchar intensity(uchar); 00102 }; 00103 00104 #endif 00105