From b9ce1555b2baf9be209775dbd4c8b217db5cd735 Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 1 May 2009 20:18:51 +0200 Subject: rewrote pixmap::read to do more sanity checks --- ue2/imgsynth2/cbitmap.cpp | 25 +- ue2/imgsynth2/cbitmap.h | 6 +- ue2/imgsynth2/cfile.h | 3 +- ue2/imgsynth2/cpixelformat_indexed8.h | 14 - ue2/imgsynth2/cpixmap.cpp | 422 ++++++++++++++---------- ue2/imgsynth2/cpixmap.h | 71 ++-- ue2/imgsynth2/cscriptparser.cpp | 2 +- ue2/imgsynth2/cwindowsbitmap.cpp | 2 +- ue2/imgsynth2/cwindowsbitmap.h | 129 +++----- ue2/imgsynth2/test/input_yellow_man1_indexed8 | 6 +- ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm | 4 +- ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm | 4 +- 12 files changed, 351 insertions(+), 337 deletions(-) (limited to 'ue2/imgsynth2') 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() m_pixelformat = NULL; /* delete colortable content */ - //TODO - /*map::iterator it2; - for (it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) - delete (*it2).second;*/ - - map >::iterator it1; - map::iterator it2; - for(it1 = xpmColors.begin(); it1 != xpmColors.end(); it1++) - { - for(it2 = (*it1).second.begin(); it2 != (*it1).second.end(); it2++) - delete[] (*it2).second; - } + map::iterator it2; + for(it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) + delete (*it2).second; } /*----------------------------------------------------------------------------*/ @@ -153,13 +144,12 @@ void CBitmap::invert(std::list params) { /* invert every entry in the colortable */ map::iterator it; - //TODO - /*for (it = m_colortable.begin(); it != m_colortable.end(); it++) + for (it = m_colortable.begin(); it != m_colortable.end(); it++) { (*it).second->red = max.red - (*it).second->red; (*it).second->green = max.green - (*it).second->green; (*it).second->blue = max.blue - (*it).second->blue; - }*/ + } } else { @@ -223,13 +213,12 @@ void CBitmap::brightness(std::list params) { /* invert every entry in the colortable */ map::iterator it; - //TODO - /*for (it = m_colortable.begin(); it != m_colortable.end(); it++) + for (it = m_colortable.begin(); it != m_colortable.end(); it++) { (*it).second->red = min(max.red, static_cast((*it).second->red * factor)); (*it).second->green = min(max.green, static_cast((*it).second->green * factor)); (*it).second->blue = min(max.blue, static_cast((*it).second->blue * factor)); - }*/ + } } else { 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 * @method write * @brief Writes Windows Bitmap to filestream. * @param out filestream to read data from - * @param filename filename (maybe useful for some handlers) * @return - * @globalvars none * @exception FileError * @exception bad_alloc * @conditions none */ - virtual void write(std::ofstream& out, std::string& filename) = 0; + virtual void write(std::ofstream& out) = 0; /** * @method getPixelData @@ -231,8 +230,7 @@ class CBitmap : public CFile /** pointer to pixelbuffer */ uint8_t *m_pixeldata; /** colortable map */ - //TODO std::map m_colortable; - std::map > xpmColors; + std::map m_colortable; /** set of supported PixelFormat handlers */ std::set m_handlers; /** 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 * @method write * @brief Pure virtual method (interface). Should write data to filestream. * @param out filestream to write data to - * @param filename filename (maybe useful for some handlers) * @return - * @globalvars none * @exception FileError * @conditions none */ - virtual void write(std::ofstream& out, std::string& filename) = 0; + virtual void write(std::ofstream& out) = 0; /** * @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 return 8; } - /** - * @method getColorMode - * @brief returns the color mode supported by this class - * @param - - * @return color mode supported by this class - * @globalvars none - * @exception none - * @conditions none - */ - const std::string getColorMode() - { - return "c"; - } - /** * @method getMaxColor * @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 @@ * @date 27.04.2009 */ +#include +#include +#include +#include +#include #include -#include - #ifdef DEBUG # include #endif -#include -#include -# include -# include - - - #include "cpixmap.h" #include "cpixelformat_indexed8.h" using namespace std; +using namespace boost; CPixmap::CPixmap() + : m_imagename("") { m_types.insert("XPM"); @@ -33,236 +31,302 @@ CPixmap::CPixmap() /*----------------------------------------------------------------------------*/ -void CPixmap::read(std::ifstream& in) +std::string CPixmap::getLine(std::ifstream& in, bool ignore_comments) { + string line(""); + while(!in.eof() && in.good()) + { + getline(in, line); + trim(line); + /* ignore simple ansi c comments. only one-liners */ + if (ignore_comments && line.find_first_of("/*") == 0) + continue; + if (!line.empty()) + break; + } + return line; +} - string str; - m_fileheader._XPMEXT = false; - m_fileheader._HOTSPOT = false; +/*----------------------------------------------------------------------------*/ - /* parse the values section */ - getline( in, str, '"'); - getline( in, str, '"'); - stringstream istr (str ); +std::string CPixmap::getArrayLine(std::ifstream& in, bool ignore_comments) +{ + string line = getLine(in, ignore_comments); + if (line.empty()) + return line; + + /* this stuff isn't correct too, but we are no c-parser anyway */ + if (line[0] != '"') + throw FileError("Pixmap array has invalid c-syntax."); + if (line[line.length() - 1] != ',' && line[line.length() - 1] != '}') + throw FileError("Pixmap array has invalid c-syntax."); + size_t end = line.find_last_of("\""); + if (end == string::npos) + throw FileError("Pixmap array has invalid c-syntax."); + + return line.substr(1, end - 1); +} - istr >> m_fileheader.xpmWidth ; - istr >> m_fileheader.xpmHeight ; - istr >> m_fileheader.nColor ; - istr >> m_fileheader.nChar ; +/*----------------------------------------------------------------------------*/ + +void CPixmap::read(std::ifstream& in) +{ + /* + * XPM + * static char * [] = { + * + * + * + * + * }; + */ + + string line, tmp; + stringstream istr; + std::vector list; + m_fileheader._XPMEXT = false; + m_fileheader._HOTSPOT = false; - /*optional values */ - if (istr.good()) + /* first line has to be PIXMAP_IDENTIFIER */ + line = getLine(in, false); + if (line != PIXMAP_IDENTIFIER) + throw FileError("Pixmap has no identifier."); + + /* second line is a c array. we don't do much syntax checking */ + line = getLine(in); + istr.str(line); + while(m_imagename.empty() && !istr.eof() && istr.good()) { - string tmp; + size_t end; istr >> tmp; - if(tmp.compare("XPMEXT") == 0) - m_fileheader._XPMEXT = true; - else + if ((end = tmp.find_first_of("[]")) != string::npos) { - m_fileheader._HOTSPOT = true; - m_fileheader.xHotspot = static_cast(strtoul(tmp.c_str(), NULL, 16)); - istr >> m_fileheader.yHotspot; + /* *[] */ + size_t start = tmp.find_first_of('*'); + start = (start == string::npos) ? 0 : start + 1; + m_imagename = tmp.substr(start, end - start); } - if (istr.good()) + } + if (m_imagename.empty()) + throw FileError("Pixmap has no imagename."); + + /* additional: check "{" exists */ + if (line[line.length() - 1] != '{') + throw FileError("Pixmap array has no opening bracket."); + + /* parse -section */ + line = getArrayLine(in); + if (line.empty()) + throw FileError("Pixmap has no Values-section."); + algorithm::split(list, line, is_any_of(" \t")); + if (list.size() < 4) + throw FileError("Pixmap has invalid Values-section."); + try + { + m_fileheader.width = lexical_cast(list[0]); + m_fileheader.height = lexical_cast(list[1]); + m_fileheader.nColor = lexical_cast(list[2]); + m_fileheader.nChar = lexical_cast(list[3]); + + if (list.size() > 4) { - istr >> tmp; - if (tmp.compare("XPMEXT") == 0) - m_fileheader._XPMEXT = true; + if (list.size() >= 6) + { + m_fileheader._HOTSPOT = true; + m_fileheader.xHotspot = lexical_cast(list[4]); + m_fileheader.yHotspot = lexical_cast(list[5]); + } + if (list.size() != 6) + { + if (list[list.size() - 1] != "XPMEXT") + throw FileError("Unknown parameter count in Values-Section."); + else + m_fileheader._XPMEXT = true; + } } } + catch(bad_lexical_cast& ex) + { + throw FileError("Value of Values-section is invalid: " + string(ex.what())); + } + /* parse -table */ + string character; + map colors; + for(uint32_t i = 0; i < m_fileheader.nColor; i++) + { + line = getArrayLine(in); + if (line.empty()) + throw FileError("Pixmap has missing colortable-entry."); + algorithm::split(list, line, is_any_of(" \t")); + if (list.size() < 3) + throw FileError("Pixmap colortable-entry is invalid."); + + /* read pixel character */ + character = list[0]; + if (character.length() != m_fileheader.nChar) + throw FileError("Pixmap colorcharacter is invalid."); + + /* read colors */ + string color(""); + if ((list.size() - 1) % 2 != 0) + throw FileError("Pixmap color entrys are invalid."); + for(uint32_t j = 1; j < list.size(); j = j + 2) + { + if (list[j + 1].length() != 7) + throw FileError("Pixmap color value is invalid."); + if (list[j + 1].at(0) != '#') + throw FileError("Pixmap color table value is not hexadecimal."); + + /* we only support c-colors! */ + if (list[j] != "c") + continue; + + CPixelFormat::RGBPIXEL *pixel = new CPixelFormat::RGBPIXEL; + pixel->red = strtoul(list[j + 1].substr(1, 2).c_str(), NULL, 16); + pixel->green = strtoul(list[j + 1].substr(3, 2).c_str(), NULL, 16); + pixel->blue = strtoul(list[j + 1].substr(5, 2).c_str(), NULL, 16); + colors[ list[j] ] = pixel; + } + /* we only support c-colors! */ + if (colors.find("c") == colors.end()) + throw FileError("Pixmap color entry has missing c-value."); - /* parse color table*/ - getline( in, str, '"'); - string character, mode, colors; - for (unsigned int i = 0; i < m_fileheader.nColor; i++ ) - { - getline( in, str, '"' ); - stringstream istr2 (str ); - - istr2 >> character; - istr2 >> mode; - istr2 >> colors; - - if ( colors.size() != 7) - throw FileError("Pixmap color tabel is invalid."); - if ( colors.at(0) != '#') - throw FileError("Pixmap color tabel value is not hexadecimal."); - - xpmColors[character][mode] = new (nothrow) unsigned int[3]; - if (xpmColors[character][mode] == 0) - throw FileError("Bad color table allocation."); - - xpmColors[character][mode][0] = - static_cast(strtoul(colors.substr(1,2).c_str(), NULL, 16)); - xpmColors[character][mode][1] = - static_cast(strtoul(colors.substr(3,2).c_str(), NULL, 16)); - xpmColors[character][mode][2] = - static_cast(strtoul(colors.substr(5,2).c_str(), NULL, 16)); - - - - - - - getline( in, str, '"' ); + /* add pixel to colortable */ + m_colortable[character] = colors["c"]; } - - /* read pixel data using separate class */ + + /* read pixel data */ if (getPixelDataSize() > 0) { if (m_pixeldata != NULL) delete[] m_pixeldata; m_pixeldata = new uint8_t[getPixelDataSize()]; - - for (unsigned int y = 0; y < getHeight(); y++ ) - { - for (unsigned int x = 0; x < getWidth(); x++ ) - m_pixeldata[y * getWidth() + x] = static_cast(in.get()); - getline( in, str); - if ( y != ( getHeight() - 1 )) - in.get(); - + for (uint32_t y = 0; y < getHeight(); y++) + { + line = getArrayLine(in); + if (line.empty()) + throw FileError("Pixmap has no pixel data."); + if (line.length() != getWidth()) + throw FileError("Pixmap pixeldata width is larger than header width."); + copy(line.c_str(), line.c_str() + line.length(), m_pixeldata + y * getWidth()); } } - /* parse extension */ - if ( m_fileheader._XPMEXT ) - getline( in, m_fileheader.extension, '}' ); - /* debug*/ - CPixmap::dump (cout); - + /* get extension */ + if (m_fileheader._XPMEXT) + getline(in, m_fileheader.extension, '}'); + if (!in.good()) + throw FileError("Pixmap array isn't closed properly."); + /* get pixelformat instance */ m_pixelformat = NULL; set::iterator it; for (it = m_handlers.begin(); it != m_handlers.end(); it++) { - /* check color mode */ - //TODO if (mode.compare((*it)->getColorMode()) == 0) - if (mode == "c") - { - m_pixelformat = *it; - break; - } + /* we only have one! */ + m_pixelformat = *it; + break; } if (m_pixelformat == NULL) - throw FileError("Pixmap color mode \""+mode+"\" is not supported."); + throw FileError("Pixmap color mode is not supported."); + +#ifdef DEBUG + /* debug*/ + CPixmap::dump(cout); +#endif } /*----------------------------------------------------------------------------*/ -void CPixmap::write(std::ofstream& out, std::string& filename) +void CPixmap::write(std::ofstream& out) { - /* header comment */ - out<<"/* XPM */"< >::iterator it1; - map::iterator it2; - - for ( it1= xpmColors.begin() ; it1 != xpmColors.end(); it1++ ) - { - out << "\""<<(*it1).first; - for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ ) - { - - out<<"\t" <<(*it2).first<<"\t#"; - - for (int i = 0 ; i < 3; i++ ) - { - out.width(2); - out << hex <::iterator it; + for (it = m_colortable.begin(); it != m_colortable.end(); it++) + { + out << "\"" << (*it).first; + /* we only support c-colors! */ + out << "\tc #"; + out << setfill('0') << setw(2) << hex << uppercase << (*it).second->red + << setfill('0') << setw(2) << hex << uppercase << (*it).second->green + << setfill('0') << setw(2) << hex << uppercase << (*it).second->blue; + out << "\"," << endl; } - + /* pixel data */ - for (unsigned int y = 0; y < getHeight(); y++ ){ - out <<"\""; - for (unsigned int x = 0; x < getWidth(); x++ ) + //TODO: better via copy? + for (uint32_t y = 0; y < getHeight(); y++) + { + out << "\""; + for (uint32_t x = 0; x < getWidth(); x++) out << m_pixeldata[y * getWidth() + x]; - out <<"\""; - if ( y != ( getHeight() - 1 )) - out <<","; - out <::iterator it; + cout << "[Color Table]" << endl; + for (it = m_colortable.begin(); it != m_colortable.end(); it++) + { + out << (*it).first << " " + << setfill('0') << setw(3) << (*it).second->red << " " + << setfill('0') << setw(3) << (*it).second->green << " " + << setfill('0') << setw(3) << (*it).second->blue << " " + << endl; } - } #endif 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 @@ #include #include "cbitmap.h" +#define PIXMAP_IDENTIFIER "/* XPM */" + /** * @class CPixmap * @brief Implementation of CFile handling Pixmap file format. @@ -70,7 +72,7 @@ class CPixmap : public CBitmap * @exception bad_alloc * @conditions none */ - void write(std::ofstream& out, std::string& filename); + void write(std::ofstream& out); #ifdef DEBUG /** @@ -85,51 +87,24 @@ class CPixmap : public CBitmap void dump(std::ostream& out); #endif - /** - * @brief Pixmap Header structure - */ -#pragma pack(push,1) - typedef struct - { - /** the xpm width in pixels (signed integer) */ - uint32_t xpmWidth; - /** the xpm height in pixels (signed integer) */ - uint32_t xpmHeight; - /** the number of colors (signed integer) */ - uint32_t nColor; - /** the number of characters per pixel (signed integer) */ - uint32_t nChar; - /** X-Position Hotspots */ - uint32_t xHotspot; - /** Y-Position Hotspots */ - uint32_t yHotspot; - /* is hotspot set */ - bool _HOTSPOT; - /* XPMEXT extension tag found*/ - bool _XPMEXT; - /* unchanged extension */ - std::string extension; - } PIXMAP_FILEHEADER; -#pragma pack(pop) - /* TODO */ const uint32_t getPixelDataSize() { - return m_fileheader.xpmWidth * m_fileheader.xpmHeight * m_fileheader.nChar; + return m_fileheader.width * m_fileheader.height * m_fileheader.nChar; } /* TODO */ const uint32_t getHeight() { /* width and height can be negativ */ - return m_fileheader.xpmHeight; + return m_fileheader.height; } /* TODO */ const uint32_t getWidth() { /* width and height can be negativ */ - return m_fileheader.xpmWidth; + return m_fileheader.width; } /** @@ -155,10 +130,42 @@ class CPixmap : public CBitmap } protected: + /** TODO */ + std::string getLine(std::ifstream& in, bool ignore_comments = true); + /** TODO */ + std::string getArrayLine(std::ifstream& in, bool ignore_comments = true); + + /** + * @brief Pixmap Header structure + */ + typedef struct + { + /** the xpm width in pixels (signed integer) */ + uint32_t width; + /** the xpm height in pixels (signed integer) */ + uint32_t height; + /** the number of colors (signed integer) */ + uint32_t nColor; + /** the number of characters per pixel (signed integer) */ + uint32_t nChar; + /** X-Position Hotspots */ + uint32_t xHotspot; + /** Y-Position Hotspots */ + uint32_t yHotspot; + /* is hotspot set */ + bool _HOTSPOT; + /* XPMEXT extension tag found*/ + bool _XPMEXT; + /* unchanged extension */ + std::string extension; + } PIXMAP_FILEHEADER; + /* members */ /** fileheader */ PIXMAP_FILEHEADER m_fileheader; - /** infoheader */ + /** TODO */ + std::string m_imagename; + /** TODO convert PIXMAP_FILEHEADER to member variables */ }; #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 funcparams) /* let handlers write() parse the file */ try { - m_handler->write(file, filename); + m_handler->write(file); if (!file.good()) throw ParserError("Error while writing image file.", m_curline); 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) /*----------------------------------------------------------------------------*/ -void CWindowsBitmap::write(std::ofstream& out, std::string& filename) +void CWindowsBitmap::write(std::ofstream& out) { /* set header values */ 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 * @method write * @brief Writes Windows Bitmap to filestream. * @param out filestream to read data from - * @param filename filename (maybe useful for some handlers) * @return - * @globalvars none * @exception FileError * @exception bad_alloc * @conditions none */ - void write(std::ofstream& out, std::string& filename); + void write(std::ofstream& out); #ifdef DEBUG /** @@ -82,83 +81,6 @@ class CWindowsBitmap : public CBitmap void dump(std::ostream& out); #endif - /** - * @brief Windows Bitmap File Header structure - */ -#pragma pack(push,1) - typedef struct - { - /** the magic number used to identify the BMP file */ - uint8_t bfType[2]; - /** the size of the BMP file in bytes */ - uint32_t bfSize; - /** reserved */ - uint32_t bfReserved; - /** the offset of the byte where the bitmap data can be found */ - uint32_t bfOffBits; - } BITMAP_FILEHEADER; -#pragma pack(pop) - - /** - * @brief Windows Bitmap Info Header structure - */ -#pragma pack(push,1) - typedef struct - { - /** the size of this header (40 bytes) */ - uint32_t biSize; - /** the bitmap width in pixels (signed integer) */ - int32_t biWidth; - /** the bitmap height in pixels (signed integer) */ - int32_t biHeight; - /** the number of color planes being used. Must be set to 1 */ - uint16_t biPlanes; - /** the number of bits per pixel, which is the color depth of the image */ - uint16_t biBitCount; - /** the compression method being used */ - uint32_t biCompression; - /** the image size */ - uint32_t biSizeImage; - /** the horizontal resolution of the image (pixel per meter) */ - int32_t biXPelsPerMeter; - /** the vertical resolution of the image (pixel per meter) */ - int32_t biYPelsPerMeter; - /** the number of colors in the color palette, or 0 to default to 2^n */ - uint32_t biClrUsed; - /** the number of important colors used, or 0 when every color is - * important; generally ignored. */ - uint32_t biClrImportant; - } BITMAP_INFOHEADER; -#pragma pack(pop) - - /** - * @method getFileHeader - * @brief Returns reference to fileheader structure of bitmap - * @param - - * @return reference to fileheader structure - * @globalvars none - * @exception none - * @conditions none - */ - BITMAP_FILEHEADER &getFileHeader() - { - return m_fileheader; - } - - /** - * @method getInfoHeader - * @brief Returns reference to infoheader structure of bitmap - * @param - - * @return reference to infoheader structure - * @globalvars none - * @exception none - * @conditions none - */ - BITMAP_INFOHEADER &getInfoHeader() - { - return m_infoheader; - } - /** * @method getPixelDataSize * @brief Return size of pixelbuffer @@ -234,6 +156,55 @@ class CWindowsBitmap : public CBitmap } protected: + /** + * @brief Windows Bitmap File Header structure + */ +#pragma pack(push,1) + typedef struct + { + /** the magic number used to identify the BMP file */ + uint8_t bfType[2]; + /** the size of the BMP file in bytes */ + uint32_t bfSize; + /** reserved */ + uint32_t bfReserved; + /** the offset of the byte where the bitmap data can be found */ + uint32_t bfOffBits; + } BITMAP_FILEHEADER; +#pragma pack(pop) + + /** + * @brief Windows Bitmap Info Header structure + */ +#pragma pack(push,1) + typedef struct + { + /** the size of this header (40 bytes) */ + uint32_t biSize; + /** the bitmap width in pixels (signed integer) */ + int32_t biWidth; + /** the bitmap height in pixels (signed integer) */ + int32_t biHeight; + /** the number of color planes being used. Must be set to 1 */ + uint16_t biPlanes; + /** the number of bits per pixel, which is the color depth of the image */ + uint16_t biBitCount; + /** the compression method being used */ + uint32_t biCompression; + /** the image size */ + uint32_t biSizeImage; + /** the horizontal resolution of the image (pixel per meter) */ + int32_t biXPelsPerMeter; + /** the vertical resolution of the image (pixel per meter) */ + int32_t biYPelsPerMeter; + /** the number of colors in the color palette, or 0 to default to 2^n */ + uint32_t biClrUsed; + /** the number of important colors used, or 0 when every color is + * important; generally ignored. */ + uint32_t biClrImportant; + } BITMAP_INFOHEADER; +#pragma pack(pop) + /* members */ /** fileheader */ 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 @@ -#in: test/yellow_man1_xpm_in.xpm -#out: test/yellow_man1_xpm_out.xpm -#ref: test/yellow_man1_xpm_ref.xpm +#in: test/yellow_man1_indexed8_in.xpm +#out: test/yellow_man1_indexed8_out.xpm +#ref: test/yellow_man1_indexed8_ref.xpm read(XPM, test/yellow_man1_indexed8_in.xpm) 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 @@ /* XPM */ static char * yellow_man1_default_xpm[] = { "9 17 2 1 0 0 XPMEXT", -". c #000000", +". c #000000 g4 #000000", "# c #FFF200", ".........", ".........", @@ -19,7 +19,7 @@ static char * yellow_man1_default_xpm[] = { "...#.#...", "...#.#...", ".........", -"........." +".........", "XPMEXT ext1 data1", "XPMEXT ext2", "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 @@ /* XPM */ -static char * yellow_man1_rgb24_ref_xpm[] = { -"9 17 4 1", +static char * yellow_man1_default_xpm[] = { +"9 17 4 1 0 0 XPMEXT", ". c #000000", "# c #FFF200", "+ c #00FF00", -- cgit v1.2.3