You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * spritedit sprite editor for libcaca
  3. * Copyright (c) 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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. #include "config.h"
  15. #include "common.h"
  16. #if !defined(__KERNEL__)
  17. # include <stdio.h>
  18. # include <string.h>
  19. # include <stdlib.h>
  20. #endif
  21. #include "cucul.h"
  22. #include "caca.h"
  23. /* Courtesy of Zashi */
  24. char *guy[] = {
  25. " O_,= \n"
  26. " | \n"
  27. " /\\ \n"
  28. " / / \n",
  29. " O_,= \n"
  30. " | \n"
  31. " /| \n"
  32. " / | \n",
  33. " O_,= \n"
  34. " | \n"
  35. " |\\ \n"
  36. " |/ \n",
  37. " O_,= \n"
  38. " | \n"
  39. " |\\ \n"
  40. " | \\ \n",
  41. };
  42. int main(int argc, char **argv)
  43. {
  44. cucul_canvas_t *sprite;
  45. unsigned long int len;
  46. void *buffer;
  47. int i;
  48. /* Create a canvas with 4 frames */
  49. sprite = cucul_create_canvas(0, 0);
  50. for(i = 0; i < 3; i++)
  51. cucul_create_frame(sprite, 0);
  52. /* Load stuff in all 4 frames */
  53. for(i = 0; i < 4; i++)
  54. {
  55. cucul_set_frame(sprite, i);
  56. cucul_import_memory(sprite, guy[i], strlen(guy[i]), "utf8");
  57. }
  58. /* Export our sprite in a memory buffer. We could save this to
  59. * disk afterwards. */
  60. buffer = cucul_export_memory(sprite, "caca", &len);
  61. /* Free our sprite and reload it from the memory buffer. We could
  62. * load this from disk, too. */
  63. cucul_free_canvas(sprite);
  64. sprite = cucul_create_canvas(0, 0);
  65. cucul_import_memory(sprite, buffer, len, "caca");
  66. free(buffer);
  67. /* Print each sprite frame to stdout */
  68. for(i = 0; i < 4; i++)
  69. {
  70. cucul_set_frame(sprite, i);
  71. printf("Frame #%i\n", i);
  72. buffer = cucul_export_memory(sprite, "utf8", &len);
  73. fwrite(buffer, len, 1, stdout);
  74. free(buffer);
  75. }
  76. /* Free our sprite */
  77. cucul_free_canvas(sprite);
  78. return 0;
  79. }