summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-05-01 15:41:07 +0200
committermanuel <manuel@nc8430.lan>2009-05-01 15:41:07 +0200
commit766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73 (patch)
treef383a621f2ad762e5be250c2ba9bd4c18bb02a0c /ue2/imgsynth2
parentf0442c8d058ae6007023ba1b898197db921e6ce1 (diff)
parentb0442de485dcb6328366d9b05a62af345e5fa39f (diff)
downloadooprog-766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73.tar.gz
ooprog-766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73.tar.bz2
ooprog-766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73.zip
merge
Diffstat (limited to 'ue2/imgsynth2')
-rw-r--r--ue2/imgsynth2/Makefile6
-rw-r--r--ue2/imgsynth2/cbitmap.cpp23
-rw-r--r--ue2/imgsynth2/cbitmap.h3
-rw-r--r--ue2/imgsynth2/cpixelformat.h1
-rw-r--r--ue2/imgsynth2/cpixelformat_indexed8.cpp84
-rw-r--r--ue2/imgsynth2/cpixelformat_indexed8.h121
-rw-r--r--ue2/imgsynth2/cpixmap.cpp269
-rw-r--r--ue2/imgsynth2/cpixmap.h166
-rw-r--r--ue2/imgsynth2/cscriptparser.cpp2
-rw-r--r--ue2/imgsynth2/test/input_yellow_man1_indexed810
-rw-r--r--ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm27
-rw-r--r--ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm24
12 files changed, 726 insertions, 10 deletions
diff --git a/ue2/imgsynth2/Makefile b/ue2/imgsynth2/Makefile
index 22e53e5..481230c 100644
--- a/ue2/imgsynth2/Makefile
+++ b/ue2/imgsynth2/Makefile
@@ -12,9 +12,11 @@ LIBS= -L/usr/local/lib -lboost_program_options
12 12
13BIN= imgsynth2 13BIN= imgsynth2
14OBJS= cpixelformat_bgr24.o cpixelformat_bgr555.o \ 14OBJS= cpixelformat_bgr24.o cpixelformat_bgr555.o \
15 cwindowsbitmap.o cbitmap.o cscriptparser.o imgsynth2.o 15 cpixelformat_indexed8.o cpixmap.o cwindowsbitmap.o \
16 cbitmap.o cscriptparser.o imgsynth2.o
16HEADERS= cpixelformat.h cpixelformat_bgr24.h cpixelformat_bgr555.h \ 17HEADERS= cpixelformat.h cpixelformat_bgr24.h cpixelformat_bgr555.h \
17 cfile.h cbitmap.h cwindowsbitmap.h cscriptparser.h 18 cpixelformat_indexed8.h cpixmap.h cfile.h cbitmap.h \
19 cwindowsbitmap.h cscriptparser.h
18 20
19.SUFFIXES: .cpp .o 21.SUFFIXES: .cpp .o
20 22
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp
index a064130..ed26600 100644
--- a/ue2/imgsynth2/cbitmap.cpp
+++ b/ue2/imgsynth2/cbitmap.cpp
@@ -28,9 +28,18 @@ CBitmap::~CBitmap()
28 m_pixelformat = NULL; 28 m_pixelformat = NULL;
29 29
30 /* delete colortable content */ 30 /* delete colortable content */
31 map<string, CPixelFormat::RGBPIXEL *>::iterator it2; 31 //TODO
32 /*map<string, CPixelFormat::RGBPIXEL *>::iterator it2;
32 for (it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) 33 for (it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++)
33 delete (*it2).second; 34 delete (*it2).second;*/
35
36 map<string, map<string, uint32_t *> >::iterator it1;
37 map<string, uint32_t *>::iterator it2;
38 for(it1 = xpmColors.begin(); it1 != xpmColors.end(); it1++)
39 {
40 for(it2 = (*it1).second.begin(); it2 != (*it1).second.end(); it2++)
41 delete[] (*it2).second;
42 }
34} 43}
35 44
36/*----------------------------------------------------------------------------*/ 45/*----------------------------------------------------------------------------*/
@@ -144,12 +153,13 @@ void CBitmap::invert(std::list<std::string> params)
144 { 153 {
145 /* invert every entry in the colortable */ 154 /* invert every entry in the colortable */
146 map<string, CPixelFormat::RGBPIXEL *>::iterator it; 155 map<string, CPixelFormat::RGBPIXEL *>::iterator it;
147 for (it = m_colortable.begin(); it != m_colortable.end(); it++) 156 //TODO
157 /*for (it = m_colortable.begin(); it != m_colortable.end(); it++)
148 { 158 {
149 (*it).second->red = max.red - (*it).second->red; 159 (*it).second->red = max.red - (*it).second->red;
150 (*it).second->green = max.green - (*it).second->green; 160 (*it).second->green = max.green - (*it).second->green;
151 (*it).second->blue = max.blue - (*it).second->blue; 161 (*it).second->blue = max.blue - (*it).second->blue;
152 } 162 }*/
153 } 163 }
154 else 164 else
155 { 165 {
@@ -213,12 +223,13 @@ void CBitmap::brightness(std::list<std::string> params)
213 { 223 {
214 /* invert every entry in the colortable */ 224 /* invert every entry in the colortable */
215 map<string, CPixelFormat::RGBPIXEL *>::iterator it; 225 map<string, CPixelFormat::RGBPIXEL *>::iterator it;
216 for (it = m_colortable.begin(); it != m_colortable.end(); it++) 226 //TODO
227 /*for (it = m_colortable.begin(); it != m_colortable.end(); it++)
217 { 228 {
218 (*it).second->red = min(max.red, static_cast<uint32_t>((*it).second->red * factor)); 229 (*it).second->red = min(max.red, static_cast<uint32_t>((*it).second->red * factor));
219 (*it).second->green = min(max.green, static_cast<uint32_t>((*it).second->green * factor)); 230 (*it).second->green = min(max.green, static_cast<uint32_t>((*it).second->green * factor));
220 (*it).second->blue = min(max.blue, static_cast<uint32_t>((*it).second->blue * factor)); 231 (*it).second->blue = min(max.blue, static_cast<uint32_t>((*it).second->blue * factor));
221 } 232 }*/
222 } 233 }
223 else 234 else
224 { 235 {
diff --git a/ue2/imgsynth2/cbitmap.h b/ue2/imgsynth2/cbitmap.h
index df7dc84..c8d4dfb 100644
--- a/ue2/imgsynth2/cbitmap.h
+++ b/ue2/imgsynth2/cbitmap.h
@@ -231,7 +231,8 @@ class CBitmap : public CFile
231 /** pointer to pixelbuffer */ 231 /** pointer to pixelbuffer */
232 uint8_t *m_pixeldata; 232 uint8_t *m_pixeldata;
233 /** colortable map */ 233 /** colortable map */
234 std::map<std::string, CPixelFormat::RGBPIXEL *> m_colortable; 234 //TODO std::map<std::string, CPixelFormat::RGBPIXEL *> m_colortable;
235 std::map<std::string, std::map< std::string, uint32_t* > > xpmColors;
235 /** set of supported PixelFormat handlers */ 236 /** set of supported PixelFormat handlers */
236 std::set<CPixelFormat *> m_handlers; 237 std::set<CPixelFormat *> m_handlers;
237 /** pointer to CPixelFormat implementation */ 238 /** pointer to CPixelFormat implementation */
diff --git a/ue2/imgsynth2/cpixelformat.h b/ue2/imgsynth2/cpixelformat.h
index a9e1e26..18d1a7d 100644
--- a/ue2/imgsynth2/cpixelformat.h
+++ b/ue2/imgsynth2/cpixelformat.h
@@ -13,7 +13,6 @@
13#include <stdexcept> 13#include <stdexcept>
14 14
15class CBitmap; 15class CBitmap;
16//#include "cbitmap.h"
17 16
18/** 17/**
19 * @class CPixelFormat 18 * @class CPixelFormat
diff --git a/ue2/imgsynth2/cpixelformat_indexed8.cpp b/ue2/imgsynth2/cpixelformat_indexed8.cpp
new file mode 100644
index 0000000..546daaf
--- /dev/null
+++ b/ue2/imgsynth2/cpixelformat_indexed8.cpp
@@ -0,0 +1,84 @@
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(RGBPIXEL& pixel, uint32_t x, uint32_t y)
14{
15#if 0
16 if (m_bitmap->getPixelData() == NULL)
17 throw PixelFormatError("No pixelbuffer allocated.");
18
19 /* calc rowsize - boundary is 32 */
20 uint32_t rowsize = 4 * static_cast<uint32_t>(
21 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
22 );*/
23
24 /* if height is positive the y-coordinates are mirrored */
25 if (m_bitmap->getInfoHeader().biHeight > 0)
26 y = m_bitmap->getInfoHeader().biHeight - y - 1;
27 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
28
29 /* boundary check */
30 if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage)
31 throw PixelFormatError("Pixel position is out of range.");
32
33 /* get pixel */
34 try
35 {
36 pixel[0] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 2));
37 pixel[1] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 1));
38 pixel[2] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset));
39 }
40 catch(boost::numeric::bad_numeric_cast& ex)
41 {
42 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
43 }
44#endif
45}
46
47void CPixelFormat_Indexed8::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y)
48{
49#if 0
50 if (m_bitmap->getPixelData() == NULL)
51 throw PixelFormatError("No pixelbuffer allocated.");
52
53 /* calc rowsize - boundary is 32 */
54 uint32_t rowsize = 4 * static_cast<uint32_t>(
55 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
56 );
57
58 /* if height is positive the y-coordinates are mirrored */
59 if (m_bitmap->getInfoHeader().biHeight > 0)
60 y = m_bitmap->getInfoHeader().biHeight - y - 1;
61 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
62
63 /* boundary check */
64 if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage)
65 throw PixelFormatError("Pixel position is out of range.");
66
67 /* convert color values to correct types */
68 uint8_t data[3];
69 try
70 {
71 data[0] = boost::numeric_cast<uint8_t>(pixel[2]);
72 data[1] = boost::numeric_cast<uint8_t>(pixel[1]);
73 data[2] = boost::numeric_cast<uint8_t>(pixel[0]);
74 }
75 catch(boost::numeric::bad_numeric_cast& ex)
76 {
77 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
78 }
79
80 copy(data, data + 3, m_bitmap->getPixelData() + offset);
81#endif
82}
83
84/* 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..2e2fc01
--- /dev/null
+++ b/ue2/imgsynth2/cpixelformat_indexed8.h
@@ -0,0 +1,121 @@
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/**
16 * @class CPixelFormat_Indexed8
17 * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps.
18 *
19 * On error CPixelFormat::PixelFormatError is thrown.
20 */
21class CPixelFormat_Indexed8 : public CPixelFormat
22{
23 public:
24 /**
25 * @method CPixelFormat_Indexed8
26 * @brief Default ctor
27 * @param bitmap pointer to CBitmap instance
28 * @return -
29 * @globalvars none
30 * @exception none
31 * @conditions none
32 */
33 CPixelFormat_Indexed8(CPixmap *pixmap)
34 : CPixelFormat(pixmap)
35 {}
36
37 /**
38 * @method ~CPixelFormat_Indexed8
39 * @brief Default dtor
40 * @param -
41 * @return -
42 * @globalvars none
43 * @exception none
44 * @conditions none
45 */
46 ~CPixelFormat_Indexed8()
47 {}
48
49 /**
50 * @method getPixel
51 * @brief Get pixel at coordinates x, y
52 * @param pixel reference to pixel data
53 * @param x x-coordinate
54 * @param y y-coordinate
55 * @return -
56 * @globalvars none
57 * @exception PixelFormatError
58 * @conditions none
59 */
60 void getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y);
61
62 /**
63 * @method setPixel
64 * @brief Modifies pixel at coordinates x, y
65 * @param pixel reference to new pixel data
66 * @param x x-coordinate
67 * @param y y-coordinate
68 * @return -
69 * @globalvars none
70 * @exception PixelFormatError
71 * @conditions none
72 */
73 void setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y);
74
75 /**
76 * @method getBitCount
77 * @brief returns the bitcount needed for indexing the color tabel.
78 * @param -
79 * @return bitcount of indexes supported by this class
80 * @globalvars none
81 * @exception none
82 * @conditions none
83 */
84 uint32_t getBitCount()
85 {
86 return 8;
87 }
88
89 /**
90 * @method getColorMode
91 * @brief returns the color mode supported by this class
92 * @param -
93 * @return color mode supported by this class
94 * @globalvars none
95 * @exception none
96 * @conditions none
97 */
98 const std::string getColorMode()
99 {
100 return "c";
101 }
102
103 /**
104 * @method getMaxColor
105 * @brief Get maximum values for RGB pixel
106 * @param pixel reference to pixel struct
107 * @return -
108 * @globalvars none
109 * @exception none
110 * @conditions none
111 */
112 void getMaxColor(RGBPIXEL& pixel)
113 {
114 /* value = 2^8 - 1 */
115 pixel.red = pixel.green = pixel.blue = 255;
116 }
117};
118
119#endif
120
121/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cpixmap.cpp b/ue2/imgsynth2/cpixmap.cpp
new file mode 100644
index 0000000..6f8c8d6
--- /dev/null
+++ b/ue2/imgsynth2/cpixmap.cpp
@@ -0,0 +1,269 @@
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 <cstdlib>
15#include <stdint.h>
16# include <string>
17# include <map>
18
19
20
21#include "cpixmap.h"
22#include "cpixelformat_indexed8.h"
23
24using namespace std;
25
26CPixmap::CPixmap()
27{
28 m_types.insert("XPM");
29
30 /* add our handlers */
31 m_handlers.insert(new CPixelFormat_Indexed8(this));
32}
33
34/*----------------------------------------------------------------------------*/
35
36void CPixmap::read(std::ifstream& in)
37{
38
39 string str;
40 m_fileheader._XPMEXT = false;
41 m_fileheader._HOTSPOT = false;
42
43 /* parse the values section */
44 getline( in, str, '"');
45 getline( in, str, '"');
46 stringstream istr (str );
47
48 istr >> m_fileheader.xpmWidth ;
49 istr >> m_fileheader.xpmHeight ;
50 istr >> m_fileheader.nColor ;
51 istr >> m_fileheader.nChar ;
52
53 /*optional values */
54 if (istr.good())
55 {
56 string tmp;
57 istr >> tmp;
58 if(tmp.compare("XPMEXT") == 0)
59 m_fileheader._XPMEXT = true;
60 else
61 {
62 m_fileheader._HOTSPOT = true;
63 m_fileheader.xHotspot = static_cast<unsigned int>(strtoul(tmp.c_str(), NULL, 16));
64 istr >> m_fileheader.yHotspot;
65 }
66 if (istr.good())
67 {
68 istr >> tmp;
69 if (tmp.compare("XPMEXT") == 0)
70 m_fileheader._XPMEXT = true;
71 }
72 }
73
74
75
76 /* parse color table*/
77 getline( in, str, '"');
78 string character, mode, colors;
79 for (unsigned int i = 0; i < m_fileheader.nColor; i++ )
80 {
81 getline( in, str, '"' );
82 stringstream istr2 (str );
83
84 istr2 >> character;
85 istr2 >> mode;
86 istr2 >> colors;
87
88 if ( colors.size() != 7)
89 throw FileError("Pixmap color tabel is invalid.");
90 if ( colors.at(0) != '#')
91 throw FileError("Pixmap color tabel value is not hexadecimal.");
92
93 xpmColors[character][mode] = new (nothrow) unsigned int[3];
94 if (xpmColors[character][mode] == 0)
95 throw FileError("Bad color table allocation.");
96
97 xpmColors[character][mode][0] =
98 static_cast<unsigned int>(strtoul(colors.substr(1,2).c_str(), NULL, 16));
99 xpmColors[character][mode][1] =
100 static_cast<unsigned int>(strtoul(colors.substr(3,2).c_str(), NULL, 16));
101 xpmColors[character][mode][2] =
102 static_cast<unsigned int>(strtoul(colors.substr(5,2).c_str(), NULL, 16));
103
104
105
106
107
108
109 getline( in, str, '"' );
110 }
111
112 /* read pixel data using separate class */
113 if (getPixelDataSize() > 0)
114 {
115 if (m_pixeldata != NULL)
116 delete[] m_pixeldata;
117 m_pixeldata = new uint8_t[getPixelDataSize()];
118
119 for (unsigned int y = 0; y < getHeight(); y++ )
120 {
121 for (unsigned int x = 0; x < getWidth(); x++ )
122 m_pixeldata[y * getWidth() + x] = static_cast<uint8_t>(in.get());
123
124 getline( in, str);
125 if ( y != ( getHeight() - 1 ))
126 in.get();
127
128 }
129 }
130
131 /* parse extension */
132 if ( m_fileheader._XPMEXT )
133 getline( in, m_fileheader.extension, '}' );
134 /* debug*/
135 CPixmap::dump (cout);
136
137 /* get pixelformat instance */
138 m_pixelformat = NULL;
139 set<CPixelFormat *>::iterator it;
140 for (it = m_handlers.begin(); it != m_handlers.end(); it++)
141 {
142 /* check color mode */
143 //TODO if (mode.compare((*it)->getColorMode()) == 0)
144 if (mode == "c")
145 {
146 m_pixelformat = *it;
147 break;
148 }
149 }
150 if (m_pixelformat == NULL)
151 throw FileError("Pixmap color mode \""+mode+"\" is not supported.");
152}
153
154/*----------------------------------------------------------------------------*/
155
156void CPixmap::write(std::ofstream& out, std::string& filename)
157{
158
159 /* header comment */
160 out<<"/* XPM */"<<endl;
161
162 /* variables*/
163 out<<"static char * "
164 <<filename.substr(filename.find_last_of("/\\") + 1, filename.size())
165 <<"[] = {"<<endl;
166 out<<"\""<<m_fileheader.xpmWidth<<" "<<m_fileheader.xpmHeight
167 <<" "<<m_fileheader.nColor<<" "<<m_fileheader.nChar;
168
169 /*optional values*/
170 if( m_fileheader._HOTSPOT )
171 out<<" "<<m_fileheader.xHotspot<<" "<<m_fileheader.yHotspot;
172 if( m_fileheader._XPMEXT )
173 out<<" "<<"XPMEXT";
174 out <<"\","<<endl;
175
176 /* color table */
177 map<string, map<string, uint32_t* > >::iterator it1;
178 map<string, uint32_t* >::iterator it2;
179
180 for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ )
181 {
182 out << "\""<<(*it1).first;
183 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ )
184 {
185
186 out<<"\t" <<(*it2).first<<"\t#";
187
188 for (int i = 0 ; i < 3; i++ )
189 {
190 out.width(2);
191 out << hex <<uppercase<<(*it2).second[i];
192 out.fill('0');
193 }
194 }
195 out<<"\","<<endl;
196 }
197
198 /* pixel data */
199 for (unsigned int y = 0; y < getHeight(); y++ ){
200 out <<"\"";
201 for (unsigned int x = 0; x < getWidth(); x++ )
202 out << m_pixeldata[y * getWidth() + x];
203 out <<"\"";
204 if ( y != ( getHeight() - 1 ))
205 out <<",";
206 out <<endl;
207 }
208
209 /* extension */
210 if (m_fileheader._XPMEXT)
211 out << m_fileheader.extension;
212
213 out <<"};";
214
215}
216
217
218/*----------------------------------------------------------------------------*/
219
220#ifdef DEBUG
221void CPixmap::dump(std::ostream& out)
222{
223
224 /* pixeldata */
225 cout<<endl<<"(_Pixel data:_)"<<endl;
226 for (unsigned int y = 0; y < getHeight(); y++ ){
227 for (unsigned int x = 0; x < getWidth(); x++ )
228 out << m_pixeldata[y * getWidth() + x];
229 out << endl;
230 }
231
232 /* values*/
233 cout<<endl<<"(_Values:_)"<<endl;
234 out << "XPM Header:" << endl
235 << "xpmWidth=" << m_fileheader.xpmWidth<< endl
236 << "xpmHeight=" << m_fileheader.xpmHeight<< endl
237 << "nColor=" << m_fileheader.nColor<< endl
238 << "nChar=" << m_fileheader.nChar<< endl
239 << "Hotspot=" << m_fileheader.xHotspot<< endl
240 << "yHotspot=" << m_fileheader.yHotspot<< endl
241 << "_HOTSPOT=" << m_fileheader._HOTSPOT<< endl
242 << "_XPMEXT=" << m_fileheader._XPMEXT<< endl
243 << "extension=" << m_fileheader.extension<< endl
244 << endl;
245
246 /* colors*/
247 map<string, map<string, uint32_t* > >::iterator it1;
248 map<string, uint32_t* >::iterator it2;
249 cout<<"(_Color table:_)"<<endl;
250 for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ )
251 {
252 out << (*it1).first;
253 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ )
254 {
255 out <<" "<< (*it2).first <<" ";
256 for (int i = 0 ; i < 3; i++ )
257 {
258 out.width(3);
259 out << (*it2).second[i]<<" ";
260 out.fill('0');
261 }
262 out<<endl;
263 }
264 }
265
266}
267#endif
268
269/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cpixmap.h b/ue2/imgsynth2/cpixmap.h
new file mode 100644
index 0000000..eb219aa
--- /dev/null
+++ b/ue2/imgsynth2/cpixmap.h
@@ -0,0 +1,166 @@
1/**
2 * @module CPixmap
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Implementation of CFile CBitmap handling XPM.
5 * @date 27.04.2009
6 */
7
8#ifndef CPixmap_H
9#define CPixmap_H
10
11#include <stdint.h>
12#include "cbitmap.h"
13
14/**
15 * @class CPixmap
16 * @brief Implementation of CFile handling Pixmap file format.
17 *
18 * In order to support operations on pixmaps in color mode an
19 * implementations of CPixelFormat is used. These classe are
20 * allowed to modify the pixmap header, pixelbuffer and color table directly.
21 *
22 * On error CFile::FileError is thrown.
23 */
24class CPixmap : public CBitmap
25{
26 public:
27 /**
28 * @method CPixmap
29 * @brief Default ctor
30 * @param -
31 * @return -
32 * @globalvars none
33 * @exception none
34 * @conditions none
35 */
36 CPixmap();
37
38 /**
39 * @method ~CPixmap
40 * @brief Default dtor
41 * @param -
42 * @return -
43 * @globalvars none
44 * @exception none
45 * @conditions none
46 */
47 ~CPixmap()
48 {}
49
50 /**
51 * @method read
52 * @brief Reads Pixmap from filestream.
53 * On error an exception is thrown.
54 * @param in filestream to read data from
55 * @return -
56 * @globalvars none
57 * @exception CFile::FileError
58 * @exception bad_alloc
59 * @conditions none
60 */
61 void read(std::ifstream& in);
62
63 /**
64 * @method write
65 * @brief Writes Pixmap to filestream.
66 * @param out filestream to read data from
67 * @return -
68 * @globalvars none
69 * @exception FileError
70 * @exception bad_alloc
71 * @conditions none
72 */
73 void write(std::ofstream& out, std::string& filename);
74
75#ifdef DEBUG
76 /**
77 * @method dump
78 * @brief Dumps the Pixmap file header and pixel data to ostream
79 * @param out output stream
80 * @return -
81 * @globalvars
82 * @exception
83 * @conditions
84 */
85 void dump(std::ostream& out);
86#endif
87
88 /**
89 * @brief Pixmap Header structure
90 */
91#pragma pack(push,1)
92 typedef struct
93 {
94 /** the xpm width in pixels (signed integer) */
95 uint32_t xpmWidth;
96 /** the xpm height in pixels (signed integer) */
97 uint32_t xpmHeight;
98 /** the number of colors (signed integer) */
99 uint32_t nColor;
100 /** the number of characters per pixel (signed integer) */
101 uint32_t nChar;
102 /** X-Position Hotspots */
103 uint32_t xHotspot;
104 /** Y-Position Hotspots */
105 uint32_t yHotspot;
106 /* is hotspot set */
107 bool _HOTSPOT;
108 /* XPMEXT extension tag found*/
109 bool _XPMEXT;
110 /* unchanged extension */
111 std::string extension;
112 } PIXMAP_FILEHEADER;
113#pragma pack(pop)
114
115 /* TODO */
116 const uint32_t getPixelDataSize()
117 {
118 return m_fileheader.xpmWidth * m_fileheader.xpmHeight * m_fileheader.nChar;
119 }
120
121 /* TODO */
122 const uint32_t getHeight()
123 {
124 /* width and height can be negativ */
125 return m_fileheader.xpmHeight;
126 }
127
128 /* TODO */
129 const uint32_t getWidth()
130 {
131 /* width and height can be negativ */
132 return m_fileheader.xpmWidth;
133 }
134
135 /**
136 * @method hasColorTable
137 * @brief Check if bitmap has a colortable
138 * (we don't support this yet for windows bitmaps)
139 * @param -
140 * @return true if bitmap has a colortable. false otherwise
141 * @globalvars none
142 * @exception none
143 * @conditions none
144 */
145 const bool hasColorTable()
146 {
147 return true;
148 }
149
150 /* TODO */
151 const bool isMirrored()
152 {
153 /* pixmap is never mirrored */
154 return false;
155 }
156
157 protected:
158 /* members */
159 /** fileheader */
160 PIXMAP_FILEHEADER m_fileheader;
161 /** infoheader */
162};
163
164#endif
165
166/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cscriptparser.cpp b/ue2/imgsynth2/cscriptparser.cpp
index 46a7c42..17ff5a4 100644
--- a/ue2/imgsynth2/cscriptparser.cpp
+++ b/ue2/imgsynth2/cscriptparser.cpp
@@ -10,6 +10,7 @@
10#include <boost/algorithm/string.hpp> 10#include <boost/algorithm/string.hpp>
11#include "cscriptparser.h" 11#include "cscriptparser.h"
12#include "cwindowsbitmap.h" 12#include "cwindowsbitmap.h"
13#include "cpixmap.h"
13 14
14using namespace std; 15using namespace std;
15using namespace boost; 16using namespace boost;
@@ -19,6 +20,7 @@ CScriptparser::CScriptparser(const std::string& scriptfile)
19{ 20{
20 /* add our handlers */ 21 /* add our handlers */
21 m_handlers.insert(new CWindowsBitmap); 22 m_handlers.insert(new CWindowsBitmap);
23 m_handlers.insert(new CPixmap);
22} 24}
23 25
24/*----------------------------------------------------------------------------*/ 26/*----------------------------------------------------------------------------*/
diff --git a/ue2/imgsynth2/test/input_yellow_man1_indexed8 b/ue2/imgsynth2/test/input_yellow_man1_indexed8
new file mode 100644
index 0000000..997cd4f
--- /dev/null
+++ b/ue2/imgsynth2/test/input_yellow_man1_indexed8
@@ -0,0 +1,10 @@
1#in: test/yellow_man1_xpm_in.xpm
2#out: test/yellow_man1_xpm_out.xpm
3#ref: test/yellow_man1_xpm_ref.xpm
4
5read(XPM, test/yellow_man1_indexed8_in.xpm)
6
7#fillrect(0,3,6,5,0,255,0)
8#fillrect(2,13,7,4,0,0,255)
9
10write(XPM, test/yellow_man1_indexed8_out.xpm)
diff --git a/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm b/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm
new file mode 100644
index 0000000..6e5fa2c
--- /dev/null
+++ b/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm
@@ -0,0 +1,27 @@
1/* XPM */
2static char * yellow_man1_default_xpm[] = {
3"9 17 2 1 0 0 XPMEXT",
4". c #000000",
5"# c #FFF200",
6".........",
7".........",
8"...###...",
9"...###...",
10"...###...",
11"....#....",
12"..#####..",
13".#.###.#.",
14".#.###.#.",
15".#.###.#.",
16".#.###.#.",
17"...#.#...",
18"...#.#...",
19"...#.#...",
20"...#.#...",
21".........",
22"........."
23"XPMEXT ext1 data1",
24"XPMEXT ext2",
25"data2_1",
26"data2_2",
27"XPMENDEXT"};
diff --git a/ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm b/ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm
new file mode 100644
index 0000000..57db73d
--- /dev/null
+++ b/ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm
@@ -0,0 +1,24 @@
1/* XPM */
2static char * yellow_man1_rgb24_ref_xpm[] = {
3"9 17 4 1",
4". c #000000",
5"# c #FFF200",
6"+ c #00FF00",
7"@ c #0000FF",
8".........",
9".........",
10"...###...",
11"++++++...",
12"++++++...",
13"++++++...",
14"++++++#..",
15"++++++.#.",
16".#.###.#.",
17".#.###.#.",
18".#.###.#.",
19"...#.#...",
20"...#.#...",
21"..@@@@@@@",
22"..@@@@@@@",
23"..@@@@@@@",
24"..@@@@@@@"};