From d4b03edc8e6f02bcf9ff71613cec10514b67d007 Mon Sep 17 00:00:00 2001 From: James Shiffer Date: Sun, 23 Apr 2023 01:40:09 -0700 Subject: [PATCH] initial commit --- Makefile | 8 ++++++++ main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Makefile create mode 100644 main.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ce44495 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +CFLAGS = -std=gnu99 `aalib-config --cflags` +LDFLAGS = `aalib-config --libs` -ljpeg +OUT = aa + +all: + gcc -g -o $(OUT) $(CFLAGS) *.c $(LDFLAGS) +clean: + rm -f $(OUT) diff --git a/main.c b/main.c new file mode 100644 index 0000000..3ff74c2 --- /dev/null +++ b/main.c @@ -0,0 +1,58 @@ +#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); +}