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


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)

        #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


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