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 2313 2008-04-23 21:24:34Z 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 | |
---|
17 | #if !defined(__KERNEL__) |
---|
18 | # include <stdio.h> |
---|
19 | # include <string.h> |
---|
20 | # include <stdlib.h> |
---|
21 | #endif |
---|
22 | |
---|
23 | #include "cucul.h" |
---|
24 | #include "caca.h" |
---|
25 | |
---|
26 | /* Courtesy of Zashi */ |
---|
27 | char *guy[] = { |
---|
28 | " O_,= \n" |
---|
29 | " | \n" |
---|
30 | " /\\ \n" |
---|
31 | " / / \n", |
---|
32 | |
---|
33 | " O_,= \n" |
---|
34 | " | \n" |
---|
35 | " /| \n" |
---|
36 | " / | \n", |
---|
37 | |
---|
38 | " O_,= \n" |
---|
39 | " | \n" |
---|
40 | " |\\ \n" |
---|
41 | " |/ \n", |
---|
42 | |
---|
43 | " O_,= \n" |
---|
44 | " | \n" |
---|
45 | " |\\ \n" |
---|
46 | " | \\ \n", |
---|
47 | }; |
---|
48 | |
---|
49 | int main(int argc, char **argv) |
---|
50 | { |
---|
51 | cucul_canvas_t *sprite; |
---|
52 | size_t len; |
---|
53 | void *buffer; |
---|
54 | int i; |
---|
55 | |
---|
56 | /* Create a canvas with 4 frames */ |
---|
57 | sprite = cucul_create_canvas(0, 0); |
---|
58 | for(i = 0; i < 3; i++) |
---|
59 | cucul_create_frame(sprite, 0); |
---|
60 | |
---|
61 | /* Load stuff in all 4 frames */ |
---|
62 | for(i = 0; i < 4; i++) |
---|
63 | { |
---|
64 | cucul_set_frame(sprite, i); |
---|
65 | cucul_import_memory(sprite, guy[i], strlen(guy[i]), "utf8"); |
---|
66 | } |
---|
67 | |
---|
68 | /* Export our sprite in a memory buffer. We could save this to |
---|
69 | * disk afterwards. */ |
---|
70 | buffer = cucul_export_memory(sprite, "caca", &len); |
---|
71 | |
---|
72 | /* Free our sprite and reload it from the memory buffer. We could |
---|
73 | * load this from disk, too. */ |
---|
74 | cucul_free_canvas(sprite); |
---|
75 | sprite = cucul_create_canvas(0, 0); |
---|
76 | cucul_import_memory(sprite, buffer, len, "caca"); |
---|
77 | free(buffer); |
---|
78 | |
---|
79 | /* Print each sprite frame to stdout */ |
---|
80 | for(i = 0; i < 4; i++) |
---|
81 | { |
---|
82 | cucul_set_frame(sprite, i); |
---|
83 | printf("Frame #%i\n", i); |
---|
84 | buffer = cucul_export_memory(sprite, "utf8", &len); |
---|
85 | fwrite(buffer, len, 1, stdout); |
---|
86 | free(buffer); |
---|
87 | } |
---|
88 | |
---|
89 | /* Free our sprite */ |
---|
90 | cucul_free_canvas(sprite); |
---|
91 | |
---|
92 | return 0; |
---|
93 | } |
---|
94 | |
---|