Older Newer
Mon, 24 Mar 2008 09:21:45 . . . . afh [fix typo]

Changes by last author:

= srcp =

== Syntax ==

:int srcp(int x, int y)

== Arguments ==

:x, y

::Image coordinates

== Return ==

:Returns the pixel value at the specified image coordinates

== Description ==

:This function lets you read a whole pixel from the source buffer. Unlike src the returned value includes the values of all color channels (including the transparency channel if one is available) of the pixel. Using scrp instead of src takes only approximately half as much time. To decode the individual color values from the returned pixel value you have to use the Rval, Gval, Bval and Aval functions. Currently only works with 8 bit images.

== Example ==




ctl(2): checkbox,"Use the faster srcp() and psetp()",size=(150,*),Val=0



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 ==

:pgetp, psetp, tgetp, tsetp, t2getp, t2setp, Rval, Gval, Bval and Aval

== Comments ==

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