/** * @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; m_fileheader.xpmColors[character] = 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) { out<<"/* XPM */"< "<< (*it2).second<