… | |
… | |
70 | } else { |
70 | } else { |
71 | return scale load "$HOME/sunday.png"; |
71 | return scale load "$HOME/sunday.png"; |
72 | } |
72 | } |
73 | |
73 | |
74 | This expression gets evaluated once per hour. It will set F<sunday.png> as |
74 | This expression gets evaluated once per hour. It will set F<sunday.png> as |
75 | background on sundays, and F<weekday.png> on all other days. |
75 | background on Sundays, and F<weekday.png> on all other days. |
76 | |
76 | |
77 | Fortunately, we expect that most expressions will be much simpler, with |
77 | Fortunately, we expect that most expressions will be much simpler, with |
78 | little Perl knowledge needed. |
78 | little Perl knowledge needed. |
79 | |
79 | |
80 | Basically, you always start with a function that "generates" an image |
80 | Basically, you always start with a function that "generates" an image |
… | |
… | |
112 | horizontal and vertical dimensions. For example, this halves the image |
112 | horizontal and vertical dimensions. For example, this halves the image |
113 | width and doubles the image height: |
113 | width and doubles the image height: |
114 | |
114 | |
115 | scale 50, 200, load "$HOME/mypic.png" |
115 | scale 50, 200, load "$HOME/mypic.png" |
116 | |
116 | |
117 | TODO |
117 | Other effects than scalign are also readily available, for exmaple, you can |
|
|
118 | tile the image to fill the whole window, instead of resizing it: |
|
|
119 | |
|
|
120 | tile load "$HOME/mypic.png" |
|
|
121 | |
|
|
122 | In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator |
|
|
123 | is kind of superfluous. |
|
|
124 | |
|
|
125 | Another common effect is to mirror the image, so that the same edges touch: |
|
|
126 | |
|
|
127 | mirror load "$HOME/mypic.png" |
|
|
128 | |
|
|
129 | This is also a typical background expression: |
|
|
130 | |
|
|
131 | rootalign root |
|
|
132 | |
|
|
133 | It first takes a snapshot of the screen background image, and then |
|
|
134 | moves it to the upper left corner of the screen - the result is |
|
|
135 | pseudo-transparency, as the image seems to be static while the window is |
|
|
136 | moved around. |
118 | |
137 | |
119 | =head3 CYCLES AND CACHING |
138 | =head3 CYCLES AND CACHING |
120 | |
139 | |
121 | TODO |
140 | As has been mentioned before, the expression might be evaluated multiple |
122 | |
|
|
123 | Each time the expression is reevaluated, a new cycle is said to have begun. Many operators |
141 | times. Each time the expression is reevaluated, a new cycle is said to |
124 | cache their results till the next cycle. For example |
142 | have begun. Many operators cache their results till the next cycle. |
|
|
143 | |
|
|
144 | For example, the C<load> operator keeps a copy of the image. If it is |
|
|
145 | asked to load the same image on the next cycle it will not load it again, |
|
|
146 | but return the cached copy. |
|
|
147 | |
|
|
148 | This only works for one cycle though, so as long as you load the same |
|
|
149 | image every time, it will always be cached, but when you load a different |
|
|
150 | image, it will forget about the first one. |
|
|
151 | |
|
|
152 | This allows you to either speed things up by keeping multiple images in |
|
|
153 | memory, or comserve memory by loading images more often. |
|
|
154 | |
|
|
155 | For example, you can keep two images in memory and use a random one like |
|
|
156 | this: |
|
|
157 | |
|
|
158 | my $img1 = load "img1.png"; |
|
|
159 | my $img2 = load "img2.png"; |
|
|
160 | (0.5 > rand) ? $img1 : $img2 |
|
|
161 | |
|
|
162 | Since both images are "loaded" every time the expression is evaluated, |
|
|
163 | they are always kept in memory. Contrast this version: |
|
|
164 | |
|
|
165 | my $path1 = "img1.png"; |
|
|
166 | my $path2 = "img2.png"; |
|
|
167 | load ((0.5 > rand) ? $path1 : $path2) |
|
|
168 | |
|
|
169 | Here, a path is selected randomly, and load is only called for one image, |
|
|
170 | so keeps only one image in memory. If, on the next evaluation, luck |
|
|
171 | decides to use the other path, then it will have to load that image again. |
125 | |
172 | |
126 | =head2 REFERENCE |
173 | =head2 REFERENCE |
127 | |
174 | |
128 | =head3 COMMAND LINE SWITCHES |
175 | =head3 COMMAND LINE SWITCHES |
129 | |
176 | |
… | |
… | |
142 | replaces the background of the character area. |
189 | replaces the background of the character area. |
143 | |
190 | |
144 | =back |
191 | =back |
145 | |
192 | |
146 | =cut |
193 | =cut |
147 | |
|
|
148 | our $EXPR;#d# |
|
|
149 | #$EXPR = 'move W * 0.1, -H * 0.1, resize W * 0.5, H * 0.5, repeat_none load "opensource.png"'; |
|
|
150 | $EXPR = 'move -TX, -TY, load "argb.png"'; |
|
|
151 | #$EXPR = ' |
|
|
152 | # rotate W, H, 50, 50, counter 1/59.95, repeat_mirror, |
|
|
153 | # clip X, Y, W, H, repeat_mirror, |
|
|
154 | # load "/root/pix/das_fette_schwein.jpg" |
|
|
155 | #'; |
|
|
156 | #$EXPR = 'solid "red"'; |
|
|
157 | #$EXPR = 'blur root, 10, 10' |
|
|
158 | #$EXPR = 'blur move (root, -x, -y), 5, 5' |
|
|
159 | #resize load "/root/pix/das_fette_schwein.jpg", w, h |
|
|
160 | |
194 | |
161 | our $HOME; |
195 | our $HOME; |
162 | our ($self, $old, $new); |
196 | our ($self, $old, $new); |
163 | our ($x, $y, $w, $h); |
197 | our ($x, $y, $w, $h); |
164 | |
198 | |
… | |
… | |
211 | =item solid $width, $height, $colour |
245 | =item solid $width, $height, $colour |
212 | |
246 | |
213 | Creates a new image and completely fills it with the given colour. The |
247 | Creates a new image and completely fills it with the given colour. The |
214 | image is set to tiling mode. |
248 | image is set to tiling mode. |
215 | |
249 | |
216 | If <$width> and C<$height> are omitted, it creates a 1x1 image, which is |
250 | If C<$width> and C<$height> are omitted, it creates a 1x1 image, which is |
217 | useful for solid backgrounds or for use in filtering effects. |
251 | useful for solid backgrounds or for use in filtering effects. |
218 | |
252 | |
219 | =cut |
253 | =cut |
220 | |
254 | |
221 | sub solid($$;$) { |
255 | sub solid($$;$) { |
… | |
… | |
520 | |
554 | |
521 | =item contrast $r, $g, $b, $a, $img |
555 | =item contrast $r, $g, $b, $a, $img |
522 | |
556 | |
523 | Adjusts the I<contrast> of an image. |
557 | Adjusts the I<contrast> of an image. |
524 | |
558 | |
|
|
559 | #TODO# |
|
|
560 | |
525 | =item brightness $factor, $img |
561 | =item brightness $factor, $img |
526 | |
562 | |
527 | =item brightness $r, $g, $b, $img |
563 | =item brightness $r, $g, $b, $img |
528 | |
564 | |
529 | =item brightness $r, $g, $b, $a, $img |
565 | =item brightness $r, $g, $b, $a, $img |
|
|
566 | |
|
|
567 | Adjusts the brightness of an image. |
530 | |
568 | |
531 | =cut |
569 | =cut |
532 | |
570 | |
533 | sub contrast($$;$$;$) { |
571 | sub contrast($$;$$;$) { |
534 | my $img = pop; |
572 | my $img = pop; |
… | |
… | |
536 | |
574 | |
537 | ($g, $b) = ($r, $r) if @_ < 4; |
575 | ($g, $b) = ($r, $r) if @_ < 4; |
538 | $a = 1 if @_ < 5; |
576 | $a = 1 if @_ < 5; |
539 | |
577 | |
540 | $img = $img->clone; |
578 | $img = $img->clone; |
541 | # $img->contrast ($r, $g, $b, $a); |
579 | $img->contrast ($r, $g, $b, $a); |
542 | $img |
580 | $img |
543 | } |
581 | } |
544 | |
582 | |
545 | sub brightness($$;$$;$) { |
583 | sub brightness($$;$$;$) { |
546 | my $img = pop; |
584 | my $img = pop; |
… | |
… | |
552 | $img = $img->clone; |
590 | $img = $img->clone; |
553 | $img->brightness ($r, $g, $b, $a); |
591 | $img->brightness ($r, $g, $b, $a); |
554 | $img |
592 | $img |
555 | } |
593 | } |
556 | |
594 | |
|
|
595 | =item blur $radius, $img |
|
|
596 | |
|
|
597 | =item blur $radius_horz, $radius_vert, $img |
|
|
598 | |
|
|
599 | Gaussian-blurs the image with (roughly) C<$radius> pixel radius. The radii |
|
|
600 | can also be specified separately. |
|
|
601 | |
|
|
602 | Blurring is often I<very> slow, at least compared or other |
|
|
603 | operators. Larger blur radii are slower than smaller ones, too, so if you |
|
|
604 | don't want to freeze your screen for long times, start experimenting with |
|
|
605 | low values for radius (<5). |
|
|
606 | |
|
|
607 | =cut |
|
|
608 | |
557 | sub blur($$;$) { |
609 | sub blur($$;$) { |
558 | my $img = pop; |
610 | my $img = pop; |
559 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
611 | $img->blur ($_[0], @_ >= 2 ? $_[1] : $_[0]) |
560 | } |
612 | } |
|
|
613 | |
|
|
614 | =item rotate $new_width, $new_height, $center_x, $center_y, $degrees |
|
|
615 | |
|
|
616 | Rotates the image by C<$degrees> degrees, counter-clockwise, around the |
|
|
617 | pointer at C<$center_x> and C<$center_y> (specified as percentage of image |
|
|
618 | width/height), generating a new image with width C<$new_width> and height |
|
|
619 | C<$new_height>. |
|
|
620 | |
|
|
621 | #TODO# new width, height, maybe more operators? |
|
|
622 | |
|
|
623 | Example: rotate the image by 90 degrees |
|
|
624 | |
|
|
625 | =cut |
561 | |
626 | |
562 | sub rotate($$$$$$) { |
627 | sub rotate($$$$$$) { |
563 | my $img = pop; |
628 | my $img = pop; |
564 | $img->rotate ( |
629 | $img->rotate ( |
565 | $_[0], |
630 | $_[0], |