Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

164 строки
5.0 KiB

  1. /*
  2. * export libcucul export test program
  3. * Copyright (c) 2006 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. # if defined(HAVE_INTTYPES_H)
  18. # include <inttypes.h>
  19. # endif
  20. # include <stdio.h>
  21. # include <stdlib.h>
  22. # include <string.h>
  23. #endif
  24. #include "cucul.h"
  25. #define WIDTH 80
  26. #define HEIGHT 32
  27. uint32_t pixels[256*256];
  28. int main(int argc, char *argv[])
  29. {
  30. cucul_canvas_t *cv;
  31. cucul_dither_t *dither;
  32. void *buffer;
  33. char *file, *format;
  34. char const * const * exports, * const * p;
  35. unsigned long int len;
  36. int x, y;
  37. exports = cucul_get_export_list();
  38. if(argc < 2 || argc > 3)
  39. {
  40. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  41. fprintf(stderr, "usage: %s [file] <format>\n", argv[0]);
  42. fprintf(stderr, "where <format> is one of:\n");
  43. for(p = exports; *p; p += 2)
  44. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  45. exit(-1);
  46. }
  47. if(argc == 2)
  48. {
  49. file = NULL;
  50. format = argv[1];
  51. }
  52. else
  53. {
  54. file = argv[1];
  55. format = argv[2];
  56. }
  57. for(p = exports; *p; p += 2)
  58. if(!strcasecmp(format, *p))
  59. break;
  60. if(!*p)
  61. {
  62. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format);
  63. fprintf(stderr, "please use one of:\n");
  64. for(p = exports; *p; p += 2)
  65. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  66. exit(-1);
  67. }
  68. if(file)
  69. {
  70. cv = cucul_create_canvas(0, 0);
  71. if(cucul_import_file(cv, file, "") < 0)
  72. {
  73. fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
  74. exit(-1);
  75. }
  76. }
  77. else
  78. {
  79. cv = cucul_create_canvas(WIDTH, HEIGHT);
  80. for(y = 0; y < 256; y++)
  81. {
  82. for(x = 0; x < 256; x++)
  83. {
  84. uint32_t r = x;
  85. uint32_t g = (255 - y + x) / 2;
  86. uint32_t b = y * (255 - x) / 256;
  87. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  88. }
  89. }
  90. dither = cucul_create_dither(32, 256, 256, 4 * 256,
  91. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  92. if(!strcmp(format, "ansi") || !strcmp(format, "utf8"))
  93. cucul_set_dither_charset(dither, "shades");
  94. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  95. cucul_get_canvas_height(cv), dither, pixels);
  96. cucul_free_dither(dither);
  97. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
  98. cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  99. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  100. cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
  101. WIDTH / 4, HEIGHT / 4, ' ');
  102. cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK);
  103. cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
  104. " lightgray on black ");
  105. cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
  106. cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
  107. " default on transparent ");
  108. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  109. cucul_put_str(cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
  110. " black on white ");
  111. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  112. cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  113. cucul_put_str(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  114. cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  115. cucul_put_str(cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
  116. cucul_set_attr(cv, CUCUL_BOLD);
  117. cucul_put_str(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  118. cucul_set_attr(cv, CUCUL_BLINK);
  119. cucul_put_str(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  120. cucul_set_attr(cv, CUCUL_ITALICS);
  121. cucul_put_str(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  122. cucul_set_attr(cv, CUCUL_UNDERLINE);
  123. cucul_put_str(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  124. cucul_set_attr(cv, 0);
  125. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE);
  126. cucul_put_str(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  127. for(x = 0; x < 16; x++)
  128. {
  129. cucul_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
  130. cucul_put_char(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 6, '#');
  131. }
  132. }
  133. buffer = cucul_export_memory(cv, format, &len);
  134. fwrite(buffer, len, 1, stdout);
  135. free(buffer);
  136. cucul_free_canvas(cv);
  137. return 0;
  138. }