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.
 
 
 
 
 
 

96 líneas
2.1 KiB

  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. }