No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

export.c 2.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. struct cucul_bitmap *bitmap;
  32. struct cucul_export *buffer;
  33. int x, y;
  34. if(argc != 2)
  35. {
  36. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  37. fprintf(stderr, "usage: %s <format>\n", argv[0]);
  38. fprintf(stderr, "where <format> is one of: ansi, html, html3, irc, ps, svg\n");
  39. exit(-1);
  40. }
  41. if(strcasecmp(argv[1], "ansi")
  42. && strcasecmp(argv[1], "html")
  43. && strcasecmp(argv[1], "html3")
  44. && strcasecmp(argv[1], "irc")
  45. && strcasecmp(argv[1], "ps")
  46. && strcasecmp(argv[1], "svg"))
  47. {
  48. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
  49. exit(-1);
  50. }
  51. qq = cucul_create(0, 0);
  52. cucul_set_size(qq, WIDTH, HEIGHT);
  53. for(y = 0; y < 256; y++)
  54. {
  55. for(x = 0; x < 256; x++)
  56. {
  57. uint32_t r = x;
  58. uint32_t g = (255 - y + x) / 2;
  59. uint32_t b = y * (255 - x) / 256;
  60. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  61. }
  62. }
  63. bitmap = cucul_create_bitmap(32, 256, 256, 4 * 256,
  64. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  65. cucul_draw_bitmap(qq, 0, 0,
  66. cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
  67. bitmap, pixels);
  68. cucul_free_bitmap(bitmap);
  69. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  70. cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1);
  71. cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
  72. cucul_fill_ellipse(qq, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
  73. cucul_putstr(qq, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
  74. cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  75. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
  76. cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  77. buffer = cucul_create_export(qq, argv[1]);
  78. fwrite(buffer->buffer, buffer->size - 1, 1, stdout);
  79. cucul_free_export(buffer);
  80. cucul_free(qq);
  81. return 0;
  82. }