/* 24 bit Device Independent Bitmap class Copyright (c) 2002,2003 Alessandro Scotti http://www.ascotti.org/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "SDL.h" #include "dib24.h" void Dib24::createBitmap( int width, int height ) { assert( width > 0 ); assert( height > 0 ); hdc_ = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); assert( hdc_ != 0 ); bitmapbits_ = (uint8_t *)hdc_->pixels; scanlength_ = hdc_->pitch; //4 * ((width*3 + 3) / 4); // Length of a scan line width_ = width; height_ = height; } Dib24::Dib24( int width, int height ) { createBitmap( width, height ); clear(); } Dib24::Dib24( const Dib24 & dib ) { createBitmap( dib.width_, dib.height_ ); memcpy( bitmapbits_, dib.bitmapbits_, scanlength_*height_ ); } Dib24::~Dib24() { SDL_FreeSurface( hdc_ ); } void Dib24::clear() { //ZeroMemory( bitmapbits_, scanlength_*height_ ); Uint32 color = SDL_MapRGB(hdc_->format, 0x00, 0x00, 0x00); SDL_FillRect(hdc_, NULL, color); } DWORD Dib24::getPixel( int x, int y ) { if( x < 0 || x >= width_ || y < 0 || y >= height_ ) return 0; return getFastPixel( x, y ); } void Dib24::setPixel( int x, int y, DWORD value ) { if( x < 0 || x >= width_ || y < 0 || y >= height_ ) return; setFastPixel( x, y, value ); }