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 2101 2007-11-30 23:48:39Z sam $ |
---|
7 | * |
---|
8 | * This program is free software. It comes without any warranty, to |
---|
9 | * the extent permitted by applicable law. You can redistribute it |
---|
10 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
11 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
13 | */ |
---|
14 | |
---|
15 | #include "config.h" |
---|
16 | #include "common.h" |
---|
17 | |
---|
18 | #if !defined(__KERNEL__) |
---|
19 | # if defined(HAVE_INTTYPES_H) |
---|
20 | # include <inttypes.h> |
---|
21 | # endif |
---|
22 | # include <stdio.h> |
---|
23 | # include <stdlib.h> |
---|
24 | # include <string.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #include "cucul.h" |
---|
28 | |
---|
29 | #define WIDTH 80 |
---|
30 | #define HEIGHT 32 |
---|
31 | |
---|
32 | uint32_t pixels[256*256]; |
---|
33 | |
---|
34 | int main(int argc, char *argv[]) |
---|
35 | { |
---|
36 | cucul_canvas_t *cv; |
---|
37 | cucul_dither_t *dither; |
---|
38 | void *buffer; |
---|
39 | char *file, *format; |
---|
40 | char const * const * exports, * const * p; |
---|
41 | unsigned long int len; |
---|
42 | int x, y; |
---|
43 | |
---|
44 | exports = cucul_get_export_list(); |
---|
45 | |
---|
46 | if(argc < 2 || argc > 3) |
---|
47 | { |
---|
48 | fprintf(stderr, "%s: wrong argument count\n", argv[0]); |
---|
49 | fprintf(stderr, "usage: %s [file] <format>\n", argv[0]); |
---|
50 | fprintf(stderr, "where <format> is one of:\n"); |
---|
51 | for(p = exports; *p; p += 2) |
---|
52 | fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); |
---|
53 | exit(-1); |
---|
54 | } |
---|
55 | |
---|
56 | if(argc == 2) |
---|
57 | { |
---|
58 | file = NULL; |
---|
59 | format = argv[1]; |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | file = argv[1]; |
---|
64 | format = argv[2]; |
---|
65 | } |
---|
66 | |
---|
67 | for(p = exports; *p; p += 2) |
---|
68 | if(!strcasecmp(format, *p)) |
---|
69 | break; |
---|
70 | |
---|
71 | if(!*p) |
---|
72 | { |
---|
73 | fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format); |
---|
74 | fprintf(stderr, "please use one of:\n"); |
---|
75 | for(p = exports; *p; p += 2) |
---|
76 | fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); |
---|
77 | exit(-1); |
---|
78 | } |
---|
79 | |
---|
80 | if(file) |
---|
81 | { |
---|
82 | cv = cucul_create_canvas(0, 0); |
---|
83 | if(cucul_import_file(cv, file, "") < 0) |
---|
84 | { |
---|
85 | fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file); |
---|
86 | exit(-1); |
---|
87 | } |
---|
88 | } |
---|
89 | else |
---|
90 | { |
---|
91 | cv = cucul_create_canvas(WIDTH, HEIGHT); |
---|
92 | |
---|
93 | for(y = 0; y < 256; y++) |
---|
94 | { |
---|
95 | for(x = 0; x < 256; x++) |
---|
96 | { |
---|
97 | uint32_t r = x; |
---|
98 | uint32_t g = (255 - y + x) / 2; |
---|
99 | uint32_t b = y * (255 - x) / 256; |
---|
100 | pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | dither = cucul_create_dither(32, 256, 256, 4 * 256, |
---|
105 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
106 | if(!strcmp(format, "ansi") || !strcmp(format, "utf8")) |
---|
107 | cucul_set_dither_charset(dither, "shades"); |
---|
108 | cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), |
---|
109 | cucul_get_canvas_height(cv), dither, pixels); |
---|
110 | cucul_free_dither(dither); |
---|
111 | |
---|
112 | cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK); |
---|
113 | cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1); |
---|
114 | |
---|
115 | cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE); |
---|
116 | cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, |
---|
117 | WIDTH / 4, HEIGHT / 4, ' '); |
---|
118 | |
---|
119 | cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK); |
---|
120 | cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6, |
---|
121 | " lightgray on black "); |
---|
122 | cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT); |
---|
123 | cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5, |
---|
124 | " default on transparent "); |
---|
125 | cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE); |
---|
126 | cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4, |
---|
127 | " black on white "); |
---|
128 | |
---|
129 | cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE); |
---|
130 | cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]"); |
---|
131 | cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]"); |
---|
132 | cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); |
---|
133 | cucul_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>"); |
---|
134 | |
---|
135 | cucul_set_attr(cv, CUCUL_BOLD); |
---|
136 | cucul_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold"); |
---|
137 | cucul_set_attr(cv, CUCUL_BLINK); |
---|
138 | cucul_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink"); |
---|
139 | cucul_set_attr(cv, CUCUL_ITALICS); |
---|
140 | cucul_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics"); |
---|
141 | cucul_set_attr(cv, CUCUL_UNDERLINE); |
---|
142 | cucul_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline"); |
---|
143 | cucul_set_attr(cv, 0); |
---|
144 | |
---|
145 | cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE); |
---|
146 | cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); |
---|
147 | |
---|
148 | for(x = 0; x < 16; x++) |
---|
149 | { |
---|
150 | cucul_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4)); |
---|
151 | cucul_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#'); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | buffer = cucul_export_memory(cv, format, &len); |
---|
156 | fwrite(buffer, len, 1, stdout); |
---|
157 | free(buffer); |
---|
158 | |
---|
159 | cucul_free_canvas(cv); |
---|
160 | |
---|
161 | return 0; |
---|
162 | } |
---|
163 | |
---|