author | alwin <alwin> | 2004-04-15 14:04:01 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-15 14:04:01 (UTC) |
commit | b07457bba11c6bc13d35c31c15353350a16ad3a4 (patch) (unidiff) | |
tree | c8d36a803eae123e75d45a904a5bfe5a93c8494b | |
parent | 41203805fb5e70df84cc2894dbd6e030c6355041 (diff) | |
download | opie-b07457bba11c6bc13d35c31c15353350a16ad3a4.zip opie-b07457bba11c6bc13d35c31c15353350a16ad3a4.tar.gz opie-b07457bba11c6bc13d35c31c15353350a16ad3a4.tar.bz2 |
added bmp file support
-rw-r--r-- | noncore/graphics/opie-eye/slave/bmp_slave.cpp | 175 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/slave/bmp_slave.h | 22 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/slave/slave.pro | 6 |
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 | |||
11 | PHUNK_VIEW_INTERFACE( "Bmp", BmpSlave ); | ||
12 | namespace { | ||
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 | |||
122 | BmpSlave::BmpSlave() | ||
123 | : SlaveInterface(QStringList("bmp")) | ||
124 | {} | ||
125 | |||
126 | BmpSlave::~BmpSlave() { | ||
127 | |||
128 | } | ||
129 | |||
130 | QString 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 | |||
144 | QString 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 | |||
166 | QPixmap 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 | |||
11 | class BmpSlave : public SlaveInterface { | ||
12 | public: | ||
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 | |||
@@ -2,16 +2,18 @@ CONFIG = qt | |||
2 | TEMPLATE = app | 2 | TEMPLATE = app |
3 | TARGET = opie-eye_slave | 3 | TARGET = opie-eye_slave |
4 | DESTDIR = $(OPIEDIR)/bin | 4 | DESTDIR = $(OPIEDIR)/bin |
5 | 5 | ||
6 | HEADERS = gif_slave.h slaveiface.h slavereciever.h \ | 6 | HEADERS = 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 | ||
9 | SOURCES = main.cpp gif_slave.cpp slavereciever.cpp \ | 10 | SOURCES = 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 | ||
13 | INCLUDEPATH += $(OPIEDIR)/include ../ | 15 | INCLUDEPATH += $(OPIEDIR)/include ../ |
14 | DEPENDSPATH += $(OPIEDIR)/include | 16 | DEPENDSPATH += $(OPIEDIR)/include |
15 | 17 | ||
16 | LIBS += -lqpe -lopiecore2 | 18 | LIBS += -lqpe -lopiecore2 |
17 | 19 | ||