Friday, July 16, 2010

Bitmapped Graphics

Just to sharpen my bits and bytes teeth, I decided to implement a Bitmapped graphics surface. The definition is simple and you can find it in most C++ books. We have a (Length * Height) screen of bits. All of the bits are placed inside a byte array. Implement a class with two basic functions of setting and resetting the bits in each.(15 + 37) MyBitmap.h
 class MyBitmap { public:  MyBitmap(int length, int height);  ~MyBitmap(void);   void set(int iHPos, int iVPos);  void reset(int iHPos, int iVPos);   void printBitmap();  private:  int _length;  int _height;  char* _pBitHolder;   void validateCoordinate(int iHPos, int iVPos); }; 
MyBitmap.cpp
 MyBitmap::MyBitmap(int length, int height) {  if( ((length * height) % 8 ) != 0)   throw std::invalid_argument(                   "Length by Height must be dividable by 8");   _length = length;  _height = height;  const int bitHolderSize = (length * height) / 8;  _pBitHolder = new char[bitHolderSize];  for(int iInitializer = 0; iInitializer < itotalbitcount            =" iVPos" ibytecounter            =" iTotalBitCount" ibitcounter             =" iTotalBitCount" itotalbitcount            =" iVPos" ibytecounter            =" iTotalBitCount" ibitcounter             =" iTotalBitCount"> iHPos)   throw std::out_of_range(                 "Invalid Argument for iHPos");  if(0 > iVPos)   throw std::out_of_range(                 "Invalid Argument for iVPos");  if(iHPos >= _length)   throw std::out_of_range(                 "Invalid Argument for iHPos");  if(iVPos >= _height)   throw std::out_of_range(                 "Invalid Argument for iVPos"); }  void MyBitmap::printBitmap() {  int iTotalBitCount = 0;  int iByteCounter = 0;  int iBitCounter  = 0;   for(int iRowCounter = 0;                  iRowCounter < icolcounter =" 0;" itotalbitcount                           =" iRowCounter" ibytecounter                           =" iTotalBitCount" ibitcounter                            =" iTotalBitCount" cholderbyte                           =" _pBitHolder[iByteCounter];">

No comments:

Post a Comment