#include #include #include #include #include aa_context *context; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; int main(int argc, char** argv) { if (argc < 2) { fprintf(stderr, "usage: aa \n"); exit(1); } cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); FILE *infile; if ((infile = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "can't open img.jpg\n"); exit(2); } jpeg_stdio_src(&cinfo, infile); jpeg_read_header(&cinfo, TRUE); cinfo.scale_num = 1; cinfo.scale_denom = 8; jpeg_start_decompress(&cinfo); context = aa_init(&curses_d, &aa_defparams, NULL); if(context == NULL) { fprintf(stderr,"Cannot initialize AA-lib. Sorry\n"); exit(1); } aa_defparams.height = aa_defparams.minheight = cinfo.output_height; aa_defparams.width = aa_defparams.minwidth = cinfo.output_width; JSAMPARRAY raw = malloc(sizeof(unsigned char*) * cinfo.output_height); printf("%dx%d, %d components\n", cinfo.output_width, cinfo.output_height, cinfo.output_components); for (int i = 0; i < cinfo.output_height; ++i) { raw[i] = malloc(cinfo.output_components * cinfo.output_width); jpeg_read_scanlines(&cinfo, &raw[i], 1); } jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); unsigned char* buf = aa_image(context); for (int i = 0; i < aa_imgheight(context); ++i) { for (int j = 0; j < aa_imgwidth(context); ++j) { buf[i*aa_imgwidth(context)+j] = raw[i][j*cinfo.output_components]; } } //memcpy(buf, raw, aa_imgheight(context) * aa_imgwidth(context)); aa_fastrender(context, 0, 0, aa_scrwidth(context), aa_scrheight(context)); aa_flush(context); getchar(); aa_close(context); fclose(infile); }