#include "thptra.h"
 
thptra::thptra()
{
	srcImage.load(":/new/prefix2/Interface/Theme/nullpixmap.png");
	srcImage2.load(":/new/prefix2/Interface/Theme/nullpixmap.png");
	srcImage3.load(":/new/prefix2/Interface/Theme/nullpixmap.png");
	dstImage.load(":/new/prefix2/Interface/Theme/nullpixmap.png");

	srcImage = srcImage.convertToFormat ( QImage::Format_ARGB32, Qt::AutoColor );
	srcImage2 = srcImage2.convertToFormat ( QImage::Format_ARGB32, Qt::AutoColor );
	srcImage3 = srcImage3.convertToFormat ( QImage::Format_ARGB32, Qt::AutoColor );
	dstImage = dstImage.convertToFormat ( QImage::Format_ARGB32, Qt::AutoColor );
}

void thptra::scaleimg(int x, int y)
{
	srcImage = srcImage.scaled( x, y, Qt::IgnoreAspectRatio, Qt::FastTransformation );
	srcImage2 = srcImage2.scaled( x, y, Qt::IgnoreAspectRatio, Qt::FastTransformation );
	srcImage3 = srcImage3.scaled( x, y, Qt::IgnoreAspectRatio, Qt::FastTransformation );
	dstImage = dstImage.scaled( x, y, Qt::IgnoreAspectRatio, Qt::FastTransformation );
}

void thptra::run()
{
	if ( numtrans == 1 )
	{
		// *** Fondu enchaine ***
		for (int y = 0; y < srcImage.height(); y=y+1)
		{
			for (int x = 0; x < srcImage.width(); x++)
			{
				srcPixel = srcImage.pixel(x, y);
				srcPixel2 = srcImage2.pixel(x, y);
				tmpcolor1 = srcPixel;
				tmpcolor2 = srcPixel2;
				tmpcolor3.setRed(tmpcolor1.red() * (1-(float)((float)sequence/(float)100)) + tmpcolor2.red() * (float)((float)sequence/(float)100));
				tmpcolor3.setGreen(tmpcolor1.green() * (1-(float)((float)sequence/(float)100)) + tmpcolor2.green() * (float)((float)sequence/(float)100));
				tmpcolor3.setBlue(tmpcolor1.blue() * (1-(float)((float)sequence/(float)100)) + tmpcolor2.blue() * (float)((float)sequence/(float)100));
				dstPixel = tmpcolor3.rgb();
				dstImage.setPixel(x, y, dstPixel);
			}				
		}
	}
	else
	{
		// *** Transitions par luma ***
		mycolor.setRed((float)((float)255/(float)100)*(float)sequence);
		mycolor.setGreen((float)((float)255/(float)100)*(float)sequence);
		mycolor.setBlue((float)((float)255/(float)100)*(float)sequence);

		for (int y = 0; y < srcImage.height(); y++)
		{
			for (int x = 0; x < srcImage.width(); x++) 
			{
				srcPixel = srcImage.pixel(x, y);
				srcPixel2 = srcImage2.pixel(x, y);
				srcPixel3 = srcImage3.pixel(x, y);
				tmpcolor1 = srcPixel;
				tmpcolor2 = srcPixel2;
				tmpcolor3 = srcPixel3;
				if ( invert == "0" )
				{
					if ( tmpcolor3.value() > mycolor.value() )
					{
						dstImage.setPixel(x, y, srcPixel);
					}
					else
					{
						dstImage.setPixel(x, y, srcPixel2);
					}
				}
				else
				{
					if ( tmpcolor3.value() > mycolor.value() )
					{
						dstImage.setPixel(x, y, srcPixel2);
					}
					else
					{
						dstImage.setPixel(x, y, srcPixel);
					}
				}
			}
		}
	}
	emit myfin();
	//exec();
}

