Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * export libcaca export test program
  3. * Copyright (c) 2006-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 <stdlib.h>
  18. # include <string.h>
  19. #endif
  20. #include "caca.h"
  21. #define WIDTH 80
  22. #define HEIGHT 32
  23. uint32_t pixels[256*256];
  24. int main(int argc, char *argv[])
  25. {
  26. caca_canvas_t *cv;
  27. caca_dither_t *dither;
  28. void *buffer;
  29. char *file, *format;
  30. char const * const * exports, * const * p;
  31. size_t len;
  32. int x, y;
  33. exports = caca_get_export_list();
  34. if(argc < 2 || argc > 3)
  35. {
  36. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  37. fprintf(stderr, "usage: %s [file] <format>\n", argv[0]);
  38. fprintf(stderr, "where <format> is one of:\n");
  39. for(p = exports; *p; p += 2)
  40. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  41. exit(-1);
  42. }
  43. if(argc == 2)
  44. {
  45. file = NULL;
  46. format = argv[1];
  47. }
  48. else
  49. {
  50. file = argv[1];
  51. format = argv[2];
  52. }
  53. for(p = exports; *p; p += 2)
  54. if(!strcasecmp(format, *p))
  55. break;
  56. if(!*p)
  57. {
  58. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format);
  59. fprintf(stderr, "please use one of:\n");
  60. for(p = exports; *p; p += 2)
  61. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  62. exit(-1);
  63. }
  64. if(file)
  65. {
  66. cv = caca_create_canvas(0, 0);
  67. if(caca_import_canvas_from_file(cv, file, "") < 0)
  68. {
  69. fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
  70. exit(-1);
  71. }
  72. }
  73. else
  74. {
  75. cv = caca_create_canvas(WIDTH, HEIGHT);
  76. for(y = 0; y < 256; y++)
  77. {
  78. for(x = 0; x < 256; x++)
  79. {
  80. uint32_t r = x;
  81. uint32_t g = (255 - y + x) / 2;
  82. uint32_t b = y * (255 - x) / 256;
  83. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  84. }
  85. }
  86. dither = caca_create_dither(32, 256, 256, 4 * 256,
  87. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  88. if(!strcmp(format, "ansi") || !strcmp(format, "utf8"))
  89. caca_set_dither_charset(dither, "shades");
  90. caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
  91. caca_get_canvas_height(cv), dither, pixels);
  92. caca_free_dither(dither);
  93. caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK);
  94. caca_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  95. caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
  96. caca_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
  97. WIDTH / 4, HEIGHT / 4, ' ');
  98. caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK);
  99. caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
  100. " lightgray on black ");
  101. caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
  102. caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
  103. " default on transparent ");
  104. caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
  105. caca_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
  106. " black on white ");
  107. caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE);
  108. caca_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  109. caca_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  110. caca_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  111. caca_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
  112. caca_set_attr(cv, CACA_BOLD);
  113. caca_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  114. caca_set_attr(cv, CACA_BLINK);
  115. caca_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  116. caca_set_attr(cv, CACA_ITALICS);
  117. caca_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  118. caca_set_attr(cv, CACA_UNDERLINE);
  119. caca_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  120. caca_set_attr(cv, 0);
  121. caca_set_color_ansi(cv, CACA_WHITE, CACA_LIGHTBLUE);
  122. caca_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  123. for(x = 0; x < 16; x++)
  124. {
  125. caca_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
  126. caca_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#');
  127. }
  128. }
  129. buffer = caca_export_canvas_to_memory(cv, format, &len);
  130. fwrite(buffer, len, 1, stdout);
  131. free(buffer);
  132. caca_free_canvas(cv);
  133. return 0;
  134. }