Diffstat (limited to 'noncore/graphics/opie-eye/slave/bmp_slave.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/opie-eye/slave/bmp_slave.cpp | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/noncore/graphics/opie-eye/slave/bmp_slave.cpp b/noncore/graphics/opie-eye/slave/bmp_slave.cpp index 2fa825f..0efadac 100644 --- a/noncore/graphics/opie-eye/slave/bmp_slave.cpp +++ b/noncore/graphics/opie-eye/slave/bmp_slave.cpp | |||
@@ -1,175 +1,173 @@ | |||
1 | #include "bmp_slave.h" | 1 | #include "bmp_slave.h" |
2 | 2 | ||
3 | #include "thumbnailtool.h" | 3 | #include "thumbnailtool.h" |
4 | 4 | ||
5 | #include <qimage.h> | 5 | #include <qimage.h> |
6 | #include <qobject.h> | 6 | #include <qobject.h> |
7 | #include <qfile.h> | 7 | #include <qfile.h> |
8 | #include <qpixmap.h> | 8 | #include <qpixmap.h> |
9 | #include <qstring.h> | 9 | #include <qstring.h> |
10 | 10 | ||
11 | PHUNK_VIEW_INTERFACE( "Bmp", BmpSlave ); | 11 | PHUNK_VIEW_INTERFACE( "Bmp", BmpSlave ); |
12 | namespace { | 12 | namespace { |
13 | 13 | ||
14 | struct pBmpHeader { | 14 | struct pBmpHeader { |
15 | // file header of bmp | 15 | // file header of bmp |
16 | char type[2]; // must be "BM" otherwise it is no bmp | 16 | char type[2]; // must be "BM" otherwise it is no bmp |
17 | Q_INT32 hSize; | 17 | Q_INT32 hSize; |
18 | Q_INT32 reserved1,reserved2; | 18 | Q_INT32 reserved1,reserved2; |
19 | 19 | ||
20 | Q_INT16 Planes; | 20 | Q_INT16 Planes; |
21 | Q_INT16 BitCount; | 21 | Q_INT16 BitCount; |
22 | Q_INT32 Size; | 22 | Q_INT32 Size; |
23 | Q_INT32 Width; | 23 | Q_INT32 Width; |
24 | Q_INT32 Height; | 24 | Q_INT32 Height; |
25 | Q_INT32 Compression; | 25 | Q_INT32 Compression; |
26 | Q_INT32 SizeImage; | 26 | Q_INT32 SizeImage; |
27 | Q_INT32 XPerMeter; | 27 | Q_INT32 XPerMeter; |
28 | Q_INT32 YPerMeter; | 28 | Q_INT32 YPerMeter; |
29 | Q_INT32 ClrUsed; | 29 | Q_INT32 ClrUsed; |
30 | Q_INT32 ClrImportant; | 30 | Q_INT32 ClrImportant; |
31 | }; | 31 | }; |
32 | 32 | ||
33 | class BmpHeader { | 33 | class BmpHeader { |
34 | protected: | 34 | protected: |
35 | void read_data(); | 35 | void read_data(); |
36 | QString _name; | 36 | QString _name; |
37 | QFile _inputfile; | 37 | QFile _inputfile; |
38 | pBmpHeader m_Header; | 38 | pBmpHeader m_Header; |
39 | 39 | ||
40 | static const int OLD = 12; | 40 | static const int OLD = 12; |
41 | static const int WIN = 40; | 41 | static const int WIN = 40; |
42 | static const int OS2 = 64; | 42 | static const int OS2 = 64; |
43 | static const int RGB = 0; | 43 | static const int RGB = 0; |
44 | static const int RLE8 = 1; | 44 | static const int RLE8 = 1; |
45 | static const int RLE4 = 2; | 45 | static const int RLE4 = 2; |
46 | 46 | ||
47 | public: | 47 | public: |
48 | BmpHeader(const QString&fname); | 48 | BmpHeader(const QString&fname); |
49 | virtual ~BmpHeader(); | 49 | virtual ~BmpHeader(); |
50 | bool isBmp()const{return qstrncmp(m_Header.type,"BM",2)==0;} | 50 | bool isBmp()const{return qstrncmp(m_Header.type,"BM",2)==0;} |
51 | bool isCompressed()const{return m_Header.Compression != 0;} | 51 | bool isCompressed()const{return m_Header.Compression != 0;} |
52 | QSize imageSize(){return QSize(m_Header.Width,m_Header.Height);} | 52 | QSize imageSize(){return QSize(m_Header.Width,m_Header.Height);} |
53 | QString imageCompression()const; | 53 | QString imageCompression()const; |
54 | int bitsPixel()const{return m_Header.BitCount;} | 54 | int bitsPixel()const{return m_Header.BitCount;} |
55 | int Size()const{return m_Header.hSize;} | 55 | int Size()const{return m_Header.hSize;} |
56 | int compressedSize()const{return m_Header.SizeImage;} | 56 | int compressedSize()const{return m_Header.SizeImage;} |
57 | int ColorsUsed()const{return m_Header.ClrUsed;} | 57 | int ColorsUsed()const{return m_Header.ClrUsed;} |
58 | int XPix()const{return m_Header.XPerMeter;} | 58 | int XPix()const{return m_Header.XPerMeter;} |
59 | int YPix()const{return m_Header.YPerMeter;} | 59 | int YPix()const{return m_Header.YPerMeter;} |
60 | }; | 60 | }; |
61 | 61 | ||
62 | QString BmpHeader::imageCompression()const | 62 | QString BmpHeader::imageCompression()const |
63 | { | 63 | { |
64 | switch (m_Header.Compression) { | 64 | switch (m_Header.Compression) { |
65 | case RLE8: | 65 | case RLE8: |
66 | return "8Bit RLE Encoding"; | 66 | return "8Bit RLE Encoding"; |
67 | break; | 67 | break; |
68 | case RLE4: | 68 | case RLE4: |
69 | return "4Bit RLE Encoding"; | 69 | return "4Bit RLE Encoding"; |
70 | break; | 70 | break; |
71 | case RGB: | 71 | case RGB: |
72 | default: | 72 | default: |
73 | return "No encoding"; | 73 | return "No encoding"; |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | BmpHeader::BmpHeader(const QString&fname) | 77 | BmpHeader::BmpHeader(const QString&fname) |
78 | : _name(fname),_inputfile(_name) | 78 | : _name(fname),_inputfile(_name) |
79 | { | 79 | { |
80 | read_data(); | 80 | read_data(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void BmpHeader::read_data() { | 83 | void BmpHeader::read_data() { |
84 | memset(&m_Header,0,sizeof(pBmpHeader)); | 84 | memset(&m_Header,0,sizeof(pBmpHeader)); |
85 | _inputfile.open(IO_Raw|IO_ReadOnly); | 85 | if (!_inputfile.open(IO_Raw|IO_ReadOnly)) |
86 | if (!_inputfile.isOpen()) { | ||
87 | return; | 86 | return; |
88 | } | ||
89 | QDataStream s(&_inputfile); | 87 | QDataStream s(&_inputfile); |
90 | s.setByteOrder( QDataStream::LittleEndian ); | 88 | s.setByteOrder( QDataStream::LittleEndian ); |
91 | s.readRawBytes(m_Header.type,2); | 89 | s.readRawBytes(m_Header.type,2); |
92 | if (!isBmp()) { | 90 | if (!isBmp()) { |
93 | _inputfile.close(); | 91 | _inputfile.close(); |
94 | return; | 92 | return; |
95 | } | 93 | } |
96 | s >> m_Header.hSize; | 94 | s >> m_Header.hSize; |
97 | s >> m_Header.reserved1 >> m_Header.reserved2; | 95 | s >> m_Header.reserved1 >> m_Header.reserved2; |
98 | s >> m_Header.Size; | 96 | s >> m_Header.Size; |
99 | if ( m_Header.Size == BmpHeader::WIN || m_Header.Size == BmpHeader::OS2 ) { | 97 | if ( m_Header.Size == BmpHeader::WIN || m_Header.Size == BmpHeader::OS2 ) { |
100 | s >> m_Header.Width >> m_Header.Height >> m_Header.Planes >> m_Header.BitCount; | 98 | s >> m_Header.Width >> m_Header.Height >> m_Header.Planes >> m_Header.BitCount; |
101 | s >> m_Header.Compression >> m_Header.SizeImage; | 99 | s >> m_Header.Compression >> m_Header.SizeImage; |
102 | s >> m_Header.XPerMeter >> m_Header.YPerMeter; | 100 | s >> m_Header.XPerMeter >> m_Header.YPerMeter; |
103 | s >> m_Header.ClrUsed >> m_Header.ClrImportant; | 101 | s >> m_Header.ClrUsed >> m_Header.ClrImportant; |
104 | } else { | 102 | } else { |
105 | Q_INT16 w, h; | 103 | Q_INT16 w, h; |
106 | s >> w >> h >> m_Header.Planes >> m_Header.BitCount; | 104 | s >> w >> h >> m_Header.Planes >> m_Header.BitCount; |
107 | m_Header.Width = w; | 105 | m_Header.Width = w; |
108 | m_Header.Height = h; | 106 | m_Header.Height = h; |
109 | m_Header.Compression = BmpHeader::RGB; | 107 | m_Header.Compression = BmpHeader::RGB; |
110 | m_Header.SizeImage = 0; | 108 | m_Header.SizeImage = 0; |
111 | m_Header.XPerMeter = m_Header.YPerMeter = 0; | 109 | m_Header.XPerMeter = m_Header.YPerMeter = 0; |
112 | m_Header.ClrUsed = m_Header.ClrImportant = 0; | 110 | m_Header.ClrUsed = m_Header.ClrImportant = 0; |
113 | } | 111 | } |
114 | _inputfile.close(); | 112 | _inputfile.close(); |
115 | } | 113 | } |
116 | 114 | ||
117 | BmpHeader::~BmpHeader() { | 115 | BmpHeader::~BmpHeader() { |
118 | } | 116 | } |
119 | } | 117 | } |
120 | 118 | ||
121 | 119 | ||
122 | BmpSlave::BmpSlave() | 120 | BmpSlave::BmpSlave() |
123 | : SlaveInterface(QStringList("bmp")) | 121 | : SlaveInterface(QStringList("bmp")) |
124 | {} | 122 | {} |
125 | 123 | ||
126 | BmpSlave::~BmpSlave() { | 124 | BmpSlave::~BmpSlave() { |
127 | 125 | ||
128 | } | 126 | } |
129 | 127 | ||
130 | QString BmpSlave::iconViewName(const QString& str) { | 128 | QString BmpSlave::iconViewName(const QString& str) { |
131 | QString st; | 129 | QString st; |
132 | BmpHeader bh(str); | 130 | BmpHeader bh(str); |
133 | if (!bh.isBmp()) { | 131 | if (!bh.isBmp()) { |
134 | st.append("No bmp file"); | 132 | st.append("No bmp file"); |
135 | return st; | 133 | return st; |
136 | } | 134 | } |
137 | QSize isize = bh.imageSize(); | 135 | QSize isize = bh.imageSize(); |
138 | st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height()); | 136 | st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height()); |
139 | st+=QObject::tr("Size: %1\n").arg(bh.Size()); | 137 | st+=QObject::tr("Size: %1\n").arg(bh.Size()); |
140 | st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel()); | 138 | st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel()); |
141 | return st; | 139 | return st; |
142 | } | 140 | } |
143 | 141 | ||
144 | QString BmpSlave::fullImageInfo( const QString& str) { | 142 | QString BmpSlave::fullImageInfo( const QString& str) { |
145 | QString st = "<qt>"; | 143 | QString st = "<qt>"; |
146 | BmpHeader bh(str); | 144 | BmpHeader bh(str); |
147 | if (!bh.isBmp()) { | 145 | if (!bh.isBmp()) { |
148 | st.append("No bmp file"); | 146 | st.append("No bmp file"); |
149 | st.append( "</qt>" ); | 147 | st.append( "</qt>" ); |
150 | return st; | 148 | return st; |
151 | } | 149 | } |
152 | QSize isize = bh.imageSize(); | 150 | QSize isize = bh.imageSize(); |
153 | st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height()); | 151 | st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height()); |
154 | st+=QObject::tr("Size: %1\n").arg(bh.Size()); | 152 | st+=QObject::tr("Size: %1\n").arg(bh.Size()); |
155 | st+=QObject::tr("Compression: %1\n").arg(bh.imageCompression()); | 153 | st+=QObject::tr("Compression: %1\n").arg(bh.imageCompression()); |
156 | if (bh.isCompressed()) { | 154 | if (bh.isCompressed()) { |
157 | st+=QObject::tr("Compressed size: %1").arg(bh.compressedSize()); | 155 | st+=QObject::tr("Compressed size: %1").arg(bh.compressedSize()); |
158 | } | 156 | } |
159 | st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel()); | 157 | st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel()); |
160 | st+=QObject::tr("used colors: %1\n").arg(bh.ColorsUsed()); | 158 | st+=QObject::tr("used colors: %1\n").arg(bh.ColorsUsed()); |
161 | st+=QObject::tr("Resolution: %1 x %2\n").arg(bh.XPix()).arg(bh.YPix()); | 159 | st+=QObject::tr("Resolution: %1 x %2\n").arg(bh.XPix()).arg(bh.YPix()); |
162 | st.append( "</qt>" ); | 160 | st.append( "</qt>" ); |
163 | return st; | 161 | return st; |
164 | } | 162 | } |
165 | 163 | ||
166 | QPixmap BmpSlave::pixmap(const QString& path, int width, int height ) { | 164 | QPixmap BmpSlave::pixmap(const QString& path, int width, int height ) { |
167 | static QImage img; | 165 | static QImage img; |
168 | img.load( path ); | 166 | img.load( path ); |
169 | if ( img.isNull() ) { | 167 | if ( img.isNull() ) { |
170 | QPixmap pix; | 168 | QPixmap pix; |
171 | return pix; | 169 | return pix; |
172 | } | 170 | } |
173 | 171 | ||
174 | return ThumbNailTool::scaleImage( img, width,height ); | 172 | return ThumbNailTool::scaleImage( img, width,height ); |
175 | } | 173 | } |