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.
 
 
 
 
 
 

114 rivejä
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_canvas_t *cv;
  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. cv = cucul_create_canvas(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(cv, 0, 0, cucul_get_canvas_width(cv),
  70. cucul_get_canvas_height(cv), dither, pixels);
  71. cucul_free_dither(dither);
  72. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
  73. cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  74. cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
  75. cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
  76. cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
  77. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  78. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
  79. cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  80. for(x = 0; x < 16; x++)
  81. {
  82. cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4));
  83. cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
  84. }
  85. buffer = cucul_export_canvas(cv, argv[1]);
  86. fwrite(cucul_get_buffer_data(buffer),
  87. cucul_get_buffer_size(buffer), 1, stdout);
  88. cucul_free_buffer(buffer);
  89. cucul_free_canvas(cv);
  90. return 0;
  91. }