From 63bbdc32d3da7d5a584b0912c5a434b4c3fa65a4 Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Sat, 17 Feb 2024 02:22:23 +0100 Subject: [PATCH] lua: Make frame:getPixel return three values This is what users will want in the majority of cases, and switching to this makes using this function much easier. However, this does break backwards compatibility. Luckily to my knowledge this function is not actually used in any existing published script (all scripts using get_frame just use getPixelFormatted instead) so the damage shouldn't be too large. But this is also why I'd rather rip off the band-aid of breaking backwards compatibility now than later. --- automation/v4-docs/get-frame.txt | 8 +++++--- src/auto4_lua.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/automation/v4-docs/get-frame.txt b/automation/v4-docs/get-frame.txt index 5d75e5055..99342ac4a 100644 --- a/automation/v4-docs/get-frame.txt +++ b/automation/v4-docs/get-frame.txt @@ -40,7 +40,7 @@ Returns: number Get RGB pixel value at a certain position of frame object. -function frame:frame:getPixel(x, y) +function frame:getPixel(x, y) @x (number) Pixel to retrieve on the x-axis @@ -48,8 +48,10 @@ function frame:frame:getPixel(x, y) @y (number) Pixel to retrieve on the y-axis -Returns: number - Integer value representing the RGB pixel value. +Returns: 3 values, all numbers + 1. R value of the pixel + 2. G value of the pixel + 3. B value of the pixel --- diff --git a/src/auto4_lua.cpp b/src/auto4_lua.cpp index b5e381fe1..449a27989 100644 --- a/src/auto4_lua.cpp +++ b/src/auto4_lua.cpp @@ -230,12 +230,13 @@ namespace { size_t pos = y * frame->pitch + x * 4; // VideoFrame is stored as BGRA, but we want to return RGB - int pixelValue = frame->data[pos+2] * 65536 + frame->data[pos+1] * 256 + frame->data[pos]; - push_value(L, pixelValue); + push_value(L, frame->data[pos+2]); + push_value(L, frame->data[pos+1]); + push_value(L, frame->data[pos]); } else { lua_pushnil(L); } - return 1; + return 3; } int FramePixelFormatted(lua_State *L) {