summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2
diff options
context:
space:
mode:
Diffstat (limited to 'ue2/imgsynth2')
-rw-r--r--ue2/imgsynth2/Makefile6
-rw-r--r--ue2/imgsynth2/cpixmap.cpp172
-rw-r--r--ue2/imgsynth2/cpixmap.h162
-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.xpm22
-rw-r--r--ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm24
7 files changed, 396 insertions, 2 deletions
diff --git a/ue2/imgsynth2/Makefile b/ue2/imgsynth2/Makefile
index 22e53e5..8c3079d 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/cpixmap.cpp b/ue2/imgsynth2/cpixmap.cpp
new file mode 100644
index 0000000..de9ec94
--- /dev/null
+++ b/ue2/imgsynth2/cpixmap.cpp
@@ -0,0 +1,172 @@
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 m_fileheader.xpmColors[character] = colors;
76
77 getline( in, str, '"' );
78 }
79
80
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)
99 {
100 if (m_pixeldata != NULL)
101 delete[] m_pixeldata;
102 m_pixeldata = new uint8_t[getPixelDataSize()];
103
104 /* parse the pixel data */
105 for (unsigned int y = 0; y < getHeight(); y++ )
106 {
107 for (unsigned int x = 0; x < getWidth(); x++ )
108 m_pixeldata[y * getWidth() + x] = static_cast<uint8_t>(in.get());
109
110 getline( in, str);
111 if ( y != ( getHeight() - 1 ))
112 in.get();
113
114 }
115 }
116
117 /* debug*/
118 CPixMap::dump (cout);
119
120
121}
122
123/*----------------------------------------------------------------------------*/
124
125void CPixMap::write(std::ofstream& out)
126{
127 out<<"/* XPM */"<<endl;
128 out<<"static char * yellow_man1_default_xpm[] = {"<<endl;
129 out<<"\""<<m_fileheader.xpmWidth<<" "<<m_fileheader.xpmHeight
130 <<" "<<m_fileheader.nColor<<" "<<m_fileheader.nChar<<"\","<<endl;
131
132
133 dump(out);
134}
135
136
137/*----------------------------------------------------------------------------*/
138
139#ifdef DEBUG
140void CPixMap::dump(std::ostream& out)
141{
142
143 /* values*/
144 out
145 << "XPM Header:" << endl
146 << ", xpmWidth=" << m_fileheader.xpmWidth<< endl
147 << ", xpmHeight=" << m_fileheader.xpmHeight<< endl
148 << ", nColor=" << m_fileheader.nColor<< endl
149 << ", nChar=" << m_fileheader.nChar<< endl
150 << endl;
151
152 /* colors*/
153 map<unsigned const char, map<std::string, std::string > >::iterator it1;
154 map<std::string, std::string >::iterator it2;
155 for ( it1=m_fileheader.xpmColors.begin() ; it1 != m_fileheader.xpmColors.end(); it1++ )
156 {
157 out << (*it1).first ;
158 for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ )
159 out << (*it2).first <<" > "<< (*it2).second<<endl;
160 }
161
162 /* pixeldata */
163 for (unsigned int y = 0; y < getHeight(); y++ ){
164 for (unsigned int x = 0; x < getWidth(); x++ )
165 out << m_pixeldata[y * getWidth() + x];
166 out << endl;
167 }
168
169}
170#endif
171
172/* 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..c7537cd
--- /dev/null
+++ b/ue2/imgsynth2/cpixmap.h
@@ -0,0 +1,162 @@
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 <map>
13#include "cbitmap.h"
14
15
16/**
17 * @class CBitmap
18 * @brief Implementation of CFile handling Windows Bitmaps.
19 *
20 * In order to support operations on bitmaps with different color bitcounts
21 * different implementations of CPixelFormat are used. These classes are
22 * allowed to modify the bitmap headers and pixelbuffer directly.
23 *
24 * On error CFile::FileError is thrown.
25 */
26class CPixMap : public CBitmap
27{
28 public:
29 /**
30 * @method CPixMap
31 * @brief Default ctor
32 * @param -
33 * @return -
34 * @globalvars none
35 * @exception none
36 * @conditions none
37 */
38 CPixMap();
39
40 /**
41 * @method ~CPixMap
42 * @brief Default dtor
43 * @param -
44 * @return -
45 * @globalvars none
46 * @exception none
47 * @conditions none
48 */
49 ~CPixMap()
50 {}
51
52 /**
53 * @method read
54 * @brief Reads Windows Bitmap from filestream.
55 * On error an exception is thrown.
56 * @param in filestream to read data from
57 * @return -
58 * @globalvars none
59 * @exception CFile::FileError
60 * @exception bad_alloc
61 * @conditions none
62 */
63 void read(std::ifstream& in);
64
65 /**
66 * @method write
67 * @brief Writes Windows Bitmap to filestream.
68 * @param out filestream to read data from
69 * @return -
70 * @globalvars none
71 * @exception FileError
72 * @exception bad_alloc
73 * @conditions none
74 */
75
76 void write(std::ofstream& out);
77#ifdef DEBUG
78 /**
79 * @method dump
80 * @brief Dumps the Windows Bitmap file headers to ostream
81 * @param out output stream
82 * @return -
83 * @globalvars
84 * @exception
85 * @conditions
86 */
87 void dump(std::ostream& out);
88#endif
89
90
91
92 /**
93 * @brief Windows Bitmap Info Header structure
94 */
95#pragma pack(push,1)
96 typedef struct
97 {
98 /** the xpm width in pixels (signed integer) */
99 uint32_t xpmWidth;
100 /** the xpm height in pixels (signed integer) */
101 uint32_t xpmHeight;
102 /** the number of colors (signed integer) */
103 uint32_t nColor;
104
105 /** the number of characters per pixel (signed integer) */
106 uint32_t nChar;
107
108 /** X-Position Hotspots */
109 uint32_t xHotspot;
110
111 /** Y-Position Hotspots */
112 uint32_t yHotspot;
113
114 /* color tables*/
115 // std::map<std::string, std::map< std::string, std::string > > xpmColors;
116 // std::map<std::string, uint32_t[3]> xpmColors;
117
118
119 } PIXMAP_FILEHEADER;
120#pragma pack(pop)
121
122 /* TODO */
123 const uint32_t getPixelDataSize()
124 {
125 return m_fileheader.xpmWidth *
126 m_fileheader.xpmHeight *
127 m_fileheader.nChar;
128 }
129
130 /* TODO */
131 const uint32_t getHeight()
132 {
133 /* width and height can be negativ */
134 return m_fileheader.xpmHeight;
135 }
136
137 /* TODO */
138 const uint32_t getWidth()
139 {
140 /* width and height can be negativ */
141 return m_fileheader.xpmWidth;
142 }
143
144 /* TODO */
145 const bool isMirrored()
146 {
147 /* pixmap is never mirrored */
148 return false;
149 }
150
151 protected:
152 /* members */
153 /** fileheader */
154 PIXMAP_FILEHEADER m_fileheader;
155 /** infoheader */
156
157
158};
159
160#endif
161
162/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cscriptparser.cpp b/ue2/imgsynth2/cscriptparser.cpp
index 46a7c42..e6bc9ae 100644
--- a/ue2/imgsynth2/cscriptparser.cpp
+++ b/ue2/imgsynth2/cscriptparser.cpp
@@ -9,6 +9,7 @@
9#include <boost/tokenizer.hpp> 9#include <boost/tokenizer.hpp>
10#include <boost/algorithm/string.hpp> 10#include <boost/algorithm/string.hpp>
11#include "cscriptparser.h" 11#include "cscriptparser.h"
12#include "cpixmap.h"
12#include "cwindowsbitmap.h" 13#include "cwindowsbitmap.h"
13 14
14using namespace std; 15using namespace std;
@@ -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..cbfe217
--- /dev/null
+++ b/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm
@@ -0,0 +1,22 @@
1/* XPM */
2static char * yellow_man1_default_xpm[] = {
3"9 17 2 1",
4". c #000000",
5"# c #FFF200",
6".........",
7".........",
8"...###...",
9"...###...",
10"...###...",
11"....#....",
12"..#####..",
13".#.###.#.",
14".#.###.#.",
15".#.###.#.",
16".#.###.#.",
17"...#.#...",
18"...#.#...",
19"...#.#...",
20"...#.#...",
21".........",
22"........."};
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"..@@@@@@@"};