Skip to main content
Richard Rosenman
Inspiring
September 4, 2018
Answered

Reading and writing pixels at X,Y

  • September 4, 2018
  • 1 reply
  • 590 views

Hi all;

Very new to the SDK but making great progress.

I see that using the following function, we can write pixels at a coordinate (as opposed to iterating through every pixel):

PF_Pixel *sampleIntegral32(PF_EffectWorld &def, int x, int y){

return (PF_Pixel*)((char*)def.data +

(y * def.rowbytes) +

(x * sizeof(PF_Pixel)));

}

And then we call it using:

PF_Pixel *myPixel = sampleIntegral32(*output,x,y);

myPixel->red      = 255;

myPixel->green  = 255;

myPixel->blue     = 255;

myPixel->alpha   = 255;

But how does one read a pixel at X,Y?

Thanks,

-Richard

This topic has been closed for replies.
Correct answer

The answer is already in the code

The myPixel pointer already contains all the pixel data you need (myPixel->red is the red channel, myPixel->green is the green channel, etc).

Here is an example to read the blue channel value, decrease it by 10, then write it back to the red channel (no boundary checks!)

myPixel->red      = myPixel->blue - 10;

Be aware that the code above is only valid in 8bpc (values 0..255), you should also support 16bpc and 32bpc

1 reply

Correct answer
September 4, 2018

The answer is already in the code

The myPixel pointer already contains all the pixel data you need (myPixel->red is the red channel, myPixel->green is the green channel, etc).

Here is an example to read the blue channel value, decrease it by 10, then write it back to the red channel (no boundary checks!)

myPixel->red      = myPixel->blue - 10;

Be aware that the code above is only valid in 8bpc (values 0..255), you should also support 16bpc and 32bpc

Richard Rosenman
Inspiring
September 4, 2018

Well don't I feel foolish.

Thank you for the explanation.