LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to use AAlib with C or C++? (https://www.linuxquestions.org/questions/programming-9/how-to-use-aalib-with-c-or-c-4175466105/)

vectrum 06-15-2013 04:47 AM

How to use AAlib with C or C++?
 
How can I use the ascii art library aalib with c or c++ code.
There is no concrete example. INFO programe explains few lines of
code but I could not understand as this is not a complete example.

I want to write a c code that will open an image file and convert
it to an ascii image art. I think it is possible with aalib as it is
written specially for this purpose.

I have come to know what header file is required and what the linker flag (-laa)
but I need to know at least a simple complete example.

Thank you.

Guttorm 06-16-2013 04:46 AM

http://aa-project.sourceforge.net/

vectrum 06-17-2013 08:27 AM

Where is the example/sample programme?

Please don't post anything irresponsibly only for the shake of posting something.


It would be really helpful if you pointed
out the specific example as I couldn't find
the solution.

Guttorm 06-17-2013 11:10 AM

Sorry I can't understand what you can't find. That page has many examples, no? The stuff is really old, and I now see many links don't work. But, many do, and I think they're complete. And 2 clicks away, on the first link on each page, you end up here:

http://aa-project.sourceforge.net/aalib/aalib_toc.html

I can't remember exactly, but I think you asked for examples and documentation for aalib no? Now I see you have edited it, so I'm not really sure what I answered. :)

Also, another way is to search your distro for examples. Here's from my Ubuntu:

Quote:

apt-cache search aalib
libaa1 - ASCII art library
libaa1-dbg - ASCII art library, debugging symbols
libaa1-dev - ASCII art library, development kit
bb - ASCII-art demo based on AAlib
caca-utils - text mode graphics utilities
fim - a scriptable frame buffer and ascii art image viewer
libaa-bin - sample programs using aalib
libggi-target-monotext - General Graphics Interface plain text target
python-aalib - Python interface to AAlib, an ASCII art library
ttv - television viewer - console application

vectrum 06-17-2013 03:41 PM

Thank you for your reply and please let me clear the amibiguity at my end.

I edited just one word. I changed (-laalib) to (-laa) as
-laalib is the wrong flag and I mistakenly wrote -laalib.

I wanted to say in my first message(2nd line);

"INFO programe explains few lines of code but
I could not understand... ."


The 'info aalib' contains the same material as that of the link you have given here but my problem is that I can't understand how to begin.

I successfully compiled the following code which opens a
blank window and terminates it.

Quote:

#include <stdio.h>
#include <aalib.h>
aa_context *context;
int main()
{
context = aa_autoinit(&aa_defparams);
if(context == NULL) {
fprintf(stderr,"Cannot initialize AA-lib. Sorry\n");
exit(1);
}
aa_close(context);
}
and when I try to compile another aalib code
(in /usr/local/info/info.aalib-1) with
$ gcc -Wall -W -O -g3 -o aalibprog aalibprog.c -laa
Quote:

#include <aalib.h>
#include <stdlib.h>
int
main (int argc, char **argv)
{
int i;
aa_context *context; /* The information about currently
initialized device. */
aa_palette palette; /* Emulatted palette (optional) */

char *framebuffer;

/* Parse command line options and output the help text. */
if (!aa_parseoptions (NULL, NULL, &argc, argv) || argc != 1)
{
printf ("%s", aa_help);
exit (1);
}

/* Initialize output driver. */
context = aa_autoinit (&aa_defparams);
if (context == NULL)
{
printf ("Failed to initialize aalib\n");
exit (1);
}

/* Pointer to the emulated videoram. */
framebuffer = aa_image (context);


/* Create palette if needed: */
for (i = 0; i < 256; i++)
aa_setpalette (palette, i /* R value 0..255 */ ,
/* G value 0..255 */ ,
/* B value 0..255 */ );

/* Draw something using: */
aa_putpixel (context /* X coord */ , /* Y coord */ , /* Color */ );

/* Render whole screen: */

aa_renderpalette (context, palette, aa_defrenderparams,
/* Top left conner of rendered area: */ 0, 0,
/* Bottom right */ aa_scrwidth (context), aa_scrheight (context));

/* If you don't use palette use following function:
aa_render (context, aa_defrenderparams,
0, 0, aa_scrwidth (context), aa_scrheight (context));
*/

/* And make it visible: */
aa_flush (context);

/* And uninitialize the AA_lib (this probably makes the picture invisible
again) */
aa_close (context);

return 1;
}
getting the following error:

but getting the following error; aalibprog.c: In function 'main':
aalibprog.c:29:20: warning: pointer targets in assignment differ in signedness [-Wpointer-sign]
aalibprog.c:36:58: error: macro "aa_setpalette" requires 5 arguments, but only 4 given
aalibprog.c:34:10: error: 'aa_setpalette' undeclared (first use in this function)
aalibprog.c:34:10: note: each undeclared identifier is reported only once for each function it appears in
aalibprog.c:39:73: error: macro "aa_putpixel" requires 4 arguments, but only 3 given
aalibprog.c:39:8: warning: statement with no effect [-Wunused-value]
aalibprog.c:45:32: error: incompatible type for argument 3 of 'aa_renderpalette'
In file included from aalibprog.c:1:0:
/usr/local/include/aalib.h:647:6: note: expected 'const struct aa_renderparams *' but argument is of type 'struct aa_renderparams'
aalibprog.c:11:14: warning: variable 'framebuffer' set but not used [-Wunused-but-set-variable]

so I've asked for the help.

Thanks again.


All times are GMT -5. The time now is 07:32 PM.