選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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