Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

75 рядки
1.7 KiB

  1. /*
  2. * pic2irc image to IRC converter
  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(__KERNEL__)
  16. # include <stdio.h>
  17. # include <string.h>
  18. # include <stdlib.h>
  19. #endif
  20. #include "cucul.h"
  21. #include "common-image.h"
  22. int main(int argc, char **argv)
  23. {
  24. /* libcucul context */
  25. cucul_canvas_t *cv;
  26. cucul_buffer_t *export;
  27. struct image *i;
  28. int cols = 56, lines;
  29. if(argc != 2)
  30. {
  31. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  32. return 1;
  33. }
  34. cv = cucul_create_canvas(0, 0);
  35. if(!cv)
  36. {
  37. fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
  38. return 1;
  39. }
  40. i = load_image(argv[1]);
  41. if(!i)
  42. {
  43. fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]);
  44. cucul_free_canvas(cv);
  45. return 1;
  46. }
  47. /* Assume a 6×10 font */
  48. lines = cols * i->h * 6 / i->w / 10;
  49. cucul_set_canvas_size(cv, cols, lines);
  50. cucul_set_color(cv, CUCUL_COLOR_DEFAULT, CUCUL_COLOR_TRANSPARENT);
  51. cucul_clear_canvas(cv);
  52. cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels);
  53. unload_image(i);
  54. export = cucul_export_canvas(cv, "irc");
  55. fwrite(cucul_get_buffer_data(export),
  56. cucul_get_buffer_size(export), 1, stdout);
  57. cucul_free_buffer(export);
  58. cucul_free_canvas(cv);
  59. return 0;
  60. }