
-----------------------------------
Zren
Sun Aug 02, 2009 3:47 am

Screen -&gt; File using Hex Output
-----------------------------------
Just because I wanted to see if I could prove DemonWasp wrong in the ability to have screen output writing to file in this thread. 

Draw.FillStar (0, 0, 99, 99, red) % for the output

var r, g, b : real % for use later with colour

var fileName : string := "Master.bmp"
var fileNo : int
open : fileNo, fileName, put

procedure hexstr (h : string)
    var v : array 0 .. 1 of int
    var value : int
    for i : 1 .. length (h)
        case (Str.Upper (h (i))) of
            label "A" :
                v (i mod 2) := 10
            label "B" :
                v (i mod 2) := 11
            label "C" :
                v (i mod 2) := 12
            label "D" :
                v (i mod 2) := 13
            label "E" :
                v (i mod 2) := 14
            label "F" :
                v (i mod 2) := 15
            label :
                v (i mod 2) := strint (h (i))
        end case
        if i mod 2 = 0 then
            value := v (0) + v (1) * 16
            put : fileNo, chr (value) ..
        end if
    end for
end hexstr

hexstr ("424D")      %Magic Number "BM"
hexstr ("46000000")  %Size of the BMP file (Doesn't matter it seems)
hexstr ("00000000")  %Application Specific
hexstr ("36000000")  %The offset where the bitmap data (pixels) can be found.
hexstr ("28000000")  %The number of bytes in the header (from this point).
hexstr ("64000000")  %The width of the bitmap in pixels
hexstr ("64000000")  %The height of the bitmap in pixels
hexstr ("0100")      %Number of colour planes being used
hexstr ("1800")      %The number of bits/pixel (24 bit)
hexstr ("00000000")  %BI_RPG, No compression used
hexstr ("10000000")  %The size of the raw BMP data (after this header)
hexstr ("130B0000")  %The horizontal resolution of the image
hexstr ("130B0000")  %The vertical resolution of the image
hexstr ("00000000")  %Number of colors in the palette
hexstr ("00000000")  %Means all colors are important

%Actual Picture
for y : 0 .. 100
    for x : 0 .. 100
        RGB.GetColor (whatdotcolor (x, y), r, g, b)
        put : fileNo, chr (floor (r * 255)), chr (floor (g * 255)), chr (floor (b * 255)) ..
    end for
    hexstr ("0000") %End Row for picture
end for

close : fileNo


PS: Turing help is a massive pain with uploading, previewing and all with this template.

-----------------------------------
Dan
Sun Aug 02, 2009 6:43 am

RE:Screen -&gt; File using Hex Output
-----------------------------------
If what you mean is save the screen to a bmp file turing can allready do this:


var myPic : int := Pic.New (0,0,maxx,maxy)
Pic.Save (myPic, "mySavedPic.bmp")


-----------------------------------
Brightguy
Sun Aug 02, 2009 11:28 am

Re: Screen -&gt; File using Hex Output
-----------------------------------
You're drawing an image of width 101 into a bitmap of width 100.  Also your alignment is off, you don't need any row padding for width 100.

-----------------------------------
Zren
Sun Aug 02, 2009 11:53 am

Re: RE:Screen -&gt; File using Hex Output
-----------------------------------
If what you mean is save the screen to a bmp file turing can allready do this:


var myPic : int := Pic.New (0,0,maxx,maxy)
Pic.Save (myPic, "mySavedPic.bmp")


Oh that's cool. I started looking through the module and found Pic.ScreenSave( x1, y1, x2, y2, filename ) and skips the first line and the extra Pic.Free() at the end.

I took out the end of line statement and it still works (got rid of that ugly diagonal line dabut). Then I remembered I started the two for loops from 0 thus making 0..100 101 pixels in dimension. Thus causing the overflow onto the next row of pixels. (Hey I first coded this past midnight).

I could go further with this and make it into a module and such but seeing as the code has already been made, this'll do.

EDIT: Thanks brightguy. You musta posted right after I click reply.

End Results:


var r, g, b : real % for use later with colour
var fileNo : int

procedure hexstr (h : string)
    if length (h) mod 2 = 0 then %If even in length
        var v : array 0 .. 1 of int
        var value : int
        for i : 1 .. length (h)
            case (Str.Upper (h (i))) of
                label "A" :
                    v (i mod 2) := 10
                label "B" :
                    v (i mod 2) := 11
                label "C" :
                    v (i mod 2) := 12
                label "D" :
                    v (i mod 2) := 13
                label "E" :
                    v (i mod 2) := 14
                label "F" :
                    v (i mod 2) := 15
                label :
                    v (i mod 2) := strint (h (i))
            end case
            if i mod 2 = 0 then
                value := v (0) + v (1) * 16
                put : fileNo, chr (value) ..
            end if
        end for
    else
        put "Error with hex input."
    end if
end hexstr

procedure ScreenToFile (filename : string)
    open : fileNo, filename, put

    hexstr ("424D")         %Magic Number "BM"
    hexstr ("46000000")         %Size of the BMP file (Doesn't matter it seems)
    hexstr ("00000000")         %Application Specific
    hexstr ("36000000")         %The offset where the bitmap data (pixels) can be found.
    hexstr ("28000000")         %The number of bytes in the header (from this point).
    hexstr ("64000000")         %The width of the bitmap in pixels
    hexstr ("64000000")         %The height of the bitmap in pixels
    hexstr ("0100")         %Number of colour planes being used
    hexstr ("1800")         %The number of bits/pixel (24 bit)
    hexstr ("00000000")         %BI_RPG, No compression used
    hexstr ("10000000")         %The size of the raw BMP data (after this header)
    hexstr ("130B0000")         %The horizontal resolution of the image
    hexstr ("130B0000")         %The vertical resolution of the image
    hexstr ("00000000")         %Number of colors in the palette
    hexstr ("00000000")         %Means all colors are important

    %Actual Picture
    for y : 0 .. 99
        for x : 0 .. 99
            RGB.GetColor (whatdotcolor (x, y), r, g, b)
            put : fileNo, chr (floor (r * 255)), chr (floor (g * 255)), chr (floor (b * 255)) ..
        end for
    end for

    close : fileNo
end ScreenToFile

Draw.FillBox (0, 0, 99, 99, black)
for decreasing i : 50 .. 10
    Draw.Oval (50, 50, i, i, i)
end for
ScreenToFile ("Master.bmp")

