source: libcaca/trunk/test/export.c @ 665

Last change on this file since 665 was 665, checked in by Sam Hocevar, 16 years ago
  • Changed the cucul_init parameter so that it now directly accepts a canvas size (use cucul_init(0, 0) for the old behaviour).
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
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 665 2006-03-22 17:46:11Z 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
19typedef unsigned char uint8_t;
20typedef unsigned short uint16_t;
21typedef 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
33uint32_t pixels[256*256];
34
35int main(int argc, char *argv[])
36{
37    cucul_t *qq;
38    enum cucul_format format;
39    struct cucul_bitmap *bitmap;
40    struct cucul_export *buffer;
41    int x, y;
42
43    if(argc != 2)
44    {
45        fprintf(stderr, "%s: wrong argument count\n", argv[0]);
46        fprintf(stderr, "usage: %s <format>\n", argv[0]);
47        fprintf(stderr, "where <format> is one of: ansi, html, html3, irc, ps, svg\n");
48        exit(-1);
49    }
50
51    if(!strcasecmp(argv[1], "ansi"))
52        format = CUCUL_FORMAT_ANSI;
53    else if(!strcasecmp(argv[1], "html"))
54        format = CUCUL_FORMAT_HTML;
55    else if(!strcasecmp(argv[1], "html3"))
56        format = CUCUL_FORMAT_HTML3;
57    else if(!strcasecmp(argv[1], "irc"))
58        format = CUCUL_FORMAT_IRC;
59    else if(!strcasecmp(argv[1], "ps"))
60        format = CUCUL_FORMAT_PS;
61    else if(!strcasecmp(argv[1], "svg"))
62        format = CUCUL_FORMAT_SVG;
63    else
64    {
65        fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
66        exit(-1);
67    }
68
69    qq = cucul_init(0, 0);
70    cucul_set_size(qq, WIDTH, HEIGHT);
71
72    for(y = 0; y < 256; y++)
73    {
74        for(x = 0; x < 256; x++)
75        {
76            uint32_t r = x;
77            uint32_t g = (255 - y + x) / 2;
78            uint32_t b = y * (255 - x) / 256;
79            pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
80        }
81    }
82
83    bitmap = cucul_create_bitmap(qq, 32, 256, 256, 4 * 256,
84                                 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
85    cucul_draw_bitmap(qq, 0, 0,
86                      cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
87                      bitmap, pixels);
88    cucul_free_bitmap(bitmap);
89
90    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
91    cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1);
92
93    cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
94    cucul_fill_ellipse(qq, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, ' ');
95    cucul_putstr(qq, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
96    cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
97
98    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
99    cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
100
101    buffer = cucul_get_export(qq, format);
102    fwrite(buffer->buffer, buffer->size - 1, 1, stdout);
103    cucul_free_export(buffer);
104
105    cucul_end(qq);
106
107    return 0;
108}
109
Note: See TracBrowser for help on using the repository browser.