Changeset 4305 for toilet/trunk/tools
- Timestamp:
- Jan 27, 2010, 1:47:58 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/tools/caca2tlf.c
r4135 r4305 28 28 29 29 enum mode { GRAY, HALFBLOCKS, QUARTERBLOCKS } mode; 30 enum charset { ASCII, UTF8 } charset;30 enum charset { SPACES, ASCII, UTF8 } charset; 31 31 32 32 static void list_fonts(void); … … 47 47 { 48 48 fprintf(stderr, 49 "Usage: %s [--half|--quarter] [-- ascii|--utf8] <font>\n",49 "Usage: %s [--half|--quarter] [--spaces|--ascii|--utf8] <font>\n", 50 50 argv[0]); 51 51 list_fonts(); … … 71 71 } 72 72 73 if((!strcmp(argv[1], "--ascii") || !strcmp(argv[1], "-a")) && argc > 2) 73 if((!strcmp(argv[1], "--spaces") || !strcmp(argv[1], "-s")) && argc > 2) 74 { 75 flag2 = "--spaces "; 76 charset = SPACES; 77 argv++; argc--; 78 } 79 else if((!strcmp(argv[1], "--ascii") || !strcmp(argv[1], "-a")) && argc > 2) 74 80 { 75 81 flag2 = "--ascii "; … … 191 197 static char const * chars[][16] = 192 198 { 199 { "_", "_", "_", "_", " " }, 200 { " ", "_", "_", "_" }, 201 { " ", "_", "_", "_", "_", "_", "_", "_", 202 "_", "_", "_", "_", "_", "_", "_", "_" }, 193 203 { "#", "$", ":", ".", " " }, 194 204 { " ", "\"", "m", "#" }, … … 201 211 }; 202 212 213 static uint8_t fgs[][4] = 214 { 215 { CACA_DEFAULT, CACA_DARKGRAY, CACA_LIGHTGRAY, CACA_WHITE }, 216 { CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT }, 217 }; 218 219 static uint8_t bgs[][4] = 220 { 221 { CACA_DEFAULT, CACA_DARKGRAY, CACA_LIGHTGRAY, CACA_WHITE }, 222 { CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT, CACA_DEFAULT }, 223 }; 224 203 225 char const **str; 204 226 void *buf; 205 227 size_t len; 206 228 unsigned int x, y, myw, mygw; 207 int off = 0;229 int coff = 0, aoff = 0; 208 230 int full = caca_utf32_is_fullwidth(ch); 209 231 … … 220 242 switch(charset) 221 243 { 244 case SPACES: 245 coff = 0; aoff = 0; 246 break; 222 247 case ASCII: 223 off = 0;248 coff = 3; aoff = 1; 224 249 break; 225 250 case UTF8: 226 off = 3;251 coff = 6; aoff = 1; 227 252 break; 228 253 } … … 231 256 { 232 257 case GRAY: 233 str = chars[ off];258 str = chars[coff]; 234 259 for(y = 0; y < h; y++) 235 260 for(x = 0; x < myw; x++) … … 237 262 uint8_t c = image[4 * (x + y * iw) + 2]; 238 263 239 if(c >= 0xa0) 264 if(c >= 0xc0) 265 { 266 caca_set_color_ansi(out, fgs[aoff][3], bgs[aoff][3]); 240 267 caca_put_str(out, x, y, str[0]); 268 } 269 else if(c >= 0x90) 270 { 271 caca_set_color_ansi(out, fgs[aoff][2], bgs[aoff][2]); 272 caca_put_str(out, x, y, str[0]); 273 } 241 274 else if(c >= 0x80) 275 { 276 caca_set_color_ansi(out, fgs[aoff][2], bgs[aoff][2]); 242 277 caca_put_str(out, x, y, str[1]); 278 } 243 279 else if(c >= 0x40) 280 { 281 caca_set_color_ansi(out, fgs[aoff][1], bgs[aoff][1]); 244 282 caca_put_str(out, x, y, str[2]); 283 } 245 284 else if(c >= 0x20) 285 { 286 caca_set_color_ansi(out, fgs[aoff][1], bgs[aoff][1]); 246 287 caca_put_str(out, x, y, str[3]); 288 } 247 289 else 290 { 291 caca_set_color_ansi(out, fgs[aoff][0], bgs[aoff][0]); 248 292 caca_put_str(out, x, y, str[4]); 293 } 249 294 } 250 295 break; 251 296 case HALFBLOCKS: 252 str = chars[ off + 1];297 str = chars[coff + 1]; 253 298 for(y = 0; y < gh; y++) 254 299 for(x = 0; x < mygw; x++) … … 261 306 break; 262 307 case QUARTERBLOCKS: 263 str = chars[ off + 2];308 str = chars[coff + 2]; 264 309 for(y = 0; y < gh; y++) 265 310 for(x = 0; x < mygw; x++) … … 276 321 } 277 322 323 caca_set_color_ansi(out, CACA_DEFAULT, CACA_DEFAULT); 324 278 325 if(ch == ' ' || ch == 0xa0) 279 326 {
Note: See TracChangeset
for help on using the changeset viewer.