Rectangle detection

J. Landman Gay jacque at hyperactivesw.com
Sat Sep 5 16:41:27 EDT 2015


On 9/5/2015 2:42 AM, Peter Reid wrote:
> 5. Here is the handler that I use to test the colour of a pixel:
>
> function getPixelColour pX, pY, pImgWidth
>     local tPix, tImgPos, tRedVal, tGreenVal, tBlueVal
>     put pY * pImgWidth + pX into tPix
>     put tPix * 4 into tImgPos
>     put charToNum(byte (tImgPos + 2) of image "graph" of stack "ImageHolder") into tRedVal
>     put charToNum(byte (tImgPosn + 3) of image "graph" of stack "ImageHolder") into tGreenVal
>     put charToNum(byte (tImgPosn + 4) of image "graph" of stack "ImageHolder") into tBlueVal
>     return (tRedVal)  -- & comma & tGreenVal & comma & tBlueVal)
> end getPixelColour

I wouldn't think the width of the image would matter in the calculation 
if you're counting downward in a straight line. I think it should be 
more like this:

   put pX,pY+1 into tPix

There's a hack to get a pixel color that might work a little faster, and 
would reduce the handler to 2 lines:

function getPixelColour pX, pY
  set the screenMouseloc to globalLoc(pX,pY)
  return the mousecolor -- or: item 1 of the mousecolor
end getPixelColour

Normally you'd store the original mouseloc and then restore it again 
after getting the mousecolor, but in this case I wouldn't restore it 
until the loop is done and you've found the bottom edge.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list