您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

159 行
4.6 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; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "config.h"
  14. #include "common.h"
  15. #if !defined(__KERNEL__)
  16. # if defined(HAVE_INTTYPES_H)
  17. # include <inttypes.h>
  18. # endif
  19. # include <stdio.h>
  20. # include <stdlib.h>
  21. # include <string.h>
  22. #endif
  23. #include "cucul.h"
  24. #define WIDTH 80
  25. #define HEIGHT 32
  26. uint32_t pixels[256*256];
  27. int main(int argc, char *argv[])
  28. {
  29. cucul_canvas_t *cv;
  30. cucul_dither_t *dither;
  31. cucul_buffer_t *buffer;
  32. char *file, *format;
  33. char const * const * exports, * const * p;
  34. int x, y;
  35. exports = cucul_get_export_list();
  36. if(argc < 2 || argc > 3)
  37. {
  38. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  39. fprintf(stderr, "usage: %s [file] <format>\n", argv[0]);
  40. fprintf(stderr, "where <format> is one of:\n");
  41. for(p = exports; *p; p += 2)
  42. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  43. exit(-1);
  44. }
  45. if(argc == 2)
  46. {
  47. file = NULL;
  48. format = argv[1];
  49. }
  50. else
  51. {
  52. file = argv[1];
  53. format = argv[2];
  54. }
  55. for(p = exports; *p; p += 2)
  56. if(!strcasecmp(format, *p))
  57. break;
  58. if(!*p)
  59. {
  60. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format);
  61. fprintf(stderr, "please use one of:\n");
  62. for(p = exports; *p; p += 2)
  63. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  64. exit(-1);
  65. }
  66. if(file)
  67. {
  68. cucul_buffer_t *tmp;
  69. tmp = cucul_load_file(file);
  70. if(!tmp)
  71. {
  72. fprintf(stderr, "%s: could not load `%s'\n", argv[0], file);
  73. exit(-1);
  74. }
  75. cv = cucul_import_canvas(tmp, "");
  76. if(!cv)
  77. {
  78. fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
  79. exit(-1);
  80. }
  81. cucul_free_buffer(tmp);
  82. }
  83. else
  84. {
  85. cv = cucul_create_canvas(WIDTH, HEIGHT);
  86. for(y = 0; y < 256; y++)
  87. {
  88. for(x = 0; x < 256; x++)
  89. {
  90. uint32_t r = x;
  91. uint32_t g = (255 - y + x) / 2;
  92. uint32_t b = y * (255 - x) / 256;
  93. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  94. }
  95. }
  96. dither = cucul_create_dither(32, 256, 256, 4 * 256,
  97. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  98. if(!strcmp(format, "ansi") || !strcmp(format, "utf8"))
  99. cucul_set_dither_charset(dither, "shades");
  100. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  101. cucul_get_canvas_height(cv), dither, pixels);
  102. cucul_free_dither(dither);
  103. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
  104. cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  105. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  106. cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
  107. WIDTH / 4, HEIGHT / 4, " ");
  108. cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 5, "(\") \\o/ <&>");
  109. cucul_putstr(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  110. cucul_putstr(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  111. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  112. cucul_set_attr(cv, CUCUL_BOLD);
  113. cucul_putstr(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  114. cucul_set_attr(cv, CUCUL_BLINK);
  115. cucul_putstr(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  116. cucul_set_attr(cv, CUCUL_ITALICS);
  117. cucul_putstr(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  118. cucul_set_attr(cv, CUCUL_UNDERLINE);
  119. cucul_putstr(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  120. cucul_set_attr(cv, 0);
  121. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE);
  122. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  123. for(x = 0; x < 16; x++)
  124. {
  125. cucul_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
  126. cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
  127. }
  128. }
  129. buffer = cucul_export_canvas(cv, format);
  130. fwrite(cucul_get_buffer_data(buffer),
  131. cucul_get_buffer_size(buffer), 1, stdout);
  132. cucul_free_buffer(buffer);
  133. cucul_free_canvas(cv);
  134. return 0;
  135. }