amiga_imgv

annotate src/main.c @ 12:20c7238c60be

img2ham unfinished
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 20 Nov 2017 08:36:16 +0200
parents 663471a80c21
children
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include <string.h>
nuclear@0 4 #include <assert.h>
nuclear@0 5 #include "gfx.h"
nuclear@0 6 #include "image.h"
nuclear@0 7 #include "logger.h"
nuclear@0 8
nuclear@0 9
nuclear@0 10 static int proc_event(union gfx_event *ev);
nuclear@0 11
nuclear@0 12 int main(int argc, char **argv)
nuclear@0 13 {
nuclear@7 14 int i;
nuclear@7 15 unsigned int flags = 0;
nuclear@7 16 const char *fname = 0;
nuclear@0 17 struct ham_image *img;
nuclear@0 18
nuclear@7 19 for(i=1; i<argc; i++) {
nuclear@7 20 if(argv[i][0] == '-') {
nuclear@7 21 if(strcmp(argv[i], "-ilace") == 0) {
nuclear@7 22 flags |= GFX_ILACE;
nuclear@7 23 } else {
nuclear@7 24 fprintf(stderr, "invalid option: %s\n", argv[i]);
nuclear@7 25 return 1;
nuclear@7 26 }
nuclear@7 27 } else {
nuclear@7 28 if(fname) {
nuclear@7 29 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
nuclear@7 30 return 1;
nuclear@7 31 }
nuclear@7 32 fname = argv[i];
nuclear@0 33 }
nuclear@7 34 }
nuclear@7 35
nuclear@7 36 if(fname) {
nuclear@7 37 if(!(img = load_ilbm(fname))) {
nuclear@7 38 if(!(img = load_ham_image(fname))) {
nuclear@7 39 fprintf(stderr, "failed to load image: %s\n", fname);
nuclear@7 40 return 1;
nuclear@7 41 }
nuclear@7 42 }
nuclear@7 43 logmsg("loaded %s: %dx%d, %d bitplanes%s\n", fname, img->width, img->height,
nuclear@7 44 img->nbitplanes, img->ham ? " (HAM)" : "");
nuclear@0 45 } else {
nuclear@0 46 printf("generating test image ...\n");
nuclear@0 47 if(!(img = gen_ham_image(320, 256, 6))) {
nuclear@0 48 fprintf(stderr, "failed to generate image\n");
nuclear@0 49 return 1;
nuclear@0 50 }
nuclear@0 51 }
nuclear@0 52
nuclear@7 53 if(img->nbitplanes >= 6) img->ham = 1; /* XXX */
nuclear@7 54 if(img->ham) flags |= GFX_HAM;
nuclear@7 55
nuclear@7 56 if(gfx_init(img->nbitplanes, flags) == -1) {
nuclear@0 57 return 1;
nuclear@0 58 }
nuclear@7 59 gfx_set_framebuffer(0, img->width, img->height);
nuclear@0 60 gfx_wait_vblank();
nuclear@3 61 gfx_show_image(img);
nuclear@0 62
nuclear@0 63 for(;;) {
nuclear@0 64 union gfx_event ev;
nuclear@0 65 if(gfx_next_event(&ev, GFX_EVLOOP_BLOCK)) {
nuclear@0 66 if(proc_event(&ev) == -1) {
nuclear@0 67 break;
nuclear@0 68 }
nuclear@0 69 }
nuclear@0 70 }
nuclear@0 71
nuclear@0 72 gfx_shutdown();
nuclear@0 73 return 0;
nuclear@0 74 }
nuclear@0 75
nuclear@0 76 static int proc_event(union gfx_event *ev)
nuclear@0 77 {
nuclear@0 78 switch(ev->type) {
nuclear@0 79 case GFX_EV_QUIT:
nuclear@0 80 return -1;
nuclear@0 81
nuclear@0 82 case GFX_EV_KEY:
nuclear@0 83 switch(ev->key.key) {
nuclear@0 84 case 27:
nuclear@0 85 return -1;
nuclear@0 86 default:
nuclear@0 87 break;
nuclear@0 88 }
nuclear@0 89 break;
nuclear@0 90
nuclear@0 91 default:
nuclear@0 92 break;
nuclear@0 93 }
nuclear@0 94 return 0;
nuclear@0 95 }