diff options
| author | manuel <manuel@nc8430.lan> | 2009-05-01 20:18:51 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-05-01 20:18:51 +0200 |
| commit | b9ce1555b2baf9be209775dbd4c8b217db5cd735 (patch) | |
| tree | 9c4b74f4a3f9e323e6d799313f9f59dd7b940fb4 | |
| parent | 6431d84ffec82db10030d918cfed8e791e62f42c (diff) | |
| download | ooprog-b9ce1555b2baf9be209775dbd4c8b217db5cd735.tar.gz ooprog-b9ce1555b2baf9be209775dbd4c8b217db5cd735.tar.bz2 ooprog-b9ce1555b2baf9be209775dbd4c8b217db5cd735.zip | |
rewrote pixmap::read to do more sanity checks
| -rw-r--r-- | ue2/imgsynth2/cbitmap.cpp | 25 | ||||
| -rw-r--r-- | ue2/imgsynth2/cbitmap.h | 6 | ||||
| -rw-r--r-- | ue2/imgsynth2/cfile.h | 3 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_indexed8.h | 14 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixmap.cpp | 422 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixmap.h | 71 | ||||
| -rw-r--r-- | ue2/imgsynth2/cscriptparser.cpp | 2 | ||||
| -rw-r--r-- | ue2/imgsynth2/cwindowsbitmap.cpp | 2 | ||||
| -rw-r--r-- | ue2/imgsynth2/cwindowsbitmap.h | 129 | ||||
| -rw-r--r-- | ue2/imgsynth2/test/input_yellow_man1_indexed8 | 6 | ||||
| -rw-r--r-- | ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm | 4 | ||||
| -rw-r--r-- | ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm | 4 |
12 files changed, 351 insertions, 337 deletions
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp index ed26600..c2cd99a 100644 --- a/ue2/imgsynth2/cbitmap.cpp +++ b/ue2/imgsynth2/cbitmap.cpp | |||
| @@ -28,18 +28,9 @@ CBitmap::~CBitmap() | |||
| 28 | m_pixelformat = NULL; | 28 | m_pixelformat = NULL; |
| 29 | 29 | ||
| 30 | /* delete colortable content */ | 30 | /* delete colortable content */ |
| 31 | //TODO | 31 | map<string, CPixelFormat::RGBPIXEL *>::iterator it2; |
| 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 | } | ||
| 43 | } | 34 | } |
| 44 | 35 | ||
| 45 | /*----------------------------------------------------------------------------*/ | 36 | /*----------------------------------------------------------------------------*/ |
| @@ -153,13 +144,12 @@ void CBitmap::invert(std::list<std::string> params) | |||
| 153 | { | 144 | { |
| 154 | /* invert every entry in the colortable */ | 145 | /* invert every entry in the colortable */ |
| 155 | map<string, CPixelFormat::RGBPIXEL *>::iterator it; | 146 | map<string, CPixelFormat::RGBPIXEL *>::iterator it; |
| 156 | //TODO | 147 | for (it = m_colortable.begin(); it != m_colortable.end(); it++) |
| 157 | /*for (it = m_colortable.begin(); it != m_colortable.end(); it++) | ||
| 158 | { | 148 | { |
| 159 | (*it).second->red = max.red - (*it).second->red; | 149 | (*it).second->red = max.red - (*it).second->red; |
| 160 | (*it).second->green = max.green - (*it).second->green; | 150 | (*it).second->green = max.green - (*it).second->green; |
| 161 | (*it).second->blue = max.blue - (*it).second->blue; | 151 | (*it).second->blue = max.blue - (*it).second->blue; |
| 162 | }*/ | 152 | } |
| 163 | } | 153 | } |
| 164 | else | 154 | else |
| 165 | { | 155 | { |
| @@ -223,13 +213,12 @@ void CBitmap::brightness(std::list<std::string> params) | |||
| 223 | { | 213 | { |
| 224 | /* invert every entry in the colortable */ | 214 | /* invert every entry in the colortable */ |
| 225 | map<string, CPixelFormat::RGBPIXEL *>::iterator it; | 215 | map<string, CPixelFormat::RGBPIXEL *>::iterator it; |
| 226 | //TODO | 216 | for (it = m_colortable.begin(); it != m_colortable.end(); it++) |
| 227 | /*for (it = m_colortable.begin(); it != m_colortable.end(); it++) | ||
| 228 | { | 217 | { |
| 229 | (*it).second->red = min(max.red, static_cast<uint32_t>((*it).second->red * factor)); | 218 | (*it).second->red = min(max.red, static_cast<uint32_t>((*it).second->red * factor)); |
| 230 | (*it).second->green = min(max.green, static_cast<uint32_t>((*it).second->green * factor)); | 219 | (*it).second->green = min(max.green, static_cast<uint32_t>((*it).second->green * factor)); |
| 231 | (*it).second->blue = min(max.blue, static_cast<uint32_t>((*it).second->blue * factor)); | 220 | (*it).second->blue = min(max.blue, static_cast<uint32_t>((*it).second->blue * factor)); |
| 232 | }*/ | 221 | } |
| 233 | } | 222 | } |
| 234 | else | 223 | else |
| 235 | { | 224 | { |
diff --git a/ue2/imgsynth2/cbitmap.h b/ue2/imgsynth2/cbitmap.h index c8d4dfb..f48ada7 100644 --- a/ue2/imgsynth2/cbitmap.h +++ b/ue2/imgsynth2/cbitmap.h | |||
| @@ -68,14 +68,13 @@ class CBitmap : public CFile | |||
| 68 | * @method write | 68 | * @method write |
| 69 | * @brief Writes Windows Bitmap to filestream. | 69 | * @brief Writes Windows Bitmap to filestream. |
| 70 | * @param out filestream to read data from | 70 | * @param out filestream to read data from |
| 71 | * @param filename filename (maybe useful for some handlers) | ||
| 72 | * @return - | 71 | * @return - |
| 73 | * @globalvars none | 72 | * @globalvars none |
| 74 | * @exception FileError | 73 | * @exception FileError |
| 75 | * @exception bad_alloc | 74 | * @exception bad_alloc |
| 76 | * @conditions none | 75 | * @conditions none |
| 77 | */ | 76 | */ |
| 78 | virtual void write(std::ofstream& out, std::string& filename) = 0; | 77 | virtual void write(std::ofstream& out) = 0; |
| 79 | 78 | ||
| 80 | /** | 79 | /** |
| 81 | * @method getPixelData | 80 | * @method getPixelData |
| @@ -231,8 +230,7 @@ class CBitmap : public CFile | |||
| 231 | /** pointer to pixelbuffer */ | 230 | /** pointer to pixelbuffer */ |
| 232 | uint8_t *m_pixeldata; | 231 | uint8_t *m_pixeldata; |
| 233 | /** colortable map */ | 232 | /** colortable map */ |
| 234 | //TODO std::map<std::string, CPixelFormat::RGBPIXEL *> m_colortable; | 233 | std::map<std::string, CPixelFormat::RGBPIXEL *> m_colortable; |
| 235 | std::map<std::string, std::map< std::string, uint32_t* > > xpmColors; | ||
| 236 | /** set of supported PixelFormat handlers */ | 234 | /** set of supported PixelFormat handlers */ |
| 237 | std::set<CPixelFormat *> m_handlers; | 235 | std::set<CPixelFormat *> m_handlers; |
| 238 | /** pointer to CPixelFormat implementation */ | 236 | /** pointer to CPixelFormat implementation */ |
diff --git a/ue2/imgsynth2/cfile.h b/ue2/imgsynth2/cfile.h index 9513a2c..020ce65 100644 --- a/ue2/imgsynth2/cfile.h +++ b/ue2/imgsynth2/cfile.h | |||
| @@ -76,13 +76,12 @@ class CFile | |||
| 76 | * @method write | 76 | * @method write |
| 77 | * @brief Pure virtual method (interface). Should write data to filestream. | 77 | * @brief Pure virtual method (interface). Should write data to filestream. |
| 78 | * @param out filestream to write data to | 78 | * @param out filestream to write data to |
| 79 | * @param filename filename (maybe useful for some handlers) | ||
| 80 | * @return - | 79 | * @return - |
| 81 | * @globalvars none | 80 | * @globalvars none |
| 82 | * @exception FileError | 81 | * @exception FileError |
| 83 | * @conditions none | 82 | * @conditions none |
| 84 | */ | 83 | */ |
| 85 | virtual void write(std::ofstream& out, std::string& filename) = 0; | 84 | virtual void write(std::ofstream& out) = 0; |
| 86 | 85 | ||
| 87 | /** | 86 | /** |
| 88 | * @method callFunc | 87 | * @method callFunc |
diff --git a/ue2/imgsynth2/cpixelformat_indexed8.h b/ue2/imgsynth2/cpixelformat_indexed8.h index 2e2fc01..3b29bf8 100644 --- a/ue2/imgsynth2/cpixelformat_indexed8.h +++ b/ue2/imgsynth2/cpixelformat_indexed8.h | |||
| @@ -86,20 +86,6 @@ class CPixelFormat_Indexed8 : public CPixelFormat | |||
| 86 | return 8; | 86 | return 8; |
| 87 | } | 87 | } |
| 88 | 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 | /** | 89 | /** |
| 104 | * @method getMaxColor | 90 | * @method getMaxColor |
| 105 | * @brief Get maximum values for RGB pixel | 91 | * @brief Get maximum values for RGB pixel |
diff --git a/ue2/imgsynth2/cpixmap.cpp b/ue2/imgsynth2/cpixmap.cpp index 6f8c8d6..d3e10d8 100644 --- a/ue2/imgsynth2/cpixmap.cpp +++ b/ue2/imgsynth2/cpixmap.cpp | |||
| @@ -5,25 +5,23 @@ | |||
| 5 | * @date 27.04.2009 | 5 | * @date 27.04.2009 |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include <sstream> | ||
| 9 | #include <iomanip> | ||
| 10 | #include <vector> | ||
| 11 | #include <boost/algorithm/string/split.hpp> | ||
| 12 | #include <boost/algorithm/string.hpp> | ||
| 8 | #include <boost/lexical_cast.hpp> | 13 | #include <boost/lexical_cast.hpp> |
| 9 | #include <boost/numeric/conversion/cast.hpp> | ||
| 10 | |||
| 11 | #ifdef DEBUG | 14 | #ifdef DEBUG |
| 12 | # include <iostream> | 15 | # include <iostream> |
| 13 | #endif | 16 | #endif |
| 14 | #include <cstdlib> | ||
| 15 | #include <stdint.h> | ||
| 16 | # include <string> | ||
| 17 | # include <map> | ||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | #include "cpixmap.h" | 17 | #include "cpixmap.h" |
| 22 | #include "cpixelformat_indexed8.h" | 18 | #include "cpixelformat_indexed8.h" |
| 23 | 19 | ||
| 24 | using namespace std; | 20 | using namespace std; |
| 21 | using namespace boost; | ||
| 25 | 22 | ||
| 26 | CPixmap::CPixmap() | 23 | CPixmap::CPixmap() |
| 24 | : m_imagename("") | ||
| 27 | { | 25 | { |
| 28 | m_types.insert("XPM"); | 26 | m_types.insert("XPM"); |
| 29 | 27 | ||
| @@ -33,236 +31,302 @@ CPixmap::CPixmap() | |||
| 33 | 31 | ||
| 34 | /*----------------------------------------------------------------------------*/ | 32 | /*----------------------------------------------------------------------------*/ |
| 35 | 33 | ||
| 36 | void CPixmap::read(std::ifstream& in) | 34 | std::string CPixmap::getLine(std::ifstream& in, bool ignore_comments) |
| 37 | { | 35 | { |
| 36 | string line(""); | ||
| 37 | while(!in.eof() && in.good()) | ||
| 38 | { | ||
| 39 | getline(in, line); | ||
| 40 | trim(line); | ||
| 41 | /* ignore simple ansi c comments. only one-liners */ | ||
| 42 | if (ignore_comments && line.find_first_of("/*") == 0) | ||
| 43 | continue; | ||
| 44 | if (!line.empty()) | ||
| 45 | break; | ||
| 46 | } | ||
| 47 | return line; | ||
| 48 | } | ||
| 38 | 49 | ||
| 39 | string str; | 50 | /*----------------------------------------------------------------------------*/ |
| 40 | m_fileheader._XPMEXT = false; | ||
| 41 | m_fileheader._HOTSPOT = false; | ||
| 42 | 51 | ||
| 43 | /* parse the values section */ | 52 | std::string CPixmap::getArrayLine(std::ifstream& in, bool ignore_comments) |
| 44 | getline( in, str, '"'); | 53 | { |
| 45 | getline( in, str, '"'); | 54 | string line = getLine(in, ignore_comments); |
| 46 | stringstream istr (str ); | 55 | if (line.empty()) |
| 56 | return line; | ||
| 57 | |||
| 58 | /* this stuff isn't correct too, but we are no c-parser anyway */ | ||
| 59 | if (line[0] != '"') | ||
| 60 | throw FileError("Pixmap array has invalid c-syntax."); | ||
| 61 | if (line[line.length() - 1] != ',' && line[line.length() - 1] != '}') | ||
| 62 | throw FileError("Pixmap array has invalid c-syntax."); | ||
| 63 | size_t end = line.find_last_of("\""); | ||
| 64 | if (end == string::npos) | ||
| 65 | throw FileError("Pixmap array has invalid c-syntax."); | ||
| 66 | |||
| 67 | return line.substr(1, end - 1); | ||
| 68 | } | ||
| 47 | 69 | ||
| 48 | istr >> m_fileheader.xpmWidth ; | 70 | /*----------------------------------------------------------------------------*/ |
| 49 | istr >> m_fileheader.xpmHeight ; | 71 | |
| 50 | istr >> m_fileheader.nColor ; | 72 | void CPixmap::read(std::ifstream& in) |
| 51 | istr >> m_fileheader.nChar ; | 73 | { |
| 74 | /* | ||
| 75 | * <C-Comment> XPM <C-Comment> | ||
| 76 | * static char * <pixmap_name>[] = { | ||
| 77 | * <Values> | ||
| 78 | * <Colors> | ||
| 79 | * <Pixels> | ||
| 80 | * <Extensions> | ||
| 81 | * }; | ||
| 82 | */ | ||
| 83 | |||
| 84 | string line, tmp; | ||
| 85 | stringstream istr; | ||
| 86 | std::vector<std::string> list; | ||
| 87 | m_fileheader._XPMEXT = false; | ||
| 88 | m_fileheader._HOTSPOT = false; | ||
| 52 | 89 | ||
| 53 | /*optional values */ | 90 | /* first line has to be PIXMAP_IDENTIFIER */ |
| 54 | if (istr.good()) | 91 | line = getLine(in, false); |
| 92 | if (line != PIXMAP_IDENTIFIER) | ||
| 93 | throw FileError("Pixmap has no identifier."); | ||
| 94 | |||
| 95 | /* second line is a c array. we don't do much syntax checking */ | ||
| 96 | line = getLine(in); | ||
| 97 | istr.str(line); | ||
| 98 | while(m_imagename.empty() && !istr.eof() && istr.good()) | ||
| 55 | { | 99 | { |
| 56 | string tmp; | 100 | size_t end; |
| 57 | istr >> tmp; | 101 | istr >> tmp; |
| 58 | if(tmp.compare("XPMEXT") == 0) | 102 | if ((end = tmp.find_first_of("[]")) != string::npos) |
| 59 | m_fileheader._XPMEXT = true; | ||
| 60 | else | ||
| 61 | { | 103 | { |
| 62 | m_fileheader._HOTSPOT = true; | 104 | /* <xxx>*<imagename>[]<yyy> */ |
| 63 | m_fileheader.xHotspot = static_cast<unsigned int>(strtoul(tmp.c_str(), NULL, 16)); | 105 | size_t start = tmp.find_first_of('*'); |
| 64 | istr >> m_fileheader.yHotspot; | 106 | start = (start == string::npos) ? 0 : start + 1; |
| 107 | m_imagename = tmp.substr(start, end - start); | ||
| 65 | } | 108 | } |
| 66 | if (istr.good()) | 109 | } |
| 110 | if (m_imagename.empty()) | ||
| 111 | throw FileError("Pixmap has no imagename."); | ||
| 112 | |||
| 113 | /* additional: check "{" exists */ | ||
| 114 | if (line[line.length() - 1] != '{') | ||
| 115 | throw FileError("Pixmap array has no opening bracket."); | ||
| 116 | |||
| 117 | /* parse <Values>-section */ | ||
| 118 | line = getArrayLine(in); | ||
| 119 | if (line.empty()) | ||
| 120 | throw FileError("Pixmap has no Values-section."); | ||
| 121 | algorithm::split(list, line, is_any_of(" \t")); | ||
| 122 | if (list.size() < 4) | ||
| 123 | throw FileError("Pixmap has invalid Values-section."); | ||
| 124 | try | ||
| 125 | { | ||
| 126 | m_fileheader.width = lexical_cast<uint32_t>(list[0]); | ||
| 127 | m_fileheader.height = lexical_cast<uint32_t>(list[1]); | ||
| 128 | m_fileheader.nColor = lexical_cast<uint32_t>(list[2]); | ||
| 129 | m_fileheader.nChar = lexical_cast<uint32_t>(list[3]); | ||
| 130 | |||
| 131 | if (list.size() > 4) | ||
| 67 | { | 132 | { |
| 68 | istr >> tmp; | 133 | if (list.size() >= 6) |
| 69 | if (tmp.compare("XPMEXT") == 0) | 134 | { |
| 70 | m_fileheader._XPMEXT = true; | 135 | m_fileheader._HOTSPOT = true; |
| 136 | m_fileheader.xHotspot = lexical_cast<uint32_t>(list[4]); | ||
| 137 | m_fileheader.yHotspot = lexical_cast<uint32_t>(list[5]); | ||
| 138 | } | ||
| 139 | if (list.size() != 6) | ||
| 140 | { | ||
| 141 | if (list[list.size() - 1] != "XPMEXT") | ||
| 142 | throw FileError("Unknown parameter count in Values-Section."); | ||
| 143 | else | ||
| 144 | m_fileheader._XPMEXT = true; | ||
| 145 | } | ||
| 71 | } | 146 | } |
| 72 | } | 147 | } |
| 148 | catch(bad_lexical_cast& ex) | ||
| 149 | { | ||
| 150 | throw FileError("Value of Values-section is invalid: " + string(ex.what())); | ||
| 151 | } | ||
| 73 | 152 | ||
| 153 | /* parse <Colors>-table */ | ||
| 154 | string character; | ||
| 155 | map<string, CPixelFormat::RGBPIXEL *> colors; | ||
| 156 | for(uint32_t i = 0; i < m_fileheader.nColor; i++) | ||
| 157 | { | ||
| 158 | line = getArrayLine(in); | ||
| 159 | if (line.empty()) | ||
| 160 | throw FileError("Pixmap has missing colortable-entry."); | ||
| 161 | algorithm::split(list, line, is_any_of(" \t")); | ||
| 162 | if (list.size() < 3) | ||
| 163 | throw FileError("Pixmap colortable-entry is invalid."); | ||
| 164 | |||
| 165 | /* read pixel character */ | ||
| 166 | character = list[0]; | ||
| 167 | if (character.length() != m_fileheader.nChar) | ||
| 168 | throw FileError("Pixmap colorcharacter is invalid."); | ||
| 169 | |||
| 170 | /* read colors */ | ||
| 171 | string color(""); | ||
| 172 | if ((list.size() - 1) % 2 != 0) | ||
| 173 | throw FileError("Pixmap color entrys are invalid."); | ||
| 174 | for(uint32_t j = 1; j < list.size(); j = j + 2) | ||
| 175 | { | ||
| 176 | if (list[j + 1].length() != 7) | ||
| 177 | throw FileError("Pixmap color value is invalid."); | ||
| 178 | if (list[j + 1].at(0) != '#') | ||
| 179 | throw FileError("Pixmap color table value is not hexadecimal."); | ||
| 180 | |||
| 181 | /* we only support c-colors! */ | ||
| 182 | if (list[j] != "c") | ||
| 183 | continue; | ||
| 184 | |||
| 185 | CPixelFormat::RGBPIXEL *pixel = new CPixelFormat::RGBPIXEL; | ||
| 186 | pixel->red = strtoul(list[j + 1].substr(1, 2).c_str(), NULL, 16); | ||
| 187 | pixel->green = strtoul(list[j + 1].substr(3, 2).c_str(), NULL, 16); | ||
| 188 | pixel->blue = strtoul(list[j + 1].substr(5, 2).c_str(), NULL, 16); | ||
| 189 | colors[ list[j] ] = pixel; | ||
| 190 | } | ||
| 74 | 191 | ||
| 192 | /* we only support c-colors! */ | ||
| 193 | if (colors.find("c") == colors.end()) | ||
| 194 | throw FileError("Pixmap color entry has missing c-value."); | ||
| 75 | 195 | ||
| 76 | /* parse color table*/ | 196 | /* add pixel to colortable */ |
| 77 | getline( in, str, '"'); | 197 | m_colortable[character] = colors["c"]; |
| 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 | } | 198 | } |
| 111 | 199 | ||
| 112 | /* read pixel data using separate class */ | 200 | /* read pixel data */ |
| 113 | if (getPixelDataSize() > 0) | 201 | if (getPixelDataSize() > 0) |
| 114 | { | 202 | { |
| 115 | if (m_pixeldata != NULL) | 203 | if (m_pixeldata != NULL) |
| 116 | delete[] m_pixeldata; | 204 | delete[] m_pixeldata; |
| 117 | m_pixeldata = new uint8_t[getPixelDataSize()]; | 205 | 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 | 206 | ||
| 124 | getline( in, str); | 207 | for (uint32_t y = 0; y < getHeight(); y++) |
| 125 | if ( y != ( getHeight() - 1 )) | 208 | { |
| 126 | in.get(); | 209 | line = getArrayLine(in); |
| 127 | 210 | if (line.empty()) | |
| 211 | throw FileError("Pixmap has no pixel data."); | ||
| 212 | if (line.length() != getWidth()) | ||
| 213 | throw FileError("Pixmap pixeldata width is larger than header width."); | ||
| 214 | copy(line.c_str(), line.c_str() + line.length(), m_pixeldata + y * getWidth()); | ||
| 128 | } | 215 | } |
| 129 | } | 216 | } |
| 130 | 217 | ||
| 131 | /* parse extension */ | 218 | /* get extension */ |
| 132 | if ( m_fileheader._XPMEXT ) | 219 | if (m_fileheader._XPMEXT) |
| 133 | getline( in, m_fileheader.extension, '}' ); | 220 | getline(in, m_fileheader.extension, '}'); |
| 134 | /* debug*/ | 221 | if (!in.good()) |
| 135 | CPixmap::dump (cout); | 222 | throw FileError("Pixmap array isn't closed properly."); |
| 136 | 223 | ||
| 137 | /* get pixelformat instance */ | 224 | /* get pixelformat instance */ |
| 138 | m_pixelformat = NULL; | 225 | m_pixelformat = NULL; |
| 139 | set<CPixelFormat *>::iterator it; | 226 | set<CPixelFormat *>::iterator it; |
| 140 | for (it = m_handlers.begin(); it != m_handlers.end(); it++) | 227 | for (it = m_handlers.begin(); it != m_handlers.end(); it++) |
| 141 | { | 228 | { |
| 142 | /* check color mode */ | 229 | /* we only have one! */ |
| 143 | //TODO if (mode.compare((*it)->getColorMode()) == 0) | 230 | m_pixelformat = *it; |
| 144 | if (mode == "c") | 231 | break; |
| 145 | { | ||
| 146 | m_pixelformat = *it; | ||
| 147 | break; | ||
| 148 | } | ||
| 149 | } | 232 | } |
| 150 | if (m_pixelformat == NULL) | 233 | if (m_pixelformat == NULL) |
| 151 | throw FileError("Pixmap color mode \""+mode+"\" is not supported."); | 234 | throw FileError("Pixmap color mode is not supported."); |
| 235 | |||
| 236 | #ifdef DEBUG | ||
| 237 | /* debug*/ | ||
| 238 | CPixmap::dump(cout); | ||
| 239 | #endif | ||
| 152 | } | 240 | } |
| 153 | 241 | ||
| 154 | /*----------------------------------------------------------------------------*/ | 242 | /*----------------------------------------------------------------------------*/ |
| 155 | 243 | ||
| 156 | void CPixmap::write(std::ofstream& out, std::string& filename) | 244 | void CPixmap::write(std::ofstream& out) |
| 157 | { | 245 | { |
| 158 | |||
| 159 | /* header comment */ | 246 | /* header comment */ |
| 160 | out<<"/* XPM */"<<endl; | 247 | out << PIXMAP_IDENTIFIER << endl; |
| 161 | 248 | ||
| 162 | /* variables*/ | 249 | /* variables*/ |
| 163 | out<<"static char * " | 250 | out << "static char * " << m_imagename << "[] = {" << endl; |
| 164 | <<filename.substr(filename.find_last_of("/\\") + 1, filename.size()) | 251 | out << "\"" << m_fileheader.width << " " << m_fileheader.height |
| 165 | <<"[] = {"<<endl; | 252 | << " " << m_fileheader.nColor << " " << m_fileheader.nChar; |
| 166 | out<<"\""<<m_fileheader.xpmWidth<<" "<<m_fileheader.xpmHeight | 253 | |
| 167 | <<" "<<m_fileheader.nColor<<" "<<m_fileheader.nChar; | 254 | /* optional values */ |
| 168 | 255 | if (m_fileheader._HOTSPOT) | |
| 169 | /*optional values*/ | 256 | out << " " << m_fileheader.xHotspot << " " << m_fileheader.yHotspot; |
| 170 | if( m_fileheader._HOTSPOT ) | 257 | if (m_fileheader._XPMEXT) |
| 171 | out<<" "<<m_fileheader.xHotspot<<" "<<m_fileheader.yHotspot; | 258 | out << " " << "XPMEXT"; |
| 172 | if( m_fileheader._XPMEXT ) | 259 | out << "\"," << endl; |
| 173 | out<<" "<<"XPMEXT"; | 260 | |
| 174 | out <<"\","<<endl; | 261 | /* color table */ |
| 175 | 262 | map<string, CPixelFormat::RGBPIXEL *>::iterator it; | |
| 176 | /* color table */ | 263 | for (it = m_colortable.begin(); it != m_colortable.end(); it++) |
| 177 | map<string, map<string, uint32_t* > >::iterator it1; | 264 | { |
| 178 | map<string, uint32_t* >::iterator it2; | 265 | out << "\"" << (*it).first; |
| 179 | 266 | /* we only support c-colors! */ | |
| 180 | for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ ) | 267 | out << "\tc #"; |
| 181 | { | 268 | out << setfill('0') << setw(2) << hex << uppercase << (*it).second->red |
| 182 | out << "\""<<(*it1).first; | 269 | << setfill('0') << setw(2) << hex << uppercase << (*it).second->green |
| 183 | for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ ) | 270 | << setfill('0') << setw(2) << hex << uppercase << (*it).second->blue; |
| 184 | { | 271 | out << "\"," << endl; |
| 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 | } | 272 | } |
| 197 | 273 | ||
| 198 | /* pixel data */ | 274 | /* pixel data */ |
| 199 | for (unsigned int y = 0; y < getHeight(); y++ ){ | 275 | //TODO: better via copy? |
| 200 | out <<"\""; | 276 | for (uint32_t y = 0; y < getHeight(); y++) |
| 201 | for (unsigned int x = 0; x < getWidth(); x++ ) | 277 | { |
| 278 | out << "\""; | ||
| 279 | for (uint32_t x = 0; x < getWidth(); x++) | ||
| 202 | out << m_pixeldata[y * getWidth() + x]; | 280 | out << m_pixeldata[y * getWidth() + x]; |
| 203 | out <<"\""; | 281 | out << "\"," << endl; |
| 204 | if ( y != ( getHeight() - 1 )) | ||
| 205 | out <<","; | ||
| 206 | out <<endl; | ||
| 207 | } | 282 | } |
| 208 | 283 | ||
| 209 | /* extension */ | 284 | /* extension */ |
| 210 | if (m_fileheader._XPMEXT) | 285 | if (m_fileheader._XPMEXT) |
| 211 | out << m_fileheader.extension; | 286 | out << m_fileheader.extension; |
| 212 | |||
| 213 | out <<"};"; | ||
| 214 | 287 | ||
| 288 | out <<"};"; | ||
| 215 | } | 289 | } |
| 216 | 290 | ||
| 217 | |||
| 218 | /*----------------------------------------------------------------------------*/ | 291 | /*----------------------------------------------------------------------------*/ |
| 219 | 292 | ||
| 220 | #ifdef DEBUG | 293 | #ifdef DEBUG |
| 221 | void CPixmap::dump(std::ostream& out) | 294 | void CPixmap::dump(std::ostream& out) |
| 222 | { | 295 | { |
| 223 | 296 | /* pixeldata */ | |
| 224 | /* pixeldata */ | 297 | cout << "[XPM Pixel Data]" << endl; |
| 225 | cout<<endl<<"(_Pixel data:_)"<<endl; | 298 | for (uint32_t y = 0; y < getHeight(); y++) |
| 226 | for (unsigned int y = 0; y < getHeight(); y++ ){ | 299 | { |
| 227 | for (unsigned int x = 0; x < getWidth(); x++ ) | 300 | for (uint32_t x = 0; x < getWidth(); x++) |
| 228 | out << m_pixeldata[y * getWidth() + x]; | 301 | out << m_pixeldata[y * getWidth() + x]; |
| 229 | out << endl; | 302 | out << endl; |
| 230 | } | 303 | } |
| 231 | 304 | out << endl; | |
| 305 | |||
| 232 | /* values*/ | 306 | /* values*/ |
| 233 | cout<<endl<<"(_Values:_)"<<endl; | 307 | cout << "[XPM Header Values]" << endl |
| 234 | out << "XPM Header:" << endl | 308 | << "width=" << m_fileheader.width << endl |
| 235 | << "xpmWidth=" << m_fileheader.xpmWidth<< endl | 309 | << "height=" << m_fileheader.height << endl |
| 236 | << "xpmHeight=" << m_fileheader.xpmHeight<< endl | 310 | << "nColor=" << m_fileheader.nColor << endl |
| 237 | << "nColor=" << m_fileheader.nColor<< endl | 311 | << "nChar=" << m_fileheader.nChar << endl |
| 238 | << "nChar=" << m_fileheader.nChar<< endl | 312 | << "Hotspot=" << m_fileheader.xHotspot << endl |
| 239 | << "Hotspot=" << m_fileheader.xHotspot<< endl | 313 | << "yHotspot=" << m_fileheader.yHotspot << endl |
| 240 | << "yHotspot=" << m_fileheader.yHotspot<< endl | 314 | << "_HOTSPOT=" << m_fileheader._HOTSPOT << endl |
| 241 | << "_HOTSPOT=" << m_fileheader._HOTSPOT<< endl | 315 | << "_XPMEXT=" << m_fileheader._XPMEXT << endl |
| 242 | << "_XPMEXT=" << m_fileheader._XPMEXT<< endl | 316 | << "extension=" << m_fileheader.extension << endl |
| 243 | << "extension=" << m_fileheader.extension<< endl | 317 | << endl; |
| 244 | << endl; | ||
| 245 | 318 | ||
| 246 | /* colors*/ | 319 | /* colors*/ |
| 247 | map<string, map<string, uint32_t* > >::iterator it1; | 320 | map<string, CPixelFormat::RGBPIXEL *>::iterator it; |
| 248 | map<string, uint32_t* >::iterator it2; | 321 | cout << "[Color Table]" << endl; |
| 249 | cout<<"(_Color table:_)"<<endl; | 322 | for (it = m_colortable.begin(); it != m_colortable.end(); it++) |
| 250 | for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ ) | 323 | { |
| 251 | { | 324 | out << (*it).first << " " |
| 252 | out << (*it1).first; | 325 | << setfill('0') << setw(3) << (*it).second->red << " " |
| 253 | for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ ) | 326 | << setfill('0') << setw(3) << (*it).second->green << " " |
| 254 | { | 327 | << setfill('0') << setw(3) << (*it).second->blue << " " |
| 255 | out <<" "<< (*it2).first <<" "; | 328 | << endl; |
| 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 | } | 329 | } |
| 265 | |||
| 266 | } | 330 | } |
| 267 | #endif | 331 | #endif |
| 268 | 332 | ||
diff --git a/ue2/imgsynth2/cpixmap.h b/ue2/imgsynth2/cpixmap.h index eb219aa..66aa1c1 100644 --- a/ue2/imgsynth2/cpixmap.h +++ b/ue2/imgsynth2/cpixmap.h | |||
| @@ -11,6 +11,8 @@ | |||
| 11 | #include <stdint.h> | 11 | #include <stdint.h> |
| 12 | #include "cbitmap.h" | 12 | #include "cbitmap.h" |
| 13 | 13 | ||
| 14 | #define PIXMAP_IDENTIFIER "/* XPM */" | ||
| 15 | |||
| 14 | /** | 16 | /** |
| 15 | * @class CPixmap | 17 | * @class CPixmap |
| 16 | * @brief Implementation of CFile handling Pixmap file format. | 18 | * @brief Implementation of CFile handling Pixmap file format. |
| @@ -70,7 +72,7 @@ class CPixmap : public CBitmap | |||
| 70 | * @exception bad_alloc | 72 | * @exception bad_alloc |
| 71 | * @conditions none | 73 | * @conditions none |
| 72 | */ | 74 | */ |
| 73 | void write(std::ofstream& out, std::string& filename); | 75 | void write(std::ofstream& out); |
| 74 | 76 | ||
| 75 | #ifdef DEBUG | 77 | #ifdef DEBUG |
| 76 | /** | 78 | /** |
| @@ -85,51 +87,24 @@ class CPixmap : public CBitmap | |||
| 85 | void dump(std::ostream& out); | 87 | void dump(std::ostream& out); |
| 86 | #endif | 88 | #endif |
| 87 | 89 | ||
| 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 */ | 90 | /* TODO */ |
| 116 | const uint32_t getPixelDataSize() | 91 | const uint32_t getPixelDataSize() |
| 117 | { | 92 | { |
| 118 | return m_fileheader.xpmWidth * m_fileheader.xpmHeight * m_fileheader.nChar; | 93 | return m_fileheader.width * m_fileheader.height * m_fileheader.nChar; |
| 119 | } | 94 | } |
| 120 | 95 | ||
| 121 | /* TODO */ | 96 | /* TODO */ |
| 122 | const uint32_t getHeight() | 97 | const uint32_t getHeight() |
| 123 | { | 98 | { |
| 124 | /* width and height can be negativ */ | 99 | /* width and height can be negativ */ |
| 125 | return m_fileheader.xpmHeight; | 100 | return m_fileheader.height; |
| 126 | } | 101 | } |
| 127 | 102 | ||
| 128 | /* TODO */ | 103 | /* TODO */ |
| 129 | const uint32_t getWidth() | 104 | const uint32_t getWidth() |
| 130 | { | 105 | { |
| 131 | /* width and height can be negativ */ | 106 | /* width and height can be negativ */ |
| 132 | return m_fileheader.xpmWidth; | 107 | return m_fileheader.width; |
| 133 | } | 108 | } |
| 134 | 109 | ||
| 135 | /** | 110 | /** |
| @@ -155,10 +130,42 @@ class CPixmap : public CBitmap | |||
| 155 | } | 130 | } |
| 156 | 131 | ||
| 157 | protected: | 132 | protected: |
| 133 | /** TODO */ | ||
| 134 | std::string getLine(std::ifstream& in, bool ignore_comments = true); | ||
| 135 | /** TODO */ | ||
| 136 | std::string getArrayLine(std::ifstream& in, bool ignore_comments = true); | ||
| 137 | |||
| 138 | /** | ||
| 139 | * @brief Pixmap Header structure | ||
| 140 | */ | ||
| 141 | typedef struct | ||
| 142 | { | ||
| 143 | /** the xpm width in pixels (signed integer) */ | ||
| 144 | uint32_t width; | ||
| 145 | /** the xpm height in pixels (signed integer) */ | ||
| 146 | uint32_t height; | ||
| 147 | /** the number of colors (signed integer) */ | ||
| 148 | uint32_t nColor; | ||
| 149 | /** the number of characters per pixel (signed integer) */ | ||
| 150 | uint32_t nChar; | ||
| 151 | /** X-Position Hotspots */ | ||
| 152 | uint32_t xHotspot; | ||
| 153 | /** Y-Position Hotspots */ | ||
| 154 | uint32_t yHotspot; | ||
| 155 | /* is hotspot set */ | ||
| 156 | bool _HOTSPOT; | ||
| 157 | /* XPMEXT extension tag found*/ | ||
| 158 | bool _XPMEXT; | ||
| 159 | /* unchanged extension */ | ||
| 160 | std::string extension; | ||
| 161 | } PIXMAP_FILEHEADER; | ||
| 162 | |||
| 158 | /* members */ | 163 | /* members */ |
| 159 | /** fileheader */ | 164 | /** fileheader */ |
| 160 | PIXMAP_FILEHEADER m_fileheader; | 165 | PIXMAP_FILEHEADER m_fileheader; |
| 161 | /** infoheader */ | 166 | /** TODO */ |
| 167 | std::string m_imagename; | ||
| 168 | /** TODO convert PIXMAP_FILEHEADER to member variables */ | ||
| 162 | }; | 169 | }; |
| 163 | 170 | ||
| 164 | #endif | 171 | #endif |
diff --git a/ue2/imgsynth2/cscriptparser.cpp b/ue2/imgsynth2/cscriptparser.cpp index 17ff5a4..58ce3a8 100644 --- a/ue2/imgsynth2/cscriptparser.cpp +++ b/ue2/imgsynth2/cscriptparser.cpp | |||
| @@ -194,7 +194,7 @@ void CScriptparser::write(std::list<std::string> funcparams) | |||
| 194 | /* let handlers write() parse the file */ | 194 | /* let handlers write() parse the file */ |
| 195 | try | 195 | try |
| 196 | { | 196 | { |
| 197 | m_handler->write(file, filename); | 197 | m_handler->write(file); |
| 198 | if (!file.good()) | 198 | if (!file.good()) |
| 199 | throw ParserError("Error while writing image file.", m_curline); | 199 | throw ParserError("Error while writing image file.", m_curline); |
| 200 | file.close(); | 200 | file.close(); |
diff --git a/ue2/imgsynth2/cwindowsbitmap.cpp b/ue2/imgsynth2/cwindowsbitmap.cpp index ca927dd..ebbdd4c 100644 --- a/ue2/imgsynth2/cwindowsbitmap.cpp +++ b/ue2/imgsynth2/cwindowsbitmap.cpp | |||
| @@ -78,7 +78,7 @@ void CWindowsBitmap::read(std::ifstream& in) | |||
| 78 | 78 | ||
| 79 | /*----------------------------------------------------------------------------*/ | 79 | /*----------------------------------------------------------------------------*/ |
| 80 | 80 | ||
| 81 | void CWindowsBitmap::write(std::ofstream& out, std::string& filename) | 81 | void CWindowsBitmap::write(std::ofstream& out) |
| 82 | { | 82 | { |
| 83 | /* set header values */ | 83 | /* set header values */ |
| 84 | m_fileheader.bfSize = m_infoheader.biSizeImage + sizeof(m_infoheader) + sizeof(m_fileheader); | 84 | m_fileheader.bfSize = m_infoheader.biSizeImage + sizeof(m_infoheader) + sizeof(m_fileheader); |
diff --git a/ue2/imgsynth2/cwindowsbitmap.h b/ue2/imgsynth2/cwindowsbitmap.h index 9fb40db..28eb88d 100644 --- a/ue2/imgsynth2/cwindowsbitmap.h +++ b/ue2/imgsynth2/cwindowsbitmap.h | |||
| @@ -60,14 +60,13 @@ class CWindowsBitmap : public CBitmap | |||
| 60 | * @method write | 60 | * @method write |
| 61 | * @brief Writes Windows Bitmap to filestream. | 61 | * @brief Writes Windows Bitmap to filestream. |
| 62 | * @param out filestream to read data from | 62 | * @param out filestream to read data from |
| 63 | * @param filename filename (maybe useful for some handlers) | ||
| 64 | * @return - | 63 | * @return - |
| 65 | * @globalvars none | 64 | * @globalvars none |
| 66 | * @exception FileError | 65 | * @exception FileError |
| 67 | * @exception bad_alloc | 66 | * @exception bad_alloc |
| 68 | * @conditions none | 67 | * @conditions none |
| 69 | */ | 68 | */ |
| 70 | void write(std::ofstream& out, std::string& filename); | 69 | void write(std::ofstream& out); |
| 71 | 70 | ||
| 72 | #ifdef DEBUG | 71 | #ifdef DEBUG |
| 73 | /** | 72 | /** |
| @@ -83,83 +82,6 @@ class CWindowsBitmap : public CBitmap | |||
| 83 | #endif | 82 | #endif |
| 84 | 83 | ||
| 85 | /** | 84 | /** |
| 86 | * @brief Windows Bitmap File Header structure | ||
| 87 | */ | ||
| 88 | #pragma pack(push,1) | ||
| 89 | typedef struct | ||
| 90 | { | ||
| 91 | /** the magic number used to identify the BMP file */ | ||
| 92 | uint8_t bfType[2]; | ||
| 93 | /** the size of the BMP file in bytes */ | ||
| 94 | uint32_t bfSize; | ||
| 95 | /** reserved */ | ||
| 96 | uint32_t bfReserved; | ||
| 97 | /** the offset of the byte where the bitmap data can be found */ | ||
| 98 | uint32_t bfOffBits; | ||
| 99 | } BITMAP_FILEHEADER; | ||
| 100 | #pragma pack(pop) | ||
| 101 | |||
| 102 | /** | ||
| 103 | * @brief Windows Bitmap Info Header structure | ||
| 104 | */ | ||
| 105 | #pragma pack(push,1) | ||
| 106 | typedef struct | ||
| 107 | { | ||
| 108 | /** the size of this header (40 bytes) */ | ||
| 109 | uint32_t biSize; | ||
| 110 | /** the bitmap width in pixels (signed integer) */ | ||
| 111 | int32_t biWidth; | ||
| 112 | /** the bitmap height in pixels (signed integer) */ | ||
| 113 | int32_t biHeight; | ||
| 114 | /** the number of color planes being used. Must be set to 1 */ | ||
| 115 | uint16_t biPlanes; | ||
| 116 | /** the number of bits per pixel, which is the color depth of the image */ | ||
| 117 | uint16_t biBitCount; | ||
| 118 | /** the compression method being used */ | ||
| 119 | uint32_t biCompression; | ||
| 120 | /** the image size */ | ||
| 121 | uint32_t biSizeImage; | ||
| 122 | /** the horizontal resolution of the image (pixel per meter) */ | ||
| 123 | int32_t biXPelsPerMeter; | ||
| 124 | /** the vertical resolution of the image (pixel per meter) */ | ||
| 125 | int32_t biYPelsPerMeter; | ||
| 126 | /** the number of colors in the color palette, or 0 to default to 2^n */ | ||
| 127 | uint32_t biClrUsed; | ||
| 128 | /** the number of important colors used, or 0 when every color is | ||
| 129 | * important; generally ignored. */ | ||
| 130 | uint32_t biClrImportant; | ||
| 131 | } BITMAP_INFOHEADER; | ||
| 132 | #pragma pack(pop) | ||
| 133 | |||
| 134 | /** | ||
| 135 | * @method getFileHeader | ||
| 136 | * @brief Returns reference to fileheader structure of bitmap | ||
| 137 | * @param - | ||
| 138 | * @return reference to fileheader structure | ||
| 139 | * @globalvars none | ||
| 140 | * @exception none | ||
| 141 | * @conditions none | ||
| 142 | */ | ||
| 143 | BITMAP_FILEHEADER &getFileHeader() | ||
| 144 | { | ||
| 145 | return m_fileheader; | ||
| 146 | } | ||
| 147 | |||
| 148 | /** | ||
| 149 | * @method getInfoHeader | ||
| 150 | * @brief Returns reference to infoheader structure of bitmap | ||
| 151 | * @param - | ||
| 152 | * @return reference to infoheader structure | ||
| 153 | * @globalvars none | ||
| 154 | * @exception none | ||
| 155 | * @conditions none | ||
| 156 | */ | ||
| 157 | BITMAP_INFOHEADER &getInfoHeader() | ||
| 158 | { | ||
| 159 | return m_infoheader; | ||
| 160 | } | ||
| 161 | |||
| 162 | /** | ||
| 163 | * @method getPixelDataSize | 85 | * @method getPixelDataSize |
| 164 | * @brief Return size of pixelbuffer | 86 | * @brief Return size of pixelbuffer |
| 165 | * @param - | 87 | * @param - |
| @@ -234,6 +156,55 @@ class CWindowsBitmap : public CBitmap | |||
| 234 | } | 156 | } |
| 235 | 157 | ||
| 236 | protected: | 158 | protected: |
| 159 | /** | ||
| 160 | * @brief Windows Bitmap File Header structure | ||
| 161 | */ | ||
| 162 | #pragma pack(push,1) | ||
| 163 | typedef struct | ||
| 164 | { | ||
| 165 | /** the magic number used to identify the BMP file */ | ||
| 166 | uint8_t bfType[2]; | ||
| 167 | /** the size of the BMP file in bytes */ | ||
| 168 | uint32_t bfSize; | ||
| 169 | /** reserved */ | ||
| 170 | uint32_t bfReserved; | ||
| 171 | /** the offset of the byte where the bitmap data can be found */ | ||
| 172 | uint32_t bfOffBits; | ||
| 173 | } BITMAP_FILEHEADER; | ||
| 174 | #pragma pack(pop) | ||
| 175 | |||
| 176 | /** | ||
| 177 | * @brief Windows Bitmap Info Header structure | ||
| 178 | */ | ||
| 179 | #pragma pack(push,1) | ||
| 180 | typedef struct | ||
| 181 | { | ||
| 182 | /** the size of this header (40 bytes) */ | ||
| 183 | uint32_t biSize; | ||
| 184 | /** the bitmap width in pixels (signed integer) */ | ||
| 185 | int32_t biWidth; | ||
| 186 | /** the bitmap height in pixels (signed integer) */ | ||
| 187 | int32_t biHeight; | ||
| 188 | /** the number of color planes being used. Must be set to 1 */ | ||
| 189 | uint16_t biPlanes; | ||
| 190 | /** the number of bits per pixel, which is the color depth of the image */ | ||
| 191 | uint16_t biBitCount; | ||
| 192 | /** the compression method being used */ | ||
| 193 | uint32_t biCompression; | ||
| 194 | /** the image size */ | ||
| 195 | uint32_t biSizeImage; | ||
| 196 | /** the horizontal resolution of the image (pixel per meter) */ | ||
| 197 | int32_t biXPelsPerMeter; | ||
| 198 | /** the vertical resolution of the image (pixel per meter) */ | ||
| 199 | int32_t biYPelsPerMeter; | ||
| 200 | /** the number of colors in the color palette, or 0 to default to 2^n */ | ||
| 201 | uint32_t biClrUsed; | ||
| 202 | /** the number of important colors used, or 0 when every color is | ||
| 203 | * important; generally ignored. */ | ||
| 204 | uint32_t biClrImportant; | ||
| 205 | } BITMAP_INFOHEADER; | ||
| 206 | #pragma pack(pop) | ||
| 207 | |||
| 237 | /* members */ | 208 | /* members */ |
| 238 | /** fileheader */ | 209 | /** fileheader */ |
| 239 | BITMAP_FILEHEADER m_fileheader; | 210 | BITMAP_FILEHEADER m_fileheader; |
diff --git a/ue2/imgsynth2/test/input_yellow_man1_indexed8 b/ue2/imgsynth2/test/input_yellow_man1_indexed8 index 997cd4f..c0385c3 100644 --- a/ue2/imgsynth2/test/input_yellow_man1_indexed8 +++ b/ue2/imgsynth2/test/input_yellow_man1_indexed8 | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #in: test/yellow_man1_xpm_in.xpm | 1 | #in: test/yellow_man1_indexed8_in.xpm |
| 2 | #out: test/yellow_man1_xpm_out.xpm | 2 | #out: test/yellow_man1_indexed8_out.xpm |
| 3 | #ref: test/yellow_man1_xpm_ref.xpm | 3 | #ref: test/yellow_man1_indexed8_ref.xpm |
| 4 | 4 | ||
| 5 | read(XPM, test/yellow_man1_indexed8_in.xpm) | 5 | read(XPM, test/yellow_man1_indexed8_in.xpm) |
| 6 | 6 | ||
diff --git a/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm b/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm index 6e5fa2c..bd11b48 100644 --- a/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm +++ b/ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | /* XPM */ | 1 | /* XPM */ |
| 2 | static char * yellow_man1_default_xpm[] = { | 2 | static char * yellow_man1_default_xpm[] = { |
| 3 | "9 17 2 1 0 0 XPMEXT", | 3 | "9 17 2 1 0 0 XPMEXT", |
| 4 | ". c #000000", | 4 | ". c #000000 g4 #000000", |
| 5 | "# c #FFF200", | 5 | "# c #FFF200", |
| 6 | ".........", | 6 | ".........", |
| 7 | ".........", | 7 | ".........", |
| @@ -19,7 +19,7 @@ static char * yellow_man1_default_xpm[] = { | |||
| 19 | "...#.#...", | 19 | "...#.#...", |
| 20 | "...#.#...", | 20 | "...#.#...", |
| 21 | ".........", | 21 | ".........", |
| 22 | "........." | 22 | ".........", |
| 23 | "XPMEXT ext1 data1", | 23 | "XPMEXT ext1 data1", |
| 24 | "XPMEXT ext2", | 24 | "XPMEXT ext2", |
| 25 | "data2_1", | 25 | "data2_1", |
diff --git a/ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm b/ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm index 57db73d..bd3beb4 100644 --- a/ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm +++ b/ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* XPM */ | 1 | /* XPM */ |
| 2 | static char * yellow_man1_rgb24_ref_xpm[] = { | 2 | static char * yellow_man1_default_xpm[] = { |
| 3 | "9 17 4 1", | 3 | "9 17 4 1 0 0 XPMEXT", |
| 4 | ". c #000000", | 4 | ". c #000000", |
| 5 | "# c #FFF200", | 5 | "# c #FFF200", |
| 6 | "+ c #00FF00", | 6 | "+ c #00FF00", |
