ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/background
(Generate patch)

Comparing rxvt-unicode/src/perl/background (file contents):
Revision 1.36 by root, Fri Jun 8 20:23:09 2012 UTC vs.
Revision 1.40 by root, Fri Jun 8 22:19:21 2012 UTC

70 } else { 70 } else {
71 return scale load "$HOME/sunday.png"; 71 return scale load "$HOME/sunday.png";
72 } 72 }
73 73
74This expression gets evaluated once per hour. It will set F<sunday.png> as 74This expression gets evaluated once per hour. It will set F<sunday.png> as
75background on sundays, and F<weekday.png> on all other days. 75background on Sundays, and F<weekday.png> on all other days.
76 76
77Fortunately, we expect that most expressions will be much simpler, with 77Fortunately, we expect that most expressions will be much simpler, with
78little Perl knowledge needed. 78little Perl knowledge needed.
79 79
80Basically, you always start with a function that "generates" an image 80Basically, you always start with a function that "generates" an image
112horizontal and vertical dimensions. For example, this halves the image 112horizontal and vertical dimensions. For example, this halves the image
113width and doubles the image height: 113width 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
117TODO 117Other effects than scalign are also readily available, for exmaple, you can
118tile the image to fill the whole window, instead of resizing it:
119
120 tile load "$HOME/mypic.png"
121
122In fact, images returned by C<load> are in C<tile> mode by default, so the C<tile> operator
123is kind of superfluous.
124
125Another common effect is to mirror the image, so that the same edges touch:
126
127 mirror load "$HOME/mypic.png"
128
129This is also a typical background expression:
130
131 rootalign root
132
133It first takes a snapshot of the screen background image, and then
134moves it to the upper left corner of the screen - the result is
135pseudo-transparency, as the image seems to be static while the window is
136moved around.
118 137
119=head3 CYCLES AND CACHING 138=head3 CYCLES AND CACHING
120 139
121TODO 140As has been mentioned before, the expression might be evaluated multiple
122
123Each time the expression is reevaluated, a new cycle is said to have begun. Many operators 141times. Each time the expression is reevaluated, a new cycle is said to
124cache their results till the next cycle. For example 142have begun. Many operators cache their results till the next cycle.
143
144For example, the C<load> operator keeps a copy of the image. If it is
145asked to load the same image on the next cycle it will not load it again,
146but return the cached copy.
147
148This only works for one cycle though, so as long as you load the same
149image every time, it will always be cached, but when you load a different
150image, it will forget about the first one.
151
152This allows you to either speed things up by keeping multiple images in
153memory, or comserve memory by loading images more often.
154
155For example, you can keep two images in memory and use a random one like
156this:
157
158 my $img1 = load "img1.png";
159 my $img2 = load "img2.png";
160 (0.5 > rand) ? $img1 : $img2
161
162Since both images are "loaded" every time the expression is evaluated,
163they 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
169Here, a path is selected randomly, and load is only called for one image,
170so keeps only one image in memory. If, on the next evaluation, luck
171decides 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
142replaces the background of the character area. 189replaces the background of the character area.
143 190
144=back 191=back
145 192
146=cut 193=cut
147
148our $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
161our $HOME; 195our $HOME;
162our ($self, $old, $new); 196our ($self, $old, $new);
163our ($x, $y, $w, $h); 197our ($x, $y, $w, $h);
164 198
211=item solid $width, $height, $colour 245=item solid $width, $height, $colour
212 246
213Creates a new image and completely fills it with the given colour. The 247Creates a new image and completely fills it with the given colour. The
214image is set to tiling mode. 248image is set to tiling mode.
215 249
216If <$width> and C<$height> are omitted, it creates a 1x1 image, which is 250If C<$width> and C<$height> are omitted, it creates a 1x1 image, which is
217useful for solid backgrounds or for use in filtering effects. 251useful 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
523Adjusts the I<contrast> of an image. 557Adjusts 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
567Adjusts 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
599Gaussian-blurs the image with (roughly) C<$radius> pixel radius. The radii
600can also be specified separately.
601
602Blurring is often I<very> slow, at least compared or other
603operators. Larger blur radii are slower than smaller ones, too, so if you
604don't want to freeze your screen for long times, start experimenting with
605low 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
616Rotates the image by C<$degrees> degrees, counter-clockwise, around the
617pointer at C<$center_x> and C<$center_y> (specified as percentage of image
618width/height), generating a new image with width C<$new_width> and height
619C<$new_height>.
620
621#TODO# new width, height, maybe more operators?
622
623Example: 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],

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines