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.42 by root, Sun Jun 10 10:42:19 2012 UTC vs.
Revision 1.45 by root, Sun Jun 10 11:53:32 2012 UTC

99its result becomes the argument to the C<scale> function. 99its result becomes the argument to the C<scale> function.
100 100
101Many operators also allow some parameters preceding the input image 101Many operators also allow some parameters preceding the input image
102that modify its behaviour. For example, C<scale> without any additional 102that modify its behaviour. For example, C<scale> without any additional
103arguments scales the image to size of the terminal window. If you specify 103arguments scales the image to size of the terminal window. If you specify
104an additional argument, it uses it as a percentage: 104an additional argument, it uses it as a scale factor (multiply by 100 to
105get a percentage):
105 106
106 scale 200, load "$HOME/mypic.png" 107 scale 2, load "$HOME/mypic.png"
107 108
108This enlarges the image by a factor of 2 (200%). As you can see, C<scale> 109This enlarges the image by a factor of 2 (200%). As you can see, C<scale>
109has now two arguments, the C<200> and the C<load> expression, while 110has now two arguments, the C<200> and the C<load> expression, while
110C<load> only has one argument. Arguments are separated from each other by 111C<load> only has one argument. Arguments are separated from each other by
111commas. 112commas.
112 113
113Scale also accepts two arguments, which are then separate factors for both 114Scale also accepts two arguments, which are then separate factors for both
114horizontal and vertical dimensions. For example, this halves the image 115horizontal and vertical dimensions. For example, this halves the image
115width and doubles the image height: 116width and doubles the image height:
116 117
117 scale 50, 200, load "$HOME/mypic.png" 118 scale 0.5, 2, load "$HOME/mypic.png"
118 119
119Other effects than scalign are also readily available, for exmaple, you can 120Other effects than scalign are also readily available, for exmaple, you can
120tile the image to fill the whole window, instead of resizing it: 121tile the image to fill the whole window, instead of resizing it:
121 122
122 tile load "$HOME/mypic.png" 123 tile load "$HOME/mypic.png"
202our $MIN_INTERVAL = 1/100; 203our $MIN_INTERVAL = 1/100;
203 204
204{ 205{
205 package urxvt::bgdsl; # background language 206 package urxvt::bgdsl; # background language
206 207
208 use List::Util qw(min max sum shuffle);
209
207=head2 PROVIDERS/GENERATORS 210=head2 PROVIDERS/GENERATORS
208 211
209These functions provide an image, by loading it from disk, grabbing it 212These functions provide an image, by loading it from disk, grabbing it
210from the root screen or by simply generating it. They are used as starting 213from the root screen or by simply generating it. They are used as starting
211points to get an image you can play with. 214points to get an image you can play with.
260 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1); 263 my $img = $self->new_img (urxvt::PictStandardARGB32, $_[0] || 1, $_[1] || 1);
261 $img->fill ($colour); 264 $img->fill ($colour);
262 $img 265 $img
263 } 266 }
264 267
268=item clone $img
269
270Returns an exact copy of the image. This is useful if you want to have
271multiple copies of the same image to apply different effects to.
272
273=cut
274
275 sub clone($) {
276 $_[0]->clone
277 }
278
265=back 279=back
266 280
281=head2 TILING MODES
282
283The following operators modify the tiling mode of an image, that is, the
284way that pixels outside the image area are painted when the image is used.
285
286=over 4
287
288=item tile $img
289
290Tiles the whole plane with the image and returns this new image - or in
291other words, it returns a copy of the image in plane tiling mode.
292
293Example: load an image and tile it over the background, without
294resizing. The C<tile> call is superfluous because C<load> already defaults
295to tiling mode.
296
297 tile load "mybg.png"
298
299=item mirror $img
300
301Similar to tile, but reflects the image each time it uses a new copy, so
302that top edges always touch top edges, right edges always touch right
303edges and so on (with normal tiling, left edges always touch right edges
304and top always touch bottom edges).
305
306Example: load an image and mirror it over the background, avoiding sharp
307edges at the image borders at the expense of mirroring the image itself
308
309 mirror load "mybg.png"
310
311=item pad $img
312
313Takes an image and modifies it so that all pixels outside the image area
314become transparent. This mode is most useful when you want to place an
315image over another image or the background colour while leaving all
316background pixels outside the image unchanged.
317
318Example: load an image and display it in the upper left corner. The rest
319of the space is left "empty" (transparent or wahtever your compisotr does
320in alpha mode, else background colour).
321
322 pad load "mybg.png"
323
324=item extend $img
325
326Extends the image over the whole plane, using the closest pixel in the
327area outside the image. This mode is mostly useful when you more complex
328filtering operations and want the pixels outside the image to have the
329same values as the pixels near the edge.
330
331Example: just for curiosity, how does this pixel extension stuff work?
332
333 extend move 50, 50, load "mybg.png"
334
335=cut
336
337 sub pad($) {
338 my $img = $_[0]->clone;
339 $img->repeat_mode (urxvt::RepeatNone);
340 $img
341 }
342
343 sub tile($) {
344 my $img = $_[0]->clone;
345 $img->repeat_mode (urxvt::RepeatNormal);
346 $img
347 }
348
349 sub mirror($) {
350 my $img = $_[0]->clone;
351 $img->repeat_mode (urxvt::RepeatReflect);
352 $img
353 }
354
355 sub extend($) {
356 my $img = $_[0]->clone;
357 $img->repeat_mode (urxvt::RepeatPad);
358 $img
359 }
360
361=back
362
267=head2 VARIABLES 363=head2 VARIABLE VALUES
268 364
269The following functions provide variable data such as the terminal window 365The following functions provide variable data such as the terminal window
270dimensions. They are not (Perl-) variables, they jsut return stuff that 366dimensions. They are not (Perl-) variables, they just return stuff that
271varies. Most of them make your expression sensitive to some events, for 367varies. Most of them make your expression sensitive to some events, for
272example using C<TW> (terminal width) means your expression is evaluated 368example using C<TW> (terminal width) means your expression is evaluated
273again when the terminal is resized. 369again when the terminal is resized.
274 370
275=over 4 371=over 4
349 $self->{counter} + 0 445 $self->{counter} + 0
350 } 446 }
351 447
352=back 448=back
353 449
354=head2 TILING MODES 450=head2 SHAPE CHANGING OPERATORS
355 451
356The following operators modify the tiling mode of an image, that is, the 452The following operators modify the shape, size or position of the image.
357way that pixels outside the image area are painted when the image is used.
358 453
359=over 4 454=over 4
360
361=item tile $img
362
363Tiles the whole plane with the image and returns this new image - or in
364other words, it returns a copy of the image in plane tiling mode.
365
366Example: load an image and tile it over the background, without
367resizing. The C<tile> call is superfluous because C<load> already defaults
368to tiling mode.
369
370 tile load "mybg.png"
371
372=item mirror $img
373
374Similar to tile, but reflects the image each time it uses a new copy, so
375that top edges always touch top edges, right edges always touch right
376edges and so on (with normal tiling, left edges always touch right edges
377and top always touch bottom edges).
378
379Example: load an image and mirror it over the background, avoiding sharp
380edges at the image borders at the expense of mirroring the image itself
381
382 mirror load "mybg.png"
383
384=item pad $img
385
386Takes an image and modifies it so that all pixels outside the image area
387become transparent. This mode is most useful when you want to place an
388image over another image or the background colour while leaving all
389background pixels outside the image unchanged.
390
391Example: load an image and display it in the upper left corner. The rest
392of the space is left "empty" (transparent or wahtever your compisotr does
393in alpha mode, else background colour).
394
395 pad load "mybg.png"
396
397=item extend $img
398
399Extends the image over the whole plane, using the closest pixel in the
400area outside the image. This mode is mostly useful when you more complex
401filtering operations and want the pixels outside the image to have the
402same values as the pixels near the edge.
403
404Example: just for curiosity, how does this pixel extension stuff work?
405
406 extend move 50, 50, load "mybg.png"
407
408=cut
409
410 sub pad($) {
411 my $img = $_[0]->clone;
412 $img->repeat_mode (urxvt::RepeatNone);
413 $img
414 }
415
416 sub tile($) {
417 my $img = $_[0]->clone;
418 $img->repeat_mode (urxvt::RepeatNormal);
419 $img
420 }
421
422 sub mirror($) {
423 my $img = $_[0]->clone;
424 $img->repeat_mode (urxvt::RepeatReflect);
425 $img
426 }
427
428 sub extend($) {
429 my $img = $_[0]->clone;
430 $img->repeat_mode (urxvt::RepeatPad);
431 $img
432 }
433
434=back
435
436=head2 PIXEL OPERATORS
437
438The following operators modify the image pixels in various ways.
439
440=over 4
441
442=item clone $img
443
444Returns an exact copy of the image.
445
446=cut
447
448 sub clone($) {
449 $_[0]->clone
450 }
451 455
452=item clip $img 456=item clip $img
453 457
454=item clip $width, $height, $img 458=item clip $width, $height, $img
455 459
479 $img->sub_rect ($_[0], $_[1], $w, $h) 483 $img->sub_rect ($_[0], $_[1], $w, $h)
480 } 484 }
481 485
482=item scale $img 486=item scale $img
483 487
484=item scale $size_percent, $img 488=item scale $size_factor, $img
485 489
486=item scale $width_percent, $height_percent, $img 490=item scale $width_factor, $height_factor, $img
487 491
488Scales the image by the given percentages in horizontal 492Scales the image by the given factors in horizontal
489(C<$width_percent>) and vertical (C<$height_percent>) direction. 493(C<$width>) and vertical (C<$height>) direction.
490 494
491If only one percentage is give, it is used for both directions. 495If only one factor is give, it is used for both directions.
492 496
493If no percentages are given, scales the image to the window size without 497If no factors are given, scales the image to the window size without
494keeping aspect. 498keeping aspect.
495 499
496=item resize $width, $height, $img 500=item resize $width, $height, $img
497 501
498Resizes the image to exactly C<$width> times C<$height> pixels. 502Resizes the image to exactly C<$width> times C<$height> pixels.
499 503
500=cut 504=item fit $img
501 505
502#TODO: maximise, maximise_fill? 506=item fit $width, $height, $img
507
508Fits the image into the given C<$width> and C<$height> without changing
509aspect, or the terminal size. That means it will be shrunk or grown until
510the whole image fits into the given area, possibly leaving borders.
511
512=item cover $img
513
514=item cover $width, $height, $img
515
516Similar to C<fit>, but shrinks or grows until all of the area is covered
517by the image, so instead of potentially leaving borders, it will cut off
518image data that doesn't fit.
519
520=cut
503 521
504 sub scale($;$;$) { 522 sub scale($;$;$) {
505 my $img = pop; 523 my $img = pop;
506 524
507 @_ == 2 ? $img->scale ($_[0] * $img->w * 0.01, $_[1] * $img->h * 0.01) 525 @_ == 2 ? $img->scale ($_[0] * $img->w, $_[1] * $img->h)
508 : @_ ? $img->scale ($_[0] * $img->w * 0.01, $_[0] * $img->h * 0.01) 526 : @_ ? $img->scale ($_[0] * $img->w, $_[0] * $img->h)
509 : $img->scale (TW, TH) 527 : $img->scale (TW, TH)
510 } 528 }
511 529
512 sub resize($$$) { 530 sub resize($$$) {
513 my $img = pop; 531 my $img = pop;
514 $img->scale ($_[0], $_[1]) 532 $img->scale ($_[0], $_[1])
533 }
534
535 sub fit($;$$) {
536 my $img = pop;
537 my $w = ($_[0] || TW) / $img->w;
538 my $h = ($_[1] || TH) / $img->h;
539 scale +(min $w, $h), $img
540 }
541
542 sub cover($;$$) {
543 my $img = pop;
544 my $w = ($_[0] || TW) / $img->w;
545 my $h = ($_[1] || TH) / $img->h;
546 scale +(max $w, $h), $img
515 } 547 }
516 548
517=item move $dx, $dy, $img 549=item move $dx, $dy, $img
518 550
519Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in 551Moves the image by C<$dx> pixels in the horizontal, and C<$dy> pixels in
520the vertical. 552the vertical.
521 553
522Example: move the image right by 20 pixels and down by 30. 554Example: move the image right by 20 pixels and down by 30.
523 555
524 move 20, 30, ... 556 move 20, 30, ...
557
558=item center $img
559
560=item center $width, $height, $img
561
562Centers the image, i.e. the center of the image is moved to the center of
563the terminal window (or the box specified by C<$width> and C<$height> if
564given).
525 565
526=item rootalign $img 566=item rootalign $img
527 567
528Moves the image so that it appears glued to the screen as opposed to the 568Moves the image so that it appears glued to the screen as opposed to the
529window. This gives the illusion of a larger area behind the window. It is 569window. This gives the illusion of a larger area behind the window. It is
545 my $img = pop->clone; 585 my $img = pop->clone;
546 $img->move ($_[0], $_[1]); 586 $img->move ($_[0], $_[1]);
547 $img 587 $img
548 } 588 }
549 589
590 sub center($;$$) {
591 my $img = pop;
592 my $w = $_[0] || TW;
593 my $h = $_[0] || TH;
594
595 move 0.5 * ($w - $img->w), 0.5 * ($h - $img->h), $img
596 }
597
550 sub rootalign($) { 598 sub rootalign($) {
551 move -TX, -TY, $_[0] 599 move -TX, -TY, $_[0]
552 } 600 }
553 601
602=back
603
604=head2 COLOUR MODIFICATIONS
605
606The following operators change the pixels of the image.
607
608=over 4
609
554=item contrast $factor, $img 610=item contrast $factor, $img
555 611
556=item contrast $r, $g, $b, $img 612=item contrast $r, $g, $b, $img
557 613
558=item contrast $r, $g, $b, $a, $img 614=item contrast $r, $g, $b, $a, $img
559 615
560Adjusts the I<contrast> of an image. 616Adjusts the I<contrast> of an image.
561 617
562#TODO# 618The first form applies a single C<$factor> to red, green and blue, the
619second form applies separate factors to each colour channel, and the last
620form includes the alpha channel.
563 621
622Values from 0 to 1 lower the contrast, values higher than 1 increase the
623contrast.
624
625Due to limitations in the underlying XRender extension, lowering contrast
626also reduces brightness, while increasing contrast currently also
627increases brightness.
628
564=item brightness $factor, $img 629=item brightness $bias, $img
565 630
566=item brightness $r, $g, $b, $img 631=item brightness $r, $g, $b, $img
567 632
568=item brightness $r, $g, $b, $a, $img 633=item brightness $r, $g, $b, $a, $img
569 634
570Adjusts the brightness of an image. 635Adjusts the brightness of an image.
636
637The first form applies a single C<$bias> to red, green and blue, the
638second form applies separate biases to each colour channel, and the last
639form includes the alpha channel.
640
641Values less than 0 reduce brightness, while values larger than 0 increase
642it. Useful range is from -1 to 1 - the former results in a black, the
643latter in a white picture.
644
645Due to idiosynchrasies in the underlying XRender extension, biases less
646than zero can be I<very> slow.
571 647
572=cut 648=cut
573 649
574 sub contrast($$;$$;$) { 650 sub contrast($$;$$;$) {
575 my $img = pop; 651 my $img = pop;
615 } 691 }
616 692
617=item rotate $new_width, $new_height, $center_x, $center_y, $degrees 693=item rotate $new_width, $new_height, $center_x, $center_y, $degrees
618 694
619Rotates the image by C<$degrees> degrees, counter-clockwise, around the 695Rotates the image by C<$degrees> degrees, counter-clockwise, around the
620pointer at C<$center_x> and C<$center_y> (specified as percentage of image 696pointer at C<$center_x> and C<$center_y> (specified as factor of image
621width/height), generating a new image with width C<$new_width> and height 697width/height), generating a new image with width C<$new_width> and height
622C<$new_height>. 698C<$new_height>.
623 699
624#TODO# new width, height, maybe more operators? 700#TODO# new width, height, maybe more operators?
625 701
630 sub rotate($$$$$$) { 706 sub rotate($$$$$$) {
631 my $img = pop; 707 my $img = pop;
632 $img->rotate ( 708 $img->rotate (
633 $_[0], 709 $_[0],
634 $_[1], 710 $_[1],
635 $_[2] * $img->w * .01, 711 $_[2] * $img->w,
636 $_[3] * $img->h * .01, 712 $_[3] * $img->h,
637 $_[4] * (3.14159265 / 180), 713 $_[4] * (3.14159265 / 180),
638 ) 714 )
639 } 715 }
640 716
641=back 717=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines