Skip to main content
Richard Rosenman
Inspiring
March 12, 2019
Answered

Reading Pixels From Other Layers

  • March 12, 2019
  • 1 reply
  • 1515 views

Hi all;

I've been struggling with this and decided to clean up the old thread and outline my steps more clearly. I'm still trying to understand the basic procedure for reading pixel data from other layers, but without using the iteration suite.

Let me walk you through what I'm doing.

First I set up my layer selection controller (and the appropriate vars in the .h file):

AEFX_CLR_STRUCT(def);

PF_ADD_LAYER("Source", 0, SOURCE);

Then in my render function I check out the layer using the following:

PF_ParamDef check;

AEFX_CLR_STRUCT(check);

ERR(PF_CHECKOUT_PARAM(  in_data,
SOURCE,
in_data->current_time,
in_data->time_step,
in_data->time_scale,

&check));

Then supposedly here, I should be able to get the specified layer's pixel info using check.u.ld but this is where I'm stuck. I don't know how to do this. How do I get the red channel, green channel, blue channel and alpha channels? A lot of my confusion stems from the fact that I don't fully understand the logic of effect worlds.

And finally, when I'm done all this, I check in the layer:

ERR2(PF_CHECKIN_PARAM(in_data,

&check));

I am not using the iteration suite so I have been using this function listed in the SDK documentation to read and write pixel info in my current layer:

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

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

(y * def.rowbytes) +

(x * sizeof(PF_Pixel)));

}

Any help so that I can get this working would be highly appreciated and apologies in advance for what I'm sure is a very basic question but I am still learning... go easy on me.

Thanks,

-Rich

This topic has been closed for replies.
Correct answer françois leroy

Here's a function that works for sure, in 8bits:

PF_Pixel getPixel(PF_EffectWorld* inputP, const A_long x, const A_long y) {

  return = *((PF_Pixel *)((char*)inputP->data + (y * inputP->rowbytes) + x * sizeof(PF_Pixel )));

}

And you would use it like this (to get the pixel data at 10,10):

PF_Pixel myPixel = getPixel(     &check.u.ld, 10, 10);

Now, you can read it's red value with myPixel.red.

1 reply

françois leroy
Inspiring
March 13, 2019

Hi Richard,

you've done almost all the work there.

PF_EffectWorld is a canvas of pixels.

So, once you have your check.u.ld you can access its pixels, either through iterations suites, or directly.

What you'll get is pixel data, it means alpha, red, green and blue values for a particular pixel. You won't get 'the red channel' of the EffectWorld.

If you want to act on the whole red channel, you have to go through iteration suites and modify the red value of each pixel...

For example, if you want to divide the red channel by 2 like this "myPixel->red *= .5;"

the iteration will go through all the pixels, one by one, and multiply its red value by .5.

You can check this thread for more details on how to access pixels directly: Re: Get Pixel Value from Layer Parameter and Arbitrary XY Coordinates

Cheers,

François

Richard Rosenman
Inspiring
March 13, 2019

Thanks for your reply, Francois.

That's what I want - the pixel data. The values for the red, green and blue. In 8 bit mode, that would be 0-255 for each.

What I don't understand is how to get that from the check.u.ld variable. I know how to sample a pixel using my pixel sampler function:

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

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

(y * def.rowbytes) +

(x * sizeof(PF_Pixel)));

}

But I don't know how to use check.u.ld together with it to get the pixel data. Could you shed some light on this?

Thanks,

-Richard

françois leroy
françois leroyCorrect answer
Inspiring
March 13, 2019

Here's a function that works for sure, in 8bits:

PF_Pixel getPixel(PF_EffectWorld* inputP, const A_long x, const A_long y) {

  return = *((PF_Pixel *)((char*)inputP->data + (y * inputP->rowbytes) + x * sizeof(PF_Pixel )));

}

And you would use it like this (to get the pixel data at 10,10):

PF_Pixel myPixel = getPixel(     &check.u.ld, 10, 10);

Now, you can read it's red value with myPixel.red.