diff options
Diffstat (limited to 'ue2/imgsynth2/cpixmap.cpp')
| -rw-r--r-- | ue2/imgsynth2/cpixmap.cpp | 172 |
1 files changed, 172 insertions, 0 deletions
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 | |||
| 19 | using namespace std; | ||
| 20 | |||
| 21 | CPixMap::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 | |||
| 34 | void 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 | |||
| 125 | void 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 | ||
| 140 | void 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: */ | ||
