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 777 2006-04-16 18:28:47Z 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 | |
---|
16 | #if defined(HAVE_INTTYPES_H) |
---|
17 | # include <inttypes.h> |
---|
18 | #else |
---|
19 | typedef unsigned char uint8_t; |
---|
20 | typedef unsigned short uint16_t; |
---|
21 | typedef unsigned int uint32_t; |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <stdio.h> |
---|
25 | #include <stdlib.h> |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | #include "cucul.h" |
---|
29 | |
---|
30 | #define WIDTH 60 |
---|
31 | #define HEIGHT 32 |
---|
32 | |
---|
33 | uint32_t pixels[256*256]; |
---|
34 | |
---|
35 | int main(int argc, char *argv[]) |
---|
36 | { |
---|
37 | cucul_t *qq; |
---|
38 | cucul_dither_t *dither; |
---|
39 | cucul_buffer_t *buffer; |
---|
40 | int x, y; |
---|
41 | |
---|
42 | if(argc != 2) |
---|
43 | { |
---|
44 | fprintf(stderr, "%s: wrong argument count\n", argv[0]); |
---|
45 | fprintf(stderr, "usage: %s <format>\n", argv[0]); |
---|
46 | fprintf(stderr, "where <format> is one of: ansi, html, html3, irc, ps, svg\n"); |
---|
47 | exit(-1); |
---|
48 | } |
---|
49 | |
---|
50 | if(strcasecmp(argv[1], "ansi") |
---|
51 | && strcasecmp(argv[1], "html") |
---|
52 | && strcasecmp(argv[1], "html3") |
---|
53 | && strcasecmp(argv[1], "irc") |
---|
54 | && strcasecmp(argv[1], "ps") |
---|
55 | && strcasecmp(argv[1], "svg")) |
---|
56 | { |
---|
57 | fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]); |
---|
58 | exit(-1); |
---|
59 | } |
---|
60 | |
---|
61 | qq = cucul_create(WIDTH, HEIGHT); |
---|
62 | |
---|
63 | for(y = 0; y < 256; y++) |
---|
64 | { |
---|
65 | for(x = 0; x < 256; x++) |
---|
66 | { |
---|
67 | uint32_t r = x; |
---|
68 | uint32_t g = (255 - y + x) / 2; |
---|
69 | uint32_t b = y * (255 - x) / 256; |
---|
70 | pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | dither = cucul_create_dither(32, 256, 256, 4 * 256, |
---|
75 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
76 | cucul_dither_bitmap(qq, 0, 0, |
---|
77 | cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, |
---|
78 | dither, pixels); |
---|
79 | cucul_free_dither(dither); |
---|
80 | |
---|
81 | cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); |
---|
82 | cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1); |
---|
83 | |
---|
84 | cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE); |
---|
85 | cucul_fill_ellipse(qq, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " "); |
---|
86 | cucul_putstr(qq, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>"); |
---|
87 | cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); |
---|
88 | |
---|
89 | cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); |
---|
90 | cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); |
---|
91 | |
---|
92 | buffer = cucul_create_export(qq, argv[1]); |
---|
93 | fwrite(cucul_get_buffer_data(buffer), |
---|
94 | cucul_get_buffer_size(buffer), 1, stdout); |
---|
95 | cucul_free_buffer(buffer); |
---|
96 | |
---|
97 | cucul_free(qq); |
---|
98 | |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|