AlbumShaper 1.0a3
pointillism.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

QImage * pointillismEffect (QString filename, ManipulationOptions *options)
 

Function Documentation

◆ pointillismEffect()

QImage * pointillismEffect ( QString filename,
ManipulationOptions * options )

Definition at line 109 of file pointillism.cpp.

110{
111 //intialize seed using current time
112 srand( unsigned(time(NULL)) );
113
114 //load original image and convert to grayscale
115 QImage* originalImage = blackWhiteEffect( filename, NULL );
116
117 //construct edited image
118 QImage* editedImage = new QImage( originalImage->width(),
119 originalImage->height(),
120 originalImage->depth() );
121
122 //fill with white since we'll be drawing black/color dots on top
123 editedImage->fill( qRgb(255,255,255) );
124
125 //break image into BLOCK_SIZE x BLOCK_SIZE blocks. iterate over
126 //each block and pick a random pixel within. Local
127 //average gray value in edited image is > originalImage + thresh
128 //then draw a dot at pixel. continue doing this for each block
129 //and repeat until ???
130 const int BLOCK_SIZE = 8;
131
132 //compute image size in blocks
133 int blocksWide = editedImage->width() / BLOCK_SIZE;
134 if(blocksWide*BLOCK_SIZE < editedImage->width())
135 { blocksWide++; }
136
137 int blocksTall = editedImage->height() / BLOCK_SIZE;
138 if(blocksTall*BLOCK_SIZE < editedImage->height())
139 { blocksTall++; }
140
141 //iterate over image say 100 times, we'll need to fix this outer loop to be smarter?
142 int bx,by,x,y;
143 for(int i=0; i<10; i++)
144 {
145 //iterate over all blocks
146 for(bx=0; bx<blocksWide; bx++)
147 {
148 for(by=0; by<blocksTall; by++)
149 {
150 //pick random pixel within block
152 editedImage->height(),
153 bx, by,
154 BLOCK_SIZE,
155 x, y );
156
157 double curGrayVal = computeLocalGrayVal( editedImage, x, y );
158 double goalGrayVal = computeLocalGrayVal( originalImage, x, y );
159
160 //too bright -> draw dot
161 if( curGrayVal > goalGrayVal )
162 { drawDotAt( editedImage, x, y, 5 ); }
163 }
164 }
165 }
166
167 //free grayscale form of original image
168 delete originalImage;
169 originalImage = NULL;
170
171 //return pointer to edited image
172 return editedImage;
173}
QImage * blackWhiteEffect(QString filename, ManipulationOptions *options)
int width
Definition blur.cpp:79
int height
Definition blur.cpp:79
double computeLocalGrayVal(QImage *image, int x, int y)
void pickRandomPixelWithinBlock(int width, int height, int blockX, int blockY, int BLOCK_SIZE, int &x, int &y)
void drawDotAt(QImage *image, int x, int y, int)
QImage * editedImage

References blackWhiteEffect(), computeLocalGrayVal(), drawDotAt(), editedImage, height, pickRandomPixelWithinBlock(), and width.

Referenced by EditingInterface::applyEffect().