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.
9
10#ifndef KIMG_RGB_H
11#define KIMG_RGB_H
12
13
14#include <QtGui/QImageIOPlugin>
15#include <QtCore/QMap>
16#include <QtCore/QVector>
17
18
19class RGBHandler : public QImageIOHandler
20{
21public:
22 RGBHandler();
23
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);
29};
30
31
32class RLEData : public QVector<uchar> {
33public:
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]);
38 }
39 bool operator<(const RLEData&) const;
40 void write(QDataStream& s);
41 uint offset() const { return _offset; }
42
43private:
44 uint _offset;
45};
46
47
48class RLEMap : public QMap<RLEData, uint> {
49public:
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; }
54
55private:
56 uint _counter;
57 uint _offset;
58};
59
60
61class SGIImage {
62public:
63 SGIImage(QIODevice *device);
64 ~SGIImage();
65
66 bool readImage(QImage&);
67 bool writeImage(const QImage&);
68
69private:
70 enum { NORMAL, DITHERED, SCREEN, COLORMAP }; // colormap
71 QIODevice *_dev;
72 QDataStream _stream;
73
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;
84
85 quint32 *_starttab;
86 quint32 *_lengthtab;
87 QByteArray _data;
88 QByteArray::Iterator _pos;
89 RLEMap _rlemap;
90 QVector<const RLEData*> _rlevector;
91 uint _numrows;
92
93 bool readData(QImage&);
94 bool getRow(uchar *dest);
95
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);
102};
103
104#endif
105
106