summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cpixmap.cpp
diff options
context:
space:
mode:
authorGünther Neuwirth <e0626638@student.tuwien.ac.at>2009-04-29 04:10:10 +0200
committerGünther Neuwirth <e0626638@student.tuwien.ac.at>2009-04-29 04:10:10 +0200
commitf2872bfd97f9297b1446f1fd6595a32dc509f301 (patch)
treebaf9aeb625588380fd33335613840460d3cf1bc1 /ue2/imgsynth2/cpixmap.cpp
parentd8e12cc6094e22ecb4a94718b4b0a0ef5284fed3 (diff)
downloadooprog-f2872bfd97f9297b1446f1fd6595a32dc509f301.tar.gz
ooprog-f2872bfd97f9297b1446f1fd6595a32dc509f301.tar.bz2
ooprog-f2872bfd97f9297b1446f1fd6595a32dc509f301.zip
Adding cpixmap.cpp, cpixmap.h and test fieles
Diffstat (limited to 'ue2/imgsynth2/cpixmap.cpp')
-rw-r--r--ue2/imgsynth2/cpixmap.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/ue2/imgsynth2/cpixmap.cpp b/ue2/imgsynth2/cpixmap.cpp
new file mode 100644
index 0000000..ff5a83c
--- /dev/null
+++ b/ue2/imgsynth2/cpixmap.cpp
@@ -0,0 +1,163 @@
1/**
2 * @module CPixMap
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Implementation of CFile handling Windows Bitmaps.
5 * @date 27.04.2009
6 */
7
8#include <boost/lexical_cast.hpp>
9#include <boost/numeric/conversion/cast.hpp>
10
11#ifdef DEBUG
12# include <iostream>
13#endif
14# include <string>
15# include <map>
16#include "cpixmap.h"
17#include "cpixelformat_indexed8.h"
18
19using namespace std;
20
21CPixMap::CPixMap()
22{
23 m_types.insert("XPM");
24
25 /* add our handlers */
26 m_handlers.insert(new CPixelFormat_Indexed8(this));
27
28}
29
30
31
32/*----------------------------------------------------------------------------*/
33
34void CPixMap::read(std::ifstream& in)
35{
36
37 string str;
38
39 /* parse the values section */
40 getline( in, str, '"');
41 getline( in, str, '"');
42 stringstream istr (str );
43
44 istr >> m_fileheader.xpmWidth ;
45 istr >> m_fileheader.xpmHeight ;
46 istr >> m_fileheader.nColor ;
47 istr >> m_fileheader.nChar ;
48
49 /* if there are optional values */
50 if (in.good())
51 {
52 istr >> m_fileheader.xHotspot;
53 istr >> m_fileheader.yHotspot;
54 }
55 else
56 {
57 m_fileheader.xHotspot = NULL;
58 m_fileheader.yHotspot = NULL;
59 }
60
61
62 /* parse the colors section */
63 getline( in, str, '"');
64 for (unsigned int i = 0; i < m_fileheader.nColor; i++ )
65 {
66 getline( in, str, '"' );
67 stringstream istr2 (str );
68 char character;
69 string mode, colors;
70
71 istr2 >> character;
72 istr2 >> mode;
73 istr2 >> colors;
74 m_fileheader.xpmColors[character][mode] = colors;
75
76 getline( in, str, '"' );
77 }
78/* colors.replace(0,1,"0x");
79 colors.insert(4, " 0x");
80 colors.insert(9," 0x");
81
82 stringstream istr3 (colors, stringstream::out|stringstream::in );
83 istr3 >>hex>> r;
84 istr3 >>hex>> g;
85 istr3 >>hex>> b;
86 //?????????????ß
87 cout<<c1<<" "<<c2<<" "<< r<<" "<< g<<" "<< b<<endl;
88 m_fileheader.xpmColors[c1]['r'] = static_cast<uint8_t>(r);
89 m_fileheader.xpmColors[c1]['g'] = static_cast<uint8_t>(g);
90 m_fileheader.xpmColors[c1]['b'] = static_cast<uint8_t>(b);*/
91
92
93
94 /* read pixel data using separate class */
95 if (getPixelDataSize() > 0)
96 {
97 if (m_pixeldata != NULL)
98 delete[] m_pixeldata;
99 m_pixeldata = new uint8_t[getPixelDataSize()];
100
101 /* parse the pixel data */
102 for (unsigned int y = 0; y < getHeight(); y++ )
103 {
104 for (unsigned int x = 0; x < getWidth(); x++ )
105 m_pixeldata[y * getWidth() + x] = static_cast<uint8_t>(in.get());
106
107 getline( in, str);
108 if ( y != ( getHeight() - 1 ))
109 in.get();
110
111 }
112 }
113
114 /* debug*/
115 CPixMap::dump (cout);
116
117
118}
119
120/*----------------------------------------------------------------------------*/
121
122void CPixMap::write(std::ofstream& out)
123{
124 dump(out);
125}
126
127
128/*----------------------------------------------------------------------------*/
129
130#ifdef DEBUG
131void CPixMap::dump(std::ostream& out)
132{
133
134 /* values*/
135 out
136 << "XPM Header:" << endl
137 << ", xpmWidth=" << m_fileheader.xpmWidth<< endl
138 << ", xpmHeight=" << m_fileheader.xpmHeight<< endl
139 << ", nColor=" << m_fileheader.nColor<< endl
140 << ", nChar=" << m_fileheader.nChar<< endl
141 << endl;
142
143 /* colors*/
144 map<unsigned const char, map<std::string, std::string > >::iterator it1;
145 map<std::string, std::string >::iterator it2;
146 for ( it1=m_fileheader.xpmColors.begin() ; it1 != m_fileheader.xpmColors.end(); it1++ )
147 {
148 out << (*it1).first ;
149 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ )
150 out << (*it2).first <<" > "<< (*it2).second<<endl;
151 }
152
153 /* pixeldata */
154 for (unsigned int y = 0; y < getHeight(); y++ ){
155 for (unsigned int x = 0; x < getWidth(); x++ )
156 out << m_pixeldata[y * getWidth() + x];
157 out << endl;
158 }
159
160}
161#endif
162
163/* vim: set et sw=2 ts=2: */