All pastes #242101 Raw Edit

Something

public text v1 · immutable
·published 2006-11-06 22:25 UTC
rendered paste body
    /** Convert the image to an one-channel grayscale image. */
    void Image::convertToGrayscale(){
	    const size_t nPixels = this->_header.width * this->_header.height;
	    const size_t depth   = this->_header.depth;
	    const size_t nBytes  = nPixels * depth;
	    unsigned char* _pixelsnew = new unsigned char[nBytes/3];
	    
		int sum = 0;
	    int j = 0;
	    for( size_t i = 0; i < nBytes; ++i ){
	       	if(i % 3 == 0 && i != 0){
	       		_pixelsnew[j]= sum/3;
	       		j++;
	       		sum = 0;
	    		sum += this->_pixels[i];
	       	}
	    	else
	    		sum += this->_pixels[i];
	    };
	    this->_pixels = _pixelsnew;
	    this->_header.depth = 1;
    };