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

Last change on this file since 1462 was 1462, checked in by Sam Hocevar, 13 years ago
  • Bwarf, typo in the no warranty clause.
  • Property svn:keywords set to Id
File size: 5.0 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 1462 2006-12-12 01:53:54Z sam $
7 *
[1462]8 *  This program is free software. It comes without any warranty, to
[1452]9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
[622]12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
[858]16#include "common.h"
[622]17
[1048]18#if !defined(__KERNEL__)
19#   if defined(HAVE_INTTYPES_H)
20#      include <inttypes.h>
21#   endif
22#   include <stdio.h>
23#   include <stdlib.h>
24#   include <string.h>
[622]25#endif
26
27#include "cucul.h"
28
[932]29#define WIDTH 80
[622]30#define HEIGHT 32
31
32uint32_t pixels[256*256];
33
34int main(int argc, char *argv[])
35{
[811]36    cucul_canvas_t *cv;
[777]37    cucul_dither_t *dither;
[1308]38    void *buffer;
[919]39    char *file, *format;
[788]40    char const * const * exports, * const * p;
[1308]41    unsigned long int len;
[622]42    int x, y;
43
[788]44    exports = cucul_get_export_list();
45
[919]46    if(argc < 2 || argc > 3)
[622]47    {
48        fprintf(stderr, "%s: wrong argument count\n", argv[0]);
[919]49        fprintf(stderr, "usage: %s [file] <format>\n", argv[0]);
[788]50        fprintf(stderr, "where <format> is one of:\n");
51        for(p = exports; *p; p += 2)
52            fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
[622]53        exit(-1);
54    }
55
[919]56    if(argc == 2)
57    {
58        file = NULL;
59        format = argv[1];
60    }
61    else
62    {
63        file = argv[1];
64        format = argv[2];
65    }
66
[788]67    for(p = exports; *p; p += 2)
[919]68        if(!strcasecmp(format, *p))
[788]69            break;
70
71    if(!*p)
[622]72    {
[919]73        fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format);
[788]74        fprintf(stderr, "please use one of:\n");
75        for(p = exports; *p; p += 2)
76            fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
[622]77        exit(-1);
78    }
79
[919]80    if(file)
[622]81    {
[1308]82        cv = cucul_create_canvas(0, 0);
83        if(cucul_import_file(cv, file, "") < 0)
[622]84        {
[919]85            fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
86            exit(-1);
87        }
[622]88    }
[919]89    else
90    {
91        cv = cucul_create_canvas(WIDTH, HEIGHT);
[622]92
[919]93        for(y = 0; y < 256; y++)
94        {
95            for(x = 0; x < 256; x++)
96            {
97                uint32_t r = x;
98                uint32_t g = (255 - y + x) / 2;
99                uint32_t b = y * (255 - x) / 256;
100                pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
101            }
102        }
[622]103
[919]104        dither = cucul_create_dither(32, 256, 256, 4 * 256,
105                                     0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
[956]106        if(!strcmp(format, "ansi") || !strcmp(format, "utf8"))
107            cucul_set_dither_charset(dither, "shades");
[919]108        cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
109                            cucul_get_canvas_height(cv), dither, pixels);
110        cucul_free_dither(dither);
[622]111
[1267]112        cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
[919]113        cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
[622]114
[1267]115        cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
[919]116        cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
[1330]117                               WIDTH / 4, HEIGHT / 4, ' ');
[1417]118
119        cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
120        cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
121                      "   lightgray on black   ");
122        cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
123        cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
124                      " default on transparent ");
125        cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
126        cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
127                      "     black on white     ");
128
129        cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
[1347]130        cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
131        cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
132        cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
[1417]133        cucul_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
[622]134
[1266]135        cucul_set_attr(cv, CUCUL_BOLD);
[1347]136        cucul_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
[1266]137        cucul_set_attr(cv, CUCUL_BLINK);
[1347]138        cucul_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
[1266]139        cucul_set_attr(cv, CUCUL_ITALICS);
[1347]140        cucul_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
[1266]141        cucul_set_attr(cv, CUCUL_UNDERLINE);
[1347]142        cucul_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
[1267]143        cucul_set_attr(cv, 0);
[1263]144
[1267]145        cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE);
[1347]146        cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, "    LIBCACA    ");
[919]147
148        for(x = 0; x < 16; x++)
149        {
[1267]150            cucul_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
[1417]151            cucul_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#');
[919]152        }
[788]153    }
154
[1308]155    buffer = cucul_export_memory(cv, format, &len);
156    fwrite(buffer, len, 1, stdout);
157    free(buffer);
[622]158
[813]159    cucul_free_canvas(cv);
[622]160
161    return 0;
162}
163
Note: See TracBrowser for help on using the repository browser.