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/cpixmap.h | 71 +++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 32 deletions(-) (limited to 'ue2/imgsynth2/cpixmap.h') 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 -- cgit v1.2.3