1 | /* |
---|
2 | * export libcucul export test program |
---|
3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: export.c 1256 2006-10-29 08:35:46Z sam $ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the Do What The Fuck You Want To |
---|
10 | * Public License, Version 2, as published by Sam Hocevar. See |
---|
11 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
12 | */ |
---|
13 | |
---|
14 | #include "config.h" |
---|
15 | #include "common.h" |
---|
16 | |
---|
17 | #if !defined(__KERNEL__) |
---|
18 | # if defined(HAVE_INTTYPES_H) |
---|
19 | # include <inttypes.h> |
---|
20 | # endif |
---|
21 | # include <stdio.h> |
---|
22 | # include <stdlib.h> |
---|
23 | # include <string.h> |
---|
24 | #endif |
---|
25 | |
---|
26 | #include "cucul.h" |
---|
27 | |
---|
28 | #define WIDTH 80 |
---|
29 | #define HEIGHT 32 |
---|
30 | |
---|
31 | uint32_t pixels[256*256]; |
---|
32 | |
---|
33 | int main(int argc, char *argv[]) |
---|
34 | { |
---|
35 | cucul_canvas_t *cv; |
---|
36 | cucul_dither_t *dither; |
---|
37 | cucul_buffer_t *buffer; |
---|
38 | char *file, *format; |
---|
39 | char const * const * exports, * const * p; |
---|
40 | int x, y; |
---|
41 | |
---|
42 | exports = cucul_get_export_list(); |
---|
43 | |
---|
44 | if(argc < 2 || argc > 3) |
---|
45 | { |
---|
46 | fprintf(stderr, "%s: wrong argument count\n", argv[0]); |
---|
47 | fprintf(stderr, "usage: %s [file] <format>\n", argv[0]); |
---|
48 | fprintf(stderr, "where <format> is one of:\n"); |
---|
49 | for(p = exports; *p; p += 2) |
---|
50 | fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); |
---|
51 | exit(-1); |
---|
52 | } |
---|
53 | |
---|
54 | if(argc == 2) |
---|
55 | { |
---|
56 | file = NULL; |
---|
57 | format = argv[1]; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | file = argv[1]; |
---|
62 | format = argv[2]; |
---|
63 | } |
---|
64 | |
---|
65 | for(p = exports; *p; p += 2) |
---|
66 | if(!strcasecmp(format, *p)) |
---|
67 | break; |
---|
68 | |
---|
69 | if(!*p) |
---|
70 | { |
---|
71 | fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format); |
---|
72 | fprintf(stderr, "please use one of:\n"); |
---|
73 | for(p = exports; *p; p += 2) |
---|
74 | fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); |
---|
75 | exit(-1); |
---|
76 | } |
---|
77 | |
---|
78 | if(file) |
---|
79 | { |
---|
80 | cucul_buffer_t *tmp; |
---|
81 | tmp = cucul_load_file(file); |
---|
82 | if(!tmp) |
---|
83 | { |
---|
84 | fprintf(stderr, "%s: could not load `%s'\n", argv[0], file); |
---|
85 | exit(-1); |
---|
86 | } |
---|
87 | cv = cucul_import_canvas(tmp, ""); |
---|
88 | if(!cv) |
---|
89 | { |
---|
90 | fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file); |
---|
91 | exit(-1); |
---|
92 | } |
---|
93 | cucul_free_buffer(tmp); |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | cv = cucul_create_canvas(WIDTH, HEIGHT); |
---|
98 | |
---|
99 | for(y = 0; y < 256; y++) |
---|
100 | { |
---|
101 | for(x = 0; x < 256; x++) |
---|
102 | { |
---|
103 | uint32_t r = x; |
---|
104 | uint32_t g = (255 - y + x) / 2; |
---|
105 | uint32_t b = y * (255 - x) / 256; |
---|
106 | pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | dither = cucul_create_dither(32, 256, 256, 4 * 256, |
---|
111 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
112 | if(!strcmp(format, "ansi") || !strcmp(format, "utf8")) |
---|
113 | cucul_set_dither_charset(dither, "shades"); |
---|
114 | cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), |
---|
115 | cucul_get_canvas_height(cv), dither, pixels); |
---|
116 | cucul_free_dither(dither); |
---|
117 | |
---|
118 | cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK, 0); |
---|
119 | cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1); |
---|
120 | |
---|
121 | cucul_set_attr_ansi(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE, 0); |
---|
122 | cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, |
---|
123 | WIDTH / 4, HEIGHT / 4, " "); |
---|
124 | cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 5, "(\") \\o/ <&>"); |
---|
125 | cucul_putstr(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]"); |
---|
126 | cucul_putstr(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]"); |
---|
127 | cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); |
---|
128 | |
---|
129 | cucul_set_attr_ansi(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE, 0); |
---|
130 | cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); |
---|
131 | |
---|
132 | for(x = 0; x < 16; x++) |
---|
133 | { |
---|
134 | cucul_set_attr_argb(cv, 0xff00 | x, 0xf00f | (x << 4), 0); |
---|
135 | cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#"); |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | buffer = cucul_export_canvas(cv, format); |
---|
140 | fwrite(cucul_get_buffer_data(buffer), |
---|
141 | cucul_get_buffer_size(buffer), 1, stdout); |
---|
142 | cucul_free_buffer(buffer); |
---|
143 | |
---|
144 | cucul_free_canvas(cv); |
---|
145 | |
---|
146 | return 0; |
---|
147 | } |
---|
148 | |
---|