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 816 2006-04-18 16:50:56Z 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_canvas_t *cv; |
---|
38 | cucul_dither_t *dither; |
---|
39 | cucul_buffer_t *buffer; |
---|
40 | char const * const * exports, * const * p; |
---|
41 | int x, y; |
---|
42 | |
---|
43 | exports = cucul_get_export_list(); |
---|
44 | |
---|
45 | if(argc != 2) |
---|
46 | { |
---|
47 | fprintf(stderr, "%s: wrong argument count\n", argv[0]); |
---|
48 | fprintf(stderr, "usage: %s <format>\n", argv[0]); |
---|
49 | fprintf(stderr, "where <format> is one of:\n"); |
---|
50 | for(p = exports; *p; p += 2) |
---|
51 | fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); |
---|
52 | exit(-1); |
---|
53 | } |
---|
54 | |
---|
55 | for(p = exports; *p; p += 2) |
---|
56 | if(!strcasecmp(argv[1], *p)) |
---|
57 | break; |
---|
58 | |
---|
59 | if(!*p) |
---|
60 | { |
---|
61 | fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]); |
---|
62 | fprintf(stderr, "please use one of:\n"); |
---|
63 | for(p = exports; *p; p += 2) |
---|
64 | fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1)); |
---|
65 | exit(-1); |
---|
66 | } |
---|
67 | |
---|
68 | cv = cucul_create_canvas(WIDTH, HEIGHT); |
---|
69 | |
---|
70 | for(y = 0; y < 256; y++) |
---|
71 | { |
---|
72 | for(x = 0; x < 256; x++) |
---|
73 | { |
---|
74 | uint32_t r = x; |
---|
75 | uint32_t g = (255 - y + x) / 2; |
---|
76 | uint32_t b = y * (255 - x) / 256; |
---|
77 | pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | dither = cucul_create_dither(32, 256, 256, 4 * 256, |
---|
82 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); |
---|
83 | cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv), |
---|
84 | cucul_get_canvas_height(cv), dither, pixels); |
---|
85 | cucul_free_dither(dither); |
---|
86 | |
---|
87 | cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); |
---|
88 | cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1); |
---|
89 | |
---|
90 | cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE); |
---|
91 | cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " "); |
---|
92 | cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>"); |
---|
93 | cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); |
---|
94 | |
---|
95 | cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); |
---|
96 | cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); |
---|
97 | |
---|
98 | for(x = 0; x < 16; x++) |
---|
99 | { |
---|
100 | cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4)); |
---|
101 | cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#"); |
---|
102 | } |
---|
103 | |
---|
104 | buffer = cucul_create_export(cv, argv[1]); |
---|
105 | fwrite(cucul_get_buffer_data(buffer), |
---|
106 | cucul_get_buffer_size(buffer), 1, stdout); |
---|
107 | cucul_free_buffer(buffer); |
---|
108 | |
---|
109 | cucul_free_canvas(cv); |
---|
110 | |
---|
111 | return 0; |
---|
112 | } |
---|
113 | |
---|