DannyD,
I dunno what your goal is, but when working with pixel processing in interpreted languages (and compiled) instruction redundancy is critically important. Depending upon the image size the snippet from your example bellow is wasting millions if not billions of cycles being interpreted..
ie.
for columns = 1 to img_width
colour_test = GetPixel ( memBlockInput, columns-1, rows-1, img_width )
if colour_test = colour_back
does lots of other stuff... that code was removed
endif
next
function GetPixel ( memBlockIn, x, y, width )
offsetPixel = 12 + (( x + ( y * width )) * 4 )
Red = GetMemBlockByte ( memBlockIn, offsetPixel )
Green = GetMemBlockByte ( memBlockIn, offsetPixel + 1 )
Blue = GetMemBlockByte ( memBlockIn, offsetPixel + 2 )
Alpha = GetMemBlockByte ( memBlockIn, offsetPixel + 3 )
PixelColourRGB = Red + Green + Blue
endfunction PixelColourRGB
Since this bit of code just skimming a linearly laid out chunk of contiguous memory, the GetPixel (among others) has a disproportionate cost at runtime. So that could be inlined.
// compute address of left most pixel once per row
offsetPixel = 12 + (( ( rows * img_width )) * 4 )
for columns = 1 to img_width
// add the RED - GREEN and BLUES together for whatever reason
colour_test = GetMemBlockByte ( memBlockInput, offsetPixel )+ GetMemBlockByte ( memBlockInput, offsetPixel + 1 )+ GetMemBlockByte ( memBlockInput, offsetPixel + 2 )
if colour_test = colour_back
does lots of other stuff... that code was removed
endif
// move to the next pixel on this row
offsetPixel=offsetPixel+4
next
That's not going to be express either, but the cost of just skimming the buffer at least 10 instructions per pixel... Which adds up