00001 #include "ImageCalculator.h"
00002 #include "ImageTiler.h"
00003 #include "fractale.h"
00004
00005 ImageCalculator::ImageCalculator(int nb, QImage *d, QRectF w, QSize r, fractale &f, char e, bool a):nbThreads(nb), destination(d), window(w), size(r), frac(f), exhaustivite(e), animate(a){
00006 for (int i=0; i<nb; i++){
00007 QImage *img = new QImage(r, QImage::Format_RGB888);
00008 img->fill(QColor(0,0,0).rgb());
00009 imageParts.push_back(img);
00010 }
00011
00012 nbProcessedRows = 0;
00013 }
00014
00015 ImageCalculator::~ImageCalculator(){
00016 for (int i=0; i<nbThreads; i++)
00017 delete imageParts[i];
00018 }
00019
00020 void ImageCalculator::run(){
00021 QVector<ImageTiler*> tilers;
00022
00023 for(int i=0; i<nbThreads; i++){
00024 ImageTiler *it = new ImageTiler(imageParts[i], window, size, &frac, exhaustivite, i, nbThreads, i);
00025
00026
00027 QObject::connect(it, SIGNAL(processed()), this, SLOT(s_processing()));
00028
00029 it->run();
00030 tilers.push_back(it);
00031 }
00032
00033 for (int i=0; i<nbThreads; i++)
00034 tilers[i]->wait();
00035
00036 sumImagesIntoDestination();
00037
00038
00039 emit render();
00040
00041 for (int i=0; i<nbThreads; i++)
00042 delete tilers[i];
00043 }
00044
00045 void ImageCalculator::sumImagesIntoDestination(){
00046 int v;
00047 maxValue = 0;
00048 for (int x = 0; x< size.width(); x++)
00049 for (int y=0; y<size.height(); y++){
00050 v = 0;
00051 for (int i=0; i<nbThreads; i++)
00052 v+= ImageCalculator::RGBAToInt(imageParts[i]->pixel(x,y));
00053 destination->setPixel(x,y,ImageCalculator::intToRGBA((v)));
00054 if (v > maxValue)
00055 maxValue = v;
00056 }
00057 }
00058
00059 void ImageCalculator::applyGamma(){
00060 for (int x = 0; x< size.width(); x++)
00061 for (int y=0; y<size.height(); y++){
00062 int value = ImageCalculator::RGBAToInt(destination->pixel(x,y));
00063 int newvalue = ((std::pow(double(value) / maxValue, .5)) ) * 1024;
00064 destination->setPixel(x,y,ImageCalculator::intToRGBA((newvalue)));
00065 }
00066 }
00067
00068
00069 void ImageCalculator::s_processing(){
00070 nbProcessedRows ++;
00071
00072 if (animate){
00073 sumImagesIntoDestination();
00074 emit render();
00075 }
00076
00077 emit progress(100 * nbProcessedRows / size.width());
00078 }
00079