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.
 
 
 
 
 
 

144 lines
3.8 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(HAVE_INTTYPES_H)
  16. # include <inttypes.h>
  17. #endif
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "cucul.h"
  22. #define WIDTH 60
  23. #define HEIGHT 32
  24. uint32_t pixels[256*256];
  25. int main(int argc, char *argv[])
  26. {
  27. cucul_canvas_t *cv;
  28. cucul_dither_t *dither;
  29. cucul_buffer_t *buffer;
  30. char *file, *format;
  31. char const * const * exports, * const * p;
  32. int x, y;
  33. exports = cucul_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. cucul_buffer_t *tmp;
  67. tmp = cucul_load_file(file);
  68. if(!tmp)
  69. {
  70. fprintf(stderr, "%s: could not load `%s'\n", argv[0], file);
  71. exit(-1);
  72. }
  73. cv = cucul_import_canvas(tmp, "");
  74. if(!tmp)
  75. {
  76. fprintf(stderr, "%s: `%s' has unknown format\n", argv[0], file);
  77. exit(-1);
  78. }
  79. cucul_free_buffer(tmp);
  80. }
  81. else
  82. {
  83. cv = cucul_create_canvas(WIDTH, HEIGHT);
  84. for(y = 0; y < 256; y++)
  85. {
  86. for(x = 0; x < 256; x++)
  87. {
  88. uint32_t r = x;
  89. uint32_t g = (255 - y + x) / 2;
  90. uint32_t b = y * (255 - x) / 256;
  91. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  92. }
  93. }
  94. dither = cucul_create_dither(32, 256, 256, 4 * 256,
  95. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  96. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  97. cucul_get_canvas_height(cv), dither, pixels);
  98. cucul_free_dither(dither);
  99. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  100. cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  101. cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
  102. cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2,
  103. WIDTH / 4, HEIGHT / 4, " ");
  104. cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
  105. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  106. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
  107. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  108. for(x = 0; x < 16; x++)
  109. {
  110. cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4));
  111. cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
  112. }
  113. }
  114. buffer = cucul_export_canvas(cv, format);
  115. fwrite(cucul_get_buffer_data(buffer),
  116. cucul_get_buffer_size(buffer), 1, stdout);
  117. cucul_free_buffer(buffer);
  118. cucul_free_canvas(cv);
  119. return 0;
  120. }