ASCII art conversion tool

If you want to create ASCII art but don't have the time or skill to do it from scratch by hand, try this tool I whipped up in an hour. You'll need the Allegro library and a compatible compiler (preferably DJGPP or another GCC port) to build it; otherwise, grab a DOS binary at http://www.cs.rose-hulman.edu/~yerricde/ascii.zip .

<attachment name="ascii.c">
/*
ascii art conversion utility
Copyright 2001 Damian Yerrick
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
/*
ascii.c converts a bitmap (in .bmp or .pcx format) to ASCII art.
It treats the least significant bitplane as a monochrome image,
making 0 dark and 1 light. Each character sent to stdout represents
a 2x2 cell in the bitmap.
It uses the Allegro library to read the bitmap. Allegro is a
multimedia library that has been ported to POSIX+X11, DOS, Windows,
BeOS, and Mac OS. There are library extensions that allow Allegro
to handle other file formats such as PNG.
http://alleg.sourceforge.net/allegro/
Because of the simple design of the program, it is also extremely
easy to port to other imaging APIs.
Compilation on DOS:
gcc -Wall -O ascii.c -lalleg -o ascii.exe
Compilation on Linux:
gcc -Wall -O ascii.c `allegro-config --libs` -o ascii
*/
#include <allegro.h>
#include <stdio.h>
#include <stdlib.h>
/* the following line is not line noise but instead the
characters that represent 2x2 pixel tiles */
char tiles[16] = "MPV\"b)\\'d/(`a., ";
int main(int argc, char **argv)
{
BITMAP *bmp;
int y;
install_allegro(SYSTEM_NONE, &errno, atexit);
if(argc != 2)
{
allegro_message("usage: ascii foo.bmp\n");
return EXIT_FAILURE;
}
/* if you've installed Allegro library extensions for
other bitmap formats, register their functions here */
bmp = load_bitmap(argv[1], NULL);
if(bmp == NULL)
{
allegro_exit();
fprintf(stderr, "ascii Error: could not load bitmap `%s'\n", argv[1]);
return EXIT_FAILURE;
}
for(y = 0; y < bmp->h; y += 2)
{
int x;
for(x = 0; x < bmp->w; x += 2)
{
int c = 0;
if(getpixel(bmp, x, y ) & 1)
c |= 8;
if(getpixel(bmp, x+1, y ) & 1)
c |= 4;
if(getpixel(bmp, x, y+1) & 1)
c |= 2;
if(getpixel(bmp, x+1, y+1) & 1)
c |= 1;
putchar(tiles[c]);
}
putchar('\n');
}
destroy_bitmap(bmp);
return EXIT_SUCCESS;
}
/* Allegro uses this to translate main() into a WinMain() for some ports */
END_OF_MAIN();
</attachment>

To use it, make sure you have a monochrome .bmp or .pcx file and then:ascii foo.bmp > foo.txt