Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification using _MEM
#6
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:

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
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.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
Clarification using _MEM - by TerryRitchie - 01-23-2024, 06:52 PM
RE: Clarification using _MEM - by SpriggsySpriggs - 01-23-2024, 07:03 PM
RE: Clarification using _MEM - by DSMan195276 - 01-23-2024, 07:12 PM
RE: Clarification using _MEM - by SMcNeill - 01-23-2024, 07:21 PM
RE: Clarification using _MEM - by DSMan195276 - 01-23-2024, 07:41 PM
RE: Clarification using _MEM - by TerryRitchie - 01-23-2024, 07:45 PM



Users browsing this thread: 1 Guest(s)