All pastes #1636181 Raw Edit

Someone

public cpp v1 · immutable
#1636181 ·published 2009-10-21 23:03 UTC
rendered paste body
void RenderArea::setMedianRadius( int newRadius ){	int maxWidth = savedImage.width(), maxHeight = savedImage.height();	int counter, tempCounter, x, y, xi, yi, xmin, ymin, xmax, ymax, xr, yr, radius, red, green, blue;	double exactRadius;	QRgb pixelArray[ newRadius * newRadius ];	bool bitMask[ newRadius + 2 ][ newRadius + 2 ];	unsigned short int tempArray[ newRadius * newRadius ];	isBinaryTemp = isBinary;	medianRadius = newRadius;	isMaskTemp = false;	if( medianRadius == 1 ) image = savedImage;	else {		radius = medianRadius / 2 + 1;		exactRadius = medianRadius / 2.0;		for( xi = 0; xi < medianRadius + 2; xi++ ) {			for( yi = 0; yi < medianRadius + 2; yi++ ) {				bitMask[ xi ][ yi ] = ( sqrt( ( radius - xi ) * ( radius - xi ) + ( radius - yi ) * ( radius - yi ) ) <= exactRadius );			}		}		if( !isBinary ) {			for( x = 0; x < maxWidth; x++ ) {				for( y = 0; y < maxHeight; y++ ) {					xmin = min( maxWidth, x + radius );					ymin = min( maxHeight, y + radius );					xmax = max( 0, x - radius + 1 );					ymax = max( 0, y - radius + 1 );					xr = x - radius;					yr = y - radius;					counter = 0;					for( xi = xmax; xi < xmin; xi++ ) {						for( yi = ymax; yi < ymin; yi++ ) {							if( bitMask[ xi - xr ][ yi - yr ] ) {								pixelArray[ counter++ ] = savedImage.pixel( xi, yi );							}						}					}					for( tempCounter = 0; tempCounter < counter; tempCounter++ ) {						tempArray[ tempCounter ] = qRed( pixelArray[ tempCounter ] );					}					std::nth_element( tempArray, tempArray + counter / 2, tempArray + counter );					red = tempArray[ counter / 2 ];					for( tempCounter = 0; tempCounter < counter; tempCounter++ ) {						tempArray[ tempCounter ] = qGreen( pixelArray[ tempCounter ] );					}					std::nth_element( tempArray, tempArray + counter / 2, tempArray + counter );					green = tempArray[ counter / 2 ];					for( tempCounter = 0; tempCounter < counter; tempCounter++ ) {						tempArray[ tempCounter ] = qBlue( pixelArray[ tempCounter ] );					}					std::nth_element( tempArray, tempArray + counter / 2, tempArray + counter );					blue = tempArray[ counter / 2 ];					image.setPixel( x, y, qRgb( red, green, blue ) );				}			}		} else {			for( x = 0; x < maxWidth; x++ ) {				for( y = 0; y < maxHeight; y++ ) {					xmin = min( maxWidth, x + radius );					ymin = min( maxHeight, y + radius );					xmax = max( 0, x - radius + 1 );					ymax = max( 0, y - radius + 1 );					xr = x - radius;					yr = y - radius;					counter = tempCounter = 0;					for( xi = xmax; xi < xmin; xi++ ) {						for( yi = ymax; yi < ymin; yi++ ) {							if( bitMask[ xi - xr ][ yi - yr ] ) {								counter++;								if( savedImage.pixel( xi, yi ) & 1 ) tempCounter++;							}						}					}					if( tempCounter > counter - tempCounter ) image.setPixel( x, y, qRgb( 255, 255, 255 ) );					else image.setPixel( x, y, qRgb( 0, 0, 0 ) );				}			}		}	}	update();}