%ffp

// This template gets you started when you plan to enhance one of 
// your Filter Factory plugins with FilterMeister. For this purpose it is
// important to be put the FF source code into FilterMeister's 
// ForEverTile handler as it gives you a lot of new possibilities.


//------------------------------------------------------------------------------------------
// Filter Infos

Category   :"FilterMeister"
Title      :"FF in FET"
Copyright  :"None"
Author     :"Harald Heim"
Organization:"The Plugin Site"
URL:"http://thepluginsite.com"
Filename   :"FFinFET.8bf"
Description:"Use your FF code in the ForEveryTile handler"
Version    :"1.01"
About      :"!T !V\n!D\n"
            "!c\n!U"

//Only apply filter to RGB and Grayscale images
SupportedModes: RGBMode,GrayScaleMode


//------------------------------------------------------------------------------------------
// Filter Control Definitions

// Determines how the filter dialog will look like
Dialog: color=#C0C0C0, NoTitlebar, Drag=Background, size=(348,145)//,Pos=Client(CENTER)

ctl(13): groupbox,color=#C0C0C0,fontcolor=#000000,pos=(180,0),size=(165,95)

// Insert you own slider label names and comment out the slider that
// you don't need
ctl(0):"Slider 1",val=28,size=(*,6),pos=(225,12),fontcolor=black
ctl(1):"Slider 2",val=201,size=(*,6),pos=(225,22),fontcolor=black
ctl(2):"Slider 3",val=0,size=(*,6),pos=(225,32),fontcolor=black
ctl(3):"Slider 4",val=76,size=(*,6),pos=(225,42),fontcolor=black
ctl(4):"Slider 5",val=82,size=(*,6),pos=(225,52),fontcolor=black
ctl(5):"Slider 6",val=149,size=(*,6),pos=(225,62),fontcolor=black
ctl(6):"Slider 7",val=8,size=(*,6),range=(0,255),pos=(225,72),fontcolor=black
ctl(7):"Slider 8",val=0,size=(*,6),range=(0,255),pos=(225,82),fontcolor=black

// Hide the Edit button and the logo
ctl[CTL_EDIT]: none
ctl[CTL_LOGO]: None


//------------------------------------------------------------------------------------------
// Here comes the filter code

ForEveryTile:{

	int x,y,r,g,b,i,u,v,m,d,M,D;

	//Calculation of unsupported FF expressions
	//Comment out the not needed variables!
	M = c2m(X,Y)/2;
	D = c2d(X,Y)/2;

	
	for (y=y_start; y<y_end; ++y){ // loop through all rows

		//Update progress bar and cancel if ESC key was pressed
		if ( updateProgress(y,Y) ) break;
			
		for (x=x_start; x<x_end; ++x){ // loop through all columns

			//Calculation of unsupported FF expressions
			//Comment out the not needed variables!
			r = src(x,y,0);
			g = src(x,y,1);
			b = src(x,y,2);
			i = ((76 * r) + (150 * g) + (29 * b))/256;
			u = ((-19 * r) + (-37 * g) + (56 * b))/256;
			v = ((78 * r) + (-65 * g) + (-13 * b))/256;
			m = c2m(x-X/2,y-Y/2);
			d = c2d(x-X/2,y-Y/2); 

			
			//Replace "255-r/g/b" with your own FF formulas here
			/* If the FF code should include puts and gets, 
			please replace the gets with the statement inside the
			put command and remove the put command itself */

			pset(x,y,0, 255-r ); //red channel
			pset(x,y,1, 255-g ); //green channel
			pset(x,y,2, 255-b ); //blue channel
		}
	}

	//Apply calculations to image
	return true;	

}//ForEveryTile