summaryrefslogtreecommitdiffstats
path: root/ue2
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
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')
-rw-r--r--ue2/imgsynth2/cpixmap.cpp163
-rw-r--r--ue2/imgsynth2/cpixmap.h162
-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
5 files changed, 381 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: */
diff --git a/ue2/imgsynth2/cpixmap.h b/ue2/imgsynth2/cpixmap.h
new file mode 100644
index 0000000..6e147ed
--- /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<unsigned const char, std::map< std::string, std::string > > xpmColors;
116
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/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"..@@@@@@@"};