~ubuntu-branches/ubuntu/gutsy/libcaca/gutsy

« back to all changes in this revision

Viewing changes to test/export.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hocevar (Debian packages)
  • Date: 2006-12-03 02:05:11 UTC
  • mfrom: (3.1.6 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203020511-h5nzqgf8nov7ns3z
Tags: 0.99.beta11.debian-2
Remove toilet from caca-utils now that it has entered testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 1079 2006-11-16 15:01:31Z 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
    void *buffer;
 
38
    char *file, *format;
 
39
    char const * const * exports, * const * p;
 
40
    unsigned long int len;
 
41
    int x, y;
 
42
 
 
43
    exports = cucul_get_export_list();
 
44
 
 
45
    if(argc < 2 || argc > 3)
 
46
    {
 
47
        fprintf(stderr, "%s: wrong argument count\n", argv[0]);
 
48
        fprintf(stderr, "usage: %s [file] <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
    if(argc == 2)
 
56
    {
 
57
        file = NULL;
 
58
        format = argv[1];
 
59
    }
 
60
    else
 
61
    {
 
62
        file = argv[1];
 
63
        format = argv[2];
 
64
    }
 
65
 
 
66
    for(p = exports; *p; p += 2)
 
67
        if(!strcasecmp(format, *p))
 
68
            break;
 
69
 
 
70
    if(!*p)
 
71
    {
 
72
        fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format);
 
73
        fprintf(stderr, "please use one of:\n");
 
74
        for(p = exports; *p; p += 2)
 
75
            fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
 
76
        exit(-1);
 
77
    }
 
78
 
 
79
    if(file)
 
80
    {
 
81
        cv = cucul_create_canvas(0, 0);
 
82
        if(cucul_import_file(cv, file, "") < 0)
 
83
        {
 
84
            fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
 
85
            exit(-1);
 
86
        }
 
87
    }
 
88
    else
 
89
    {
 
90
        cv = cucul_create_canvas(WIDTH, HEIGHT);
 
91
 
 
92
        for(y = 0; y < 256; y++)
 
93
        {
 
94
            for(x = 0; x < 256; x++)
 
95
            {
 
96
                uint32_t r = x;
 
97
                uint32_t g = (255 - y + x) / 2;
 
98
                uint32_t b = y * (255 - x) / 256;
 
99
                pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
 
100
            }
 
101
        }
 
102
 
 
103
        dither = cucul_create_dither(32, 256, 256, 4 * 256,
 
104
                                     0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
 
105
        if(!strcmp(format, "ansi") || !strcmp(format, "utf8"))
 
106
            cucul_set_dither_charset(dither, "shades");
 
107
        cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
 
108
                            cucul_get_canvas_height(cv), dither, pixels);
 
109
        cucul_free_dither(dither);
 
110
 
 
111
        cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
 
112
        cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
 
113
 
 
114
        cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
 
115
        cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
 
116
                               WIDTH / 4, HEIGHT / 4, ' ');
 
117
 
 
118
        cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
 
119
        cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
 
120
                      "   lightgray on black   ");
 
121
        cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
 
122
        cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
 
123
                      " default on transparent ");
 
124
        cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
 
125
        cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
 
126
                      "     black on white     ");
 
127
 
 
128
        cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
 
129
        cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
 
130
        cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
 
131
        cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
 
132
        cucul_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
 
133
 
 
134
        cucul_set_attr(cv, CUCUL_BOLD);
 
135
        cucul_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
 
136
        cucul_set_attr(cv, CUCUL_BLINK);
 
137
        cucul_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
 
138
        cucul_set_attr(cv, CUCUL_ITALICS);
 
139
        cucul_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
 
140
        cucul_set_attr(cv, CUCUL_UNDERLINE);
 
141
        cucul_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
 
142
        cucul_set_attr(cv, 0);
 
143
 
 
144
        cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE);
 
145
        cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
 
146
 
 
147
        for(x = 0; x < 16; x++)
 
148
        {
 
149
            cucul_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
 
150
            cucul_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#');
 
151
        }
 
152
    }
 
153
 
 
154
    buffer = cucul_export_memory(cv, format, &len);
 
155
    fwrite(buffer, len, 1, stdout);
 
156
    free(buffer);
 
157
 
 
158
    cucul_free_canvas(cv);
 
159
 
 
160
    return 0;
 
161
}
 
162