Liberty BASIC Community Forum
« Pixel manipulation in images »

Welcome Guest. Please Login or Register.
Mar 29th, 2017, 04:09am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Pixel manipulation in images  (Read 389 times)
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1138
xx Pixel manipulation in images
« Thread started 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.
Code:
nomainwin

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
        scan
        end if
wend

wait

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

sub timeout t
    timer t, [j]
    wait
    [j]
    timer 0
end sub
 
User IP Logged

Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14909
xx Re: Pixel manipulation in images
« Reply #1 on: Dec 27th, 2015, 11:38am »

That's a great algorithm! Well done!
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls