Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Reading Pixels From Other Layers

Engaged ,
Mar 11, 2019 Mar 11, 2019

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

TOPICS
SDK
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Mar 12, 2019 Mar 12, 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.

Translate
Enthusiast ,
Mar 12, 2019 Mar 12, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 12, 2019 Mar 12, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 12, 2019 Mar 12, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 12, 2019 Mar 12, 2019

Hi Francois;

Thank you! This is exactly what I wanted to understand.

My code now compiles without errors although it crashes AE as soon as the plugin is applied. It is due to the calling of the myPixel function:

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

I will try to investigate why.

-Richard

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 12, 2019 Mar 12, 2019
LATEST

Make sure {10,10} is inside the range of available pixels (smaller than the size of the layer) and make sure check.u.ld is valid (and not checked in yet!).

Also, the example only works in 8 bits (for 16 bits replace PF_Pixel by PF_Pixel16, same for 32 bits...), so make sure your project is 8 bits for now...

Cheers,

François

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines