AlbumShaper 1.0a3
mosaic.h File Reference
#include "manipulationOptions.h"
#include <qsize.h>
Include dependency graph for mosaic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  MosaicOptions
 

Functions

QImage * mosaicEffect (QString filename, MosaicOptions *options)
 

Function Documentation

◆ mosaicEffect()

QImage * mosaicEffect ( QString filename,
MosaicOptions * options )

Definition at line 293 of file mosaic.cpp.

294{
295 //load image
296 QImage* editedImage = new QImage( filename );
297
298 //convert to 32-bit depth if necessary
299 if( editedImage->depth() < 32 )
300 {
301 QImage* tmp = editedImage;
302 editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
303 delete tmp; tmp=NULL;
304 }
305
306 //determine if busy indicators will be used
307 bool useBusyIndicators = false;
308 StatusWidget* status = NULL;
309 if( options != NULL && options->getStatus() != NULL )
310 {
311 useBusyIndicators = true;
312 status = options->getStatus();
313 }
314
315 //intialize seed using current time
316 srand( unsigned(time(NULL)) );
317
318 //determine tile size
319 QSize tileSize;
320 if(options == NULL) tileSize = QSize(6,6); //6 is big enough to be visible, but not so blocky the image looks bad
321 else tileSize =options->getTileSize();
322
323 //construct tile set
324 TileSet* tileSet = NULL;
325 if( options != NULL && options->getFileList().size() > 0 )
326 {
327 constructImageTiles(options->getFileList(), tileSize);
328 tileSet = &imageTiles;
329 }
330 else
331 {
332 constructColorTiles(tileSize);
333 tileSet = &colorTiles;
334 }
335
336 //setup progress bar
337 if(useBusyIndicators)
338 {
339 QString statusMessage = qApp->translate( "mosaicEffect", "Applying Mosaic Effect:" );
340 status->showProgressBar( statusMessage, 100 );
341 qApp->processEvents();
342 }
343
344 //update progress bar for every 1% of completion
345 const int updateIncrement = (int) ( (0.01 * editedImage->width() * editedImage->height()) /
346 (tileSize.width() * tileSize.height()) );
347 int newProgress = 0;
348
349 //iterate over each selected scanline
350 int x, y;
351 for(y=0; y<editedImage->height(); y+=tileSize.height())
352 {
353 for( x=0; x<editedImage->width(); x+=tileSize.width())
354 {
355 //splat the best tile
356 splatBestTile( editedImage, QPoint(x,y), tileSet );
357
358 //update status bar if significant progress has been made since last update
359 if(useBusyIndicators)
360 {
361 newProgress++;
363 {
364 newProgress = 0;
366 qApp->processEvents();
367 }
368 }
369
370 }
371 }
372
373 //return pointer to edited image
374 return editedImage;
375}
StatusWidget * getStatus()
QStringList getFileList()
Definition mosaic.cpp:254
QSize getTileSize()
Definition mosaic.cpp:255
void showProgressBar(QString message, int numSteps)
Initializes the progress bar.
void incrementProgress()
Updates the progress bar by one step.
void splatBestTile(QImage *image, QPoint topLeftCorner, TileSet *tileSet)
Definition mosaic.cpp:601
TileSet imageTiles
Definition mosaic.cpp:286
void constructImageTiles(QStringList files, QSize tileSize)
Definition mosaic.cpp:416
void constructColorTiles(QSize tileSize)
Definition mosaic.cpp:378
TileSet colorTiles
Definition mosaic.cpp:285
int updateIncrement
QImage * editedImage
StatusWidget * status
int newProgress

References colorTiles, constructColorTiles(), constructImageTiles(), editedImage, MosaicOptions::getFileList(), ManipulationOptions::getStatus(), MosaicOptions::getTileSize(), imageTiles, StatusWidget::incrementProgress(), newProgress, StatusWidget::showProgressBar(), splatBestTile(), status, and updateIncrement.

Referenced by EditingInterface::applyEffect().