Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER for Video Editing/Mangling

Reply
 
Thread Tools Display Modes
Old 11-07-2022, 09:01 PM   #1
tbrown92030
Human being with feelings
 
tbrown92030's Avatar
 
Join Date: Jul 2019
Location: Los Angeles, CA USA
Posts: 6
Default gfx_evalrect and coordinate specific logic

I was toying with the idea of using gfx_evalrect to do some runtime alpha masking of an image but in a way that required knowing where a given pixel is in the image, not just its current RGBA values.

Am I missing something or is the current pixel position not available to the code being evaluated by gfx_evalrect?

I'm thinking I could disable multi-processing, ensure horizontal processing, top-down, and just use local variables to track the pixel coordinates, but that seems a bit kludgy and, since I don't need to rely on pixel order, slower due to loss of multi-processing. And, is that really any different from just doing my own nested loop with gfx_getpixel()/gfx_set()?

Alternatively, here is more exactly what I want to do and perhaps there's a better way:

I want to be able to define an arbitrary polygon by vertex coordinates, allow those coordinates to be automated so that the polygon can move and morph about the space of the project and then be used to set an alpha mask by implementing a ray-trace "point in polygon" test for a pixel.
tbrown92030 is offline   Reply With Quote
Old 11-08-2022, 05:31 AM   #2
papagirafe
Human being with feelings
 
papagirafe's Avatar
 
Join Date: Aug 2020
Location: Brasil
Posts: 690
Default

Quote:
Originally Posted by tbrown92030 View Post
I was toying with the idea of using gfx_evalrect to do some runtime alpha masking of an image but in a way that required knowing where a given pixel is in the image, not just its current RGBA values.

Am I missing something or is the current pixel position not available to the code being evaluated by gfx_evalrect?

I'm thinking I could disable multi-processing, ensure horizontal processing, top-down, and just use local variables to track the pixel coordinates, but that seems a bit kludgy and, since I don't need to rely on pixel order, slower due to loss of multi-processing. And, is that really any different from just doing my own nested loop with gfx_getpixel()/gfx_set()?

Alternatively, here is more exactly what I want to do and perhaps there's a better way:

I want to be able to define an arbitrary polygon by vertex coordinates, allow those coordinates to be automated so that the polygon can move and morph about the space of the project and then be used to set an alpha mask by implementing a ray-trace "point in polygon" test for a pixel.
All your questions about gfx_evalrect() are right on and have been mine too! Fortunately I have all your answers:
  • current pixel position: until proven wrong, you have to deduce the position by calculating x/y coordinates along the way. There is a logic behind multithreading that makes it possible to write a formula that works even with multiple threads
  • about vector adressing (r[i], g[i], b[i]): this gives you, through the same formula mentionned above, access to nearby pixels for inter pixels transform formulas. NB: negative indexes are allowed.
  • nested gfx_getpixel()/gfx_set() loops: gfx_evalrect() is faster from my experience even in single thread. Also, until v6.69, gfx_fillrect() had an alpha plane bug that prevented this method to work properly in RGBA colorspace.
  • polygons: I have made a preset just for that and it just happen to answer all your question about evalrect(). You can find it in this thread: https://forum.cockos.com/showthread.php?t=270737 but the initial discussions that lead to it are in here https://forum.cockos.com/showthread.php?t=270023. If you find this preset usefull please consider a small donation :-)
  • for gfx_evalrect() to work properly don't forget to set the colorspace according to your needs.

Last edited by papagirafe; 11-08-2022 at 01:10 PM. Reason: complementary info on vector
papagirafe is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.