News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Pages (2): « First [1] 2 Next > Last »
Convert bitmap image to ascii
Author Message
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #1
Convert bitmap image to ascii

Heya, I need to convert 256 images to a individual strings of 8x8 ones and zeroes.
Is this doable in murgaLua.

I found a pc program that does the job, but its going to be about 2100
mouseclicks so I'd rather try to program it and just rip a folder
of images and clean up after my mess.

Any ideas?

01-09-2009 11:04 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #2
RE: Convert bitmap image to ascii

You may want to use convert from ImageMagick.

For example "convert -resize 8x8 -extent 8x8 -monochrome -compress none ifile.png ofile.pbm" converts any ifile.png to an ASCII ofile.pbm. If you cut the first two lines you have what you want.

If you want to do it with 256 images you can use a simple shell script like:

Code:
for image in $(ls *.png); do convert -resize 8x8 -extent 8x8 -monochrome -compress none $image $(basename $image .png).pbm ; done


Should convert all png pictures in the directory.

Juergen

01-09-2009 01:07 PM
Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #3
RE: Convert bitmap image to ascii

Hey thanks.
Couldn't do ImageMagick as I need a new OS so I purchased Graphic Converter for $35 and it did the magick I needed to do.

So I got this 1983 Custom Ascii Character set batch converted to
256 individual 3D objects, dropped into a game level and blinking
different colors and shades.
Yay! 11,000 + polys of wonder.
Flash Movie of that here!

And then I parsed a screenshot of the old computer running in emulation.
Here's the console output at like a 2 point font size.


Having trouble mapping that back to the old computer though.
I'll have to clean up my code and post it.

So now, FLTK has some kind of embedded graphic format yes?
Where does the strange data for those images come from?
I've seen it in some scripts and it just confuses me.

So last year I was working on a little graphics creator for the old computer
in murgaLua and had planned to do more with it, but things happened.
Using pngs I was not able to deal with colors and the mouse is
drawing in the window even when you are choosing characters.

You can get the binaries and scripts in a zipped file, as long as see sample images in this directory

I'm pretty much aiming at a universal grid based mapping tool.
Of course I'm straying form universal all the time.
Right now its a world of zombies mapper. muahaha.

Anyway thanks in advance for any ideas or infos about such things.

This post was last modified: 01-10-2009 10:09 PM by iGame3D.

01-10-2009 10:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: Convert bitmap image to ascii

Quote:
So now, FLTK has some kind of embedded graphic format yes?
Where does the strange data for those images come from?
I've seen it in some scripts and it just confuses me.

It can use embedded pixmap (xpm) and bitmap (xbm) data, stored as Fl_Pixmap and Fl_Bitmap objects. I don't understand the bitmap data structure, probably less than you do. The xpm format is simple text, and it translates to FLTK pretty easily.
See here for the XPM image format:
http://www.fileformat.info/format/xpm/
An example of its use in FLTK:
http://seriss.com/people/erco/fltk/#DraggableBoxes
In MurgaLua I've noticed that the comments, including /* XPM */, must be removed from xpm data.

The 2-color thing would probably be better served with Fl_Bitmap, but sorry I just haven't figured out what format the data must be.

I'm pretty sure there are other ways of creating and manipulating embedded image data in FLTK, but that's all I know.

This post was last modified: 01-13-2009 12:04 AM by mikshaw.

01-13-2009 12:01 AM
Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #5
RE: Convert bitmap image to ascii

Thanks for the link to the format.
I was able to at least parse some colors from a screenshot and create
a little random line pattern generator and write a file out. Woohoo!

Can't remember the last time I 'wrote' an image to disk by code.
1993?

Anyhow here's my first xpm code before I go much it up.

Code:
cCommentsStart="/".."*"
cCommentsEnd="*".."/"
Q='"'
SPC=" "
XPMEndOfFile="};"
-- These values is temporary from Aquarius ScreenShot
XPMimageName="XPMFile.xpm"
XPMImageWidth,XPMImageHeight,XPMNumberOfImageColors,XPMCharsPerPixel = 352,232,16,1

XPMLines={}
XPMCodesHexOffset = 4 ;-- thats where the xpm hex color strings are in the XPMColorCodes table

-- XPMColorCodes HEX and color names sourced from an Mattel Aquarius 16 color Screenshot
XPMColorCodes={
{"A","Black","0","A c #101010101010"},
{"B","Red","1","B c #F0F010101010"},
{"C","Green","2","C c #1010F0F01010"},
{"D","Yellow","3","D c #F0F0E8E81010"},
{"E","Blue","4", "E c #20202020D8D8"},
{"F","Violet","5", "F c #F0F01010F0F0"},
{"G","Light Blue-Green","6", "G c #3030C0C0C0C0"},
{"H","White","7", "H c #F0F0F0F0F0F0"},
{"I","Light Gray","8", "I c #C0C0C0C0C0C0"},
{"J","Blue Green","9", "J c #2828A8A8A8A8"},
{"K","Magenta","10", "K c #C0C02020C0C0"},
{"L","Dark Blue","11", "L c #404010108888"},
{"M","Light Yellow","12", "M c #F0F0F0F07070"},
{"N","Light Green","13", "N c #2020C8C84040"},
{"O","Orange","14", "O c #A8A820202020"},
{"P","Dark Grey","15", "P c #303030303030"}
}


--
function init_XPMHeaderLines()
local XPMHexColorsHeader=""
XPMLines[1]= cCommentsStart.." XPM ".. cCommentsEnd.."\n";
XPMLines[2]="static char *"..XPMimageName.."[] = {\n";
XPMLines[3]=cCommentsStart.." width height ncolors chars_per_pixel ".. cCommentsEnd.."\n";
XPMLines[4]=Q..XPMImageWidth..SPC..XPMImageHeight..SPC..#XPMColorCodes..SPC..XPMCharsPerPixel..Q..",\n";
XPMLines[5]=cCommentsStart..SPC.."colors"..SPC..cCommentsEnd.."\n";

for i =1,#XPMColorCodes,1 do
XPMHexColorsHeader=XPMHexColorsHeader..Q..XPMColorCodes[i][XPMCodesHexOffset]..Q..",\n"
end
XPMLines[6]=XPMHexColorsHeader
XPMLines[7]= cCommentsStart..SPC.."pixels" ..SPC .. cCommentsEnd.. "\n" ;
-- OK now you are ready to write hundreds of XPMStrings that look like this
--  "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP"
end



function init_RandomXPM(w,h)
init_XPMHeaderLines()
local s=""
local sb=""
for i = 1,w,1 do
s=s..string.char(math.random(65,64+#XPMColorCodes))
end
for i =1,h,1 do
sb=sb..Q..s..Q..",\n"
end
XPMLines[#XPMLines+1]=string.sub(sb,1,-3)..XPMEndOfFile
end

function save_XPM(name)
local n = 0
local shortname=""
for i=string.len(name),1,-1 do
    if string.sub(name,i,i) == "/" then
    if string.sub(name,-4,-4) == "." then
    shortname = string.sub(name,i+1,-5)
    else
    shortname = string.sub(name,i+1,-1)
    end
    end
    if shortname~="" then break end

end
XPMimageName=shortname
init_RandomXPM(XPMImageWidth,XPMImageHeight)
local XPMDataOut=""
for i = 1,#XPMLines,1 do
        XPMDataOut= XPMDataOut..XPMLines[i]
    end

    f=io.open(name,"w")
    f:write(XPMDataOut)
    io.close(f)
end

This post was last modified: 01-13-2009 09:37 AM by iGame3D.

01-13-2009 09:31 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #6
RE: Convert bitmap image to ascii

iGame3D Wrote:
Hey thanks.
Couldn't do ImageMagick as I need a new OS so I purchased Graphic Converter for $35 and it did the magick I needed to do.

So I got this 1983 Custom Ascii Character set batch converted to
256 individual 3D objects, dropped into a game level and blinking
different colors and shades.
Yay! 11,000 + polys of wonder.
Flash Movie of that here!

I don't get that. Do you want to say that you can't run the binary release, because you have an older OSX release? Then you can still install it via macports (macports) or you can run linux in a virtual machine.

With imagemagick it definitely works:

Code:
for image in $(ls *.png); do convert -resize 8x8 -extent 8x8 -monochrome -compress none $image ${image%.png}.pbm ; done

This should also work on OSX. The only problem is that the font uses shadows and I'm not 100% sure that you can scale it down to 8x8 that easy. A little bit of tuning is still necessary and maybe it may be necessary to optimize a few chars by hand.

Quote:
So now, FLTK has some kind of embedded graphic format yes?
Where does the strange data for those images come from?
I've seen it in some scripts and it just confuses me.

So last year I was working on a little graphics creator for the old computer
in murgaLua and had planned to do more with it, but things happened.
Using pngs I was not able to deal with colors and the mouse is
drawing in the window even when you are choosing characters.


Of course this should also work with murgaLua. I can get it working with gifs and xpms, but not with pngs. When I try the data() method on the fltk image buffer I get a string of 1024 nil. While I did get a 1024 character string (16x16=256*4=1024 for rgba), there was no data in there. Maybe there is a bug somewhere or data() doesn't currently support RGB buffers.

You can test it with gifs for examle:
convert a png to gif like

Code:
convert aquarius_chr_006.png aquarius_chr_006.gif


The start murgaLua

Code:
> fltk.fl_register_images()
> my_image=Fl_Shared_Image.get(./"aquarius_chr_006.gif")
> my_image_data=my_image:data()
> table.foreach(my_image_data,print)
1       16 16 -2 1
2        
3                      
4                 !!    
5                 !!    
6                 !!    
7                   !!  
8                   !!  
9       !!!!!!!!!!!!!!!!
10      !!!!!!!!!!!!!!!!
11      !!!!!!!!!!!!!!!!
12      !!!!!!!!!!!!!!!!
13                  !!  
14                  !!  
15                !!    
16                !!    
17                !!    
18                      
d       1
h       16
w       16
ld      0


VoilĂ  tout!

Juergen

01-13-2009 11:03 AM
Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #7
RE: Convert bitmap image to ascii

No go on the ImageMagick install.
After endless time spent trying its a dead end.
I followed directions here

After frustration of using that install attempt I read the posts, nobody had success.
Finally a post from three days ago says install Xcode 3.1.2 which is OS X10.5 only.

I've got Graphic Converter, it does the job.
That final bit of code you posted is great.
Access to the data so fast!
Doesn't do much on black and white PBM but its great on the XPM.
Thanks.

01-14-2009 04:08 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jyf1987
Member
***


Posts: 58
Group: Registered
Joined: Jun 2008
Status: Offline
Reputation: 0
Post: #8
RE: Convert bitmap image to ascii

i think the lua-gd lib will be more helpful than imageMagick


Cheers
jyf
01-16-2009 11:47 PM
Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #9
RE: Convert bitmap image to ascii

Well here's the progress. I was able to convert the binary bits of an 1982 bitmap custom font into 3D objects with no effort, once the code was done of course.
Looks like this:
http://aquarius.residenteasel.com/aquari...amovie.swf

Here are some downloads.
MAC OS X version:
http://aquarius.residenteasel.com/aquari...quaMac.zip

Windows Version:
http://aquarius.residenteasel.com/aquari...quaWin.zip

You'll need to move your mouse down a bit to orient yourself to the 'floor'
of Aquarius Characters.

Keyboard works like a video game:
W = forward
S = back
A = slide left
D = slide right
R = rise
F = fall

Command F on the Mac will toggle fullscreen.
Maximize the window on Windows witht he usual control.

Command or Control L will exit into the editor, the mouse may be locked
to the camera, a second press of those keys should unlock it.

The editor is an adventure in undocumented discovery.
A ton of lua scripts and fluid files in there for exploration
if you are into reading code and stuff.

I've also been able to do some screenshot conversion that translates back into ye olde BASIC statements that POKE the characters back into the ancient computer.
That needs some work and will have to wait until I'm at a stand still in zombie game making to continue.

In all its been a cool experiment that murgaLua has made possible.
Eventually I'll pull together some kind of BASIC emulation in Lua,
so that you can play some really old school games in your console!
There is nothing like driving a pound sign down the dangerous curving
roads of asterisk alley.

Is there a wait to get input in console in Lua?
Like "you are in a dungeon there are exits north and west, what will you do?
And then the program waits for input like "N" or "W" before continuing.
I could and probably should do in a gui I suppose.

01-17-2009 11:29 AM
Visit this user's website Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #10
RE: Convert bitmap image to ascii

Quote:
Is there a wait to get input in console in Lua?
Like "you are in a dungeon there are exits north and west, what will you do?
And then the program waits for input like "N" or "W" before continuing.

my_variable=io.read()
if string.lower(my_variable)=="n" then print("north") end

This post was last modified: 01-17-2009 02:23 PM by mikshaw.

01-17-2009 02:22 PM
Find all posts by this user Quote this message in a reply
Pages (2): « First [1] 2 Next > Last »
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: