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

Last change on this file since 858 was 858, checked in by Sam Hocevar, 15 years ago
  • Added "common.h", a placeholder for simple features and functions missing from some systems.
  • 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 858 2006-04-24 19:57:23Z 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(HAVE_INTTYPES_H)
18#   include <inttypes.h>
19#endif
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include "cucul.h"
26
27#define WIDTH 60
28#define HEIGHT 32
29
30uint32_t pixels[256*256];
31
32int main(int argc, char *argv[])
33{
34    cucul_canvas_t *cv;
35    cucul_dither_t *dither;
36    cucul_buffer_t *buffer;
37    char const * const * exports, * const * p;
38    int x, y;
39
40    exports = cucul_get_export_list();
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:\n");
47        for(p = exports; *p; p += 2)
48            fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
49        exit(-1);
50    }
51
52    for(p = exports; *p; p += 2)
53        if(!strcasecmp(argv[1], *p))
54            break;
55
56    if(!*p)
57    {
58        fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
59        fprintf(stderr, "please use one of:\n");
60        for(p = exports; *p; p += 2)
61            fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
62        exit(-1);
63    }
64
65    cv = cucul_create_canvas(WIDTH, HEIGHT);
66
67    for(y = 0; y < 256; y++)
68    {
69        for(x = 0; x < 256; x++)
70        {
71            uint32_t r = x;
72            uint32_t g = (255 - y + x) / 2;
73            uint32_t b = y * (255 - x) / 256;
74            pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
75        }
76    }
77
78    dither = cucul_create_dither(32, 256, 256, 4 * 256,
79                                 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
80    cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
81                        cucul_get_canvas_height(cv), dither, pixels);
82    cucul_free_dither(dither);
83
84    cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
85    cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
86
87    cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
88    cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
89    cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
90    cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
91
92    cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
93    cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
94
95    for(x = 0; x < 16; x++)
96    {
97        cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4));
98        cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
99    }
100
101    buffer = cucul_export_canvas(cv, argv[1]);
102    fwrite(cucul_get_buffer_data(buffer),
103           cucul_get_buffer_size(buffer), 1, stdout);
104    cucul_free_buffer(buffer);
105
106    cucul_free_canvas(cv);
107
108    return 0;
109}
110
Note: See TracBrowser for help on using the repository browser.