aalib2.bac

'-----------------------------------------------------------------------------------------------------------------------

CONST file$ = "baconeyes3.png"                             : ' File to convert to ASCII

PROTO stbi_image_free aa_recommendhi aa_putpixel aa_render aa_flush aa_close

'-----------------------------------------------------------------------------------------------------------------------

PRAGMA INCLUDE canvas/stb-master/stb_image.h               : ' Include the stb_image header file
PRAGMA OPTIONS -DSTB_IMAGE_IMPLEMENTATION                  : ' Enable graphical functions

DECLARE Wd, Ht, n TYPE int
DECLARE data TYPE unsigned char*

data = stbi_load(file$, &Wd, &Ht, &n, 1)                   : ' Load the actual image in greyscale

'-----------------------------------------------------------------------------------------------------------------------

PRAGMA INCLUDE <aalib.h>                                   : ' Include the Ascii Art library header file
PRAGMA LDFLAGS aa                                          : ' Link with libaa

DECLARE context TYPE aa_context*                           : ' This is the AALib memory pointer

aa_recommendhi(&aa_displayrecommended, "stdout")           : ' Use 'stdout' to display our ASCII art

aa_defparams.font = &aa_fontcourier                        : ' Font we're using for our image 
aa_defparams.supported = AA_NORMAL_MASK                    : ' Supported rendering types AA_NORMAL_MASK,AA_DIM_MASK,AA_BOLD_MASK,AA_BOLDFONT_MASK,AA_REVERSE_MASK
aa_defparams.width = Wd/2                                  : ' Width and height of resulting ASCII Art picture.
aa_defparams.height = Ht/2                                 : '         -> The aalib output sizes are 1/2 image input (2x2 pixels -> 1 char)

context = aa_autoinit(&aa_defparams)                       : ' Initialize Ascii Art library

FOR y = 0 TO Ht-1
    FOR x = 0 TO Wd-1
        aa_putpixel(context, x, y, PEEK(data+y*Wd+x))      : ' Put the pixels from STB loaded image into AA memory
    NEXT
NEXT

aa_defrenderparams.bright = 0                              : ' Add BRIGHTNESS to the resulting image (int 0=normal to 255=white)
aa_defrenderparams.contrast = 0                            : ' Add CONTRAST to the resulting image (int 0=normal to 127=white)
aa_defrenderparams.gamma = 0.8                             : ' Add GAMMA to the resulting image (float 0 to 1)
aa_defrenderparams.inversion = FALSE                       : ' Should the resulting image be inverted
aa_defrenderparams.dither = AA_FLOYD_S                     : ' Add DITHERING to the resulting image (AA_NONE, AA_ERRORDISTRIB, AA_FLOYD_S)
aa_defrenderparams.randomval = 0                           : ' Range for random value to create dithering effect (int)

aa_render(context, &aa_defrenderparams, 0, 0, \
        aa_scrwidth(context), aa_scrheight(context))       : ' Now let AAlib render the picture
              
aa_flush(context)                                          : ' Flush the result to stdout

aa_close(context)                                          : ' Free memory from AAlib

'-----------------------------------------------------------------------------------------------------------------------

stbi_image_free(data)                                      : ' Free memory from STB

'-----------------------------------------------------------------------------------------------------------------------

Generated by GNU Enscript 1.6.5.90.