Rasterbator Rasto10.bas


Rasterbator, available online or stand alone accepts an image & returns pdf pages which print cheaply on a laser printer& assemble as tiles to make possibly huge posters.
See also my earlier version, using dll calls, at Mark 1 The following code runs in LB or JB on Windows XP. Read the 'rem'med notes about where to obtain ImageMagick, and about changing the hard-coded scratch pad area. It accepts ANY type of image, and at present leaves you with the GIFs for printing the tiles and tiling your wall!
I'll be adding to it. The aim is to make an on-line interface probably with RunBasic.


    '                 ///////////////////        Rast010.bas           \\\\\\\\\\\\\\\\\\\\\\

    '                                       tenochtitlanuk July 2009


    '   Requires you to have installed ImageMagick                       http://www.imagemagick.org/script/index.php

    '   Also at present it is 'hard coded' to use RAMdisk R:. Edit to C: or whatever you wish..

    '   Loads an image of your choice and saves it broken up into smaller tiles.
    '       These are for printing on separate sheets of paper to tile a poster of large size.
    '       Based on 'Rasterbator', hence the name                       http://homokaasu.org/rasterbator/



    '   NB in this version the array is not used. Full version will use it to average or otherwise process the pixels
    '       and draw circles (or other shapes) of suitable radius. A work-in-progress!

    '   See version on my website which uses a different method.         http://atschool.eduweb.co.uk/taunton/LB/rast.html
    '       ( It calls the WINMM.DLL)
    '       This present one should work on LB, or JB.

    '   At present I get crashes which take down LB as well!!! Not sure why /when...
    '       Also get glitches on the re-drawn screen, & bmpsave grabs any overlapping windows.
    '       So don't move any windows over it while processing!

    '   'To-do's.  User edited grid to show number of pages. Process image for contrast/gamma/distortions. Colour option.
    '       Add help/instruction menu.
    '   Convert to RB. Check out Linux version...


    nomainwin

    WindowWidth     =840
    WindowHeight    =550
    UpperLeftX      = 40
    UpperLeftY      = 10

    graphicbox #a.graph, 10,  10, 404, 410
    graphicbox #a.g2,   420,  10, 408, 410

    button     #a.b, "Quit", [quit], LR,  40,  10

    menu       #a,   "&File", "&Open...", [openpic], | , "&Quit", [quit]

    dim pr( 400, 400), pg( 400, 400), pb( 400, 400)                 '   arrays to hold colour pixel data for processing.

    '   ------------------------------------------------------------------------------------------
    open "Rasto10- convert images into huge posters" for window as #a

    #a.graph, "down"
    #a.g2,    "down"

    #a,       "trapclose [quit]"

[begin]
    wait

    '   -------------------------------------------------------------------------------------------
[openpic]
    filedialog "Open image for processing", "*.bmp; *.gif; *.jpg", filename$
    if filename$ ="" then goto [begin]
                                                                    '   Unlike LB, Imagemagick can load any graphic filetype.
                                                                    '       And can convert or process them very fast.
                                                                    '       Here, I convert chosen file to 400x400 size.
                                                                    '       This avoids all sort of scaling problems.
                                                                    '   \\ converts chosen.anyimagetype into 400x400 bmp //
    file$  ="convert -sample 400x400 "; chr$(34); filename$; chr$( 34); " R:\pic400x400.bmp"

    run "cmd.exe /k "; chr$( 34); file$; chr$( 34), HIDE

    timer 3000, [carryon]
    wait
[carryon]
    timer 0

    loadbmp   "workimage", "R:\pic400x400.bmp"                      '   NB either or both of l & w will be 400... ie longest dimension fits exactly.
    #a.graph, "drawbmp workimage 1 3"
    #a.graph, "flush"
    unloadbmp "workimage"

    open "R:\pic400x400.bmp" for input as #bmp                      '   BMP is now a string in memory...
        bi$ =input$( #bmp, LOF( #bmp))
    close #bmp

    w =asc( mid$( bi$, 19, 1)) +256 *asc( mid$( bi$, 20, 1))        '   lo byte at offset 18, ie string pos 19
    h =asc( mid$( bi$, 23, 1)) +256 *asc( mid$( bi$, 24, 1))        '   hi byte at offset 22, ie string pos 23

    o =( w *3) mod 4                                                '   Check how many bytes beyond a 4-byte block we are.

    pntr =55                                                        '   Points to start of data in a 24 bit bmp file.

    for y =1 to h                                                   '   Read the rows...
        for x =1 to w                                               '       ...and columns.
            '                                                           The bytes we want start at 54th, ie string position 55.
            '                                                           They are in blocks of 3, bgr. The end of each row of blocks is 4-byte aligned.
            '                                                           I save an array, but do not use it further in the present app.
            pb( x, y) =asc( mid$( bi$, pntr,   1))
            pg( x, y) =asc( mid$( bi$, pntr+1, 1))
            pr( x, y) =asc( mid$( bi$, pntr+2, 1))
            p =(0.299 *pr( x, y)    +0.587 *pg( x, y)     +0.114 *pb( x, y))
                                                                    '   Eye responsivity values
            #a.g2, "color "; p; " "; p; " "; p
            #a.g2, "set "; x +1; " "; 2 +h -y                       '   Draw the processed version- here in b&w
            pntr =pntr +3
        next x
        scan
        if o <>0 then pntr =pntr +( 4 -o)   '                       '   Make 4-byte-aligned
    next y

    '                                                               '   Draw grid to show chosen sectional areas.
    #a.g2, "color white ; up ; goto 200 0 ; down ; line 200 0 200 400 ; up"
    #a.g2, "goto 0 200 ; down ; line 0 200 400 200"
    #a.g2, "flush"

    #a.g2, "getbmp rast1     1    1   199  199" '                   '   Now we'll save the image in 4 panels...
    bmpsave "rast1", "R:\rast1.bmp"                                 '   First, top left panel
        file$  ="convert R:\rast1.bmp R:\rast1.gif"                 '   Calling Imagemagick to convert file bmp to gif.
        run "cmd.exe /k "; chr$( 34); file$; chr$( 34), HIDE

    #a.g2, "getbmp rast2   200    1   199  199"
    bmpsave "rast2", "R:\rast2.bmp"
        file$  ="convert R:\rast2.bmp R:\rast2.gif"
        run "cmd.exe /k "; chr$( 34); file$; chr$( 34), HIDE

    #a.g2, "getbmp rast3     1  200   199  199"
    bmpsave "rast3", "R:\rast3.bmp"
        file$  ="convert R:\rast3.bmp R:\rast3.gif"
        run "cmd.exe /k "; chr$( 34); file$; chr$( 34), HIDE

    #a.g2, "getbmp rast4   200  200   199  199"
    bmpsave "rast4", "R:\rast4.bmp"
        file$  ="convert R:\rast4.bmp R:\rast4.gif"
        run "cmd.exe /k "; chr$( 34); file$; chr$( 34), HIDE


    timer 3000, [carryon2]   '                                     '    Allow time for all to complete, then delete bmp versions
    wait
[carryon2]
    timer 0

    kill "R:\rast1.bmp" '                                          '    Can now safely delete the bmp versions.
    kill "R:\rast2.bmp"
    kill "R:\rast3.bmp"
    kill "R:\rast4.bmp"
    wait

[quit]
    close #a
    timer 0 '                                                      '    So timer does not keep firing if interrupted or ended.
    end