amiga_imgv

view src/main.c @ 7:4c36d0f44aa6

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