Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

111 linhas
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. #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 const * const * exports, * const * p;
  31. int x, y;
  32. exports = cucul_get_export_list();
  33. if(argc != 2)
  34. {
  35. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  36. fprintf(stderr, "usage: %s <format>\n", argv[0]);
  37. fprintf(stderr, "where <format> is one of:\n");
  38. for(p = exports; *p; p += 2)
  39. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  40. exit(-1);
  41. }
  42. for(p = exports; *p; p += 2)
  43. if(!strcasecmp(argv[1], *p))
  44. break;
  45. if(!*p)
  46. {
  47. fprintf(stderr, "%s: unknown format `%s'\n", argv[0], argv[1]);
  48. fprintf(stderr, "please use one of:\n");
  49. for(p = exports; *p; p += 2)
  50. fprintf(stderr, " \"%s\" (%s)\n", *p, *(p + 1));
  51. exit(-1);
  52. }
  53. cv = cucul_create_canvas(WIDTH, HEIGHT);
  54. for(y = 0; y < 256; y++)
  55. {
  56. for(x = 0; x < 256; x++)
  57. {
  58. uint32_t r = x;
  59. uint32_t g = (255 - y + x) / 2;
  60. uint32_t b = y * (255 - x) / 256;
  61. pixels[y * 256 + x] = (r << 16) | (g << 8) | (b << 0);
  62. }
  63. }
  64. dither = cucul_create_dither(32, 256, 256, 4 * 256,
  65. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  66. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  67. cucul_get_canvas_height(cv), dither, pixels);
  68. cucul_free_dither(dither);
  69. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  70. cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  71. cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
  72. cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
  73. cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
  74. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  75. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
  76. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  77. for(x = 0; x < 16; x++)
  78. {
  79. cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4));
  80. cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
  81. }
  82. buffer = cucul_export_canvas(cv, argv[1]);
  83. fwrite(cucul_get_buffer_data(buffer),
  84. cucul_get_buffer_size(buffer), 1, stdout);
  85. cucul_free_buffer(buffer);
  86. cucul_free_canvas(cv);
  87. return 0;
  88. }