Turning Pictures into .bin Files
In lab #3, we gave you a .bin file to load into the memory. You might want to create your own picture(s) from .gif, .jpeg, or animated .gif formats. This page tells you how to do such a conversion.
To perform these conversions, we use the intermediate "portable file format" for images. There are three types of portable file formats, to support color, grayscale, and black/white pictures. The one you chose to use will depend on the needs of your project. Here they are:Reducing the image to your screen size and available memory Mapping the colors in your original image to the colors supported by your VGA interface.
ppm -- Portable pixmap file format
pgm -- Portable graymap file format
pbm -- Portable bitmap file format
(pnm -- Portable any file format) <--- Utilities support all
types
These file formats are convenient to use since there are a bunch of Unix utilities for image manipulation and conversion. The portable file type "pnm" is not a file type at all but used to label utilities that can run on any of the three file types: ppm, pgm, and pbm. Here is an overview of the utilities for each type. I don't know what all of these do, but you can find out by running "man utility" from a Unix command line.
ppm
ppm3d ppmmake
ppmrelief ppmtomitsu ppmtosixel
ppmbrighten ppmmerge
ppmshift ppmtopcx
ppmtotga
ppmchange ppmmix
ppmspread ppmtopgm
ppmtouil
ppmdim ppmnorm
ppmtoacad ppmtopi1
ppmtoxpm
ppmdist ppmntsc
ppmtobmp ppmtopict
ppmtoyuv
ppmdither ppmpat
ppmtogif ppmtopj
ppmtoyuvsplit
ppmflash ppmquant
ppmtoicr ppmtopjxl
ppmforge ppmquantall
ppmtoilbm ppmtopuzz
ppmhist ppmqvga
ppmtomap ppmtorgb3
pgm
pgmbentley pgmenhance pgmmerge pgmoil
pgmtofits pgmtopbm
pgmcrater pgmhist pgmnoise
pgmramp pgmtofs pgmtoppm
pgmedge pgmkernel pgmnorm
pgmtexture pgmtolispm
pbm
pbmclean pbmpscale pbmtoascii pbmtoepson pbmtolj
pbmtopgm pbmtox10bm
pbmlife pbmreduce pbmtoatk
pbmtog3 pbmtoln03 pbmtopi3 pbmtoxbm
pbmmake pbmtext pbmtobbnbg
pbmtogem pbmtolps pbmtopk pbmtoybm
pbmmask pbmto10x pbmtocmuwm pbmtogo
pbmtomacp pbmtoplot pbmtozinc
pbmmerge pbmto4425 pbmtoepsi pbmtoicon
pbmtomgr pbmtoptx pbmupc
pnm
pnmalias pnmcrop pnmflip
pnmmargin pnmpaste pnmtile pnmtosgi
pnmarith pnmcut pnmgamma
pnmmerge pnmrotate pnmtoddif pnmtosir
pnmcat pnmdepth pnmhistmap
pnmnlfilt pnmscale pnmtofits pnmtotiff
pnmcomp pnmenlarge pnmindex pnmnoraw
pnmshear pnmtops pnmtoxwd
pnmconvol pnmfile pnminvert pnmpad
pnmsmooth pnmtorast
NOTE: The above programs are from hobbes.cs. On orcas, you might have a slightly different set of utilities. To see what you programs are available on your local machine, you can use a handy feature of the "tcsh" shell. From an orcas prompt, run "tcsh". Then type "ppm^D" (that is ppm followed by a control-d). The shell will perform file completion based on your path. This tells you all the executables in your path that begin with the letters "ppm". You can do this for "pgm", "pbm", and "pnm" as well.
In addition, you will need "giftoppm" to convert your image into a portable pixmap. We have written a C-program for "ppmtobin" which converts an ascii ppm file to a binary file supporting a VGA interface with 6 bit color (2 bits per R, G, B). We have also written a script which extracts images from an animated gif file and tiles them into a single picture story board, like the scared mouse you animate in lab #3. This script is called "agiftoppm". Of course, you will want to use "xv" to view these images.
Note: you will need to get some files and scripts from: /cse/courses/cse477/1999sp/imageconv/ on orcas.
Now to convert it to 128x128 you type:
pnmscale -xsize 128 -ysize 128 bob.ppm > bob2.ppm
The resulting file is still represented as 24-bit color but is
guaranteed to use only the 64 colors that our VGA interface supports.
ppmquant is nice since it tries to be intelligent about color selection.
Do a "man ppmquant" to find out more.
It does this with a simple switch statement in the C-code. For
more information you can look at "ppmtobin.cc". This program
takes as input an ASCII version of a ppm file (also called a "no raw" format).
Most of the ppm utilities output a raw format since the file sizes are
smaller. The utility "pnmnoraw" converts a raw ppm file to an ascii
file. Hence, to convert "bob3.ppm" to a bin file, you would run:
pnmnoraw bob3.ppm > bob4.ppm
ppmtobin bob4.ppm > bob.bin
The resulting .bin file can be loaded into your xess board's RAM using "xsram".
which performs steps #1-#3 (note that I've swapped steps #1 and #2 here,
but that doesn't matter). Based on this piped command, we have
written a C-script "giftobin" that takes two arguments (the scaled image
sizes) and outputs a bin file. Hence, you could also just write:
giftobin 64 64 bob.gif > bob.bin
We have put three animations in /cse/courses/cse477/1999sp/imageconv/
for fun. They are scaredmouse.gif, dove.gif, and secatwalkn.gif.
The first is from your lab #3. Try running:
agiftobin scaredmouse.gif
and then
xv scaredmouse.ppm
to see the script in action.