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

Last change on this file since 811 was 811, checked in by Sam Hocevar, 14 years ago
  • Renamed caca_t into caca_display_t.
  • Renamed canvas handle variables from "c" to "cv". Eh ouais mon gros.
  • Property svn:keywords set to Id
File size: 3.1 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 811 2006-04-18 15:11:25Z 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_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(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,
84                        cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
85                        dither, pixels);
86    cucul_free_dither(dither);
87
88    cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
89    cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
90
91    cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
92    cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
93    cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
94    cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
95
96    cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
97    cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
98
99    for(x = 0; x < 16; x++)
100    {
101        cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4));
102        cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
103    }
104
105    buffer = cucul_create_export(cv, argv[1]);
106    fwrite(cucul_get_buffer_data(buffer),
107           cucul_get_buffer_size(buffer), 1, stdout);
108    cucul_free_buffer(buffer);
109
110    cucul_free(cv);
111
112    return 0;
113}
114
Note: See TracBrowser for help on using the repository browser.