Image::BMP - Bitmap parser/viewer
use Image::BMP; # Example one: my $img = new Image::BMP( file => 'some.bmp', debug => 1, ); $img->view_ascii; # Example two: my $img2 = new Image::BMP; $img2->open_file('another.bmp'); my $color = $img2->xy(100,100); # Get pixel at 100,100 my ($r,$g,$b) = $img2->xy_rgb(100,200);
Image::BMP
objects can parse and even ascii view bitmaps of the .BMP format. It can read most of the common forms of this format.
It can be used to:
my $img = new Image::BMP(file => 'some.bmp'); print "Resolution: $img->{Width} x $img->{Height}\n";
(See C<SYNOPSIS> example one)
(See C<SYNOPSIS> example two)
(See C<ADD_PIXEL> below)
It does not currently write bmap data, simply because I didn't have a use for that yet. Convince me and I'll add it.
The following data/keys are read when opening an image:
FileSize, DataOffset, HeaderSize, Width, Height, Planes, BitCount, ColorBytes, Compression, (compression enum: RGB, RLE8, RLE4, BITFIELDS) ImageSize, XpixelsPerM, YpixelsPerM, ColorsUsed, ColorsImportant
Constructs a new Image::BMP
object:
Opens a file and reads the initial image information and colormap.
Opens a pipe to a command that outputs a bitmap (and reads image info/colormap). Example:
$img->open_pipe("convert some.jpg bmp:-");
Close a file.
Read the image in. Uses the file in %options if not specified.
Lookup an index in the colormap;
Lookup or set a pixel in the image by color. (Calls load
if necessary)
Lookup or set a pixel in the image by index. (Calls load
if necessary)
Lookup or set a pixel in the image by rgb values. (Calls load
if necessary)
Do a print of the image in crude ASCII fashion. Useful for debugging of small images. For kicks, open an xterm, set the font to "unreadable" and view the output. (Calls load
if necessary)
Get/set the debug
setting. Values are:
Generally only debug=0 or =1 are useful.
Get/set the remember_image
setting. See ADD_PIXEL
below.
Get/set the add_pixel subroutine pointer.
Instead of having the object read the image into memory (or in addition to), you can process all the image data yourself by supplying a callback function:
sub my_add { my ($img,$x,$y,$r,$g,$b) = @_; print "add pixel $x,$y = $r,$g,$b\n"; } my $img = new Image::BMP(file => 'some.bmp', add_pixel = \&my_add); $img->load;
It may be useful to note that most bitmaps are read from left to right and bottom to top (x from 0 to width, y from height to 0), though the compression can skip values.
If you supply an add_pixel
callback then load
will not store the image data for efficiency. This means, however, that view_ascii
, xy
and xy_rgb
will not work. You can use add_pixel
and still save the image in memory by setting remember_image
.
I haven't seen an image like this yet, it wouldn't be hard to add.
I don't even know what that is..
This isn't tested yet - I haven't seen an image that uses this portion of RLE compression, so it currently does what I think is right and then prints a message asking you to send me the image/results.
Copyright 2004 <a href="http://GetDave.com/">David Ljung Madison</a>. All rights reserved. See: <a href="http://MarginalHacks.com/">MarginalHacks.com</a>