summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGünther Neuwirth <e0626638@student.tuwien.ac.at>2009-05-01 14:58:58 +0200
committerGünther Neuwirth <e0626638@student.tuwien.ac.at>2009-05-01 14:58:58 +0200
commitb0442de485dcb6328366d9b05a62af345e5fa39f (patch)
tree594628ba235e526ed54554cf72794b71624f4591
parent6b89034cd15a2ca270591aec89b8b13c868b86fc (diff)
downloadooprog-b0442de485dcb6328366d9b05a62af345e5fa39f.tar.gz
ooprog-b0442de485dcb6328366d9b05a62af345e5fa39f.tar.bz2
ooprog-b0442de485dcb6328366d9b05a62af345e5fa39f.zip
Adding cpixelformat_indexd8.h and .cpp. Adding virtual methode getColorMode to CPixelFormat. Adding color table to CBitmap. Adding implementation of CPixmap
-rw-r--r--ue2/imgsynth2/cbitmap.cpp8
-rw-r--r--ue2/imgsynth2/cbitmap.h5
-rw-r--r--ue2/imgsynth2/cpixelformat.h11
-rw-r--r--ue2/imgsynth2/cpixelformat_bgr24.h15
-rw-r--r--ue2/imgsynth2/cpixelformat_bgr555.h14
-rw-r--r--ue2/imgsynth2/cpixelformat_indexed8.cpp90
-rw-r--r--ue2/imgsynth2/cpixelformat_indexed8.h102
-rw-r--r--ue2/imgsynth2/cpixmap.cpp226
-rw-r--r--ue2/imgsynth2/cpixmap.h62
-rw-r--r--ue2/imgsynth2/cscriptparser.cpp2
-rw-r--r--ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm9
11 files changed, 444 insertions, 100 deletions
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp
index b9cfc62..acee870 100644
--- a/ue2/imgsynth2/cbitmap.cpp
+++ b/ue2/imgsynth2/cbitmap.cpp
@@ -25,6 +25,14 @@ CBitmap::~CBitmap()
25 for (it = m_handlers.begin(); it != m_handlers.end(); it++) 25 for (it = m_handlers.begin(); it != m_handlers.end(); it++)
26 delete *it; 26 delete *it;
27 m_pixelformat = NULL; 27 m_pixelformat = NULL;
28
29 /* delete color table */
30 map<string, map<string, uint32_t* > >::iterator it1;
31 map<string, uint32_t* >::iterator it2;
32 for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ )
33 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ )
34 delete [] (*it2).second;
35
28} 36}
29 37
30/*----------------------------------------------------------------------------*/ 38/*----------------------------------------------------------------------------*/
diff --git a/ue2/imgsynth2/cbitmap.h b/ue2/imgsynth2/cbitmap.h
index f8f8850..f521bcc 100644
--- a/ue2/imgsynth2/cbitmap.h
+++ b/ue2/imgsynth2/cbitmap.h
@@ -9,6 +9,8 @@
9#define CBITMAP_H 9#define CBITMAP_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <map>
13#include <string>
12#include "cfile.h" 14#include "cfile.h"
13 15
14class CPixelFormat; 16class CPixelFormat;
@@ -132,6 +134,9 @@ class CBitmap : public CFile
132 std::set<CPixelFormat *> m_handlers; 134 std::set<CPixelFormat *> m_handlers;
133 /** pointer to CPixelFormat implementation */ 135 /** pointer to CPixelFormat implementation */
134 CPixelFormat *m_pixelformat; 136 CPixelFormat *m_pixelformat;
137 /* color table */
138 std::map<std::string, std::map< std::string, uint32_t* > > xpmColors;
139
135}; 140};
136 141
137#endif 142#endif
diff --git a/ue2/imgsynth2/cpixelformat.h b/ue2/imgsynth2/cpixelformat.h
index 911a141..2300f2f 100644
--- a/ue2/imgsynth2/cpixelformat.h
+++ b/ue2/imgsynth2/cpixelformat.h
@@ -10,6 +10,7 @@
10#define CPIXELFORMAT_H 10#define CPIXELFORMAT_H
11 11
12#include <fstream> 12#include <fstream>
13#include <string>
13#include <stdexcept> 14#include <stdexcept>
14 15
15class CBitmap; 16class CBitmap;
@@ -108,6 +109,16 @@ class CPixelFormat
108 */ 109 */
109 virtual uint32_t getBitCount() = 0; 110 virtual uint32_t getBitCount() = 0;
110 111
112 /**
113 * @method getColorMode
114 * @brief returns the color mode supported by this class
115 * @param -
116 * @return color mode supported by this class
117 * @globalvars none
118 * @exception none
119 * @conditions none
120 */
121 virtual std::string getColorMode() = 0;
111 /* 122 /*
112 * TODO 123 * TODO
113 */ 124 */
diff --git a/ue2/imgsynth2/cpixelformat_bgr24.h b/ue2/imgsynth2/cpixelformat_bgr24.h
index 73f22c1..da1592b 100644
--- a/ue2/imgsynth2/cpixelformat_bgr24.h
+++ b/ue2/imgsynth2/cpixelformat_bgr24.h
@@ -74,7 +74,20 @@ class CPixelFormat_BGR24 : public CPixelFormat
74 { 74 {
75 return 24; 75 return 24;
76 } 76 }
77 77
78 /**
79 * @method getColorMode
80 * @brief returns the color mode supported by this class
81 * @param -
82 * @return color mode supported by this class
83 * @globalvars none
84 * @exception none
85 * @conditions none
86 */
87 std::string getColorMode()
88 {
89 return "c";
90 }
78 /* 91 /*
79 * TODO 92 * TODO
80 */ 93 */
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.h b/ue2/imgsynth2/cpixelformat_bgr555.h
index b04e4be..890b744 100644
--- a/ue2/imgsynth2/cpixelformat_bgr555.h
+++ b/ue2/imgsynth2/cpixelformat_bgr555.h
@@ -85,6 +85,20 @@ class CPixelFormat_BGR555 : public CPixelFormat
85 return 16; 85 return 16;
86 } 86 }
87 87
88 /**
89 * @method getColorMode
90 * @brief returns the color mode supported by this class
91 * @param -
92 * @return color mode supported by this class
93 * @globalvars none
94 * @exception none
95 * @conditions none
96 */
97 std::string getColorMode()
98 {
99 return "c";
100 }
101
88 /* 102 /*
89 * TODO 103 * TODO
90 */ 104 */
diff --git a/ue2/imgsynth2/cpixelformat_indexed8.cpp b/ue2/imgsynth2/cpixelformat_indexed8.cpp
new file mode 100644
index 0000000..c62a1ba
--- /dev/null
+++ b/ue2/imgsynth2/cpixelformat_indexed8.cpp
@@ -0,0 +1,90 @@
1/**
2 * @module CPixelFormat_Indexed8
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps.
5 * @date 18.04.2009
6 */
7
8#include <boost/numeric/conversion/cast.hpp>
9#include "cpixelformat_indexed8.h"
10
11using namespace std;
12
13void CPixelFormat_Indexed8::getPixel(uint32_t *pixel, uint32_t x, uint32_t y)
14{
15 /*
16 * pixel[0] ... red
17 * pixel[1] ... green
18 * pixel[2] ... blue
19 */
20 // if (m_bitmap->getPixelData() == NULL)
21 // throw PixelFormatError("No pixelbuffer allocated.");
22
23 /* calc rowsize - boundary is 32 */
24 /* uint32_t rowsize = 4 * static_cast<uint32_t>(
25 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
26 );*/
27
28 /* if height is positive the y-coordinates are mirrored */
29 /* if (m_bitmap->getInfoHeader().biHeight > 0)
30 y = m_bitmap->getInfoHeader().biHeight - y - 1;
31 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
32
33 /* boundary check */
34 /* if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage)
35 throw PixelFormatError("Pixel position is out of range.");
36
37 /* get pixel */
38/* try
39 {
40 pixel[0] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 2));
41 pixel[1] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 1));
42 pixel[2] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset));
43 }
44 catch(boost::numeric::bad_numeric_cast& ex)
45 {
46 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
47 }*/
48}
49
50void CPixelFormat_Indexed8::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y)
51{
52 /*
53 * pixel[0] ... red
54 * pixel[1] ... green
55 * pixel[2] ... blue
56 */
57/* if (m_bitmap->getPixelData() == NULL)
58 throw PixelFormatError("No pixelbuffer allocated.");
59
60 /* calc rowsize - boundary is 32 */
61 /* uint32_t rowsize = 4 * static_cast<uint32_t>(
62 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
63 );
64
65 /* if height is positive the y-coordinates are mirrored */
66 /* if (m_bitmap->getInfoHeader().biHeight > 0)
67 y = m_bitmap->getInfoHeader().biHeight - y - 1;
68 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
69
70 /* boundary check */
71 /* if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage)
72 throw PixelFormatError("Pixel position is out of range.");
73
74 /* convert color values to correct types */
75 /*uint8_t data[3];
76 try
77 {
78 data[0] = boost::numeric_cast<uint8_t>(pixel[2]);
79 data[1] = boost::numeric_cast<uint8_t>(pixel[1]);
80 data[2] = boost::numeric_cast<uint8_t>(pixel[0]);
81 }
82 catch(boost::numeric::bad_numeric_cast& ex)
83 {
84 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
85 }
86
87 copy(data, data + 3, m_bitmap->getPixelData() + offset);
88*/}
89
90/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cpixelformat_indexed8.h b/ue2/imgsynth2/cpixelformat_indexed8.h
new file mode 100644
index 0000000..ff95840
--- /dev/null
+++ b/ue2/imgsynth2/cpixelformat_indexed8.h
@@ -0,0 +1,102 @@
1/**
2 * @module cpixelformat_bgr24
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps.
5 * @date 18.04.2009
6 */
7
8#ifndef CPixelFormat_Indexed8_H
9#define CPixelFormat_Indexed8_H
10
11#include <fstream>
12#include "cpixelformat.h"
13#include "cpixmap.h"
14/**
15 * @class CPixelFormat_Indexed8
16 * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps.
17 *
18 * On error CPixelFormat::PixelFormatError is thrown.
19 */
20class CPixelFormat_Indexed8 : public CPixelFormat
21{
22 public:
23 /**
24 * @method CPixelFormat_Indexed8
25 * @brief Default ctor
26 * @param bitmap pointer to CBitmap instance
27 * @return -
28 * @globalvars none
29 * @exception none
30 * @conditions none
31 */
32 CPixelFormat_Indexed8(CPixmap *pixmap)
33 : CPixelFormat(pixmap)
34 {}
35
36 /**
37 * @method ~CPixelFormat_Indexed8
38 * @brief Default dtor
39 * @param -
40 * @return -
41 * @globalvars none
42 * @exception none
43 * @conditions none
44 */
45 ~CPixelFormat_Indexed8()
46 {}
47
48 /**
49 * @method setPixel
50 * @brief Modifies pixel at coordinates x, y
51 * @param pixel pointer to new pixel data
52 * @param x x-coordinate
53 * @param y y-coordinate
54 * @return -
55 * @globalvars none
56 * @exception PixelFormatError
57 * @conditions none
58 */
59 void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y);
60
61 /* TODO */
62 void getPixel(uint32_t *pixel, uint32_t x, uint32_t y);
63
64 /**
65 * @method getBitCount
66 * @brief returns the bitcount needed for indexing the color tabel.
67 * @param -
68 * @return bitcount of indexes supported by this class
69 * @globalvars none
70 * @exception none
71 * @conditions none
72 */
73 uint32_t getBitCount()
74 {
75 return 8;
76 }
77
78 /**
79 * @method getColorMode
80 * @brief returns the color mode supported by this class
81 * @param -
82 * @return color mode supported by this class
83 * @globalvars none
84 * @exception none
85 * @conditions none
86 */
87 std::string getColorMode()
88 {
89 return "c";
90 }
91 /*
92 * TODO
93 */
94 void getMaxColor(unsigned int *red, unsigned int *green, unsigned int *blue)
95 {
96 *red = *green = *blue = 255; /* 2^8 - 1 */
97 }
98};
99
100#endif
101
102/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cpixmap.cpp b/ue2/imgsynth2/cpixmap.cpp
index de9ec94..91419b6 100644
--- a/ue2/imgsynth2/cpixmap.cpp
+++ b/ue2/imgsynth2/cpixmap.cpp
@@ -1,5 +1,5 @@
1/** 1/**
2 * @module CPixMap 2 * @module CPixmap
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Implementation of CFile handling Windows Bitmaps. 4 * @brief Implementation of CFile handling Windows Bitmaps.
5 * @date 27.04.2009 5 * @date 27.04.2009
@@ -11,14 +11,19 @@
11#ifdef DEBUG 11#ifdef DEBUG
12# include <iostream> 12# include <iostream>
13#endif 13#endif
14#include <cstdlib>
15#include <stdint.h>
14# include <string> 16# include <string>
15# include <map> 17# include <map>
18
19
20
16#include "cpixmap.h" 21#include "cpixmap.h"
17#include "cpixelformat_indexed8.h" 22#include "cpixelformat_indexed8.h"
18 23
19using namespace std; 24using namespace std;
20 25
21CPixMap::CPixMap() 26CPixmap::CPixmap()
22{ 27{
23 m_types.insert("XPM"); 28 m_types.insert("XPM");
24 29
@@ -31,10 +36,12 @@ CPixMap::CPixMap()
31 36
32/*----------------------------------------------------------------------------*/ 37/*----------------------------------------------------------------------------*/
33 38
34void CPixMap::read(std::ifstream& in) 39void CPixmap::read(std::ifstream& in)
35{ 40{
36 41
37 string str; 42 string str;
43 m_fileheader._XPMEXT = false;
44 m_fileheader._HOTSPOT = false;
38 45
39 /* parse the values section */ 46 /* parse the values section */
40 getline( in, str, '"'); 47 getline( in, str, '"');
@@ -46,62 +53,73 @@ void CPixMap::read(std::ifstream& in)
46 istr >> m_fileheader.nColor ; 53 istr >> m_fileheader.nColor ;
47 istr >> m_fileheader.nChar ; 54 istr >> m_fileheader.nChar ;
48 55
49 /* if there are optional values */ 56 /*optional values */
50 if (in.good()) 57 if (istr.good())
51 {
52 istr >> m_fileheader.xHotspot;
53 istr >> m_fileheader.yHotspot;
54 }
55 else
56 { 58 {
57 m_fileheader.xHotspot = NULL; 59 string tmp;
58 m_fileheader.yHotspot = NULL; 60 istr >> tmp;
61 if(tmp.compare("XPMEXT") == 0)
62 m_fileheader._XPMEXT = true;
63 else
64 {
65 m_fileheader._HOTSPOT = true;
66 m_fileheader.xHotspot =
67 static_cast<unsigned int>(strtoul(tmp.c_str(), NULL, 16));
68 istr >> m_fileheader.yHotspot;
69 }
70 if (istr.good())
71 {
72 istr >> tmp;
73 if (tmp.compare("XPMEXT") == 0)
74 m_fileheader._XPMEXT = true;
75 }
59 } 76 }
77
60 78
61 79
62 /* parse the colors section */ 80 /* parse color table*/
63 getline( in, str, '"'); 81 getline( in, str, '"');
82 string character, mode, colors;
64 for (unsigned int i = 0; i < m_fileheader.nColor; i++ ) 83 for (unsigned int i = 0; i < m_fileheader.nColor; i++ )
65 { 84 {
66 getline( in, str, '"' ); 85 getline( in, str, '"' );
67 stringstream istr2 (str ); 86 stringstream istr2 (str );
68 char character; 87
69 string mode, colors;
70
71 istr2 >> character; 88 istr2 >> character;
72 istr2 >> mode; 89 istr2 >> mode;
73 istr2 >> colors; 90 istr2 >> colors;
74 //m_fileheader.xpmColors[character][mode] = colors; 91
75 m_fileheader.xpmColors[character] = colors; 92 if ( colors.size() != 7)
93 throw FileError("Pixmap color tabel is invalid.");
94 if ( colors.at(0) != '#')
95 throw FileError("Pixmap color tabel value is not hexadecimal.");
96
97 xpmColors[character][mode] = new (nothrow) unsigned int[3];
98 if (xpmColors[character][mode] == 0)
99 throw FileError("Bad color table allocation.");
100
101 xpmColors[character][mode][0] =
102 static_cast<unsigned int>(strtoul(colors.substr(1,2).c_str(), NULL, 16));
103 xpmColors[character][mode][1] =
104 static_cast<unsigned int>(strtoul(colors.substr(3,2).c_str(), NULL, 16));
105 xpmColors[character][mode][2] =
106 static_cast<unsigned int>(strtoul(colors.substr(5,2).c_str(), NULL, 16));
107
108
76 109
110
111
112
77 getline( in, str, '"' ); 113 getline( in, str, '"' );
78 } 114 }
79 115
80 116 /* read pixel data using separate class */
81/* colors.replace(0,1,"0x");
82 colors.insert(4, " 0x");
83 colors.insert(9," 0x");
84
85 stringstream istr3 (colors, stringstream::out|stringstream::in );
86 istr3 >>hex>> r;
87 istr3 >>hex>> g;
88 istr3 >>hex>> b;
89 //?????????????ß
90 cout<<c1<<" "<<c2<<" "<< r<<" "<< g<<" "<< b<<endl;
91 m_fileheader.xpmColors[c1]['r'] = static_cast<uint8_t>(r);
92 m_fileheader.xpmColors[c1]['g'] = static_cast<uint8_t>(g);
93 m_fileheader.xpmColors[c1]['b'] = static_cast<uint8_t>(b);*/
94
95
96
97 /* read pixel data using separate class */
98 if (getPixelDataSize() > 0) 117 if (getPixelDataSize() > 0)
99 { 118 {
100 if (m_pixeldata != NULL) 119 if (m_pixeldata != NULL)
101 delete[] m_pixeldata; 120 delete[] m_pixeldata;
102 m_pixeldata = new uint8_t[getPixelDataSize()]; 121 m_pixeldata = new uint8_t[getPixelDataSize()];
103 122
104 /* parse the pixel data */
105 for (unsigned int y = 0; y < getHeight(); y++ ) 123 for (unsigned int y = 0; y < getHeight(); y++ )
106 { 124 {
107 for (unsigned int x = 0; x < getWidth(); x++ ) 125 for (unsigned int x = 0; x < getWidth(); x++ )
@@ -114,58 +132,140 @@ void CPixMap::read(std::ifstream& in)
114 } 132 }
115 } 133 }
116 134
135 /* parse extension */
136 if ( m_fileheader._XPMEXT )
137 getline( in, m_fileheader.extension, '}' );
117 /* debug*/ 138 /* debug*/
118 CPixMap::dump (cout); 139 CPixmap::dump (cout);
119 140
120 141 /* get pixelformat instance */
142 m_pixelformat = NULL;
143 set<CPixelFormat *>::iterator it;
144 for (it = m_handlers.begin(); it != m_handlers.end(); it++)
145 {
146 /* check color mode */
147 if (mode.compare((*it)->getColorMode()) == 0)
148 {
149 m_pixelformat = *it;
150 break;
151 }
152 }
153 if (m_pixelformat == NULL)
154 throw FileError("Pixmap color mode \""+mode+"\" is not supported.");
121} 155}
122 156
123/*----------------------------------------------------------------------------*/ 157/*----------------------------------------------------------------------------*/
124 158
125void CPixMap::write(std::ofstream& out) 159void CPixmap::write(std::ofstream& out, std::string& filename)
126{ 160{
161
162 /* header comment */
127 out<<"/* XPM */"<<endl; 163 out<<"/* XPM */"<<endl;
128 out<<"static char * yellow_man1_default_xpm[] = {"<<endl; 164
165 /* variables*/
166 out<<"static char * "
167 <<filename.substr(filename.find_last_of("/\\") + 1, filename.size())
168 <<"[] = {"<<endl;
129 out<<"\""<<m_fileheader.xpmWidth<<" "<<m_fileheader.xpmHeight 169 out<<"\""<<m_fileheader.xpmWidth<<" "<<m_fileheader.xpmHeight
130 <<" "<<m_fileheader.nColor<<" "<<m_fileheader.nChar<<"\","<<endl; 170 <<" "<<m_fileheader.nColor<<" "<<m_fileheader.nChar;
171
172 /*optional values*/
173 if( m_fileheader._HOTSPOT )
174 out<<" "<<m_fileheader.xHotspot<<" "<<m_fileheader.yHotspot;
175 if( m_fileheader._XPMEXT )
176 out<<" "<<"XPMEXT";
177 out <<"\","<<endl;
178
179 /* color table */
180 map<string, map<string, uint32_t* > >::iterator it1;
181 map<string, uint32_t* >::iterator it2;
182
183 for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ )
184 {
185 out << "\""<<(*it1).first;
186 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ )
187 {
188
189 out<<"\t" <<(*it2).first<<"\t#";
190
191 for (int i = 0 ; i < 3; i++ )
192 {
193 out.width(2);
194 out << hex <<uppercase<<(*it2).second[i];
195 out.fill('0');
196 }
197 }
198 out<<"\","<<endl;
199 }
131 200
201 /* pixel data */
202 for (unsigned int y = 0; y < getHeight(); y++ ){
203 out <<"\"";
204 for (unsigned int x = 0; x < getWidth(); x++ )
205 out << m_pixeldata[y * getWidth() + x];
206 out <<"\"";
207 if ( y != ( getHeight() - 1 ))
208 out <<",";
209 out <<endl;
210 }
211
212 /* extension */
213 if (m_fileheader._XPMEXT)
214 out << m_fileheader.extension;
215
216 out <<"};";
132 217
133 dump(out);
134} 218}
135 219
136 220
137/*----------------------------------------------------------------------------*/ 221/*----------------------------------------------------------------------------*/
138 222
139#ifdef DEBUG 223#ifdef DEBUG
140void CPixMap::dump(std::ostream& out) 224void CPixmap::dump(std::ostream& out)
141{ 225{
226
227 /* pixeldata */
228 cout<<endl<<"(_Pixel data:_)"<<endl;
229 for (unsigned int y = 0; y < getHeight(); y++ ){
230 for (unsigned int x = 0; x < getWidth(); x++ )
231 out << m_pixeldata[y * getWidth() + x];
232 out << endl;
233 }
142 234
143 /* values*/ 235 /* values*/
144 out 236 cout<<endl<<"(_Values:_)"<<endl;
145 << "XPM Header:" << endl 237 out << "XPM Header:" << endl
146 << ", xpmWidth=" << m_fileheader.xpmWidth<< endl 238 << "xpmWidth=" << m_fileheader.xpmWidth<< endl
147 << ", xpmHeight=" << m_fileheader.xpmHeight<< endl 239 << "xpmHeight=" << m_fileheader.xpmHeight<< endl
148 << ", nColor=" << m_fileheader.nColor<< endl 240 << "nColor=" << m_fileheader.nColor<< endl
149 << ", nChar=" << m_fileheader.nChar<< endl 241 << "nChar=" << m_fileheader.nChar<< endl
242 << "Hotspot=" << m_fileheader.xHotspot<< endl
243 << "yHotspot=" << m_fileheader.yHotspot<< endl
244 << "_HOTSPOT=" << m_fileheader._HOTSPOT<< endl
245 << "_XPMEXT=" << m_fileheader._XPMEXT<< endl
246 << "extension=" << m_fileheader.extension<< endl
150 << endl; 247 << endl;
151 248
152 /* colors*/ 249 /* colors*/
153 map<unsigned const char, map<std::string, std::string > >::iterator it1; 250 map<string, map<string, uint32_t* > >::iterator it1;
154 map<std::string, std::string >::iterator it2; 251 map<string, uint32_t* >::iterator it2;
155 for ( it1=m_fileheader.xpmColors.begin() ; it1 != m_fileheader.xpmColors.end(); it1++ ) 252 cout<<"(_Color table:_)"<<endl;
253 for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ )
156 { 254 {
157 out << (*it1).first ; 255 out << (*it1).first;
158 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ ) 256 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ )
159 out << (*it2).first <<" > "<< (*it2).second<<endl; 257 {
160 } 258 out <<" "<< (*it2).first <<" ";
161 259 for (int i = 0 ; i < 3; i++ )
162 /* pixeldata */ 260 {
163 for (unsigned int y = 0; y < getHeight(); y++ ){ 261 out.width(3);
164 for (unsigned int x = 0; x < getWidth(); x++ ) 262 out << (*it2).second[i]<<" ";
165 out << m_pixeldata[y * getWidth() + x]; 263 out.fill('0');
166 out << endl; 264 }
265 out<<endl;
266 }
167 } 267 }
168 268
169} 269}
170#endif 270#endif
171 271
diff --git a/ue2/imgsynth2/cpixmap.h b/ue2/imgsynth2/cpixmap.h
index c7537cd..863cbd4 100644
--- a/ue2/imgsynth2/cpixmap.h
+++ b/ue2/imgsynth2/cpixmap.h
@@ -1,33 +1,32 @@
1/** 1/**
2 * @module CPixMap 2 * @module CPixmap
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Implementation of CFile CBitmap handling XPM. 4 * @brief Implementation of CFile CBitmap handling XPM.
5 * @date 27.04.2009 5 * @date 27.04.2009
6 */ 6 */
7 7
8#ifndef CPixMap_H 8#ifndef CPixmap_H
9#define CPixMap_H 9#define CPixmap_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <map>
13#include "cbitmap.h" 12#include "cbitmap.h"
14 13
15 14
16/** 15/**
17 * @class CBitmap 16 * @class CPixmap
18 * @brief Implementation of CFile handling Windows Bitmaps. 17 * @brief Implementation of CFile handling Pixmap file format.
19 * 18 *
20 * In order to support operations on bitmaps with different color bitcounts 19 * In order to support operations on pixmaps in color mode an
21 * different implementations of CPixelFormat are used. These classes are 20 * implementations of CPixelFormat is used. These classe are
22 * allowed to modify the bitmap headers and pixelbuffer directly. 21 * allowed to modify the pixmap header, pixelbuffer and color table directly.
23 * 22 *
24 * On error CFile::FileError is thrown. 23 * On error CFile::FileError is thrown.
25 */ 24 */
26class CPixMap : public CBitmap 25class CPixmap : public CBitmap
27{ 26{
28 public: 27 public:
29 /** 28 /**
30 * @method CPixMap 29 * @method CPixmap
31 * @brief Default ctor 30 * @brief Default ctor
32 * @param - 31 * @param -
33 * @return - 32 * @return -
@@ -35,10 +34,10 @@ class CPixMap : public CBitmap
35 * @exception none 34 * @exception none
36 * @conditions none 35 * @conditions none
37 */ 36 */
38 CPixMap(); 37 CPixmap();
39 38
40 /** 39 /**
41 * @method ~CPixMap 40 * @method ~CPixmap
42 * @brief Default dtor 41 * @brief Default dtor
43 * @param - 42 * @param -
44 * @return - 43 * @return -
@@ -46,12 +45,12 @@ class CPixMap : public CBitmap
46 * @exception none 45 * @exception none
47 * @conditions none 46 * @conditions none
48 */ 47 */
49 ~CPixMap() 48 ~CPixmap()
50 {} 49 {}
51 50
52 /** 51 /**
53 * @method read 52 * @method read
54 * @brief Reads Windows Bitmap from filestream. 53 * @brief Reads Pixmap from filestream.
55 * On error an exception is thrown. 54 * On error an exception is thrown.
56 * @param in filestream to read data from 55 * @param in filestream to read data from
57 * @return - 56 * @return -
@@ -64,7 +63,7 @@ class CPixMap : public CBitmap
64 63
65 /** 64 /**
66 * @method write 65 * @method write
67 * @brief Writes Windows Bitmap to filestream. 66 * @brief Writes Pixmap to filestream.
68 * @param out filestream to read data from 67 * @param out filestream to read data from
69 * @return - 68 * @return -
70 * @globalvars none 69 * @globalvars none
@@ -73,11 +72,11 @@ class CPixMap : public CBitmap
73 * @conditions none 72 * @conditions none
74 */ 73 */
75 74
76 void write(std::ofstream& out); 75 void write(std::ofstream& out, std::string& filename);
77#ifdef DEBUG 76#ifdef DEBUG
78 /** 77 /**
79 * @method dump 78 * @method dump
80 * @brief Dumps the Windows Bitmap file headers to ostream 79 * @brief Dumps the Pixmap file header and pixel data to ostream
81 * @param out output stream 80 * @param out output stream
82 * @return - 81 * @return -
83 * @globalvars 82 * @globalvars
@@ -90,7 +89,7 @@ class CPixMap : public CBitmap
90 89
91 90
92 /** 91 /**
93 * @brief Windows Bitmap Info Header structure 92 * @brief Pixmap Header structure
94 */ 93 */
95#pragma pack(push,1) 94#pragma pack(push,1)
96 typedef struct 95 typedef struct
@@ -101,25 +100,23 @@ class CPixMap : public CBitmap
101 uint32_t xpmHeight; 100 uint32_t xpmHeight;
102 /** the number of colors (signed integer) */ 101 /** the number of colors (signed integer) */
103 uint32_t nColor; 102 uint32_t nColor;
104
105 /** the number of characters per pixel (signed integer) */ 103 /** the number of characters per pixel (signed integer) */
106 uint32_t nChar; 104 uint32_t nChar;
107
108 /** X-Position Hotspots */ 105 /** X-Position Hotspots */
109 uint32_t xHotspot; 106 uint32_t xHotspot;
110
111 /** Y-Position Hotspots */ 107 /** Y-Position Hotspots */
112 uint32_t yHotspot; 108 uint32_t yHotspot;
113 109 /* is hotspot set */
114 /* color tables*/ 110 bool _HOTSPOT;
115 // std::map<std::string, std::map< std::string, std::string > > xpmColors; 111 /* XPMEXT extension tag found*/
116 // std::map<std::string, uint32_t[3]> xpmColors; 112 bool _XPMEXT;
117 113 /* unchanged extension */
118 114 std::string extension;
119 } PIXMAP_FILEHEADER; 115
116 } PIXMAP_FILEHEADER;
120#pragma pack(pop) 117#pragma pack(pop)
121 118
122 /* TODO */ 119
123 const uint32_t getPixelDataSize() 120 const uint32_t getPixelDataSize()
124 { 121 {
125 return m_fileheader.xpmWidth * 122 return m_fileheader.xpmWidth *
@@ -127,21 +124,20 @@ class CPixMap : public CBitmap
127 m_fileheader.nChar; 124 m_fileheader.nChar;
128 } 125 }
129 126
130 /* TODO */ 127
131 const uint32_t getHeight() 128 const uint32_t getHeight()
132 { 129 {
133 /* width and height can be negativ */ 130 /* width and height can be negativ */
134 return m_fileheader.xpmHeight; 131 return m_fileheader.xpmHeight;
135 } 132 }
136 133
137 /* TODO */
138 const uint32_t getWidth() 134 const uint32_t getWidth()
139 { 135 {
140 /* width and height can be negativ */ 136 /* width and height can be negativ */
141 return m_fileheader.xpmWidth; 137 return m_fileheader.xpmWidth;
142 } 138 }
143 139
144 /* TODO */ 140
145 const bool isMirrored() 141 const bool isMirrored()
146 { 142 {
147 /* pixmap is never mirrored */ 143 /* pixmap is never mirrored */
diff --git a/ue2/imgsynth2/cscriptparser.cpp b/ue2/imgsynth2/cscriptparser.cpp
index e6bc9ae..6b886a3 100644
--- a/ue2/imgsynth2/cscriptparser.cpp
+++ b/ue2/imgsynth2/cscriptparser.cpp
@@ -20,7 +20,7 @@ CScriptparser::CScriptparser(const std::string& scriptfile)
20{ 20{
21 /* add our handlers */ 21 /* add our handlers */
22 m_handlers.insert(new CWindowsBitmap); 22 m_handlers.insert(new CWindowsBitmap);
23 m_handlers.insert(new CPixMap); 23 m_handlers.insert(new CPixmap);
24} 24}
25 25
26/*----------------------------------------------------------------------------*/ 26/*----------------------------------------------------------------------------*/
diff --git a/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm b/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm
index cbfe217..6e5fa2c 100644
--- a/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm
+++ b/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm
@@ -1,6 +1,6 @@
1/* XPM */ 1/* XPM */
2static char * yellow_man1_default_xpm[] = { 2static char * yellow_man1_default_xpm[] = {
3"9 17 2 1", 3"9 17 2 1 0 0 XPMEXT",
4". c #000000", 4". c #000000",
5"# c #FFF200", 5"# c #FFF200",
6".........", 6".........",
@@ -19,4 +19,9 @@ static char * yellow_man1_default_xpm[] = {
19"...#.#...", 19"...#.#...",
20"...#.#...", 20"...#.#...",
21".........", 21".........",
22"........."}; 22"........."
23"XPMEXT ext1 data1",
24"XPMEXT ext2",
25"data2_1",
26"data2_2",
27"XPMENDEXT"};