eqemu

view libs/libimago/test/test.c @ 10:819c7ebb1bec

added libimago to avoid the external dependency
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 18 Jul 2014 05:07:40 +0300
parents
children
line source
1 #include <stdio.h>
2 #include <imago2.h>
4 int main(int argc, char **argv)
5 {
6 const char *infile = "foo.jpg";
7 const char *outfile = "bar.jpg";
8 int i, j, xsz = 512, ysz = 512;
9 struct img_pixmap img;
11 for(i=1; i<argc; i++) {
12 if(argv[i][0] == '-' && argv[i][2] == 0) {
13 switch(argv[i][1]) {
14 case 'i':
15 infile = argv[++i];
16 break;
18 case 'o':
19 outfile = argv[++i];
20 break;
22 default:
23 fprintf(stderr, "invalid option: %s\n", argv[i]);
24 return 1;
25 }
26 } else {
27 fprintf(stderr, "invalid argument: %s\n", argv[i]);
28 return 1;
29 }
30 }
32 img_init(&img);
34 if(img_load(&img, infile) == -1) {
35 unsigned char *pix;
37 fprintf(stderr, "failed to load image: %s, generating instead\n", infile);
39 if(img_set_pixels(&img, xsz, ysz, IMG_FMT_RGB24, 0) == -1) {
40 perror("wtf");
41 return 1;
42 }
44 pix = img.pixels;
45 for(i=0; i<ysz; i++) {
46 for(j=0; j<xsz; j++) {
47 int bw = ((i >> 5) & 1) == ((j >> 5) & 1);
49 *pix++ = bw ? 255 : 0;
50 *pix++ = 127;
51 *pix++ = bw ? 0 : 255;
52 }
53 }
54 }
56 if(img_save(&img, outfile) == -1) {
57 fprintf(stderr, "failed to save file %s\n", outfile);
58 return 1;
59 }
61 img_destroy(&img);
62 return 0;
63 }