… | |
… | |
2 | |
2 | |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
3 | #:META:X_RESOURCE:%.expr:string:background expression |
4 | #:META:X_RESOURCE:%.enable:boolean:some boolean |
4 | #:META:X_RESOURCE:%.enable:boolean:some boolean |
5 | #:META:X_RESOURCE:%.extra.:value:extra config |
5 | #:META:X_RESOURCE:%.extra.:value:extra config |
6 | |
6 | |
7 | our $EXPR = 'clip move X, Y, load "MagnoliaAlpha.png"'; |
7 | our $EXPR; |
|
|
8 | #$EXPR = 'move W * 0.1, -H * 0.1, resize W * 0.5, H * 0.5, repeat_none load "opensource.png"'; |
|
|
9 | $EXPR = 'border; move -X, -Y, load "argb.png"'; |
8 | #$EXPR = ' |
10 | #$EXPR = ' |
9 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
11 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
10 | # clip X, Y, W, H, repeat_mirror, |
12 | # clip X, Y, W, H, repeat_mirror, |
11 | # load "/root/pix/das_fette_schwein.jpg" |
13 | # load "/root/pix/das_fette_schwein.jpg" |
12 | #'; |
14 | #'; |
… | |
… | |
15 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
17 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
16 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
18 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
17 | |
19 | |
18 | use Safe; |
20 | use Safe; |
19 | |
21 | |
|
|
22 | our $border; |
20 | our ($bgdsl_self, $old, $new); |
23 | our ($bgdsl_self, $old, $new); |
21 | our ($l, $t, $w, $h); |
24 | our ($l, $t, $w, $h); |
22 | |
25 | |
23 | # enforce at least this interval between updates |
26 | # enforce at least this interval between updates |
24 | our $MIN_INTERVAL = 1/100; |
27 | our $MIN_INTERVAL = 1/100; |
… | |
… | |
80 | $bgdsl_self->{counter} + 0 |
83 | $bgdsl_self->{counter} + 0 |
81 | } |
84 | } |
82 | |
85 | |
83 | =back |
86 | =back |
84 | |
87 | |
85 | =head2 OPERATORS |
88 | =head2 TILING MODES |
|
|
89 | |
|
|
90 | The following operators modify the tiling mode of an image, that is, the |
|
|
91 | way that pixels outside the image area are painted when the image is used. |
86 | |
92 | |
87 | =over 4 |
93 | =over 4 |
88 | |
94 | |
89 | =cut |
95 | =item tile $img |
90 | |
96 | |
|
|
97 | Tiles the whole plane with the image and returns this new image - or in |
|
|
98 | other words, it returns a copy of the image in plane tiling mode. |
|
|
99 | |
|
|
100 | =item mirror $img |
|
|
101 | |
|
|
102 | Similar to tile, but reflects the image each time it uses a new copy, so |
|
|
103 | that top edges always touch top edges, right edges always touch right |
|
|
104 | edges and so on (with normal tiling, left edges always touch right edges |
|
|
105 | and top always touch bottom edges). |
|
|
106 | |
|
|
107 | =item pad $img |
|
|
108 | |
|
|
109 | Takes an image and modifies it so that all pixels outside the image area |
|
|
110 | become transparent. This mode is most useful when you want to place an |
|
|
111 | image over another image or the background colour while leaving all |
|
|
112 | background pixels outside the image unchanged. |
|
|
113 | |
|
|
114 | =item extend $img |
|
|
115 | |
|
|
116 | Extends the image over the whole plane, using the closest pixel in the |
|
|
117 | area outside the image. This mode is mostly useful when you more complex |
|
|
118 | filtering operations and want the pixels outside the image to have the |
|
|
119 | same values as the pixels near the edge. |
|
|
120 | |
|
|
121 | =cut |
|
|
122 | |
|
|
123 | sub pad($) { |
|
|
124 | my $img = $_[0]->clone; |
|
|
125 | $img->repeat_mode (urxvt::RepeatNone); |
|
|
126 | $img |
|
|
127 | } |
|
|
128 | |
|
|
129 | sub tile($) { |
|
|
130 | my $img = $_[0]->clone; |
|
|
131 | $img->repeat_mode (urxvt::RepeatNormal); |
|
|
132 | $img |
|
|
133 | } |
|
|
134 | |
|
|
135 | sub mirror($) { |
|
|
136 | my $img = $_[0]->clone; |
|
|
137 | $img->repeat_mode (urxvt::RepeatReflect); |
|
|
138 | $img |
|
|
139 | } |
|
|
140 | |
|
|
141 | sub extend($) { |
|
|
142 | my $img = $_[0]->clone; |
|
|
143 | $img->repeat_mode (urxvt::RepeatPad); |
|
|
144 | $img |
|
|
145 | } |
|
|
146 | |
|
|
147 | =back |
|
|
148 | |
|
|
149 | =head2 PIXEL OPERATORS |
|
|
150 | |
|
|
151 | The following operators modify the image pixels in various ways. |
|
|
152 | |
|
|
153 | =over 4 |
|
|
154 | |
|
|
155 | =item clone $img |
|
|
156 | |
|
|
157 | Returns an exact copy of the image. |
|
|
158 | |
|
|
159 | =cut |
|
|
160 | |
91 | # sub clone($) { |
161 | sub clone($) { |
92 | # $_[0]->clone |
162 | $_[0]->clone |
93 | # } |
163 | } |
|
|
164 | |
|
|
165 | =item clip $img |
|
|
166 | |
|
|
167 | =item clip $width, $height, $img |
|
|
168 | |
|
|
169 | =item clip $x, $y, $width, $height, $img |
|
|
170 | |
|
|
171 | Clips an image to the given rectangle. If the rectangle is outside the |
|
|
172 | image area (e.g. when C<$x> or C<$y> are negative) or the rectangle is |
|
|
173 | larger than the image, then the tiling mode defines how the extra pixels |
|
|
174 | will be filled. |
|
|
175 | |
|
|
176 | If C<$x> an C<$y> are missing, then C<0> is assumed for both. |
|
|
177 | |
|
|
178 | If C<$width> and C<$height> are missing, then the window size will be |
|
|
179 | assumed. |
|
|
180 | |
|
|
181 | Example: load an image, blur it, and clip it to the window size to save |
|
|
182 | memory. |
|
|
183 | |
|
|
184 | clip blur 10, load "mybg.png" |
|
|
185 | |
|
|
186 | =cut |
94 | |
187 | |
95 | sub clip($;$$;$$) { |
188 | sub clip($;$$;$$) { |
96 | my $img = pop; |
189 | my $img = pop; |
97 | my $h = pop || H; |
190 | my $h = pop || H; |
98 | my $w = pop || W; |
191 | my $w = pop || W; |
99 | $img->sub_rect ($_[0], $_[1], $w, $h) |
192 | $img->sub_rect ($_[0], $_[1], $w, $h) |
|
|
193 | } |
|
|
194 | |
|
|
195 | =item scale $img |
|
|
196 | |
|
|
197 | =item scale $size_percent, $img |
|
|
198 | |
|
|
199 | =item scale $width_percent, $height_percent, $img |
|
|
200 | |
|
|
201 | Scales the image by the given percentages in horizontal |
|
|
202 | (C<$width_percent>) and vertical (C<$height_percent>) direction. |
|
|
203 | |
|
|
204 | If only one percentage is give, it is used for both directions. |
|
|
205 | |
|
|
206 | If no percentages are given, scales the image to the window size without |
|
|
207 | keeping aspect. |
|
|
208 | |
|
|
209 | =item resize $width, $height, $img |
|
|
210 | |
|
|
211 | Resizes the image to exactly C<$width> times C<$height> pixels. |
|
|
212 | |
|
|
213 | =cut |
|
|
214 | |
|
|
215 | #TODO: maximise, maximise_fill? |
|
|
216 | |
|
|
217 | sub scale($$$) { |
|
|
218 | my $img = pop; |
|
|
219 | |
|
|
220 | @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) |
|
|
221 | : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) |
|
|
222 | : $img->scale (W, H) |
100 | } |
223 | } |
101 | |
224 | |
102 | sub resize($$$) { |
225 | sub resize($$$) { |
103 | my $img = pop; |
226 | my $img = pop; |
104 | $img->scale ($_[0], $_[1]) |
227 | $img->scale ($_[0], $_[1]) |
… | |
… | |
126 | $_[3] * $img->h * .01, |
249 | $_[3] * $img->h * .01, |
127 | $_[4] * (3.14159265 / 180), |
250 | $_[4] * (3.14159265 / 180), |
128 | ) |
251 | ) |
129 | } |
252 | } |
130 | |
253 | |
131 | sub blur($$$) { |
254 | sub blur($$;$) { |
132 | my ($rh, $rv, $img) = @_; |
255 | my $img = pop; |
133 | |
256 | |
134 | $img->blur ($rh, $rv); |
257 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]); |
135 | } |
258 | } |
136 | |
259 | |
137 | sub contrast($$;$$;$) { |
260 | sub contrast($$;$$;$) { |
138 | my $img = pop; |
261 | my $img = pop; |
139 | my ($r, $g, $b, $a) = @_; |
262 | my ($r, $g, $b, $a) = @_; |
… | |
… | |
154 | $a = 1 if @_ < 5; |
277 | $a = 1 if @_ < 5; |
155 | |
278 | |
156 | $img = $img->clone; |
279 | $img = $img->clone; |
157 | $img->brightness ($r, $g, $b, $a); |
280 | $img->brightness ($r, $g, $b, $a); |
158 | $img |
281 | $img |
|
|
282 | } |
|
|
283 | |
|
|
284 | =back |
|
|
285 | |
|
|
286 | =head2 SETTINGS |
|
|
287 | |
|
|
288 | =over 4 |
|
|
289 | |
|
|
290 | =item border $respect_border=1 |
|
|
291 | |
|
|
292 | Sets whether the image should respect the terminal border (argument true |
|
|
293 | or missing), or whether it should fill the whole window (the default). |
|
|
294 | |
|
|
295 | By default, the image will cover the whole toplevel window. If C<border> |
|
|
296 | is enabled, then it will only fill the character area and leave a normal |
|
|
297 | border in the background colour around it and behind the scrollbar. |
|
|
298 | |
|
|
299 | =cut |
|
|
300 | |
|
|
301 | sub border { |
|
|
302 | $border = @_ ? $_[0] : 1; |
159 | } |
303 | } |
160 | |
304 | |
161 | =back |
305 | =back |
162 | |
306 | |
163 | =cut |
307 | =cut |
… | |
… | |
194 | $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
338 | $self->{next_refresh} = urxvt::NOW + $MIN_INTERVAL; |
195 | |
339 | |
196 | # set environment to evaluate user expression |
340 | # set environment to evaluate user expression |
197 | |
341 | |
198 | local $bgdsl_self = $self; |
342 | local $bgdsl_self = $self; |
|
|
343 | local $border; |
199 | |
344 | |
200 | local $old = $self->{state}; |
345 | local $old = $self->{state}; |
201 | local $new = my $state = $self->{state} = {}; |
346 | local $new = my $state = $self->{state} = {}; |
202 | |
347 | |
203 | ($l, $t, $w, $h) = |
348 | ($l, $t, $w, $h) = |
… | |
… | |
258 | # prepare and set background pixmap |
403 | # prepare and set background pixmap |
259 | |
404 | |
260 | $img = $img->sub_rect (0, 0, $w, $h) |
405 | $img = $img->sub_rect (0, 0, $w, $h) |
261 | if $img->w != $w || $img->h != $h; |
406 | if $img->w != $w || $img->h != $h; |
262 | |
407 | |
263 | $self->set_background ($img); |
408 | $self->set_background ($img, $border); |
264 | $self->scr_recolour (0); |
409 | $self->scr_recolour (0); |
265 | $self->want_refresh; |
410 | $self->want_refresh; |
266 | } |
411 | } |
267 | |
412 | |
268 | sub on_start { |
413 | sub on_start { |