No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

94 líneas
2.1 KiB

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