// image.cpp -- base class for image data // // Written by Frederic Bouvier, started October 2001. // // Copyright (C) 2001 Frederic Bouvier - fredb@users.sourceforge.net // // 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., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id: image.cpp,v 1.6 2005/05/09 07:01:52 fredb Exp $ #include "image.hpp" FGSD_Image::FGSD_Image() : _buffer( 0 ) , _width( 0 ) , _height( 0 ) , _rowStride( 0 ) , _depth( 0 ) { } FGSD_Image::~FGSD_Image() { if ( _buffer != 0 ) delete[] _buffer; } void FGSD_Image::allocImage( unsigned int __width, unsigned int __height, unsigned int __depth ) { if ( _buffer ) delete _buffer; _buffer = new unsigned char[ __width * __height * __depth ]; _width = __width; _height = __height; _rowStride = __depth * _width; _depth = __depth; } unsigned char * FGSD_Image::buffer( unsigned int __row ) { return &_buffer[ __row * _rowStride ]; } bool FGSD_Image::load( const char *__fileName ) { return false; } bool FGSD_Image::save( const char *__fileName ) { return false; } void FGSD_Image::getAverageColor( float &red, float &green, float &blue ) { red = green = blue = 0.0; float total = 0.0; for ( unsigned int r = 0; r < _height; ++r ) { unsigned char *b = buffer( r ); for ( unsigned int c = 0; c < _width; c += _depth ) { red += (float)b[ c * _depth ]; green += (float)b[ c * _depth + 1 ]; blue += (float)b[ c * _depth + 2 ]; total += 255.0; } } if ( total == 0.0 ) return; red /= total; green /= total; blue /= total; }