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

Get Pixel Value from Layer Parameter and Arbitrary XY Coordinates

Explorer ,
Aug 22, 2016 Aug 22, 2016

So this is driving me crazy. I've searched the forums and found a few promising leads, but nothing seems to work.

I am inside a float iterator for the current layer (suites.IterateFloatSuite1()->iterate_origin()).

I have passed my layer parameter into it, as a PF_LayerDef.

How do I get a pixel value from it?

What I want to do is something like this:

out =  getPixelValue(id->layer.data, xCoord, yCoord);

Am I simply approaching this in the wrong way?

Any help would be amazingly appreciated.

Thanks.

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 , Aug 23, 2016 Aug 23, 2016

Hi,

if you go the suites way, you can try PF_SAMPLINGSUITE and subpixel_sample.

The manual way would be:

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

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

}

so with a pixel at [10,10], you'll get:

*((PF_PixelFloat *)((char*)inputP->data + (10 * inputP->rowbytes) + 10 * sizeof(PF_PixelFloat )));

}

Cheers,

François

Translate
Community Expert ,
Aug 23, 2016 Aug 23, 2016

you need to use PF_CHECKOUT_PARAM() or checkout_layer_pixels() to get an

PF_EffectWorld filled with pixels.

only then will your plug-in get the actual pixels of the layer.

now that you have it, you can use effectWorld->data as a pointer to the

first pixel and effectWorld->rowbytes to get to the address of the pixel

you want.

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
Explorer ,
Aug 23, 2016 Aug 23, 2016

Thanks Shachar,

I've got the layer checked out, and have access to data and rowbytes. I'm just not certain of how to actually extract a pixel out of it.

Using "data"; how do I get a PF_PixelFloat out of a PF_PixelPtr? Also, what would the use in returning the first pixel?

And with regards to "rowbytes", what would an example of using that look like?

As an example, say I wanted the pixel at [10,10] in the layer?

I'm assuming it's not as simple as rowbytes[10,10] or rowbytes[width*10+10].

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 ,
Aug 23, 2016 Aug 23, 2016

Hi,

if you go the suites way, you can try PF_SAMPLINGSUITE and subpixel_sample.

The manual way would be:

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

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

}

so with a pixel at [10,10], you'll get:

*((PF_PixelFloat *)((char*)inputP->data + (10 * inputP->rowbytes) + 10 * sizeof(PF_PixelFloat )));

}

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
Explorer ,
Aug 23, 2016 Aug 23, 2016

Thanks so much for that Francois. That looks like exactly the explanation I was looking for.

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 ,
Aug 23, 2016 Aug 23, 2016

Well, I got it from Toby 😉

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
Explorer ,
Aug 23, 2016 Aug 23, 2016

Hey again.

I tried your function out, but replacing PF_EffectWorld with PF_LayerDef, as that is what my PF_CHECKOUT_PARAM() returns.

However in trying this:

PF_PixelFloat testPixel = getPixel(id->layer, 10, 10);

I get the following error:

No suitable conversion function from PF_LayerDef to PF_LayerDef* exists.

I tried removing the star from the function, but that throws more errors, saying that it needs to be a pointer type.

Sorry if this is a dumb question. I really don't know the fundamentals of C++ (I'll have to fix that). I've only ever really used C#, python and extendscript.

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 ,
Aug 24, 2016 Aug 24, 2016

instead of removing the star* from the function, you should add & when you use it, like this:

PF_PixelFloat testPixel = getPixel(     &id->layer, 10, 10);

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
Explorer ,
Aug 24, 2016 Aug 24, 2016
LATEST

You're amazing! Thanks again.

It's working perfectly.

After I had a few crashes and realised I needed to check that the layer wasn't null, and that the coordinates were valid haha.

Studying up on pointers and references now

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