psetp

Syntax

int psetp(int x, int y, int val)

Arguments

x, y
Image coordinates
val
Pixel value that shall be stored

Return

Always returns a value of 1

Description

This function lets you write a whole pixel to the output buffer. Using psetp instead of pset takes only approximately half as much time. You have to use the RGB or RGBA function to create a pixel value from individual color values. Make sure that the individual color values lie between 0 and 255, otherwise you will get a strange image effect when passing the pixel value to this function. For details please have a look at the example below. Currently only works with 8 bit images.

Example

%ffp

ctl(0):"Brightness",size=(*,6),Range=(-300,300),val=100
ctl(2): checkbox,"Use the faster srcp() and psetp()",size=(150,*),Val=0
ctl(10):statictext,pos=(*,60),fontcolor=red,size=(150,*)


ForEveryTile:{

		int c,r,g,b;
		int a=255;
			
		const int startclock = clock();
		int endclock;


		for (y=y_start; y<y_end; y++){
			if(updateProgress(y,y_end)) abort();
		for (x=x_start; x<x_end; x++){

				
			if (ctl(2)){

				//Read a whole pixel
				c = srcp (x,y);

				//Explode it into the color values
				r =  Rval(c); //c & 0xff;
				g =  Gval(c); //c >> 8 & 0xff;
				b =  Bval(c); //c >> 16 & 0xff;
				if (Z>3) a =  Aval(c); //c >> 24 & 0xff;

				//Adjust brightness
				r += ctl(0);
				g += ctl(0);
				b += ctl(0);
				if (Z>3) a += ctl(0);

				//Makes sure that the color values are in the right range, 
				//otherwise we might get a strange image result
				if (r<0) r=0; else if (r>255) r=255;
				if (g<0) g=0; else if (g>255) g=255;
				if (b<0) b=0; else if (b>255) b=255;
				if (Z>3) {if (a<0) a=0; else if (a>255) a=255;}
				
				//Write back the color values
				psetp (x,y, RGBA(r,g,b,a) );


			} else {

				r =  src(x,y,0);
				g =  src(x,y,1);
				b =  src(x,y,2);
				if (Z>3) a =  src(x,y,3);

				r += ctl(0);
				g += ctl(0);
				b += ctl(0);
				if (Z>3) a += ctl(0);

				pset (x,y,0,r);
				pset (x,y,1,g);
				pset (x,y,2,b);
				if (Z>3) pset (x,y,3,a);
				
			}


		}}


	endclock = clock() - startclock;
	setCtlTextv(10, "Render time needed: %d ms", endclock);

	//Display after applying the effect to the image
	//Should make the speed difference more clear
	if (!doingProxy) Info ("Render time needed: %d ms", endclock);


	return true;
}

Also see

set_psetp_mode, srcp, pgetp, tgetp, tsetp, t2getp, t2setp, RGB, RGBA

Comments

Everyone can add his comments about his experiences with this function here. Tips for using it are welcome, too.