Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

110 righe
3.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; 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. enum cucul_format format;
  32. struct cucul_bitmap *bitmap;
  33. struct cucul_buffer *buffer;
  34. int x, y;
  35. if(argc != 2)
  36. {
  37. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  38. fprintf(stderr, "usage: %s <format>\n", argv[0]);
  39. fprintf(stderr, "where <format> is one of: ansi, html, html3, irc, ps, svg\n");
  40. exit(-1);
  41. }
  42. if(!strcasecmp(argv[1], "ansi"))
  43. format = CUCUL_FORMAT_ANSI;
  44. else if(!strcasecmp(argv[1], "html"))
  45. format = CUCUL_FORMAT_HTML;
  46. else if(!strcasecmp(argv[1], "html3"))
  47. format = CUCUL_FORMAT_HTML3;
  48. else if(!strcasecmp(argv[1], "irc"))
  49. format = CUCUL_FORMAT_IRC;
  50. else if(!strcasecmp(argv[1], "ps"))
  51. format = CUCUL_FORMAT_PS;
  52. else if(!strcasecmp(argv[1], "svg"))
  53. format = CUCUL_FORMAT_SVG;
  54. else
  55. {
  56. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
  57. exit(-1);
  58. }
  59. qq = cucul_init();
  60. cucul_set_size(qq, WIDTH, HEIGHT);
  61. for(y = 0; y < 256; y++)
  62. {
  63. for(x = 0; x < 256; x++)
  64. {
  65. uint32_t r = x;
  66. uint32_t g = (255 - y + x) / 2;
  67. uint32_t b = y * (255 - x) / 256;
  68. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  69. }
  70. }
  71. bitmap = cucul_create_bitmap(qq, 32, 256, 256, 4 * 256,
  72. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  73. cucul_draw_bitmap(qq, 0, 0,
  74. cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
  75. bitmap, pixels);
  76. cucul_free_bitmap(qq, bitmap);
  77. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  78. cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1);
  79. cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
  80. cucul_fill_ellipse(qq, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, ' ');
  81. cucul_putstr(qq, WIDTH / 2 - 1, HEIGHT / 2 - 4, "\\o/");
  82. cucul_putstr(qq, WIDTH / 2 - 1, HEIGHT / 2 + 4, "\\o/");
  83. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
  84. cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  85. buffer = cucul_export(qq, format);
  86. fwrite(buffer->buffer, buffer->size, 1, stdout);
  87. cucul_free(buffer);
  88. cucul_end(qq);
  89. return 0;
  90. }