Computer Science Canada

pic creator

Author:  agnivohneb [ Sun Nov 11, 2007 3:02 pm ]
Post subject:  pic creator

This is just a quick program i made when i was bored.

Pic Creator

WARNING: This Program is still in the Beta stage and errors may occur.

This program allows you to convert a .bmp or .jpg file to a turing readable .t file using the View.WhatDotColor (x, y) function. This is useful if you are creating a game (eg. mario) that uses moving pictures and you want to be able to compile it to an .exe file and send it to everyone but you don't want to have all of those picture files following allong. Why not just use this program and convert your pictures to a format turing recognizes and compile them with your program. All of your pictures are now in one .exe file. No need for a .zip folder!

To use this program just copy your pic to the same dir as this program and enter the file name (don't forget the extension) into the program. It automatically will do the rest. and export it as a .t file.

NOTE: Colour loss may occur. Only use small images.

Author:  CodeMonkey2000 [ Sun Nov 11, 2007 4:33 pm ]
Post subject:  RE:pic creator

Wow that's pretty cool. Did you try using turing RGB.GetColour and RGB.SetColor functions? I think you get a better variety with that.

Author:  agnivohneb [ Sun Nov 11, 2007 5:37 pm ]
Post subject:  RE:pic creator

Thanks I will try that and post a update

Author:  agnivohneb [ Sun Nov 11, 2007 6:28 pm ]
Post subject:  RE:pic creator

Just tried and there is no difference.

Author:  Nick [ Sun Nov 11, 2007 6:30 pm ]
Post subject:  Re: pic creator

agnivohneb @ Sun Nov 11, 2007 3:02 pm wrote:
NOTE: Colour loss may occur.


wouldnt RGB prevent this?

Author:  StealthArcher [ Mon Nov 12, 2007 7:23 pm ]
Post subject:  Re: pic creator

The functions you refer to only read turings default colors.

Author:  SNIPERDUDE [ Mon Nov 12, 2007 8:32 pm ]
Post subject:  Re: pic creator

lol, I made a programme like this about a year ago. I kinda cheated though: I stored all of the RGB info in a text file (using a VB programme I made to get the RGB data, the turing whatdotcolour isn't that good), then made a corresponding turing program that converted the text file info into the pic.

It works though... Very Happy

Author:  agnivohneb [ Tue Nov 13, 2007 6:24 pm ]
Post subject:  Re: pic creator

momop @ Sun Nov 11, 2007 6:30 pm wrote:
agnivohneb @ Sun Nov 11, 2007 3:02 pm wrote:
NOTE: Colour loss may occur.


wouldnt RGB prevent this?

I did try but it stays the same colours and it was to confusing to get working. I just gave up and used turings default colours.

Author:  agnivohneb [ Tue Nov 13, 2007 6:36 pm ]
Post subject:  Re: pic creator

Sorry to post 2 messages so quickly but I have uploaded the source and a new license (by-nc-sa). Please respect the license. Have a look at it and upload any changes. Beta projects should not have just one person working on them.

Author:  StealthArcher [ Tue Nov 13, 2007 10:53 pm ]
Post subject:  Re: pic creator

You will get more help from me when yoiu change it to a gpl license.(Not meant to sound threatening or insulting, but it's hard to do with just text...)


Anyhow, after seeing this, I decided to try and make my own, however, instead of creating another turing file, it creates a binary with your photo in it, all made with View.WhatDotColor, and it has 24bit bitmap quality. I'm serious, I can take any bitmap, turn it into a .tbm with this using whatdotcolor, and turn it back out with drawdot, and it has 24 bit quality.

Now all i have to do is figure out a way to make it take less space than the original bitmap(though it does tkae less space than the .t files this makes).

Any ideas on how to do so? It's still in mega rough format, so dont mind the obvious blights like global vars, and commenting lack.

Turing:
setscreen ("nobuttonbar")
setscreen ("graphics:400;200")
var choice, quality : string := "1"
var n : int
var d : int := 1
var redam, blueam, greenam : real
var yopic : int

proc colorred
    for x : 1 .. 254
        redam := x / 254
        RGB.SetColor (x, redam, 0, 0)
    end for
end colorred

proc colorgreen
    for x : 1 .. 254
        greenam := x / 254
        RGB.SetColor (x, 0, greenam, 0)
    end for
end colorgreen

proc colorblue
    for x : 1 .. 254
        blueam := x / 254
        RGB.SetColor (x, 0, 0, blueam)
    end for
end colorblue

proc mainprogression
    put "Please enter the path to the photo to be converted to a transferrable Bitmap."
    get choice
    yopic := Pic.FileNew (choice)
    var wide, tall, file, tem, wind : int := 0
    var wde, tll, tempo, setup : string
    wide := Pic.Width (yopic)
    tall := Pic.Height (yopic)
    wde := intstr (wide)
    tll := intstr (tall)
    var photocolors : array 1 .. wide, 1 .. tall, 1 .. 3 of int
    wind := Window.Open ("position;top;center,graphics;max;max,offscreenonly")
    Window.SetActive (wind)
    cls
    Pic.Draw (yopic, 0, 0, picCopy)
    RGB.SetColor (0, 0, 0, 0)
    View.Update
    open : file, (choice + ".tbm"), write
    write : file, wde
    write : file, tll
    colorred
    for t : 1 .. tall
        for u : 1 .. wide
            photocolors (u, t, 1) := View.WhatDotColor (u, t)
        end for
    end for
    colorgreen
    for t : 1 .. tall
        for u : 1 .. wide
            photocolors (u, t, 2) := View.WhatDotColor (u, t)
        end for
    end for
    colorblue
    for t : 1 .. tall
        for u : 1 .. wide
            photocolors (u, t, 3) := View.WhatDotColor (u, t)
        end for
    end for
    for r : 1 .. tall
        for p : 1 .. wide
            write : file, photocolors (p, r, 1), photocolors (p, r, 2), photocolors (p, r, 3)
        end for
    end for
    close : file
    put "Bitmap made transferrable."
end mainprogression

proc secondprogression
    RGB.SetColor (0, 0, 0, 0)
    var wide, tall, file, wind, rr, gg, bb : int := 0
    var wde, tll, setup : string
    put "Please enter your transferrable bitmaps file path."
    get choice
    open : file, choice, read
    read : file, wde
    read : file, tll
    wide := strint (wde)
    tall := strint (tll)
    cls
    wind := Window.Open ("position;top;center,graphics;max;max,offscreenonly")
    Window.SetActive (wind)
    cls
    put "Drawing bitmap"
    View.Update
    for r : 1 .. tall
        for p : 1 .. wide
            read : file, rr, gg, bb
            redam:=rr/254
            greenam:=gg/254
            blueam:=bb/254
            RGB.SetColor(1,redam,greenam,blueam)
            Draw.Dot (p, r, 1)
        end for
    end for
    close : file
    View.Update
end secondprogression

put "Welcome to the Transferrable Bitmap File(.tbf) Converter."
delay (500)
put "Would you like to convert a photo?(Bitmap, Jpg, or gif only), or examine a photo?"
View.Update
loop
    get choice
    if choice = "convert" then
        mainprogression
        exit
    elsif choice = "examine" then
        secondprogression
        exit
    elsif choice = "no" then

        exit
    else
    end if
end loop

Author:  StealthArcher [ Thu Nov 15, 2007 12:53 am ]
Post subject:  Re: pic creator

New version, posting on PSP.

Author:  StealthArcher [ Thu Nov 15, 2007 5:54 pm ]
Post subject:  RE:pic creator

No matter what I seem to do I cannot cut down on size....
I've tried strings(dont ask...)
And boolean as well now(why oh why can they not be 1 bit instead of one byte????)

Reals, welll, im not really having the urge to try.....


Any one have any ideas at all to cut down on filespace usage?

Author:  Mazer [ Thu Nov 15, 2007 7:14 pm ]
Post subject:  RE:pic creator

Is a tbf image bigger than the respective bitmap image?

Author:  StealthArcher [ Thu Nov 15, 2007 7:38 pm ]
Post subject:  Re: pic creator

Yes, that's why I'm looking for ways to cut down on filespace.

If a boolean was a bit instead of a byte, I probably would just make it under the bitmaps original size.

This is the boolean one.

Author:  Mazer [ Thu Nov 15, 2007 9:30 pm ]
Post subject:  RE:pic creator

You generally don't write single bits. How many booleans are you using anyway? Can you not just store the RGB values?

Author:  StealthArcher [ Thu Nov 15, 2007 9:38 pm ]
Post subject:  Re: pic creator

Thats just it.

Storing each RGB value as a binary integer, makes the file almost 10x the size of the original bmp.
Storing a pixels each rgb value as a modified integer, using 9 as a split, makes it only about 5% bigger, but converting a 300x300 photo takes almost 20 minutes.

I attempted to use strings, a 100x100 photo wound up as a 30 mb tbm file......

So i thought about using boolean like basic binary, so as if first one is true then add 1 to r value and if the next 2 and then 4 and so on. But booleans are a byte each, not a bit, so I wound up with the same problem, of a ridiculous oversized file compared to the original bmp.

I was thinking of reals and storing as many values as possible, but that as calculated, makes them too big AGAIN......

So, I'm out of ideas, and I'm asking you.


: