Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

93 wiersze
2.2 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. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. #include "config.h"
  15. #include "common.h"
  16. #if !defined(__KERNEL__)
  17. # include <stdio.h>
  18. # include <string.h>
  19. # include <stdlib.h>
  20. #endif
  21. #include "cucul.h"
  22. #include "common-image.h"
  23. static void usage(int argc, char **argv)
  24. {
  25. fprintf(stderr, "Usage: %s <image>\n", argv[0]);
  26. fprintf(stderr, " %s <image> <columns>\n", argv[0]);
  27. fprintf(stderr, " %s [-h|--help]\n", argv[0]);
  28. }
  29. int main(int argc, char **argv)
  30. {
  31. /* libcucul context */
  32. cucul_canvas_t *cv;
  33. void *export;
  34. unsigned long int len;
  35. struct image *i;
  36. int cols, lines;
  37. if(argc < 2 || argc > 3)
  38. {
  39. fprintf(stderr, "%s: wrong argument count\n", argv[0]);
  40. usage(argc, argv);
  41. return 1;
  42. }
  43. if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
  44. {
  45. fprintf(stderr, "%s: convert images to IRC file data\n", argv[0]);
  46. usage(argc, argv);
  47. return 0;
  48. }
  49. cv = cucul_create_canvas(0, 0);
  50. if(!cv)
  51. {
  52. fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
  53. return 1;
  54. }
  55. i = load_image(argv[1]);
  56. if(!i)
  57. {
  58. fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]);
  59. cucul_free_canvas(cv);
  60. return 1;
  61. }
  62. /* Assume a 6×10 font */
  63. cols = argc == 3 ? atoi(argv[2]) : 0;
  64. cols = cols ? cols : 60;
  65. lines = cols * i->h * 6 / i->w / 10;
  66. cucul_set_canvas_size(cv, cols, lines);
  67. cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
  68. cucul_clear_canvas(cv);
  69. cucul_dither_bitmap(cv, 0, 0, cols, lines, i->dither, i->pixels);
  70. unload_image(i);
  71. export = cucul_export_memory(cv, "irc", &len);
  72. fwrite(export, len, 1, stdout);
  73. free(export);
  74. cucul_free_canvas(cv);
  75. return 0;
  76. }