You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

151 lines
4.3 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. void *buffer;
  32. char *file, *format;
  33. char const * const * exports, * const * p;
  34. unsigned long int len;
  35. int x, y;
  36. exports = cucul_get_export_list();
  37. if(argc < 2 || argc > 3)
  38. {
  39. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  40. fprintf(stderr, "usage: %s [file] <format>\n", argv[0]);
  41. fprintf(stderr, "where <format> is one of:\n");
  42. for(p = exports; *p; p += 2)
  43. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  44. exit(-1);
  45. }
  46. if(argc == 2)
  47. {
  48. file = NULL;
  49. format = argv[1];
  50. }
  51. else
  52. {
  53. file = argv[1];
  54. format = argv[2];
  55. }
  56. for(p = exports; *p; p += 2)
  57. if(!strcasecmp(format, *p))
  58. break;
  59. if(!*p)
  60. {
  61. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], format);
  62. fprintf(stderr, "please use one of:\n");
  63. for(p = exports; *p; p += 2)
  64. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  65. exit(-1);
  66. }
  67. if(file)
  68. {
  69. cv = cucul_create_canvas(0, 0);
  70. if(cucul_import_file(cv, file, "") < 0)
  71. {
  72. fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
  73. exit(-1);
  74. }
  75. }
  76. else
  77. {
  78. cv = cucul_create_canvas(WIDTH, HEIGHT);
  79. for(y = 0; y < 256; y++)
  80. {
  81. for(x = 0; x < 256; x++)
  82. {
  83. uint32_t r = x;
  84. uint32_t g = (255 - y + x) / 2;
  85. uint32_t b = y * (255 - x) / 256;
  86. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  87. }
  88. }
  89. dither = cucul_create_dither(32, 256, 256, 4 * 256,
  90. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  91. if(!strcmp(format, "ansi") || !strcmp(format, "utf8"))
  92. cucul_set_dither_charset(dither, "shades");
  93. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  94. cucul_get_canvas_height(cv), dither, pixels);
  95. cucul_free_dither(dither);
  96. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLACK);
  97. cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  98. cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE);
  99. cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
  100. WIDTH / 4, HEIGHT / 4, " ");
  101. cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 5, "(\") \\o/ <&>");
  102. cucul_putstr(cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  103. cucul_putstr(cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  104. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  105. cucul_set_attr(cv, CUCUL_BOLD);
  106. cucul_putstr(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  107. cucul_set_attr(cv, CUCUL_BLINK);
  108. cucul_putstr(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  109. cucul_set_attr(cv, CUCUL_ITALICS);
  110. cucul_putstr(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  111. cucul_set_attr(cv, CUCUL_UNDERLINE);
  112. cucul_putstr(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  113. cucul_set_attr(cv, 0);
  114. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_LIGHTBLUE);
  115. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  116. for(x = 0; x < 16; x++)
  117. {
  118. cucul_set_color_argb(cv, 0xff00 | x, 0xf00f | (x << 4));
  119. cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
  120. }
  121. }
  122. buffer = cucul_export_memory(cv, format, &len);
  123. fwrite(buffer, len, 1, stdout);
  124. free(buffer);
  125. cucul_free_canvas(cv);
  126. return 0;
  127. }