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

Last change on this file since 706 was 706, checked in by Sam Hocevar, 15 years ago
  • Changed the 2nd argument of cucul_create_export to a string. This way we can add new exporters without changing the API.
  • Property svn:keywords set to Id
File size: 2.8 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 706 2006-03-27 22:16:58Z 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    struct cucul_bitmap *bitmap;
39    struct cucul_export *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(0, 0);
62    cucul_set_size(qq, WIDTH, HEIGHT);
63
64    for(y = 0; y < 256; y++)
65    {
66        for(x = 0; x < 256; x++)
67        {
68            uint32_t r = x;
69            uint32_t g = (255 - y + x) / 2;
70            uint32_t b = y * (255 - x) / 256;
71            pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
72        }
73    }
74
75    bitmap = cucul_create_bitmap(32, 256, 256, 4 * 256,
76                                 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
77    cucul_draw_bitmap(qq, 0, 0,
78                      cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
79                      bitmap, pixels);
80    cucul_free_bitmap(bitmap);
81
82    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
83    cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1);
84
85    cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
86    cucul_fill_ellipse(qq, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
87    cucul_putstr(qq, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
88    cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
89
90    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
91    cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
92
93    buffer = cucul_create_export(qq, argv[1]);
94    fwrite(buffer->buffer, buffer->size - 1, 1, stdout);
95    cucul_free_export(buffer);
96
97    cucul_free(qq);
98
99    return 0;
100}
101
Note: See TracBrowser for help on using the repository browser.