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

Last change on this file since 826 was 826, checked in by Sam Hocevar, 16 years ago
  • Moved cucul_load_canvas() into cucul/import.c and renamed it into cucul_import_canvas().
  • Renamed cucul_create_export() into cucul_export_canvas() for consistency.
  • Property svn:keywords set to Id
File size: 3.1 KB
RevLine 
[622]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 826 2006-04-21 18:44:04Z 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{
[811]37    cucul_canvas_t *cv;
[777]38    cucul_dither_t *dither;
39    cucul_buffer_t *buffer;
[788]40    char const * const * exports, * const * p;
[622]41    int x, y;
42
[788]43    exports = cucul_get_export_list();
44
[622]45    if(argc != 2)
46    {
47        fprintf(stderr, "%s: wrong argument count\n", argv[0]);
48        fprintf(stderr, "usage: %s <format>\n", argv[0]);
[788]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));
[622]52        exit(-1);
53    }
54
[788]55    for(p = exports; *p; p += 2)
56        if(!strcasecmp(argv[1], *p))
57            break;
58
59    if(!*p)
[622]60    {
61        fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
[788]62        fprintf(stderr, "please use one of:\n");
63        for(p = exports; *p; p += 2)
64            fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
[622]65        exit(-1);
66    }
67
[813]68    cv = cucul_create_canvas(WIDTH, HEIGHT);
[622]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
[734]81    dither = cucul_create_dither(32, 256, 256, 4 * 256,
[622]82                                 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
[816]83    cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
84                        cucul_get_canvas_height(cv), dither, pixels);
[734]85    cucul_free_dither(dither);
[622]86
[811]87    cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
88    cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
[622]89
[811]90    cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
91    cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
92    cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
93    cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
[622]94
[811]95    cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
96    cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
[622]97
[788]98    for(x = 0; x < 16; x++)
99    {
[811]100        cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4));
101        cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
[788]102    }
103
[826]104    buffer = cucul_export_canvas(cv, argv[1]);
[777]105    fwrite(cucul_get_buffer_data(buffer),
106           cucul_get_buffer_size(buffer), 1, stdout);
107    cucul_free_buffer(buffer);
[622]108
[813]109    cucul_free_canvas(cv);
[622]110
111    return 0;
112}
113
Note: See TracBrowser for help on using the repository browser.