source: libcaca/trunk/examples/spritedit.c @ 4333

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/*
2 *  spritedit     sprite editor for libcaca
3 *  Copyright (c) 2003-2009 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  This program is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#include "config.h"
14
15#if !defined(__KERNEL__)
16#   include <stdio.h>
17#   include <string.h>
18#   include <stdlib.h>
19#endif
20
21#include "caca.h"
22
23/* Courtesy of Zashi */
24char *guy[] = {
25  "  O_,= \n"
26  "  |    \n"
27  "  /\\   \n"
28  " / /   \n",
29
30  "  O_,= \n"
31  "  |    \n"
32  "  /|   \n"
33  " / |   \n",
34
35  "  O_,= \n"
36  "  |    \n"
37  "  |\\   \n"
38  "  |/   \n",
39
40  "  O_,= \n"
41  "  |    \n"
42  "  |\\   \n"
43  "  | \\  \n",
44};
45
46int main(int argc, char **argv)
47{
48    caca_canvas_t *sprite;
49    size_t len;
50    void *buffer;
51    int i;
52
53    /* Create a canvas with 4 frames */
54    sprite = caca_create_canvas(0, 0);
55    for(i = 0; i < 3; i++)
56        caca_create_frame(sprite, 0);
57
58    /* Load stuff in all 4 frames */
59    for(i = 0; i < 4; i++)
60    {
61        caca_set_frame(sprite, i);
62        caca_import_canvas_from_memory(sprite, guy[i], strlen(guy[i]), "utf8");
63    }
64
65    /* Export our sprite in a memory buffer. We could save this to
66     * disk afterwards. */
67    buffer = caca_export_canvas_to_memory(sprite, "caca", &len);
68
69    /* Free our sprite and reload it from the memory buffer. We could
70     * load this from disk, too. */
71    caca_free_canvas(sprite);
72    sprite = caca_create_canvas(0, 0);
73    caca_import_canvas_from_memory(sprite, buffer, len, "caca");
74    free(buffer);
75
76    /* Print each sprite frame to stdout */
77    for(i = 0; i < 4; i++)
78    {
79        caca_set_frame(sprite, i);
80        printf("Frame #%i\n", i);
81        buffer = caca_export_canvas_to_memory(sprite, "utf8", &len);
82        fwrite(buffer, len, 1, stdout);
83        free(buffer);
84    }
85
86    /* Free our sprite */
87    caca_free_canvas(sprite);
88
89    return 0;
90}
91
Note: See TracBrowser for help on using the repository browser.