Changing bitmap image to raster, width modulated.

Every pixel in this image is represented by three numbers, representing each, on a range from 0 to 255, the amounts of red, green and blue at that point. Black is ( 0, 0, 0); white is ( 255, 355, 255); red is ( 255, 0, 0) and yellow ( 255, 255, 0). I scan across this image every 10 pixels vertically, finding the average brightness in the vertical ten-pixel sample, and plot it as a vertical displacement. This is an effective way to simplify the image in an interesting way. But you could represent samples as other shapes- eg circles, whose area represents the pixel average, as done on my 'rasterbator' clone. Or alter the colour by rotating RGB to GBR. Or any king of processing you fancy.

How it all works

If you know you will always have a 24 bit bitmap image you can load it as a string in memory and read the pixels directly. That way it does not have to fit an LB graphic area. But LB has the easy ability to call Windows dll's, in particular one to read a pixel's colour. By using this to analyse a screen image it can be turned into a 2D matrix of values and manipulated- or processed small areas at a time. This is only one of many such programs I've written. Particularly good for drawing on an eggbot or 2D drawing machine.

By calling ImageMagick you could load/save as GIF or other image type. I find it easy to do these 'by hand', so at present you need to save first a 24 bit BMP of the right size. Easily added. And should add the equally easy 'Save as' to any image type.

Note this is still a work-in-progress. Plenty of ideas still for development, see also the remmed lines for examples!

How young I looked 50 years ago!




'   *******************************************************
'   **                                                   **
'   **   rasterWidth1.bas   tenochtitlanuk   2016-2018   **
'   **                                                   **
'   *******************************************************


'   To-dos
'       Add saving option
'       Include ImageMagick to resize and enable other image types



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

filedialog "Choose bitmap- ideally <800x600", "*.bmp", fn$
if fn$ ="" then close #w: end

loadbmp "scr", fn$
#w "down ; drawbmp scr 10 10 ; backcolor white ; flush"


for y =10 to 790 step 10
    for x =10 to 590 step 1
        grey   =0

        for dy =y to y +9
            calldll #gdi32, "GetPixel", hDC as ulong, x as long, dy as long, pixcol as ulong
            bl      = int(  pixcol /( 256*256))
            gr      = int( (pixcol -bl *256*256) / 256)
            re      = int(  pixcol -bl *256*256 -gr *256)
            grey    = grey +int( ( bl +gr +re) /3 /32)
        next dy

        grey =int( grey /10)
        scan

        #w "up; color 220 220 240 ; goto "; x; " "; y; " ; down ; goto "; x; " "; y +grey
        #w "color black ; goto "; x; " "; y +9
    next x
next y


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



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

[getFile]
filedialog "Choose image", "*.bmp", fn$
if fn$ ="" then [getFile]

loadbmp "scr", fn$

#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$
    callDll #user32, "ReleaseDC", handleg as ulong, hDC as ulong, result as ushort
    close #h$
    end
end sub

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