some more win32'fication to fix non-ascii filename handling
[kdelibs.git] / kimgio / rgb.h
blob3fa5d687cdced928d8780d79dcc0190d8654475b
1 // kimgio module for SGI images
2 //
3 // Copyright (C) 2004 Melchior FRANZ <mfranz@kde.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the Lesser GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 #ifndef KIMG_RGB_H
11 #define KIMG_RGB_H
14 #include <QtGui/QImageIOPlugin>
15 #include <QtCore/QMap>
16 #include <QtCore/QVector>
19 class RGBHandler : public QImageIOHandler
21 public:
22 RGBHandler();
24 bool canRead() const;
25 bool read(QImage *image);
26 bool write(const QImage &image);
27 QByteArray name() const;
28 static bool canRead(QIODevice *device);
32 class RLEData : public QVector<uchar> {
33 public:
34 RLEData() {}
35 RLEData(const uchar *d, uint l, uint o) : _offset(o) {
36 for (uint i = 0; i < l; i++)
37 append(d[i]);
39 bool operator<(const RLEData&) const;
40 void write(QDataStream& s);
41 uint offset() const { return _offset; }
43 private:
44 uint _offset;
48 class RLEMap : public QMap<RLEData, uint> {
49 public:
50 RLEMap() : _counter(0), _offset(0) {}
51 uint insert(const uchar *d, uint l);
52 QVector<const RLEData*> vector();
53 void setBaseOffset(uint o) { _offset = o; }
55 private:
56 uint _counter;
57 uint _offset;
61 class SGIImage {
62 public:
63 SGIImage(QIODevice *device);
64 ~SGIImage();
66 bool readImage(QImage&);
67 bool writeImage(const QImage&);
69 private:
70 enum { NORMAL, DITHERED, SCREEN, COLORMAP }; // colormap
71 QIODevice *_dev;
72 QDataStream _stream;
74 quint8 _rle;
75 quint8 _bpc;
76 quint16 _dim;
77 quint16 _xsize;
78 quint16 _ysize;
79 quint16 _zsize;
80 quint32 _pixmin;
81 quint32 _pixmax;
82 char _imagename[80];
83 quint32 _colormap;
85 quint32 *_starttab;
86 quint32 *_lengthtab;
87 QByteArray _data;
88 QByteArray::Iterator _pos;
89 RLEMap _rlemap;
90 QVector<const RLEData*> _rlevector;
91 uint _numrows;
93 bool readData(QImage&);
94 bool getRow(uchar *dest);
96 void writeHeader();
97 void writeRle();
98 void writeVerbatim(const QImage&);
99 bool scanData(const QImage&);
100 uint compact(uchar *, uchar *);
101 uchar intensity(uchar);
104 #endif