AlbumShaper  1.0a3
Classes | Functions
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

QImage* mosaicEffect ( QString  filename,
MosaicOptions options 
)

Definition at line 290 of file mosaic.cpp.

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().

{
  //load image
  QImage* editedImage = new QImage( filename );
  
  //convert to 32-bit depth if necessary
  if( editedImage->depth() < 32 )
  {
    QImage* tmp = editedImage;
    editedImage = new QImage( tmp->convertDepth( 32, Qt::AutoColor ) );
    delete tmp; tmp=NULL;
  }
  
  //determine if busy indicators will be used
  bool useBusyIndicators = false;
  StatusWidget* status = NULL;
  if( options != NULL && options->getStatus() != NULL )
  {
    useBusyIndicators = true;
    status = options->getStatus(); 
  }
  
  //intialize seed using current time
  srand( unsigned(time(NULL)) );
  
  //determine tile size
  QSize tileSize;
  if(options == NULL) tileSize = QSize(6,6); //6 is big enough to be visible, but not so blocky the image looks bad
  else                tileSize =options->getTileSize();
  
  //construct tile set
  TileSet* tileSet = NULL;
  if( options != NULL && options->getFileList().size() > 0 )
  {
    constructImageTiles(options->getFileList(), tileSize);
    tileSet = &imageTiles;
  }
  else
  { 
    constructColorTiles(tileSize);
    tileSet = &colorTiles;
  }

  //setup progress bar
  if(useBusyIndicators)
  {
    QString statusMessage = qApp->translate( "mosaicEffect", "Applying Mosaic Effect:" );
    status->showProgressBar( statusMessage, 100 );
    qApp->processEvents();  
  }

  //update progress bar for every 1% of completion
  const int updateIncrement = (int) ( (0.01 * editedImage->width() * editedImage->height()) / 
                                      (tileSize.width() * tileSize.height()) );
  int newProgress = 0; 

  //iterate over each selected scanline 
  int x, y;
  for(y=0; y<editedImage->height(); y+=tileSize.height())
  {
    for( x=0; x<editedImage->width(); x+=tileSize.width())
    {
      //splat the best tile
      splatBestTile( editedImage, QPoint(x,y), tileSet );
     
      //update status bar if significant progress has been made since last update
      if(useBusyIndicators)
      {
        newProgress++;
        if(newProgress >= updateIncrement)
        {
          newProgress = 0;
          status->incrementProgress();
          qApp->processEvents();  
        }
      }

    }
  }
   
  //return pointer to edited image
  return editedImage;  
}