From f2872bfd97f9297b1446f1fd6595a32dc509f301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Neuwirth?= Date: Wed, 29 Apr 2009 04:10:10 +0200 Subject: Adding cpixmap.cpp, cpixmap.h and test fieles --- ue2/imgsynth2/cpixmap.cpp | 163 ++++++++++++++++++++++++ ue2/imgsynth2/cpixmap.h | 162 +++++++++++++++++++++++ ue2/imgsynth2/test/input_yellow_man1_indexed8 | 10 ++ ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm | 22 ++++ ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm | 24 ++++ 5 files changed, 381 insertions(+) create mode 100644 ue2/imgsynth2/cpixmap.cpp create mode 100644 ue2/imgsynth2/cpixmap.h create mode 100644 ue2/imgsynth2/test/input_yellow_man1_indexed8 create mode 100644 ue2/imgsynth2/test/yellow_man1_indexed8_in.xpm create mode 100644 ue2/imgsynth2/test/yellow_man1_indexed8_ref.xpm (limited to 'ue2') 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 @@ +/** + * @module CPixMap + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief Implementation of CFile handling Windows Bitmaps. + * @date 27.04.2009 + */ + +#include +#include + +#ifdef DEBUG +# include +#endif +# include +# include +#include "cpixmap.h" +#include "cpixelformat_indexed8.h" + +using namespace std; + +CPixMap::CPixMap() +{ + m_types.insert("XPM"); + + /* add our handlers */ + m_handlers.insert(new CPixelFormat_Indexed8(this)); + +} + + + +/*----------------------------------------------------------------------------*/ + +void CPixMap::read(std::ifstream& in) +{ + + string str; + + /* parse the values section */ + getline( in, str, '"'); + getline( in, str, '"'); + stringstream istr (str ); + + istr >> m_fileheader.xpmWidth ; + istr >> m_fileheader.xpmHeight ; + istr >> m_fileheader.nColor ; + istr >> m_fileheader.nChar ; + + /* if there are optional values */ + if (in.good()) + { + istr >> m_fileheader.xHotspot; + istr >> m_fileheader.yHotspot; + } + else + { + m_fileheader.xHotspot = NULL; + m_fileheader.yHotspot = NULL; + } + + + /* parse the colors section */ + getline( in, str, '"'); + for (unsigned int i = 0; i < m_fileheader.nColor; i++ ) + { + getline( in, str, '"' ); + stringstream istr2 (str ); + char character; + string mode, colors; + + istr2 >> character; + istr2 >> mode; + istr2 >> colors; + m_fileheader.xpmColors[character][mode] = colors; + + getline( in, str, '"' ); + } +/* colors.replace(0,1,"0x"); + colors.insert(4, " 0x"); + colors.insert(9," 0x"); + + stringstream istr3 (colors, stringstream::out|stringstream::in ); + istr3 >>hex>> r; + istr3 >>hex>> g; + istr3 >>hex>> b; + //?????????????ß + cout<(r); + m_fileheader.xpmColors[c1]['g'] = static_cast(g); + m_fileheader.xpmColors[c1]['b'] = static_cast(b);*/ + + + + /* read pixel data using separate class */ + if (getPixelDataSize() > 0) + { + if (m_pixeldata != NULL) + delete[] m_pixeldata; + m_pixeldata = new uint8_t[getPixelDataSize()]; + + /* parse the pixel data */ + 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(); + + } + } + + /* debug*/ + CPixMap::dump (cout); + + +} + +/*----------------------------------------------------------------------------*/ + +void CPixMap::write(std::ofstream& out) +{ + dump(out); +} + + +/*----------------------------------------------------------------------------*/ + +#ifdef DEBUG +void CPixMap::dump(std::ostream& out) +{ + + /* values*/ + out + << "XPM Header:" << endl + << ", xpmWidth=" << m_fileheader.xpmWidth<< endl + << ", xpmHeight=" << m_fileheader.xpmHeight<< endl + << ", nColor=" << m_fileheader.nColor<< endl + << ", nChar=" << m_fileheader.nChar<< endl + << endl; + + /* colors*/ + map >::iterator it1; + map::iterator it2; + for ( it1=m_fileheader.xpmColors.begin() ; it1 != m_fileheader.xpmColors.end(); it1++ ) + { + out << (*it1).first ; + for ( it2=(*it1).second.begin() ; it2 != (*it1).second.end(); it2++ ) + out << (*it2).first <<" > "<< (*it2).second< +#include +#include "cbitmap.h" + + +/** + * @class CBitmap + * @brief Implementation of CFile handling Windows Bitmaps. + * + * In order to support operations on bitmaps with different color bitcounts + * different implementations of CPixelFormat are used. These classes are + * allowed to modify the bitmap headers and pixelbuffer directly. + * + * On error CFile::FileError is thrown. + */ +class CPixMap : public CBitmap +{ + public: + /** + * @method CPixMap + * @brief Default ctor + * @param - + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + CPixMap(); + + /** + * @method ~CPixMap + * @brief Default dtor + * @param - + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + ~CPixMap() + {} + + /** + * @method read + * @brief Reads Windows Bitmap from filestream. + * On error an exception is thrown. + * @param in filestream to read data from + * @return - + * @globalvars none + * @exception CFile::FileError + * @exception bad_alloc + * @conditions none + */ + void read(std::ifstream& in); + + /** + * @method write + * @brief Writes Windows Bitmap to filestream. + * @param out filestream to read data from + * @return - + * @globalvars none + * @exception FileError + * @exception bad_alloc + * @conditions none + */ + + void write(std::ofstream& out); +#ifdef DEBUG + /** + * @method dump + * @brief Dumps the Windows Bitmap file headers to ostream + * @param out output stream + * @return - + * @globalvars + * @exception + * @conditions + */ + void dump(std::ostream& out); +#endif + + + + /** + * @brief Windows Bitmap Info 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; + + /* color tables*/ + std::map > xpmColors; + + + + } PIXMAP_FILEHEADER; +#pragma pack(pop) + + /* TODO */ + const uint32_t getPixelDataSize() + { + return m_fileheader.xpmWidth * + m_fileheader.xpmHeight * + m_fileheader.nChar; + } + + /* TODO */ + const uint32_t getHeight() + { + /* width and height can be negativ */ + return m_fileheader.xpmHeight; + } + + /* TODO */ + const uint32_t getWidth() + { + /* width and height can be negativ */ + return m_fileheader.xpmWidth; + } + + /* TODO */ + const bool isMirrored() + { + /* pixmap is never mirrored */ + return false; + } + + protected: + /* members */ + /** fileheader */ + PIXMAP_FILEHEADER m_fileheader; + /** infoheader */ + + +}; + +#endif + +/* 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 @@ +#in: test/yellow_man1_xpm_in.xpm +#out: test/yellow_man1_xpm_out.xpm +#ref: test/yellow_man1_xpm_ref.xpm + +read(XPM, test/yellow_man1_indexed8_in.xpm) + +#fillrect(0,3,6,5,0,255,0) +#fillrect(2,13,7,4,0,0,255) + +write(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 @@ +/* XPM */ +static char * yellow_man1_default_xpm[] = { +"9 17 2 1", +". c #000000", +"# c #FFF200", +".........", +".........", +"...###...", +"...###...", +"...###...", +"....#....", +"..#####..", +".#.###.#.", +".#.###.#.", +".#.###.#.", +".#.###.#.", +"...#.#...", +"...#.#...", +"...#.#...", +"...#.#...", +".........", +"........."}; 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 @@ +/* XPM */ +static char * yellow_man1_rgb24_ref_xpm[] = { +"9 17 4 1", +". c #000000", +"# c #FFF200", +"+ c #00FF00", +"@ c #0000FF", +".........", +".........", +"...###...", +"++++++...", +"++++++...", +"++++++...", +"++++++#..", +"++++++.#.", +".#.###.#.", +".#.###.#.", +".#.###.#.", +"...#.#...", +"...#.#...", +"..@@@@@@@", +"..@@@@@@@", +"..@@@@@@@", +"..@@@@@@@"}; -- cgit v1.2.3