Changeset 1900 for libcaca/trunk/src
- Timestamp:
- Nov 6, 2007, 1:53:52 PM (15 years ago)
- Location:
- libcaca/trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/Makefile.am
r1766 r1900 30 30 cacaserver_LDADD = ../cucul/libcucul.la 31 31 32 img2irc_SOURCES = img2irc.c common-image.c common-image.h32 img2irc_SOURCES = img2irc.c mygetopt.c mygetopt.h common-image.c common-image.h 33 33 img2irc_LDADD = ../cucul/libcucul.la 34 34 img2irc_CFLAGS = $(IMLIB2_CFLAGS) -
libcaca/trunk/src/img2irc.c
r1462 r1900 2 2 * pic2irc image to IRC converter 3 3 * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> 4 * 2007 Jean-Yves Lamoureux <jylam@lnxscene.org> 4 5 * All Rights Reserved 5 6 * … … 22 23 #endif 23 24 25 #if !defined HAVE_GETOPT_LONG 26 # include "mygetopt.h" 27 #elif defined HAVE_GETOPT_H 28 # include <getopt.h> 29 #endif 30 #if defined HAVE_GETOPT_LONG 31 # define mygetopt getopt_long 32 # define myoptind optind 33 # define myoptarg optarg 34 # define myoption option 35 #endif 36 24 37 #include "cucul.h" 25 38 #include "common-image.h" … … 27 40 static void usage(int argc, char **argv) 28 41 { 29 fprintf(stderr, "Usage: %s <image>\n", argv[0]); 30 fprintf(stderr, " %s <image> <columns>\n", argv[0]); 31 fprintf(stderr, " %s [-h|--help]\n", argv[0]); 42 fprintf(stderr, "Usage: %s [OPTIONS]... <IMAGE>\n", argv[0]); 43 fprintf(stderr, "Convert IMAGE to any text based available format.\n"); 44 fprintf(stderr, "Example : %s -w 80 -f ansi ./caca.png\n\n", argv[0]); 45 fprintf(stderr, "Options:\n"); 46 fprintf(stderr, " -h, --help\tThis help\n"); 47 fprintf(stderr, " -W, --width=WIDTH\tWidth of resulting image\n"); 48 fprintf(stderr, " -H, --HEIGHT=HEIGHT\tHeight of resulting image\n"); 49 fprintf(stderr, " -f, --format=FORMAT\tFormat of the resulting image :\n"); 50 fprintf(stderr, "\t\t\tansi : coulored ANSI\n"); 51 fprintf(stderr, "\t\t\tcaca : internal libcaca format\n"); 52 fprintf(stderr, "\t\t\tutf8 : UTF8 with CR\n"); 53 fprintf(stderr, "\t\t\tutf8 : UTF8 with CRLF (MS Windows)\n"); 54 fprintf(stderr, "\t\t\thtml : HTML with CSS and DIV support\n"); 55 fprintf(stderr, "\t\t\thtml : Pure HTML3 with tables\n"); 56 fprintf(stderr, "\t\t\tirc : IRC with ctrl-k codes\n"); 57 fprintf(stderr, "\t\t\tps : Postscript\n"); 58 fprintf(stderr, "\t\t\tsvg : Scalable Vector Graphics\n"); 59 fprintf(stderr, "\t\t\ttga : Targa Image\n\n"); 32 60 } 33 61 … … 39 67 unsigned long int len; 40 68 struct image *i; 41 int cols, lines; 69 unsigned int cols = 0, lines = 0; 70 char *format = NULL; 42 71 43 if(argc < 2 || argc > 3) 72 73 if(argc < 2) 44 74 { 45 75 fprintf(stderr, "%s: wrong argument count\n", argv[0]); … … 48 78 } 49 79 50 if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))80 for(;;) 51 81 { 52 fprintf(stderr, "%s: convert images to IRC file data\n", argv[0]); 53 usage(argc, argv); 54 return 0; 82 int option_index = 0; 83 static struct myoption long_options[] = 84 { 85 { "width", 1, NULL, 'W' }, 86 { "height", 1, NULL, 'H' }, 87 { "format", 1, NULL, 'f' }, 88 { "help", 0, NULL, 'h' }, 89 }; 90 int c = mygetopt(argc, argv, "W:H:f:h", long_options, &option_index); 91 if(c == -1) 92 break; 93 94 switch(c) 95 { 96 case 'W': /* --width */ 97 cols = atoi(myoptarg); 98 break; 99 case 'H': /* --height */ 100 lines = atoi(myoptarg); 101 break; 102 case 'f': /* --help */ 103 format = myoptarg; 104 break; 105 case 'h': /* --help */ 106 usage(argc, argv); 107 return 0; 108 break; 109 default: 110 return 1; 111 break; 112 } 55 113 } 114 115 56 116 57 117 cv = cucul_create_canvas(0, 0); … … 62 122 } 63 123 64 i = load_image(argv[ 1]);124 i = load_image(argv[argc-1]); 65 125 if(!i) 66 126 { … … 71 131 72 132 /* Assume a 6×10 font */ 73 cols = argc == 3 ? atoi(argv[2]) : 0; 74 cols = cols ? cols : 60; 75 lines = cols * i->h * 6 / i->w / 10; 133 if(!cols && !lines) 134 { 135 cols = 60; 136 lines = cols * i->h * 6 / i->w / 10; 137 } 138 else if(cols && !lines) 139 { 140 lines = cols * i->h * 6 / i->w / 10; 141 } 142 else if(!cols && lines) 143 { 144 cols = lines * i->w * 10 / i->h / 6; 145 } 146 76 147 77 148 cucul_set_canvas_size(cv, cols, lines); … … 82 153 unload_image(i); 83 154 84 export = cucul_export_memory(cv, "irc", &len); 85 fwrite(export, len, 1, stdout); 86 free(export); 155 export = cucul_export_memory(cv, format?format:"ansi", &len); 156 if(!export) 157 { 158 fprintf(stderr, "Can't export to format '%s'\n", format); 159 } 160 else 161 { 162 fwrite(export, len, 1, stdout); 163 free(export); 164 } 87 165 88 166 cucul_free_canvas(cv);
Note: See TracChangeset
for help on using the changeset viewer.