Allegro::Bitmap - Allegro Bitmap routines
use Allegro;
$al = Allegro->new() or die; $screen = $al->Display(width => 640, height => 480);
# Display images given on command line
for $file (@ARGV) {
$bmp = $screen->Bitmap(file => $file) or die;
$w = $bmp->width;
$h = $bmp->height;
$screen->clear();
$screen->blit($bmp);
$screen->text(x => 10, y => 10, text => "$file: $w x $h");
sleep 10;
}
The Allegro::Bitmap module provides an object-oriented interface to the Allegro bitmap related routines.
Allegro::Bitmap is included automatically by the Allegro module, so an
explicit use Allegro::Bitmap is not needed.
This method can be used in three ways:
$bmp = $disp->Bitmap(file => "test.bmp");
This routine will load any file format supported by Allegro (BMP, PCX,
LBM, TGA). PNG and JPEG support is also available if the GD module can be
found. $Allegro::GD will be set if GD is available.
$bmp = $disp->Bitmap(width => 400,
height => 100,
depth => 32);
memoryvideosystem
$bmp = $disp->Bitmap(parent => $disp,
x => 10,
y => 10,
width => $disp->width - 20,
height => $disp->height - 20);
acquire. If
the bitmap was acquired multiple times, you must release it the same
number of times before it will truly be unlocked.
$bmp->clear(color => $color);
color is optional, and defaults to black.
$bmp->putpixel(x => $x,
y => $y,
color => 'blue');
Note that if you don't specify a color the default is to pick one at random.
$color = $bmp->getpixel(x => $x,
y => $y);
$bmp->line(x1 => $x1,
y1 => $y1,
x2 => $x2,
y2 => $y2,
color => 'white');
$bmp->triangle(x1 => $x1, y1 => $y1,
x2 => $x2, y2 => $y2,
x3 => $x3, y3 => $y3,
color => $color);
$bmp->rect(x => $x,
y => $y,
width => $width,
height => $height,
color => $fill,
border => $border);
Either the width and height or the x2 and y2 options must be specified.
$bmp->ellipse(x => $x,
y => $y,
width => $rx,
height => $ry,
color => $fill,
border => $border);
Either width and height or radius is required.
$bmp->floodfill(x => $x,
y => $y,
color => $c);
$bmp->text(x => $x,
y => $y,
font => $font,
color => $color,
bg => $bg,
align => 'left',
text => "Hello World");
justify.
$bmp->polygon($color,
$x1, $y1,
$x2, $y2,
$x3, $y3,
...);
$bmp->polygon($x1, $y1,
$x2, $y2,
$x3, $y3,
...);
# These calls are equivalent. $bmp->blit_to($screen, ...); $screen->blit($bmp, ...);
See blit below for a full description.
$bmp->blit($source,
sx => $sx,
sy => $sy,
dx => $dx,
dy => $dy,
sw => $sw,
sh => $sh,
dw => $dw,
dh => $dh,
masked => $masked);
Blender support is not yet implemented (translucency, lighting, etc).
Examples:
$bmp->blit($source, x => 20, y => 20);
Blits $source to $bmp at (20, 20) in $bmp.
$bmp->blit($source, dw => 640, dh => 480);
Stretches $source to 640x480 and copies to $bmp.
$bmp->blit($source, masked => 1);
Copies $source to $bmp ignoring parts of $source that are masked out.
$bmp->blit($source, dw => $dest->{width},
dh => $dest->{height},
masked => 1);
The above operations can be combined in a single call.
Be warned that temporary bitmaps may be created behind your back to perform certain combinations. Using different source and destination widths/heights with a non-memory bitmap as a source, or masked blits with a non-memory bitmap as a source (on certain hardware) will create a temporary memory bitmap. The same is true when converting between color depths when using masked or stretched blits.
Colin O'Leary <colin@mx3.org>
Copyright 2003 by Colin O'Leary. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The Allegro library is copyright its authors, and is giftware. See http://alleg.sf.net for more information.