Copy link to clipboard
Copied
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.
1 Correct answer
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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].
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks so much for that Francois. That looks like exactly the explanation I was looking for.
Copy link to clipboard
Copied
Well, I got it from Toby 😉
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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

