Old 11-26-2018, 12:26 PM   #1
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,443
Default Video processor reference...

Pressing F1 (on Windows) when the video processor has focus brings up a small dialog explaining parts of the video processor programming language. For me, that text mass is too small and too un-formatted to be of any real use, and I think that some of what is in there is outdated. So here, mainly for my own reference, I post a better formatted version of that text. Maybe it is useful for someone else, as well.

Special variables:
  • project_time: project time in seconds
  • project_tempo: current tempo in BPM
  • project_ts_num: current time signature numerator
  • project_ts_denom: current time signature denominator
  • project_time_qn: current project position in QN
  • time: item time in seconds (if in item)
  • framerate: project FPS (30.0, 29.97, etc)
  • project_w: project preferred video width
  • project_h: project preferred video height
  • project_wh_valid: set nonzero if project_w/project_h reflect actual project setting (otherwise could be media-defined)
  • colorspace: current rendering colorspace, e.g. 'RGBA', 'YV12', or 'YUY2'. you can override this with extreme caution.
  • param_wet: if in FX form, wet/dry mix of effect.
  • param1, ..., param16: parameters, you can name these by adding lines:
    //@param<idx>[:varname] 'name' [defval minval maxval centval step].
    (Be sure to NOT have space between the colon and the varname!)
  • gfx_r: current drawing color (red 0..1)
  • gfx_g: current drawing color (green 0..1)
  • gfx_b: current drawing color (blue 0..1)
  • gfx_a: current drawing alpha (0..1)
  • gfx_mode:
    • 0 = normal
    • 1 = additive
    • 3 = multiply (very different in YUV vs RGBA)
    • 17 = (dest + src*gfx_a)*.5 + .5 (only valid when using YUV colorspaces)
    • 18 = dest + (src-0.5)*gfx_a*2.0 (only valid when using YUV colorspaces)
    • 19 = absolute difference: abs(dest-src)*gfx_a (only valid when using YUV colorspaces)
    • add 0x100 for blit() to enable filtering (if possible)
    • add 0x10000 to use source alpha (only valid when using RGBA colorspace)
    • add 0x40000 to use extra clamping in normal mode (for out of range alpha/gradient values)
    • add 0x80000 to treat gfx_r/gfx_g/gfx_b as YUV values (in YUV colorspaces)
  • gfx_dest: destination image handle, or -1 for main framebuffer

Functions:
  • input_count() returns number of inputs available (total), range [0..n)
  • input_track_count() returns the number of available inputs on discrete tracks
  • input_track(x) returns input for bottommost item or FX on discrete-track x (0 is first track with video item above current, etc)
  • input_track_exact_count() returns the number of tracks above the current track that could possibly contain video items.
  • input_track_exact(x) returns input for bottommost item or FX on track relative to current track. Returns -1000 if track does not contain any video items at the current time, or -10000 if no further tracks contain video.
  • input_next_item(x) returns the next input after x which is on a different item or track
  • input_next_track(x) returns the next input after x which is on a different track
  • input_ismaster() returns 1.0 if current FX is on master chain, 2.0 if on monitoring FX chain
  • input_info(input, w, h [,srctime, wet, parm1, ...]) returns 1 if input is available, sets w/h to dimensions. If srctime specified, it will be set with the source-local time of the underlying media. if input is a video processor in effect form, automated parameters can be queried via wet/parm1/etc.
  • gfx_img_alloc([w,h,clear]) returns an image index for drawing (can create up to 32 images). contents of image undefined unless clear set.
  • gfx_img_resize(handle,w,h [,clear]) sets an image size (handle can be -1 for main framebuffer). contents of image undefined after resize, unless clear set. clear=-1 will only clear if resize occurred.
    (Returns the handle, the "image index")
  • gfx_img_hold(handle) (cheaply) retains a read-only copy of an image in handle. This copy should be released using gfx_img_free() when finished. Up to 32 images can be held.
    (Returns the image index of the copy)
  • gfx_img_getptr(handle) gets a unique identifier for an image, valid for while the image is retained. can be used (along with gfx_img_hold) to detect when frames change in a low frame rate video
  • gfx_img_free(handle) frees an earlier allocated image index.
  • gfx_img_info(handle,w,h) gets dimensions of image, returns 1 if valid (resize if inexplicably invalidated)
  • gfx_set(r,g,b [, a=1, mode=0, dest]) - updates r/g/b/a/mode always, dest only if specified
  • gfx_blit(input [,preserve_aspect=0,x,y,w,h,srcx,srcy,srcw,srch]) copies input to framebuffer. preserve_aspect=-1 for no fill in pad areas
  • gfx_fillrect(x,y,w,h) fills a rectangle
  • gfx_procrect(x,y,w,h,channel_tab[,mode]) processes a rectangle with 768-entry channel table [256 items of 0..1 per channel]. specify mode=1 to use Y value for U/V source channels (colorization mode)
  • gfx_evalrect(x,y,w,h,code_string [,flags,src2]) processes a rectangle with code_string being executed for every pixel/pixel-group. code should reference, depending on colorspace:
    • RGBA: r/g/b/a,
    • YUY2: y1,y2,u,v,
    • YV12: y1-y4, u, v.
    Values are 0-255, and are not clamped. set flags|=1 in order to prevent multiprocessing (if your routine needs to process pixels in-order; side-note: variables _1-_99 are thread-local variables which will always be initialized to 0, and _0 will be initialized to the thread index (0 or 1 usually)). set flags|=2 to ignore output (analysis-only). if src2 specified, sr/sg/sb/sa, sy1/su/sv etc will be available to read. In this case only the intersection of valid rectangles between src2 and the destination buffer will be valid.
  • gfx_gradrect(x,y,w,h, r,g,b,a [,drdx,dgdx,dbdx,dadx, drdy,dgdy,dbdy,dady]);
  • gfx_rotoblit(srcidx, angle [, x,y,w,h, srcx,srcy, w,h, cliptosrcrect = 0, centxoffs=0, centyoffs=0])
  • gfx_deltablit(srcidx, x,y,w,h, srcx,srcy, dsdx,dtdx, dsdy,dtdy, dsdxdy, dtdxdy [, dadx, dady, dadxdy])
  • gfx_xformblit(srcidx, x,y,w,h, wdiv, hdiv, tab [, wantalpha=0]) - tab is wdiv*hdiv*2 table of src points. if wantalpha=1, tab is wdiv*hdiv*3 table of src points including alpha.
  • gfx_keyedblit(input [,x,y,w,h, srcx,srcy, kv1,kv2,kv3,kv4]) chroma-key blits, using the source color as key. kv1-kv4 meaning depends on colorspace:
    • YV12/YUY2: kv1 is U target (-0.5 default), kv2 is V target (-0.5 default), kv3 is closeness-factor (0.4 default), kv4 is the gain (2.0 default)
    • RGBA: kv1 is green-factor (1.0 default), kv2 is blue-factor (-1.0 default), kv3 is offset (-1.0 default), kv4 enables spill removal (1.0 default)
  • gfx_destkeyedblit(input [,x,y,w,h, srcx,srcy, kv1,kv2,kv3,kv4]) chroma-key blits, using destination color as key. ignores gfx_a and gfx_mode.
  • gfx_setfont(pxsize [,#fontname, flags) - sets a font, flags can be 'B' for bold, 'I' for italics, 'BI' for bold italics, etc
  • gfx_str_measure(#string [,w,h]) - measures the size of #string, returns width
  • gfx_str_draw(#string [,x,y, fxc_r,fxc_g,fxc_b]) - draw string
  • rgb2yuv(r,g,b) -- utility, converts r,g,b to YUV, does not clamp [0..1]
  • yuv2rgb(r,g,b) -- utility, converts YUV to r,g,b, not clamping [0..1]
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...

Last edited by Fabian; 12-01-2018 at 09:36 AM.
Fabian is offline   Reply With Quote
Old 11-26-2018, 12:41 PM   #2
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,443
Default

And then we can post comments, questions, and corrections.

I have three:
  • For gfx_blit, are the src* parameters really correct? Looking at the available presets, it seems that what is called "x,y,w,h" above are really the source parameters, while what is now called "srcx,srcy,srcw,srch" above are the destination parameters. This is also the way gfx_blit is defined in the JSFX documentation https://www.reaper.fm/sdk/js/gfx.php#js_gfx. Anyone knows for sure?
  • The way gfx_set is defined above it requires "r,g,b" parameters, but looking into the "invert colors" preset, I see gfx_set(1); So, what gives...?
  • It seems that at least gfx_img_resize returns a value that can be assigned to gfx_dest (see for instance the Selective Blender by wwwmaze here https://forum.cockos.com/showpost.ph...5&postcount=44 ). Are there other undocumented useful return values?
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 11-26-2018, 02:24 PM   #3
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,436
Default

Also: the EEL2 language reference is here: https://www.cockos.com/EEL2/
Justin is offline   Reply With Quote
Old 11-26-2018, 02:30 PM   #4
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 12,436
Default

Quote:
Originally Posted by Fabian View Post
For gfx_blit, are the src* parameters really correct? Looking at the available presets, it seems that what is called "x,y,w,h" above are really the source parameters, while what is now called "srcx,srcy,srcw,srch" above are the destination parameters.
If srcx-srch are not specified, they are automatically set to the full source image dimensions. x/y/w/h represent the destination coordinates.

Quote:
The way gfx_set is defined above it requires "r,g,b" parameters, but looking into the "invert colors" preset, I see gfx_set(1);
Heh this one has been documented in the development branch -- if only r is specified, gfx_set() sets g/b to the same value (white/gray/black/etc).

Quote:
It seems that at least gfx_img_resize returns a value that can be assigned to gfx_dest
gfx_img_resize() returns the handle. There is a shorthand, too -- gfx_img_resize(0,w,h) allocates a new image buffer (it's the same as gfx_img_alloc()), so you can use code like:
Code:
img = gfx_img_resize(img,w,h);
Which will always ensure that img is the correct dimensions, allocating it if necessary. I'll update the built-in docs to reflect this.
Justin is offline   Reply With Quote
Old 11-27-2018, 12:15 PM   #5
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,443
Default

Thanks for this, Justin. This is exactly the kind of info we (well... at least I) need.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   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 01:46 AM.


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