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