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