Qbasicnews.com

Full Version: graphics>text.....
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
any way to convert....? Like nathan's star wars thingy?
http://www.glassgiant.com/misc_ascii.php

Jason Earl also wrote a PHP script to do something similar...plus there are also loads of programs that generate ASCII art from images...
I posted code a while ago. It is in C.

I'm a lazy person, so it uses Allegro too Big Grin

Code:
#include <stdio.h>
#include <allegro.h>
#include <string.h>

// This uses a conversion for bitmap only images.
// the conversion is based on Rob Harley's (robert@vlsi.cs.caltech.edu)
// code mapping.

char mapping[]={
' ',',','.','_','-','i','v','g','-','c','i','s','=','e','z','m',

'\'','!','/','2','!',']','/','d','/','(','/','K','Y','4','Z','W',

'`','\\','|','L','\\','\\',')','G','!','t','[','b','+','N','D','W',

'~','T','7','X','V','Y','Z','8','f','5','P','K','*','M','A','@'} ;

// ordered by six-bit numbers in 2x3 cells.

int main(int argc, char *argv[])
{
    BITMAP *bp;
    FILE *pf;
    PALETTE dummy;
    int x,y,xx,yy;
    int i;
    char c;
    char ct;
    char invert=0;

    allegro_init(); set_color_depth(8);

    puts("2 colour bitmap to ASCII converter by Na Than");
    puts("Based on Rob Harley's mapping for 2x3 bitmap cells.");
    puts("Contact me at na_th_an@hotmail.com");
    puts(" ");
    if (argc<3) {puts("ERROR 1 :: Arguments required.");
                     puts("Usage: ASC_B&W INPUT.{BMP|PCX|LBM|TGA} OUTPUT.EXT [invert]");
                     return 1;}

    if (!strcmp(argv[3],"invert"))
        invert=1;

    // Convert

    if((bp = load_bitmap(argv[1],dummy))==NULL)
    {
        puts("ERROR 2 :: unable to open input file."); return 2;
    }

    if((pf = fopen(argv[2],"wb"))==NULL)
    {
        puts("ERROR 3 :: unable to open output file.");return 3;
    }

    puts("Now converting. If you see a wrong picture, maybe the BITMAP is not");
    puts("maped to have 0 for black, 1 for white.");
    if (invert) puts("Doing it inverting colours");

    for(y=0;y<bp->h;y+=3)
    {
        for(x=0;x<bp->w;x+=2)
        {
            // build binary
            c=0;ct=0;
            for (yy=2;yy>=0;yy--)
                for (xx=1;xx>=0;xx--)
                {
                    if (getpixel(bp,x+xx,y+yy) == 0)
                        c += (1<<ct);
                    ct++;
                }
            printf("Done :: %i%\r",1+ (100 * (x+y*bp->w))/(bp->h*bp->w));
            // output character
            fputc(mapping[c],pf);
        }
        fputc(13,pf);fputc(10,pf);
    }

    fclose(pf);
    printf("\n");
    puts("Done :)");

    destroy_bitmap(bp);
    allegro_exit();
}

If you want a compiled version, tell me do. I'll be bothered to upload it.
Ah... so it looks like there isn't any pattern matching, just density. Now, the first person who makes a color matcher + ascii matcher (extra points for pattern matching......) AND makes a Star Wars demo that's several minutes long wins... my appreciation!!!!! Smile
In fact there is a pattern matcher. The ASCII are selected so their shape match the dot patterns (this works with 1 bit files).

For example,

Code:
.X
X.
.X

is translated to ( .
*scratches head*

Oh. Well I didn't really understand your example... or your code. Pointers make things obscure to me...... especially things like "(1<<ct)"..........
Just DL Nate's Jedi2 and Joe's FMV. Those we're koolness!!!!
Quote:*scratches head*

Oh. Well I didn't really understand your example... or your code. Pointers make things obscure to me...... especially things like "(1<<ct)"..........

The program reads blocks of 2x3 pixels that can be ON or OFF (white or black, 1 bit GFX). Depending on the shape in the 2x3 pixels it selects a letter.

Code:
..
XX
..

would translate to "-", for example.

(1<<ct) is just like 2^ct, but faster.