- Timestamp:
- Apr 27, 2006, 3:02:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/test/export.c
r858 r919 35 35 cucul_dither_t *dither; 36 36 cucul_buffer_t *buffer; 37 char *file, *format; 37 38 char const * const * exports, * const * p; 38 39 int x, y; … … 40 41 exports = cucul_get_export_list(); 41 42 42 if(argc != 2)43 if(argc < 2 || argc > 3) 43 44 { 44 45 fprintf(stderr, "%s: wrong argument count\n", argv[0]); 45 fprintf(stderr, "usage: %s <format>\n", argv[0]);46 fprintf(stderr, "usage: %s [file] <format>\n", argv[0]); 46 47 fprintf(stderr, "where <format> is one of:\n"); 47 48 for(p = exports; *p; p += 2) … … 50 51 } 51 52 53 if(argc == 2) 54 { 55 file = NULL; 56 format = argv[1]; 57 } 58 else 59 { 60 file = argv[1]; 61 format = argv[2]; 62 } 63 52 64 for(p = exports; *p; p += 2) 53 if(!strcasecmp( argv[1], *p))65 if(!strcasecmp(format, *p)) 54 66 break; 55 67 56 68 if(!*p) 57 69 { 58 fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);70 fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format); 59 71 fprintf(stderr, "please use one of:\n"); 60 72 for(p = exports; *p; p += 2) … … 63 75 } 64 76 65 cv = cucul_create_canvas(WIDTH, HEIGHT); 77 if(file) 78 { 79 cucul_buffer_t *tmp; 80 tmp = cucul_load_file(file); 81 if(!tmp) 82 { 83 fprintf(stderr, "%s: could not load `%s'\n", argv[0], file); 84 exit(-1); 85 } 86 cv = cucul_import_canvas(tmp, ""); 87 if(!tmp) 88 { 89 fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file); 90 exit(-1); 91 } 92 cucul_free_buffer(tmp); 93 } 94 else 95 { 96 cv = cucul_create_canvas(WIDTH, HEIGHT); 66 97 67 for(y = 0; y < 256; y++) 68 { 69 for(x = 0; x < 256; x++) 98 for(y = 0; y < 256; y++) 70 99 { 71 uint32_t r = x; 72 uint32_t g = (255 - y + x) / 2; 73 uint32_t b = y * (255 - x) / 256; 74 pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0); 100 for(x = 0; x < 256; x++) 101 { 102 uint32_t r = x; 103 uint32_t g = (255 - y + x) / 2; 104 uint32_t b = y * (255 - x) / 256; 105 pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0); 106 } 107 } 108 109 dither = cucul_create_dither(32, 256, 256, 4 * 256, 110 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 111 cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), 112 cucul_get_canvas_height(cv), dither, pixels); 113 cucul_free_dither(dither); 114 115 cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); 116 cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1); 117 118 cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE); 119 cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, 120 WIDTH / 4, HEIGHT / 4, " "); 121 cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>"); 122 cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); 123 124 cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); 125 cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); 126 127 for(x = 0; x < 16; x++) 128 { 129 cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4)); 130 cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#"); 75 131 } 76 132 } 77 133 78 dither = cucul_create_dither(32, 256, 256, 4 * 256, 79 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 80 cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), 81 cucul_get_canvas_height(cv), dither, pixels); 82 cucul_free_dither(dither); 83 84 cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); 85 cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1); 86 87 cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE); 88 cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " "); 89 cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>"); 90 cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); 91 92 cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); 93 cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); 94 95 for(x = 0; x < 16; x++) 96 { 97 cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4)); 98 cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#"); 99 } 100 101 buffer = cucul_export_canvas(cv, argv[1]); 134 buffer = cucul_export_canvas(cv, format); 102 135 fwrite(cucul_get_buffer_data(buffer), 103 136 cucul_get_buffer_size(buffer), 1, stdout);
Note: See TracChangeset
for help on using the changeset viewer.