/* PXM C++ file for using PBM, PGM & PPM graphic file formats inside Borland VCL environments Created by Slightly Mad Programming Team Version: 1.1 [14.02.2004], a bit generalized form v. 1.0 [16.08.2001] Author: Konrad Grochowski with some help from Ryszard Kostecki E-mail: konrad_grochowski@op.pl This file can be developed and distributed under terms of GNU General Public License, or as an Open Source code, as You, will (however, this credits comment should stay). */ //--------------------------------------------------------------------------- #ifndef class_pxmH #define class_pxmH #include #include //--------------------------------------------------------------------------- class pxm { private: unsigned short type_p; unsigned height; unsigned width; unsigned short max_colors; unsigned short red; unsigned short green; unsigned short blue; Graphics::TBitmap * bitmap; public: pxm (char * file_name); void paint (TCanvas *Canvas); void paintxy (TCanvas *Canvas, unsigned short x, unsigned short y); ~pxm(); }; //--------------------------------------------------------------------------- pxm::pxm(char * file_name) { bitmap = new Graphics::TBitmap; fstream file(file_name,ios::in); file.clear(); file.seekg(1); file >> type_p; while(file.get()!='#'); while(file.get()!='\n'); file >> height >> width; if (type_p!=1) file >> max_colors; bitmap->Height = height; bitmap->Width = width; if(type_p==1) { for (unsigned y=0;y> temp; red=green=blue=(!temp)*255; bitmap->Canvas->Pixels[x][y]=(TColor)RGB(red,green,blue); } } } else if (type_p==2) { for (unsigned y=0;y> red; green=blue=red; bitmap->Canvas->Pixels[x][y]=(TColor)RGB(red,green,blue); } } } else if (type_p==3) { for (unsigned y=0;y> red; file >> green; file >> blue; bitmap->Canvas->Pixels[x][y]=(TColor)RGB(red,green,blue); } } } else ; //some error msg file.close(); } //--------------------------------------------------------------------------- void pxm::paint(TCanvas *Canvas) { Canvas->Draw(0,0,bitmap); } //--------------------------------------------------------------------------- void pxm::paintxy(TCanvas *Canvas,unsigned short x,unsigned short y) { Canvas->Draw(x,y,bitmap); } //--------------------------------------------------------------------------- pxm::~pxm() { delete bitmap; } //--------------------------------------------------------------------------- #endif