Converting image file to monochrome HEX or MIF?

FPGA projects on this site, or abroad

Converting image file to monochrome HEX or MIF?

Postby russosv » Tue Dec 26, 2006 5:52 am

Hi All,

I am working through the Graphic LCD example, and I am able to use the Quartus Megafunction Generator to create a pre-programmed block RAM programmed with a MIF/HEX file which I can hand-edit.

This is great if I want to type in the data bit-by-bit, but HOW on earth do you convert an image FILE (i.e. bmp file) to a monochrome MIF/HEX file?

Thanks in advance for any help!!!
russosv
 
Posts: 2
Joined: Wed Dec 20, 2006 5:57 pm

Postby fpga4fun » Tue Dec 26, 2006 3:28 pm

I wrote a routine a long time ago... I doubt I can find it. You probably have to write your own. Write a routine that reads the bmp file in binary mode, extracts each pixel and outputs the mif/hex text file.
fpga4fun
Site Admin
 
Posts: 837
Joined: Thu Sep 18, 2003 6:47 am

Postby russosv » Wed Dec 27, 2006 2:35 am

Thanks...

Here's an update, in case this might help anyone else. I was able to successfully create a MIF file this way:

I saved a monochrome graphic file (i.e. converted it to 1-bit graphics) in RAW format in GIMP, then used the following command on it (using Cygwin):

Code: Select all
od -td1 -v -w8 VGAtest | nl -v0 | gawk "{print \"\t\",$1,\":\",$3$4$5$6$7$8$9$10\";\"}" > VGA_Mem.mif


Then I edited the resulting file (VGA_Mem.mif) with Notepad, and put the following at the top:

Code: Select all
WIDTH=8;
DEPTH=512;

ADDRESS_RADIX=DEC;
DATA_RADIX=BIN;

BEGIN CONTENT


At the end, I put:

Code: Select all
END;


Please post any other suggestions if you have them!

EDIT: I actually used Gnuwin32(CoreUtils and Gawk packages) for the above, not Cygwin. The difference is that Gnuwin runs natively on Windows, while Cygwin uses a UNIX emulation layer. I executed the above commands in a DOS prompt, not a UNIX shell, which is why the quotes are so odd-looking for GAWK.
Last edited by russosv on Thu Dec 28, 2006 9:31 pm, edited 2 times in total.
russosv
 
Posts: 2
Joined: Wed Dec 20, 2006 5:57 pm

Postby fpga4fun » Wed Dec 27, 2006 6:09 am

Looks very reasonable.
fpga4fun
Site Admin
 
Posts: 837
Joined: Thu Sep 18, 2003 6:47 am


Return to General projects