Blob
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>4 #include <memdraw.h>5 #include <ctype.h>6 #include <bio.h>7 #include <flate.h>8 #include "imagefile.h"10 void11 usage(void)12 {13 fprint(2, "usage: topng [-c 'comment'] [-g 'gamma'] [file]\n");14 exits("usage");15 }17 void18 main(int argc, char *argv[])19 {20 Biobuf bout;21 Memimage *i;22 int fd;23 char *err, *filename;24 ImageInfo II;26 ARGBEGIN{27 case 'c':28 II.comment = ARGF();29 if(II.comment == nil)30 usage();31 II.fields_set |= II_COMMENT;32 break;33 case 'g':34 II.gamma = atof(ARGF());35 if(II.gamma == 0.)36 usage();37 II.fields_set |= II_GAMMA;38 break;39 case 't':40 break;41 default:42 usage();43 }ARGEND45 if(Binit(&bout, 1, OWRITE) < 0)46 sysfatal("Binit failed: %r");47 memimageinit();49 if(argc == 0){50 fd = 0;51 filename = "<stdin>";52 }else{53 fd = open(argv[0], OREAD);54 if(fd < 0)55 sysfatal("can't open %s: %r", argv[0]);56 filename = argv[0];57 }59 i = readmemimage(fd);60 if(i == nil)61 sysfatal("can't readimage %s: %r", filename);62 close(fd);64 err = memwritepng(&bout, i, &II);65 freememimage(i);67 if(err != nil)68 fprint(2, "topng: %s\n", err);69 exits(err);70 }