01-23-2024, 07:45 PM
(This post was last modified: 01-23-2024, 09:15 PM by TerryRitchie.)
Ok, thank for the replies guys, that does make sense. I wrote a subroutine the makes a negative image (inspired by another recent post) and wanted to see how small and fast I could make it. Here is what I have:
As you can see I use a variable named Size that calculates the total number of pixels and then use that as a count down within the loop. I thought I could use .SIZE to achieve this same result and remove another variable from my subroutine.
Code: (Select All)
' _______________________________________________________________________________________________________
'/ \
SUB __Negative (i AS LONG) ' __Negative |
' ___________________________________________________________________________________________________|___
'/ \
'| Creates a negative image |
'| |
'| i - the image to work with |
'\_______________________________________________________________________________________________________/
DIM MemBlock AS _MEM ' memory block holding image data
DIM Offset AS _OFFSET ' pixel location within memory block
DIM Pixel AS _UNSIGNED LONG ' pixel data at pixel location
DIM Size AS LONG ' total number of pixels
Size = _WIDTH(i) * _HEIGHT(i) ' calculate number of total pixels
MemBlock = _MEMIMAGE(i) ' set memory block to image data
Offset = MemBlock.OFFSET ' get start position of memory block
$CHECKING:OFF
DO ' begin pixel count
_MEMGET MemBlock, Offset, Pixel ' get pixel data from memory block
Pixel = 16777215 XOR Pixel ' make negative (only RGB is affected, not alpha)
_MEMPUT MemBlock, Offset, Pixel ' update pixel color in memory block
Offset = Offset + 4 ' next pixel location in buffer
Size = Size - 1 ' decrement pixels remaining
LOOP UNTIL Size = 0 ' leave when no pixels remain
_MEMFREE MemBlock ' free memory block
$CHECKING:ON
END SUB