#include <QtGui>
#include "mainfrm.h"
//#include "imageeditor.h"

void mainfrm::f_import_folder()
{
    	QList<QListWidgetItem *> listsfile = lstfiles->selectedItems();
    	QListWidgetItem *mywidget = new QListWidgetItem;
	mywidget = listsfile.at(0);
	QDir tmpdir;
	tmpdir.setPath(current_path + "/" + mywidget->text());
	QStringList filters;
	filters << "*.jpg" << "*.JPG" << "*.jpeg" << "*.JPEG" << "*.png" << "*.PNG";
	tmpdir.setNameFilters(filters);
	tmpdir.setSorting(QDir::Name);
	QString wlfile;
	if ( current_diapo >= 0 )
	{
		pnttimeline->drop_x = 10 + ((current_diapo+1) * 107);
	}
	else
	{
		pnttimeline->drop_x = 0;
	}

	int wlcurr = current_diapo;

	pb_import->setValue(0);
	pb_import->setMaximum(tmpdir.count());

	foreach (wlfile, tmpdir.entryList(QDir::Files,QDir::Name))
	{
		pnttimeline->wl_pathname = current_path + "/" + mywidget->text() + "/" + wlfile;
		pnttimeline->drop_x = 10 + ((wlcurr+1) * 107);
		insert_photo();
		pb_import->setValue(wlcurr);
		wlcurr++;
	}
	pb_import->setValue(tmpdir.count());
}

void mainfrm::f_import_background()
{
	f_change_fond();
	f_close_bib();
}

void mainfrm::f_import_pictures()
{
    	QList<QListWidgetItem *> listsfile = lstfiles->selectedItems();
    	QListWidgetItem *mywidget = new QListWidgetItem;
	if ( current_diapo >= 0 )
	{
		pnttimeline->drop_x = 10 + ((current_diapo+1) * 107);
	}
	else
	{
		pnttimeline->drop_x = 0;
	}
	int wlcurr = current_diapo+1;
	pb_import->setValue(0);
	pb_import->setMaximum(listsfile.size());

	for (int i = 0; i < listsfile.size(); ++i) 
	{
		mywidget = listsfile.at(i);
		if ( mywidget->statusTip() == "IMAGE" )
		{
			pnttimeline->wl_pathname = current_path + "/" + mywidget->toolTip();
			insert_photo();
			pnttimeline->drop_x = 10 + ((wlcurr+1) * 107);
			wlcurr++;
			pb_import->setValue(i);
		}
	}
	pb_import->setValue(listsfile.size());
	current_diapo = wlcurr-1;
}

void mainfrm::f_charge_liste_files(QString local_path)
{
	if ( local_path != "" )
	{
		poursuite = 0;
		lstfiles->clear();
		QDir tmpdir;
		tmpdir.setPath(local_path);
		QStringList filters;
     		filters << "*.jpg" << "*.JPG" << "*.jpeg" << "*.JPEG" << "*.png" << "*.PNG";
     		tmpdir.setNameFilters(filters);
		QString wlfile;
		foreach (wlfile, tmpdir.entryList(QDir::AllDirs))
		{
			if ( wlfile == "." )
			{
			}
			else
			{
				QListWidgetItem *item = new QListWidgetItem(lstfiles);
				if ( wlfile == ".." )
				{
					item->setIcon(QIcon(":/new/prefix2/Interface/Theme/2uparrow.png"));	
				}
				else
				{
					item->setIcon(QIcon(":/new/prefix2/Interface/Theme/folder.png"));
				}
				item->setStatusTip("FOLDER");
				item->setText(wlfile);
			}
		}
		foreach (wlfile, tmpdir.entryList(QDir::Files))
		{
			QListWidgetItem *item = new QListWidgetItem(lstfiles);
			item->setIcon(QIcon(":/new/prefix2/Interface/Theme/image.png"));
			item->setStatusTip("IMAGE");
			item->setToolTip(wlfile);
		}

		if ( lstfiles->count() > 0 )
		{
			poursuite_2 = 0;
			QTimer::singleShot(2, this, SLOT(f_affiche_preview()));
		}
	}
}

void mainfrm::f_refresh_liste()
{
	thread_thu->quit();
	thread_thu->wait();
	pntdir->refresh(idxmod);
	QTimer::singleShot(20, this, SLOT(f_chng_directory()));
}

void mainfrm::f_dbl_load_photo()
{
    	QList<QListWidgetItem *> listsfile = lstfiles->selectedItems();
    	QListWidgetItem *mywidget = new QListWidgetItem;
	mywidget = listsfile.at(0);
	if ( mywidget->statusTip() == "FOLDER" )
	{
		if ( thread_thu->isRunning() == true )
		{
			thread_thu->quit();
			thread_thu->wait();
		}
		current_path = current_path + "/" + mywidget->text();
		lstfiles->wl_current_path = current_path;
		poursuite = 1;
		QTimer::singleShot(20, this, SLOT(f_chng_directory()));
	}
	else
	{
		if ( tmpint_5 == 0 )
		{
			pnttimeline->drop_x = (current_diapo + 1) * 107;
			pnttimeline->wl_pathname = current_path + "/" + mywidget->toolTip();
			insert_photo();
			tmpint_5 = 0;
		}
		else
		{
			f_change_fond();
			f_close_bib();
		}
	}
}

void mainfrm::f_affiche_preview()
{
    	mywidget = lstfiles->item(poursuite_2);

	if ( mywidget->statusTip() == "FOLDER" )
	{
		poursuite_2++;
		if ( poursuite_2 < lstfiles->count() && poursuite == 0 )
		{
			QTimer::singleShot(2, this, SLOT(f_affiche_preview()));
		}
	}
	else
	{
		thread_thu->mywidget = mywidget;
		thread_thu->run();
	}
}

void mainfrm::f_update_thumbail()
{
	if ( thread_thu->result == 1 )
	{
		mywidget->setIcon(thread_thu->wlico);
	}
	else
	{
		mywidget = lstfiles->takeItem(poursuite_2);
	}
	poursuite_2++;
	if ( poursuite_2 < lstfiles->count() && poursuite == 0 )
	{
		QTimer::singleShot(2, this, SLOT(f_affiche_preview()));
	}
}

void mainfrm::f_chng_directory()
{
	thread_thu->current_path = current_path;
	f_charge_liste_files(current_path);
}

void mainfrm::f_open_bib()
{
	toolsmenu->hide();
	tmpint_5 = 0;
	lstfiles->status = 0;
	lstfiles->setSelectionMode(QAbstractItemView::ExtendedSelection);
	lstfiles->setSelectionRectVisible(true);
	pntmygl->resize(0,0);
	top_timeline->setDisabled(true);
	menubar->setDisabled(true);
	toolBar->setDisabled(true);
	pb_import->setValue(0);
	frame_bibliotheque->show();
	frame_bibliotheque->raise();
	lstfiles->wl_current_path = current_path;
	if ( poursuite_2 < lstfiles->count() )
	{
		poursuite = 0;
		QTimer::singleShot(3, this, SLOT(f_affiche_preview()));
	}
}

void mainfrm::f_open_bib_fond()
{
	toolsmenu->hide();
	tmpint_5 = 1;
	lstfiles->status = 1;
	lstfiles->setSelectionMode(QAbstractItemView::SingleSelection);
	pntmygl->resize(0,0);
	top_timeline->setDisabled(true);
	menubar->setDisabled(true);
	toolBar->setDisabled(true);
	pb_import->setValue(0);
	frame_bibliotheque->show();
	frame_bibliotheque->raise();
	lstfiles->wl_current_path = current_path;
	if ( poursuite_2 < lstfiles->count() )
	{
		poursuite = 0;
		QTimer::singleShot(3, this, SLOT(f_affiche_preview()));
	}
}

void mainfrm::f_close_bib()
{
	poursuite = 1;
	if ( thread_thu->isRunning() == true )
	{
		thread_thu->quit();
		thread_thu->wait();
	}
	lstfiles->clearSelection();
	pntmygl->resize(size_dia_x,size_dia_y);
	menubar->setEnabled(true);
	toolBar->setEnabled(true);
	frame_bibliotheque->hide();
	toolsmenu->show();
	if ( nbre_photos >= 0 )
	{
		if ( current_diapo < 0 )
		{
			current_diapo = 0;
		}
		tabmenus->setEnabled(true);
		toolsmenu->setEnabled(true);
		actionDeplacement->setEnabled(true);
		actionZoom->setEnabled(true);
		actionRotation_X->setEnabled(true);
		actionRotation_Y->setEnabled(true);
		actionRotation_Z->setEnabled(true);
		actionRotation_libre->setEnabled(true);
		actionReinitialiser->setEnabled(true);
		actionMarquer_depart->setEnabled(true);
		actionMarquer_fin->setEnabled(true);
		actionEditer_diapositive->setEnabled(true);
		actionSupprimer_diapositive->setEnabled(true);
		actionDupliquer_la_diapositive_actuelle->setEnabled(true);
		actionCopier->setEnabled(true);
		actionColler->setEnabled(true);
		actionPrendre_photo->setEnabled(true);
		actionDeplacer_gauche->setEnabled(true);
		actionDeplacer_droite->setEnabled(true);
		actionRender->setEnabled(true);
		actionEnregistrer->setEnabled(true);
		actionEnregistrer_sous->setEnabled(true);
		top_timeline->setEnabled(true);
		affichage_diapo();
		pntmygl->bcle_render = 1;
	}
}

void mainfrm::f_launch_editor()
{
	QPixmap wl_img_001;
	if ( wl_img_001.load(wpathprojet + "/" + table_photos[current_diapo][0]) == true )
	{
		frame_eraser_param->hide();
		frame_rotation_img->hide();
		thread_img->must_redraw = 0;
		slider_lumiere->setValue(0);
		slider_contraste->setValue(0);
		slider_R->setValue(0);
		slider_V->setValue(0);
		slider_B->setValue(0);
		slider_ouverture->setValue(0);
		slider_ouverture_longueur->setValue(50);
		slider_ouverture_radius->setValue(50);
		slider_ouverture_opacity->setValue(255);
		imageeditor *myprv = new imageeditor(frame_fond_editor);
		scrollArea_1->setWidget(myprv);
		pntlabel = myprv;
		pntlabel->setGeometry((frame_fond_editor->width()-wl_img_001.width())/2,(frame_fond_editor->height()-wl_img_001.height())/2,wl_img_001.width(),wl_img_001.height());
		pntlabel->setImage(wl_img_001,wpathprojet + "/" + table_photos[current_diapo][0], wl_img_001.width(), wl_img_001.height());
		connect(pntlabel, SIGNAL( deplace_fade() ),this, SLOT(f_update_fade()));
		connect(pntlabel, SIGNAL( moveoneditor(int,int) ),this, SLOT(f_update_move_editor(int,int)));
		group_crop->setEnabled(true);
		thread_img->must_redraw = 1;

		QImage wlimg = pntlabel->img2resu.toImage();
		thread_img->c_r = 0;
		thread_img->c_v = 0;
		thread_img->c_b = 0;
		thread_img->cont = 0;
		thread_img->lumi = 0;
		thread_img->rouge = 0;
		thread_img->vert = 0;
		thread_img->bleu = 0;
		thread_img->ouverture = 0;
		thread_img->radius = 50;
		thread_img->longueur = 50;
		thread_img->composition = 0;
		thread_img->opacity = 255;
		// *** CALCUL MOYENNE DU CONTRATSE ***
		QColor trtcolor;
		QRgb srcPixel;
		for (int y = 0; y < wlimg.height(); y++)
		{
			for (int x = 0; x < wlimg.width(); x++)
			{
				srcPixel = wlimg.pixel(x, y);
				trtcolor = srcPixel;
				thread_img->c_r = thread_img->c_r + trtcolor.red();
				thread_img->c_v = thread_img->c_v + trtcolor.green();
				thread_img->c_b = thread_img->c_b + trtcolor.blue();
			}
		}
		thread_img->c_r = thread_img->c_r / (wlimg.height()*wlimg.width());
		thread_img->c_v = thread_img->c_v / (wlimg.height()*wlimg.width());
		thread_img->c_b = thread_img->c_b / (wlimg.height()*wlimg.width());
		//
		f_gene_vignette(wlimg);
		//
		pntmygl->resize(0,0);
		bt_rogner->setChecked(false);
		bt_ok_rogner->setDisabled(true);
		comboforme->setCurrentIndex(0);
		frame_editor->show();
		frame_editor->raise();
		menu_imgedit->raise();
		thread_img->must_redraw = 1;
		//
		toolBar->setDisabled(true);
		menubar->setDisabled(true);
	}
}

void mainfrm::f_update_move_editor(int x,int y)
{
	scrollArea_1->ensureVisible ( x, y, 50, 50 );
}

void mainfrm::f_cancel_editor()
{
	delete pntlabel;
	frame_editor->hide();
	toolBar->setEnabled(true);
	menubar->setEnabled(true);
	pntmygl->resize(size_dia_x,size_dia_y);
	affichage_diapo();
}

void mainfrm::f_ok_editor()
{
	QImage wl_pix_1 = pntlabel->img2resu.toImage();
	//wl_pix_1 = wl_pix_1.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	QPixmap wl_pix_2(97,77);
	QImage wl_pix_3;
	QPainter p;
	wl_pix_2 = wg_diapositive;

	//pntlabel->img2resu.save(wpathprojet + "/" + table_photos[current_diapo][0]);
	wl_pix_1.save(wpathprojet + "/" + table_photos[current_diapo][0],"PNG",100);
	pntmygl->resize(size_dia_x,size_dia_y);
	affichage_diapo();
	delete pntlabel;
	frame_editor->hide();

	// *** CREATION DE LA MINIATURE ***
	if ( wl_pix_1.height() >= wl_pix_1.width() )
	{
		wl_pix_3 = wl_pix_1.scaledToHeight ( 63, Qt::FastTransformation );
	}
	else
	{
		wl_pix_3 = wl_pix_1.scaledToWidth ( 83, Qt::FastTransformation );
	}
	p.begin(&wl_pix_2);
	p.drawImage(7 + ((83 - wl_pix_3.width()) / 2), 7 + ((63 - wl_pix_3.height()) / 2), wl_pix_3, 0, 0, wl_pix_3.width(), wl_pix_3.height());
	QIcon myicon = lst_transitions->itemIcon(lst_transitions->currentIndex());
	myicon.paint ( &p, 5, 40, 32, 32, Qt::AlignCenter, QIcon::Normal, QIcon::On );
	if ( table_photos[current_diapo][24] != "" )
	{
		p.drawPixmap(68, 57, wg_comment, 0, 0, -1, -1 );
	}
	p.end();
	QLabel *mylabel = table_pnt_img[current_diapo];
	mylabel->setPixmap ( wl_pix_2 );
	affichage_diapo();
	toolBar->setEnabled(true);
	menubar->setEnabled(true);
}

void mainfrm::f_gene_vignette(QImage wlimg)
{
	// *** PREPARATION DES VIGNETTES ***
	QColor trtcolor;
	QImage wlimg2;
	if ( wlimg.width() > wlimg.height() )
	{
		wlimg = wlimg.scaledToWidth ( 90, Qt::FastTransformation );
	}
	else
	{
		wlimg = wlimg.scaledToHeight ( 70, Qt::FastTransformation );
	}
	wlimg2 = wlimg.mirrored(true,false);
	bt_tool_editor_2->setIcon(QPixmap::fromImage ( wlimg2, Qt::AutoColor ));
	wlimg2 = wlimg.mirrored(false,true);
	bt_tool_editor_3->setIcon(QPixmap::fromImage ( wlimg2, Qt::AutoColor ));
	wlimg2 = wlimg;
	wlimg2.invertPixels ( QImage::InvertRgb );
	bt_tool_editor_4->setIcon(QPixmap::fromImage ( wlimg2, Qt::AutoColor ));
	//
	wlimg2 = wlimg;
	QRgb srcPixel;
	for (int y = 0; y < wlimg2.height(); y++)
	{
		for (int x = 0; x < wlimg2.width(); x++)
		{
			srcPixel = wlimg2.pixel(x, y);
			trtcolor = srcPixel;

			trtcolor.setGreen(trtcolor.red() / 1.24);
			trtcolor.setBlue(trtcolor.green() / 1.36);
			//
			wlimg2.setPixel(x, y, trtcolor.rgb());
		}
	}
	bt_tool_editor_6->setIcon(QPixmap::fromImage ( wlimg2, Qt::AutoColor ));
	//
	int moyenne;
	wlimg2 = wlimg;
	for (int y2 = 0; y2 < wlimg2.height(); y2++)
	{
		for (int x2 = 0; x2 < wlimg2.width(); x2++)
		{
			srcPixel = wlimg2.pixel(x2, y2);
			trtcolor = srcPixel;

			moyenne = (trtcolor.red() + trtcolor.green() + trtcolor.blue())/3;
			trtcolor.setRed(moyenne);
			trtcolor.setGreen(moyenne);
			trtcolor.setBlue(moyenne);
			//
			wlimg2.setPixel(x2, y2, trtcolor.rgb());
		}
	}
	bt_tool_editor_5->setIcon(QPixmap::fromImage ( wlimg2, Qt::AutoColor ));
	//
	QPainter p;
	QPixmap wlpix1(QPixmap::fromImage ( wlimg, Qt::AutoColor ));
	p.begin(&wlpix1);
	p.fillRect ( 0, 0, wlimg.width(), 7, QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.fillRect ( 0, wlimg.height()-7, wlimg.width(), 7, QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.fillRect ( 0, 0, 7, wlimg.height(), QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.fillRect ( wlimg.width()-7, 0, 7, wlimg.height(), QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.end();
	bt_tool_editor_7->setIcon(wlpix1);

	//
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	QColor trtcolor1;
	QColor trtcolor2;
	QColor trtcolor3;
	QColor trtcolor4;
	QColor trtcolor5;
	QColor trtcolor6;
	QColor trtcolor7;
	QColor trtcolor8;
	QColor trtcolor9;
	QColor dstcolor;
	wlimg2 = wlimg;
	QRgb srcPixel1;
	QRgb srcPixel2;
	QRgb srcPixel3;
	QRgb srcPixel4;
	QRgb srcPixel5;
	QRgb srcPixel6;
	QRgb srcPixel7;
	QRgb srcPixel8;
	QRgb srcPixel9;
	for (int y = 1; y < wlimg.height()-1; y++)
	{
		for (int x = 1; x < wlimg.width()-1; x++)
		{
			srcPixel5 = wlimg.pixel(x, y);
			if (qAlpha(srcPixel5) > 10 )
			{
				srcPixel1 = wlimg.pixel(x-1, y-1);
				srcPixel2 = wlimg.pixel(x, y-1);
				srcPixel3 = wlimg.pixel(x+1, y-1);
				srcPixel4 = wlimg.pixel(x-1, y);
				srcPixel6 = wlimg.pixel(x+1, y);
				srcPixel7 = wlimg.pixel(x-1, y+1);
				srcPixel8 = wlimg.pixel(x, y+1);
				srcPixel9 = wlimg.pixel(x+1, y+1);

				trtcolor1 = srcPixel1;
				trtcolor2 = srcPixel2;
				trtcolor3 = srcPixel3;
				trtcolor4 = srcPixel4;
				trtcolor5 = srcPixel5;
				trtcolor6 = srcPixel6;
				trtcolor7 = srcPixel7;
				trtcolor8 = srcPixel8;
				trtcolor9 = srcPixel9;

				dstcolor.setRed((trtcolor1.red()+trtcolor2.red()+trtcolor3.red()+trtcolor4.red()+trtcolor5.red()+trtcolor6.red()+trtcolor7.red()+trtcolor8.red()+trtcolor9.red())/9);
				dstcolor.setGreen((trtcolor1.green()+trtcolor2.green()+trtcolor3.green()+trtcolor4.green()+trtcolor5.green()+trtcolor6.green()+trtcolor7.green()+trtcolor8.green()+trtcolor9.green())/9);
				dstcolor.setBlue((trtcolor1.blue()+trtcolor2.blue()+trtcolor3.blue()+trtcolor4.blue()+trtcolor5.blue()+trtcolor6.blue()+trtcolor7.blue()+trtcolor8.blue()+trtcolor9.blue())/9);
				//
				wlimg2.setPixel(x, y, dstcolor.rgb());
			}
		}
	}
	bt_tool_editor_8->setIcon(QPixmap::fromImage ( wlimg2, Qt::AutoColor ));
	wlimg2 = wlimg;
	for (int y = 1; y < wlimg.height()-1; y++)
	{
		for (int x = 1; x < wlimg.width()-1; x++)
		{
			QRgb srcPixel5 = wlimg.pixel(x, y);
			if (qAlpha(srcPixel5) > 10 )
			{
				srcPixel1 = wlimg.pixel(x-1, y-1);
				srcPixel2 = wlimg.pixel(x, y-1);
				srcPixel3 = wlimg.pixel(x+1, y-1);
				srcPixel4 = wlimg.pixel(x-1, y);
				srcPixel6 = wlimg.pixel(x+1, y);
				srcPixel7 = wlimg.pixel(x-1, y+1);
				srcPixel8 = wlimg.pixel(x, y+1);
				srcPixel9 = wlimg.pixel(x+1, y+1);

				trtcolor1 = srcPixel1;
				trtcolor2 = srcPixel2;
				trtcolor3 = srcPixel3;
				trtcolor4 = srcPixel4;
				trtcolor5 = srcPixel5;
				trtcolor6 = srcPixel6;
				trtcolor7 = srcPixel7;
				trtcolor8 = srcPixel8;
				trtcolor9 = srcPixel9;

				if ( (18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6 >= 0 && (18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6 <= 255 )
				{
					dstcolor.setRed((18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6);
				}
				else
				{
					if (  (18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6 < 0 )
					{
						dstcolor.setRed(0);
					}
					else
					{
						dstcolor.setRed(255);
					}
				}

				if (  (18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6 >= 0 &&  (18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6 <= 255)
				{
					dstcolor.setGreen((18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6);
				}
				else
				{
					if (  (18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6 < 0 )
					{
						dstcolor.setGreen(0);
					}
					else
					{
						dstcolor.setGreen(255);
					}
				}

				if ( (18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6 >= 0 && (18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6 <= 255)
				{
					dstcolor.setBlue((18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6);
				}
				else
				{
					if (  (18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6 < 0 )
					{
						dstcolor.setBlue(0);
					}
					else
					{
						dstcolor.setBlue(255);
					}
				}
				//
				wlimg2.setPixel(x, y, dstcolor.rgb());
			}
		}
	}
	bt_tool_editor_9->setIcon(QPixmap::fromImage ( wlimg2, Qt::AutoColor ));

}

void mainfrm::f_gommer()
{
	if ( bt_gommer->isChecked() == true )
	{
		pntlabel->img32b_eraser = pntlabel->img2resu.toImage();
		pntlabel->img32b_eraser = pntlabel->img32b_eraser.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
		pntlabel->opacgomme = slider_opacity_eraser->value();
		pntlabel->colorgomme.setRed(pntwheeleraser->red);
		pntlabel->colorgomme.setGreen(pntwheeleraser->green);
		pntlabel->colorgomme.setBlue(pntwheeleraser->blue);
		frame_eraser_param->show();
		frame_eraser_param->raise();
		group_crop->setDisabled(true);
		bt_rotation_img->setDisabled(true);
		bt_annuler_editor->setDisabled(true);
		bt_cancel_editor->setDisabled(true);
		bt_ok_editor->setDisabled(true);
		bt_tool_editor_2->setDisabled(true);
		bt_tool_editor_3->setDisabled(true);
		bt_tool_editor_4->setDisabled(true);
		bt_tool_editor_5->setDisabled(true);
		bt_tool_editor_6->setDisabled(true);
		bt_tool_editor_7->setDisabled(true);
		bt_tool_editor_8->setDisabled(true);
		bt_tool_editor_9->setDisabled(true);
		group_forme->setDisabled(true);
		menu_imgedit->hide();
		pntlabel->raise();
		pntlabel->startcrop = 100;
	}
	else
	{
		pntlabel->img32b = pntlabel->img32b_eraser;
		frame_eraser_param->hide();
		group_crop->setEnabled(true);
		bt_rotation_img->setEnabled(true);
		bt_annuler_editor->setEnabled(true);
		bt_cancel_editor->setEnabled(true);
		bt_ok_editor->setEnabled(true);
		bt_tool_editor_2->setEnabled(true);
		bt_tool_editor_3->setEnabled(true);
		bt_tool_editor_4->setEnabled(true);
		bt_tool_editor_5->setEnabled(true);
		bt_tool_editor_6->setEnabled(true);
		bt_tool_editor_7->setEnabled(true);
		bt_tool_editor_8->setEnabled(true);
		bt_tool_editor_9->setEnabled(true);
		group_forme->setEnabled(true);
		pntlabel->startcrop = 0;
		f_gene_vignette(pntlabel->img32b);
		menu_imgedit->show();
		menu_imgedit->raise();
		pntlabel->repaint();
	}
}

void mainfrm::f_size_gommer(int value)
{
	pntlabel->sizegomme = value;
}

void mainfrm::f_change_color_eraser()
{
	pntlabel->colorgomme.setRed(pntwheeleraser->red);
	pntlabel->colorgomme.setGreen(pntwheeleraser->green);
	pntlabel->colorgomme.setBlue(pntwheeleraser->blue);
}

void mainfrm::f_opac_gommer(int value)
{
	pntlabel->opacgomme = value;
}

void mainfrm::f_annuler_editor()
{
	thread_img->must_redraw = 0;
	slider_lumiere->setValue(0);
	slider_contraste->setValue(0);
	slider_R->setValue(0);
	slider_V->setValue(0);
	slider_B->setValue(0);
	slider_ouverture->setValue(0);
	slider_ouverture_longueur->setValue(50);
	slider_ouverture_radius->setValue(50);
	slider_ouverture_opacity->setValue(255);
	group_crop->setEnabled(true);
	combo_composition->setCurrentIndex(0);
	pntlabel->setPixmap(pntlabel->img2crop);
	pntlabel->img2resu = pntlabel->img2crop;	
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setGeometry ((frame_fond_editor->width() - pntlabel->img2resu.width())/2,(frame_fond_editor->height() - pntlabel->img2resu.height())/2,pntlabel->img2resu.width(),pntlabel->img2resu.height());
	pntlabel->repaint();
	pntlabel->startcrop = 0;
	pntlabel->realw = pntlabel->img2resu.width();
	pntlabel->realh = pntlabel->img2resu.height();
	thread_img->must_redraw = 1;
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	pntlabel->img32b = wlimg;
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_tool_editor_2()
{
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	wlimg = wlimg.mirrored(true,false);
	pntlabel->img2resu = QPixmap::fromImage ( wlimg, Qt::AutoColor ) ;
	pntlabel->img32b = wlimg;
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_tool_editor_3()
{
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	wlimg = wlimg.mirrored(false,true);
	pntlabel->img2resu = QPixmap::fromImage ( wlimg, Qt::AutoColor ) ;
	pntlabel->img32b = wlimg;
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_tool_editor_4()
{
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	wlimg.invertPixels ( QImage::InvertRgb );
	pntlabel->img2resu = QPixmap::fromImage ( wlimg, Qt::AutoColor ) ;
	pntlabel->img32b = wlimg;
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_tool_editor_10()
{
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	QColor trtcolor;

	int moyenne;

	for (int y = 0; y < wlimg.height(); y++)
	{
		for (int x = 0; x < wlimg.width(); x++)
		{
			QRgb srcPixel = wlimg.pixel(x, y);
			trtcolor = srcPixel;

			moyenne = (trtcolor.red() + trtcolor.green() + trtcolor.blue())/3;
			trtcolor.setRed(moyenne);
			trtcolor.setGreen(moyenne);
			trtcolor.setBlue(moyenne);
			//
			wlimg.setPixel(x, y, trtcolor.rgb());
		}
	}

	pntlabel->img2resu = QPixmap::fromImage ( wlimg, Qt::AutoColor ) ;
	pntlabel->img32b = wlimg;
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_tool_editor_11()
{
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	QColor trtcolor;

	for (int y = 0; y < wlimg.height(); y++)
	{
		for (int x = 0; x < wlimg.width(); x++)
		{
			QRgb srcPixel = wlimg.pixel(x, y);
			trtcolor = srcPixel;

			trtcolor.setGreen(trtcolor.red() / 1.24);
			trtcolor.setBlue(trtcolor.green() / 1.36);
			//
			wlimg.setPixel(x, y, trtcolor.rgb());
		}
	}

	pntlabel->img2resu = QPixmap::fromImage ( wlimg, Qt::AutoColor ) ;
	pntlabel->img32b = wlimg;
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_update_editor()
{
	pntlabel->img2resu = QPixmap::fromImage ( thread_img->wlimg, Qt::AutoColor ) ;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_tool_editor_5(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->lumi = value;
		thread_img->run();
	}
}

void mainfrm::f_tool_editor_6(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->rouge = value;
		thread_img->run();
	}
}

void mainfrm::f_tool_editor_7(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->vert = value;
		thread_img->run();
	}
}

void mainfrm::f_tool_editor_8(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->bleu = value;
		thread_img->run();
	}
}

void mainfrm::f_tool_editor_9(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->cont = value;
		thread_img->wlimg = pntlabel->img32b;
		thread_img->run();
	}
}

void mainfrm::f_tool_editor_13(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->ouverture = value;
		thread_img->run();
	}
}

void mainfrm::f_tool_editor_13_r(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->radius = value;
		thread_img->run();
	}
}

void mainfrm::f_update_fade()
{
	if ( slider_ouverture->value() > 0 )
	{
		thread_img->must_redraw=0;
		slider_ouverture_radius->setValue(pntlabel->fadex);
		thread_img->radius = pntlabel->fadex;
		thread_img->must_redraw=1;
		slider_ouverture_longueur->setValue(pntlabel->fadey);
	}
}

void mainfrm::f_tool_editor_13_l(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->longueur = value;
		thread_img->run();
	}
}

void mainfrm::f_change_color_ouv()
{
	QColor wlcolor(pntwheelouv->red,pntwheelouv->green,pntwheelouv->blue);
	if ( wlcolor.isValid() == true )
	{
		thread_img->ouvcolor = wlcolor;
		if (thread_img->must_redraw == 1)
		{
			thread_img->wlimg = pntlabel->img32b;
			thread_img->run();
		}
	}
}

void mainfrm::f_tool_editor_13_o(int value)
{
	if (thread_img->must_redraw == 1)
	{
		thread_img->wlimg = pntlabel->img32b;
		thread_img->opacity = value;
		thread_img->run();
	}
}

void mainfrm::f_apply_composition(int value)
{
	thread_img->wlimg = pntlabel->img32b;
	thread_img->composition = table_compo[value];
	thread_img->run();
}

void mainfrm::f_tool_editor_14()
{
	this->setDisabled(true);
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	QColor trtcolor1;
	QColor trtcolor2;
	QColor trtcolor3;
	QColor trtcolor4;
	QColor trtcolor5;
	QColor trtcolor6;
	QColor trtcolor7;
	QColor trtcolor8;
	QColor trtcolor9;
	QColor dstcolor;

	for (int y = 1; y < wlimg.height()-1; y++)
	{
		for (int x = 1; x < wlimg.width()-1; x++)
		{
			QRgb srcPixel5 = wlimg.pixel(x, y);
			if (qAlpha(srcPixel5) > 10 )
			{
				QRgb srcPixel1 = wlimg.pixel(x-1, y-1);
				QRgb srcPixel2 = wlimg.pixel(x, y-1);
				QRgb srcPixel3 = wlimg.pixel(x+1, y-1);
				QRgb srcPixel4 = wlimg.pixel(x-1, y);
				QRgb srcPixel6 = wlimg.pixel(x+1, y);
				QRgb srcPixel7 = wlimg.pixel(x-1, y+1);
				QRgb srcPixel8 = wlimg.pixel(x, y+1);
				QRgb srcPixel9 = wlimg.pixel(x+1, y+1);

				trtcolor1 = srcPixel1;
				trtcolor2 = srcPixel2;
				trtcolor3 = srcPixel3;
				trtcolor4 = srcPixel4;
				trtcolor5 = srcPixel5;
				trtcolor6 = srcPixel6;
				trtcolor7 = srcPixel7;
				trtcolor8 = srcPixel8;
				trtcolor9 = srcPixel9;

				dstcolor.setRed((trtcolor1.red()+trtcolor2.red()+trtcolor3.red()+trtcolor4.red()+trtcolor5.red()+trtcolor6.red()+trtcolor7.red()+trtcolor8.red()+trtcolor9.red())/9);
				dstcolor.setGreen((trtcolor1.green()+trtcolor2.green()+trtcolor3.green()+trtcolor4.green()+trtcolor5.green()+trtcolor6.green()+trtcolor7.green()+trtcolor8.green()+trtcolor9.green())/9);
				dstcolor.setBlue((trtcolor1.blue()+trtcolor2.blue()+trtcolor3.blue()+trtcolor4.blue()+trtcolor5.blue()+trtcolor6.blue()+trtcolor7.blue()+trtcolor8.blue()+trtcolor9.blue())/9);
				//
				wlimg.setPixel(x, y, dstcolor.rgb());
			}
		}
	}

	pntlabel->img2resu = QPixmap::fromImage ( wlimg, Qt::AutoColor ) ;
	pntlabel->img32b = wlimg;
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
	this->setEnabled(true);
}

void mainfrm::f_tool_editor_15()
{
	this->setDisabled(true);
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	QColor trtcolor1;
	QColor trtcolor2;
	QColor trtcolor3;
	QColor trtcolor4;
	QColor trtcolor5;
	QColor trtcolor6;
	QColor trtcolor7;
	QColor trtcolor8;
	QColor trtcolor9;
	QColor dstcolor;

	for (int y = 1; y < wlimg.height()-1; y++)
	{
		for (int x = 1; x < wlimg.width()-1; x++)
		{
			QRgb srcPixel5 = wlimg.pixel(x, y);
			if (qAlpha(srcPixel5) > 10 )
			{
				QRgb srcPixel1 = wlimg.pixel(x-1, y-1);
				QRgb srcPixel2 = wlimg.pixel(x, y-1);
				QRgb srcPixel3 = wlimg.pixel(x+1, y-1);
				QRgb srcPixel4 = wlimg.pixel(x-1, y);
				QRgb srcPixel6 = wlimg.pixel(x+1, y);
				QRgb srcPixel7 = wlimg.pixel(x-1, y+1);
				QRgb srcPixel8 = wlimg.pixel(x, y+1);
				QRgb srcPixel9 = wlimg.pixel(x+1, y+1);

				trtcolor1 = srcPixel1;
				trtcolor2 = srcPixel2;
				trtcolor3 = srcPixel3;
				trtcolor4 = srcPixel4;
				trtcolor5 = srcPixel5;
				trtcolor6 = srcPixel6;
				trtcolor7 = srcPixel7;
				trtcolor8 = srcPixel8;
				trtcolor9 = srcPixel9;

				if ( (18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6 >= 0 && (18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6 <= 255 )
				{
					dstcolor.setRed((18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6);
				}
				else
				{
					if (  (18*trtcolor5.red()-trtcolor1.red()-trtcolor2.red()-2*trtcolor3.red()-2*trtcolor4.red()-2*trtcolor6.red()-trtcolor7.red()-trtcolor8.red()-2*trtcolor9.red())/6 < 0 )
					{
						dstcolor.setRed(0);
					}
					else
					{
						dstcolor.setRed(255);
					}
				}

				if (  (18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6 >= 0 &&  (18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6 <= 255)
				{
					dstcolor.setGreen((18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6);
				}
				else
				{
					if (  (18*trtcolor5.green()-trtcolor1.green()-trtcolor2.green()-2*trtcolor3.green()-2*trtcolor4.green()-2*trtcolor6.green()-trtcolor7.green()-trtcolor8.green()-2*trtcolor9.green())/6 < 0 )
					{
						dstcolor.setGreen(0);
					}
					else
					{
						dstcolor.setGreen(255);
					}
				}

				if ( (18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6 >= 0 && (18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6 <= 255)
				{
					dstcolor.setBlue((18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6);
				}
				else
				{
					if (  (18*trtcolor5.blue()-trtcolor1.blue()-trtcolor2.blue()-2*trtcolor3.blue()-2*trtcolor4.blue()-2*trtcolor6.blue()-trtcolor7.blue()-trtcolor8.blue()-2*trtcolor9.blue())/6 < 0 )
					{
						dstcolor.setBlue(0);
					}
					else
					{
						dstcolor.setBlue(255);
					}
				}
				//
				wlimg.setPixel(x, y, dstcolor.rgb());
			}
		}
	}

	pntlabel->img2resu = QPixmap::fromImage ( wlimg, Qt::AutoColor ) ;
	pntlabel->img32b = wlimg;
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
	this->setEnabled(true);
}

void mainfrm::f_rogner()
{
	if (bt_rogner->isChecked() == true )
	{
		bt_ok_rogner->setEnabled(true);
		bt_gommer->setDisabled(true);
		bt_annuler_editor->setDisabled(true);
		bt_cancel_editor->setDisabled(true);
		bt_ok_editor->setDisabled(true);
		bt_tool_editor_2->setDisabled(true);
		bt_tool_editor_3->setDisabled(true);
		bt_tool_editor_4->setDisabled(true);
		bt_tool_editor_5->setDisabled(true);
		bt_tool_editor_6->setDisabled(true);
		bt_tool_editor_7->setDisabled(true);
		bt_tool_editor_8->setDisabled(true);
		bt_tool_editor_9->setDisabled(true);
		bt_rotation_img->setDisabled(true);
		group_forme->setDisabled(true);
		menu_imgedit->hide();
		pntlabel->startcrop = 3;
	}
	else
	{
		pntlabel->startcrop = 0;
		bt_gommer->setEnabled(true);
		bt_ok_rogner->setDisabled(true);
		bt_annuler_editor->setEnabled(true);
		bt_cancel_editor->setEnabled(true);
		bt_ok_editor->setEnabled(true);
		bt_tool_editor_2->setEnabled(true);
		bt_tool_editor_3->setEnabled(true);
		bt_tool_editor_4->setEnabled(true);
		bt_tool_editor_5->setEnabled(true);
		bt_tool_editor_6->setEnabled(true);
		bt_tool_editor_7->setEnabled(true);
		bt_tool_editor_8->setEnabled(true);
		bt_tool_editor_9->setEnabled(true);
		bt_rotation_img->setEnabled(true);
		group_forme->setEnabled(true);
		menu_imgedit->show();
		pntlabel->repaint();
	}
}

void mainfrm::f_ok_rogner()
{
	pntlabel->startcrop = 0;
	pntlabel->gocrop();
	bt_rogner->setChecked(false);
	bt_ok_rogner->setDisabled(true);
	bt_gommer->setEnabled(true);
	group_crop->setEnabled(true); //false
	bt_annuler_editor->setEnabled(true);
	bt_cancel_editor->setEnabled(true);
	bt_ok_editor->setEnabled(true);
	bt_tool_editor_2->setEnabled(true);
	bt_tool_editor_3->setEnabled(true);
	bt_tool_editor_4->setEnabled(true);
	bt_tool_editor_5->setEnabled(true);
	bt_tool_editor_6->setEnabled(true);
	bt_tool_editor_7->setEnabled(true);
	bt_tool_editor_8->setEnabled(true);
	bt_tool_editor_9->setEnabled(true);
	bt_rotation_img->setEnabled(true);
	group_forme->setEnabled(true);
	QImage wlimg = pntlabel->img2resu.toImage();
	wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	pntlabel->img32b = wlimg;
	f_gene_vignette(pntlabel->img32b);
	menu_imgedit->show();
}

void mainfrm::f_img_over()
{
	QString wl_string_001 = QFileDialog::getOpenFileName(
        	this,
        	tr("Image"),
        	current_path,
        	"(*.PNG *.png *.jpg *.JPG *.jpeg *.JPEG)");
	if ( wl_string_001.isNull() )
	{
	}
	else
	{
		if ( thread_img->overpix.load(wl_string_001) == true )
		{
			thread_img->hasover = 1;
			thread_img->wlimg = pntlabel->img32b;
			thread_img->run();
		}
	}
}

void mainfrm::f_invert_img_over()
{
	if ( bt_image_over_invert->isChecked() == true )
	{
		thread_img->hasinvert = 1;
		thread_img->wlimg = pntlabel->img32b;
		thread_img->run();
	}
	else
	{
		thread_img->hasinvert = 0;
		thread_img->wlimg = pntlabel->img32b;
		thread_img->run();
	}
}

void mainfrm::f_cancel_img_over()
{
	thread_img->hasover = 0;
	thread_img->wlimg = pntlabel->img32b;
	thread_img->run();
}

void mainfrm::f_forme()
{
	if (bt_forme->isChecked() == true )
	{
		comboforme->setCurrentIndex(0);
		bt_ok_forme->setEnabled(true);
		comboforme->setEnabled(true);
		bt_gommer->setDisabled(true);
		bt_annuler_editor->setDisabled(true);
		bt_cancel_editor->setDisabled(true);
		bt_ok_editor->setDisabled(true);
		bt_tool_editor_2->setDisabled(true);
		bt_tool_editor_3->setDisabled(true);
		bt_tool_editor_4->setDisabled(true);
		bt_tool_editor_5->setDisabled(true);
		bt_tool_editor_6->setDisabled(true);
		bt_tool_editor_7->setDisabled(true);
		bt_tool_editor_8->setDisabled(true);
		bt_tool_editor_9->setDisabled(true);
		bt_rotation_img->setDisabled(true);
		group_crop->setDisabled(true);
		menu_imgedit->hide();
	}
	else
	{
		pntlabel->setPixmap(pntlabel->img2save);
		pntlabel->img2resu = pntlabel->img2save;
		pntlabel->img32b = pntlabel->img2save.toImage();
		bt_ok_forme->setDisabled(true);
		comboforme->setDisabled(true);
		bt_gommer->setEnabled(true);
		bt_annuler_editor->setEnabled(true);
		bt_cancel_editor->setEnabled(true);
		bt_ok_editor->setEnabled(true);
		bt_tool_editor_2->setEnabled(true);
		bt_tool_editor_3->setEnabled(true);
		bt_tool_editor_4->setEnabled(true);
		bt_tool_editor_5->setEnabled(true);
		bt_tool_editor_6->setEnabled(true);
		bt_tool_editor_7->setEnabled(true);
		bt_tool_editor_8->setEnabled(true);
		bt_tool_editor_9->setEnabled(true);
		bt_rotation_img->setEnabled(true);
		group_crop->setEnabled(true);
		menu_imgedit->show();
		pntlabel->repaint();
	}
}

void mainfrm::f_ok_forme()
{
	QPixmap wlmask;
	QPixmap wlpix1;
	switch(comboforme->currentIndex())
	{
	case 0:
		pntlabel->setPixmap(pntlabel->img2save);
		pntlabel->img2resu = pntlabel->img2save;
		pntlabel->img32b = pntlabel->img2save.toImage();
		f_gene_vignette(pntlabel->img32b);
		break;
	case 1:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/coeur.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img2save = pntlabel->img2resu;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		f_gene_vignette(pntlabel->img32b);
		break;
	case 2:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/star.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img2save = pntlabel->img2resu;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		f_gene_vignette(pntlabel->img32b);
		break;
	case 3:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/fleur.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img2save = pntlabel->img2resu;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		f_gene_vignette(pntlabel->img32b);
		break;
	case 4:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/lune.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img2save = pntlabel->img2resu;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		f_gene_vignette(pntlabel->img32b);
		break;
	case 5:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/nuage.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img2save = pntlabel->img2resu;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		f_gene_vignette(pntlabel->img32b);
		break;
	case 6:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/soleil.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img2save = pntlabel->img2resu;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		f_gene_vignette(pntlabel->img32b);
		break;
	case 7:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/puzzle.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img2save = pntlabel->img2resu;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		f_gene_vignette(pntlabel->img32b);
		break;
	}
	bt_forme->setChecked(false);
	bt_gommer->setEnabled(true);
	bt_ok_forme->setDisabled(true);
	comboforme->setDisabled(true);
	bt_annuler_editor->setEnabled(true);
	bt_cancel_editor->setEnabled(true);
	bt_ok_editor->setEnabled(true);
	bt_tool_editor_2->setEnabled(true);
	bt_tool_editor_3->setEnabled(true);
	bt_tool_editor_4->setEnabled(true);
	bt_tool_editor_5->setEnabled(true);
	bt_tool_editor_6->setEnabled(true);
	bt_tool_editor_7->setEnabled(true);
	bt_tool_editor_8->setEnabled(true);
	bt_tool_editor_9->setEnabled(true);
	bt_rotation_img->setEnabled(true);
	group_crop->setEnabled(true);
	menu_imgedit->show();
	pntlabel->repaint();
}

void mainfrm::f_apply_forme(int value)
{
	QPixmap wlmask;
	QPixmap wlpix1;
	switch(value)
	{
	case 0:
		pntlabel->setPixmap(pntlabel->img2save);
		pntlabel->img2resu = pntlabel->img2save;
		pntlabel->img32b = pntlabel->img2save.toImage();
		break;
	case 1:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/coeur.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		break;
	case 2:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/star.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		break;
	case 3:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/fleur.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		break;
	case 4:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/lune.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		break;
	case 5:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/nuage.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		break;
	case 6:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/soleil.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		break;
	case 7:
		wlpix1 = pntlabel->img2save;
		wlmask.load(":/new/prefix2/Interface/Theme/puzzle.png");
		wlmask = wlmask.scaled( wlpix1.width(), wlpix1.height(), Qt::IgnoreAspectRatio, Qt::FastTransformation );
		wlpix1.setMask(wlmask);
		pntlabel->img2resu = wlpix1;
		pntlabel->img32b = wlpix1.toImage();
		pntlabel->setPixmap(pntlabel->img2resu);
		break;
	}
}

void mainfrm::f_tool_editor_12()
{
	QPixmap wlpix1 = pntlabel->img2resu;
	//wlimg = wlimg.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
	int sizec = (pntlabel->img2resu.width()*5)/100;
	QPainter p;
	p.begin(&wlpix1);
	p.fillRect ( 0, 0, pntlabel->img2resu.width(), sizec, QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.fillRect ( 0, pntlabel->img2resu.height()-sizec, pntlabel->img2resu.width(), sizec, QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.fillRect ( 0, 0, sizec, pntlabel->img2resu.height(), QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.fillRect ( pntlabel->img2resu.width()-sizec, 0, sizec, pntlabel->img2resu.height(), QBrush( QColor(255,255,255,255), Qt::SolidPattern ) );
	p.end();
	pntlabel->img2resu = wlpix1;
	pntlabel->img32b = wlpix1.toImage();
	pntlabel->img2save = pntlabel->img2resu;
	pntlabel->setPixmap(pntlabel->img2resu);
	f_gene_vignette(pntlabel->img32b);
}

void mainfrm::f_btrotation_img()
{
	if (bt_rotation_img->isChecked() == true )
	{
		must_redraw = 1;
		slider_rotation_img->setValue(0);
		spinrotation->setValue(0);
		comboforme->setCurrentIndex(0);
		bt_ok_forme->setEnabled(true);
		comboforme->setEnabled(true);
		bt_gommer->setDisabled(true);
		bt_annuler_editor->setDisabled(true);
		bt_cancel_editor->setDisabled(true);
		bt_ok_editor->setDisabled(true);
		bt_tool_editor_2->setDisabled(true);
		bt_tool_editor_3->setDisabled(true);
		bt_tool_editor_4->setDisabled(true);
		bt_tool_editor_5->setDisabled(true);
		bt_tool_editor_6->setDisabled(true);
		bt_tool_editor_7->setDisabled(true);
		bt_tool_editor_8->setDisabled(true);
		bt_tool_editor_9->setDisabled(true);
		group_crop->setDisabled(true);
		group_forme->setDisabled(true);
		frame_rotation_img->show();
		frame_rotation_img->raise();
		must_redraw = 0;
		pntlabel->oldcrop = pntlabel->startcrop;
		pntlabel->startcrop = 10;
		gl_pix_1.load(":/new/prefix2/Interface/Theme/nullpixmap.png");
		gl_pix_1 = gl_pix_1.scaled(pntlabel->img2save.width(),pntlabel->img2save.height());
		gl_pix_1.fill(QColor(0,0,0,0));
		menu_imgedit->hide();
	}
	else
	{
		if ( slider_rotation_img->value() != 0 )
		{
			pntlabel->img2resu = gl_pix_1;
			pntlabel->img32b = gl_pix_1.toImage();
			pntlabel->img2save = pntlabel->img2resu;
			f_gene_vignette(pntlabel->img32b);
		}
		pntlabel->startcrop = pntlabel->oldcrop;
		bt_ok_forme->setDisabled(true);
		comboforme->setDisabled(true);
		bt_gommer->setEnabled(true);
		bt_annuler_editor->setEnabled(true);
		bt_cancel_editor->setEnabled(true);
		bt_ok_editor->setEnabled(true);
		bt_tool_editor_2->setEnabled(true);
		bt_tool_editor_3->setEnabled(true);
		bt_tool_editor_4->setEnabled(true);
		bt_tool_editor_5->setEnabled(true);
		bt_tool_editor_6->setEnabled(true);
		bt_tool_editor_7->setEnabled(true);
		bt_tool_editor_8->setEnabled(true);
		bt_tool_editor_9->setEnabled(true);
		group_crop->setEnabled(true);
		group_forme->setEnabled(true);
		frame_rotation_img->hide();
		menu_imgedit->show();
		pntlabel->repaint();
	}
}

void mainfrm::f_rotation_img(int value)
{
	if ( must_redraw == 0 )
	{
		gl_pix_1.fill(QColor(0,0,0,0));
		QPainter p;
		p.begin(&gl_pix_1);
		p.translate(gl_pix_1.width()/2,gl_pix_1.height()/2);
		p.rotate(value);
		p.translate(-gl_pix_1.width()/2,-gl_pix_1.height()/2);
		p.drawPixmap ( 0,0,-1,-1, pntlabel->img2save);
		p.end();
		must_redraw = 1;
		spinrotation->setValue(value);

		pntlabel->img2resu = gl_pix_1;
		pntlabel->repaint();
	}
	must_redraw = 0;
}

void mainfrm::f_rotation_spin(int value)
{
	if ( must_redraw == 0 )
	{
		gl_pix_1.fill(QColor(0,0,0,0));
		QPainter p;
		p.begin(&gl_pix_1);
		p.translate(gl_pix_1.width()/2,gl_pix_1.height()/2);
		p.rotate(value);
		p.translate(-gl_pix_1.width()/2,-gl_pix_1.height()/2);
		p.drawPixmap ( 0,0,-1,-1, pntlabel->img2save);
		p.end();
		slider_rotation_img->setValue(value);
		must_redraw = 1;
		pntlabel->img2resu = gl_pix_1;
		pntlabel->repaint();
	}
	must_redraw = 0;
}

