Liberty BASIC Community Forum
Liberty BASIC Programming Discussions >> Liberty BASIC Code >> Pixel manipulation in images

Pixel manipulation in images
Post by tenochtitlanuk on Dec 26th, 2015, 2:39pm

Season's Greetings to everyone- whatever your timezone!
And in the Northern Hemisphere our days start getting longer again. Can't be bad..
User Image
This is just an illustration of getting screen pixel values. It seemed suitable seasonal!

The challenge was to space the dots that replace the b&w values AND do so irregularly rather than on a fixed grid. I'm quite pleased by the result, although I may play further!
Note the image name and size are fixed at 800x600 and I posterised the image first- 'tho I could call ImageMagick to resize and do this pre-processing automatically. Bear that in mind in trying the code below!

Have a great New Year everyone, and special thoughts to those who haven't been having an easy time.

WindowWidth  =850
WindowHeight =660

open "Display" for graphics_nsb as #w

#w "trapclose quit"

handleg  =hwnd( #w)
calldll  #user32, "GetDC", handleg as ulong, hDC as ulong

loadbmp "scr", "tenoch.bmp"
#w "down ; drawbmp scr 20 20 ; backcolor white ; flush"

while 1
    x = 20 +int( 800 *rnd( 1))
    y = 20 +int( 600 *rnd( 1))

    calldll #gdi32, "GetPixel", hDC as ulong, x as long, y as long, pixcol as ulong
    if pixcol <>255 and pixcol <> 2^24 -1 then
        bl = int(  pixcol /( 256*256)): gr = int( (pixcol -bl *256*256) / 256): re = int(  pixcol -bl *256*256 -gr *256)
        grey =int( ( bl +gr +re) /3 /32)
        print x, y, re, gr, bl, grey
        #w "color white"
        #w "place "; x; " "; y
        #w "circlefilled "; grey -2
        #w "size "; 4
        #w "color red"
        #w "set "; x; " "; y
        'call timeout 100
        end if


sub quit h$
    close #h$
    callDll #user32, "ReleaseDC", handleg as ulong, hDC as ulong, result as ushort
end sub

sub timeout t
    timer t, [j]
    timer 0
end sub

Re: Pixel manipulation in images
Post by Alyce Watson on Dec 27th, 2015, 11:38am

That's a great algorithm! Well done!