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.
 
 
 
 
 
 

92 líneas
2.1 KiB

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