|
AlbumShaper
1.0a3
|

Go to the source code of this file.
Functions | |
| QImage * | pointillismEffect (QString filename, ManipulationOptions *options) |
| QImage* pointillismEffect | ( | QString | filename, |
| ManipulationOptions * | options | ||
| ) |
Definition at line 109 of file pointillism.cpp.
References blackWhiteEffect(), computeLocalGrayVal(), drawDotAt(), editedImage, height, pickRandomPixelWithinBlock(), and width.
Referenced by EditingInterface::applyEffect().
{
//intialize seed using current time
srand( unsigned(time(NULL)) );
//load original image and convert to grayscale
QImage* originalImage = blackWhiteEffect( filename, NULL );
//construct edited image
QImage* editedImage = new QImage( originalImage->width(),
originalImage->height(),
originalImage->depth() );
//fill with white since we'll be drawing black/color dots on top
editedImage->fill( qRgb(255,255,255) );
//break image into BLOCK_SIZE x BLOCK_SIZE blocks. iterate over
//each block and pick a random pixel within. Local
//average gray value in edited image is > originalImage + thresh
//then draw a dot at pixel. continue doing this for each block
//and repeat until ???
const int BLOCK_SIZE = 8;
//compute image size in blocks
int blocksWide = editedImage->width() / BLOCK_SIZE;
if(blocksWide*BLOCK_SIZE < editedImage->width())
{ blocksWide++; }
int blocksTall = editedImage->height() / BLOCK_SIZE;
if(blocksTall*BLOCK_SIZE < editedImage->height())
{ blocksTall++; }
//iterate over image say 100 times, we'll need to fix this outer loop to be smarter?
int bx,by,x,y;
for(int i=0; i<10; i++)
{
//iterate over all blocks
for(bx=0; bx<blocksWide; bx++)
{
for(by=0; by<blocksTall; by++)
{
//pick random pixel within block
pickRandomPixelWithinBlock( editedImage->width(),
editedImage->height(),
bx, by,
BLOCK_SIZE,
x, y );
double curGrayVal = computeLocalGrayVal( editedImage, x, y );
double goalGrayVal = computeLocalGrayVal( originalImage, x, y );
//too bright -> draw dot
if( curGrayVal > goalGrayVal )
{ drawDotAt( editedImage, x, y, 5 ); }
}
}
}
//free grayscale form of original image
delete originalImage;
originalImage = NULL;
//return pointer to edited image
return editedImage;
}
1.7.5.1