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.
 
 
 
 
 
 

115 lines
3.1 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. #if defined(HAVE_INTTYPES_H)
  15. # include <inttypes.h>
  16. #else
  17. typedef unsigned char uint8_t;
  18. typedef unsigned short uint16_t;
  19. typedef unsigned int uint32_t;
  20. #endif
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include "cucul.h"
  25. #define WIDTH 60
  26. #define HEIGHT 32
  27. uint32_t pixels[256*256];
  28. int main(int argc, char *argv[])
  29. {
  30. cucul_t *qq;
  31. cucul_dither_t *dither;
  32. cucul_buffer_t *buffer;
  33. char const * const * exports, * const * p;
  34. int x, y;
  35. exports = cucul_get_export_list();
  36. if(argc != 2)
  37. {
  38. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  39. fprintf(stderr, "usage: %s <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. for(p = exports; *p; p += 2)
  46. if(!strcasecmp(argv[1], *p))
  47. break;
  48. if(!*p)
  49. {
  50. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
  51. fprintf(stderr, "please use one of:\n");
  52. for(p = exports; *p; p += 2)
  53. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  54. exit(-1);
  55. }
  56. qq = cucul_create(WIDTH, HEIGHT);
  57. for(y = 0; y < 256; y++)
  58. {
  59. for(x = 0; x < 256; x++)
  60. {
  61. uint32_t r = x;
  62. uint32_t g = (255 - y + x) / 2;
  63. uint32_t b = y * (255 - x) / 256;
  64. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  65. }
  66. }
  67. dither = cucul_create_dither(32, 256, 256, 4 * 256,
  68. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  69. cucul_dither_bitmap(qq, 0, 0,
  70. cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
  71. dither, pixels);
  72. cucul_free_dither(dither);
  73. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  74. cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1);
  75. cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
  76. cucul_fill_ellipse(qq, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
  77. cucul_putstr(qq, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
  78. cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  79. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
  80. cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  81. for(x = 0; x < 16; x++)
  82. {
  83. cucul_set_truecolor(qq, 0xff00 | x, 0xf00f | (x << 4));
  84. cucul_putstr(qq, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
  85. }
  86. buffer = cucul_create_export(qq, argv[1]);
  87. fwrite(cucul_get_buffer_data(buffer),
  88. cucul_get_buffer_size(buffer), 1, stdout);
  89. cucul_free_buffer(buffer);
  90. cucul_free(qq);
  91. return 0;
  92. }