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

Last change on this file since 2147 was 2147, checked in by Sam Hocevar, 12 years ago
  • Fix canvas export for the caca format. We now export all frames.
  • Fix the sprite import/export example.
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/*
2 *  spritedit     sprite editor for libcaca
3 *  Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: spritedit.c 2147 2007-12-20 15:26:12Z sam $
7 *
8 *  This program is free software. It comes without any warranty, to
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
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15#include "config.h"
16#include "common.h"
17
18#if !defined(__KERNEL__)
19#   include <stdio.h>
20#   include <string.h>
21#   include <stdlib.h>
22#endif
23
24#include "cucul.h"
25#include "caca.h"
26
27/* Courtesy of Zashi */
28char *guy[] = {
29  "  O_,= \n"
30  "  |    \n"
31  "  /\\   \n"
32  " / /   \n",
33
34  "  O_,= \n"
35  "  |    \n"
36  "  /|   \n"
37  " / |   \n",
38
39  "  O_,= \n"
40  "  |    \n"
41  "  |\\   \n"
42  "  |/   \n",
43
44  "  O_,= \n"
45  "  |    \n"
46  "  |\\   \n"
47  "  | \\  \n",
48};
49
50int main(int argc, char **argv)
51{
52    cucul_canvas_t *sprite;
53    unsigned long int len;
54    void *buffer;
55    int i;
56
57    /* Create a canvas with 4 frames */
58    sprite = cucul_create_canvas(0, 0);
59    for(i = 0; i < 3; i++)
60        cucul_create_frame(sprite, 0);
61
62    /* Load stuff in all 4 frames */
63    for(i = 0; i < 4; i++)
64    {
65        cucul_set_frame(sprite, i);
66        cucul_import_memory(sprite, guy[i], strlen(guy[i]), "utf8");
67    }
68
69    /* Export our sprite in a memory buffer. We could save this to
70     * disk afterwards. */
71    buffer = cucul_export_memory(sprite, "caca", &len);
72
73    /* Free our sprite and reload it from the memory buffer. We could
74     * load this from disk, too. */
75    cucul_free_canvas(sprite);
76    sprite = cucul_create_canvas(0, 0);
77    cucul_import_memory(sprite, buffer, len, "caca");
78    free(buffer);
79
80    /* Print each sprite frame to stdout */
81    for(i = 0; i < 4; i++)
82    {
83        cucul_set_frame(sprite, i);
84        printf("Frame #%i\n", i);
85        buffer = cucul_export_memory(sprite, "utf8", &len);
86        fwrite(buffer, len, 1, stdout);
87        free(buffer);
88    }
89
90    /* Free our sprite */
91    cucul_free_canvas(sprite);
92
93    return 0;
94}
95
Note: See TracBrowser for help on using the repository browser.