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.
 
 
 
 
 
 

130 lines
3.2 KiB

  1. /*
  2. * TOIlet The Other Implementation’s letters
  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. /*
  14. * This file contains post-processing filter functions.
  15. */
  16. #include "config.h"
  17. #if defined(HAVE_INTTYPES_H)
  18. # include <inttypes.h>
  19. #endif
  20. #include <cucul.h>
  21. #include "filters.h"
  22. void filter_autocrop(cucul_canvas_t *cv)
  23. {
  24. unsigned int x, y, w, h;
  25. unsigned int xmin, xmax, ymin, ymax;
  26. xmin = w = cucul_get_canvas_width(cv);
  27. xmax = 0;
  28. ymin = h = cucul_get_canvas_height(cv);
  29. ymax = 0;
  30. for(y = 0; y < h; y++)
  31. for(x = 0; x < w; x++)
  32. {
  33. unsigned long int ch = cucul_getchar(cv, x, y);
  34. if(ch != (unsigned char)' ')
  35. {
  36. if(x < xmin)
  37. xmin = x;
  38. if(x > xmax)
  39. xmax = x;
  40. if(y < ymin)
  41. ymin = y;
  42. if(y > ymax)
  43. ymax = y;
  44. }
  45. }
  46. if(xmax < xmin || ymax < ymin)
  47. return;
  48. cucul_set_canvas_boundaries(cv, xmin, ymin,
  49. xmax - xmin + 1, ymax - ymin + 1);
  50. }
  51. void filter_metal(cucul_canvas_t *cv)
  52. {
  53. static struct
  54. {
  55. char ch[6];
  56. unsigned char fg, bg;
  57. }
  58. const palette[] =
  59. {
  60. { " ", CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_LIGHTBLUE },
  61. { "░", CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE },
  62. { "▒", CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE },
  63. { "░", CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLUE },
  64. { " ", CUCUL_COLOR_BLUE, CUCUL_COLOR_BLUE },
  65. { " ", CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_LIGHTGRAY },
  66. { "░", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY },
  67. { "▒", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY },
  68. { "░", CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY },
  69. { " ", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_DARKGRAY },
  70. };
  71. unsigned int x, y, w, h;
  72. w = cucul_get_canvas_width(cv);
  73. h = cucul_get_canvas_height(cv);
  74. for(y = 0; y < h; y++)
  75. for(x = 0; x < w; x++)
  76. {
  77. int i;
  78. if(cucul_getchar(cv, x, y) == (unsigned char)' ')
  79. continue;
  80. i = y * 10 / h;
  81. cucul_set_color(cv, palette[i].fg, palette[i].bg);
  82. cucul_putstr(cv, x, y, palette[i].ch);
  83. }
  84. }
  85. void filter_gay(cucul_canvas_t *cv)
  86. {
  87. static unsigned char const rainbow[] =
  88. {
  89. CUCUL_COLOR_LIGHTMAGENTA,
  90. CUCUL_COLOR_LIGHTRED,
  91. CUCUL_COLOR_YELLOW,
  92. CUCUL_COLOR_LIGHTGREEN,
  93. CUCUL_COLOR_LIGHTCYAN,
  94. CUCUL_COLOR_LIGHTBLUE,
  95. };
  96. unsigned int x, y, w, h;
  97. w = cucul_get_canvas_width(cv);
  98. h = cucul_get_canvas_height(cv);
  99. for(y = 0; y < h; y++)
  100. for(x = 0; x < w; x++)
  101. {
  102. unsigned long int ch = cucul_getchar(cv, x, y);
  103. if(ch != (unsigned char)' ')
  104. {
  105. cucul_set_color(cv, rainbow[(x / 2 + y) % 6],
  106. CUCUL_COLOR_TRANSPARENT);
  107. cucul_putchar(cv, x, y, ch);
  108. }
  109. }
  110. }