File: //usr/local/share/man/man3/Image::Xbm.3pm
.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Xbm 3"
.TH Xbm 3 "2016-02-23" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Image::Xbm \- Load, create, manipulate and save xbm image files.
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Image::Xbm ;
\&
\& my $j = Image::Xbm\->new( \-file, \*(AqbalArrow.xbm\*(Aq ) ;
\&
\& my $i = Image::Xbm\->new( \-width => 10, \-height => 16 ) ;
\&
\& my $h = $i\->new ; # Copy of $i
\&
\& my $p = Image::Xbm\->new_from_string( "###\en#\-#\en###" ) ;
\&
\& my $q = $p\->new_from_string( "H##", "#\-#", "###" ) ;
\&
\& my $s = $q\->serialse ; # Compresses a little too.
\& my $t = Image::Xbm\->new_from_serialsed( $s ) ;
\&
\& $i\->xybit( 5, 8, 1 ) ; # Set a bit
\& print \*(Aq1\*(Aq if $i\->xybit( 9, 3 ) ; # Get a bit
\& print $i\->xy( 4, 5 ) ; # Will print black or white
\&
\& $i\->vec( 24, 0 ) ; # Set a bit using a vector offset
\& print \*(Aq1\*(Aq if $i\->vec( 24 ) ; # Get a bit using a vector offset
\&
\& print $i\->get( \-width ) ; # Get and set object and class attributes
\& $i\->set( \-height, 15 ) ;
\&
\& $i\->load( \*(Aqtest.xbm\*(Aq ) ;
\& $i\->save ;
\&
\& print "equal\en" if $i\->is_equal( $j ) ;
\&
\& print $j\->as_string ;
\&
\& #####\-
\& ###\-\-\-
\& ###\-\-\-
\& #\-\-#\-\-
\& #\-\-\-#\-
\& \-\-\-\-\-#
\&
\& print $j\->as_binstring ;
\&
\& 1111101110001110001001001000100000010000
.Ve
.PP
View an xbm file from the command line:
.PP
.Vb 1
\& % perl \-MImage::Xbm \-e\*(Aqprint Image::Xbm\->new(\-file,shift)\->as_string\*(Aq file
.Ve
.PP
Create an xbm file from the command line:
.PP
.Vb 1
\& % perl \-MImage::Xbm \-e\*(AqImage::Xbm\->new_from_string("###\en#\-#\en\-#\-")\->save("test.xbm")\*(Aq
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This class module provides basic load, manipulate and save functionality for
the xbm file format. It inherits from \f(CW\*(C`Image::Base\*(C'\fR which provides additional
manipulation functionality, e.g. \f(CW\*(C`new_from_image()\*(C'\fR. See the \f(CW\*(C`Image::Base\*(C'\fR
pod for information on adding your own functionality to all the \f(CW\*(C`Image::Base\*(C'\fR
derived classes.
.SS "\fBnew()\fP"
.IX Subsection "new()"
.Vb 3
\& my $i = Image::Xbm\->new( \-file => \*(Aqtest.xbm\*(Aq ) ;
\& my $j = Image::Xbm\->new( \-width => 12, \-height => 18 ) ;
\& my $k = $i\->new ;
.Ve
.PP
We can create a new xbm image by reading in a file, or by creating an image
from scratch (all the bits are unset by default), or by copying an image
object that we created earlier.
.PP
If we set \f(CW\*(C`\-file\*(C'\fR then all the other arguments are ignored (since they're
taken from the file). If we don't specify a file, \f(CW\*(C`\-width\*(C'\fR and \f(CW\*(C`\-height\*(C'\fR are
mandatory.
.ie n .IP """\-file""" 4
.el .IP "\f(CW\-file\fR" 4
.IX Item "-file"
The name of the file to read when creating the image. May contain a full path.
This is also the default name used for \f(CW\*(C`load\*(C'\fRing and \f(CW\*(C`save\*(C'\fRing, though it
can be overridden when you load or save.
.ie n .IP """\-width""" 4
.el .IP "\f(CW\-width\fR" 4
.IX Item "-width"
The width of the image; taken from the file or set when the object is created;
read-only.
.ie n .IP """\-height""" 4
.el .IP "\f(CW\-height\fR" 4
.IX Item "-height"
The height of the image; taken from the file or set when the object is created;
read-only.
.ie n .IP """\-hotx""" 4
.el .IP "\f(CW\-hotx\fR" 4
.IX Item "-hotx"
The x\-coord of the image's hotspot; taken from the file or set when the object
is created. Set to \-1 if there is no hotspot.
.ie n .IP """\-hoty""" 4
.el .IP "\f(CW\-hoty\fR" 4
.IX Item "-hoty"
The y\-coord of the image's hotspot; taken from the file or set when the object
is created. Set to \-1 if there is no hotspot.
.ie n .IP """\-bits""" 4
.el .IP "\f(CW\-bits\fR" 4
.IX Item "-bits"
The bit vector that stores the image; read-only.
.SS "\fBnew_from_string()\fP"
.IX Subsection "new_from_string()"
.Vb 3
\& my $p = Image::Xbm\->new_from_string( "###\en#\-#\en###" ) ;
\& my $q = $p\->new_from_string( "H##", "#\-#", "###" ) ;
\& my $r = $p\->new_from_string( $p\->as_string ) ;
.Ve
.PP
Create a new bitmap from a string or from an array or list of strings. If you
want to use different characters you can:
.PP
.Vb 2
\& Image::Xbm\->set( \-setch => \*(AqX\*(Aq, \-unsetch => \*(Aq \*(Aq ) ;
\& my $s = $p\->new_from_string( "XXX", "X X", "XhX" ) ;
.Ve
.PP
You can also specify a hotspot by making one of the characters a 'H' (set bit
hotspot) or 'h' (unset bit hotspot) \*(-- you can use different characters by
setting \f(CW\*(C`\-sethotch\*(C'\fR and \f(CW\*(C`\-unsethotch\*(C'\fR respectively.
.SS "\fBnew_from_serialised()\fP"
.IX Subsection "new_from_serialised()"
.Vb 1
\& my $i = Image::Xbm\->new_from_serialised( $s ) ;
.Ve
.PP
Creates an image from a string created with the \f(CW\*(C`serialse()\*(C'\fR method. Since
such strings are a little more compressed than xbm files or Image::Xbm objects
they might be useful if storing a lot of bitmaps, or for transferring bitmaps
over comms links.
.SS "\fBserialise()\fP"
.IX Subsection "serialise()"
.Vb 1
\& my $s = $i\->serialise ;
.Ve
.PP
Creates a string version of the image which can be completed recreated using
the \f(CW\*(C`new_from_serialised\*(C'\fR method.
.SS "\fBget()\fP"
.IX Subsection "get()"
.Vb 2
\& my $width = $i\->get( \-width ) ;
\& my( $hotx, $hoty ) = $i\->get( \-hotx, \-hoty ) ;
.Ve
.PP
Get any of the object's attributes. Multiple attributes may be requested in a
single call.
.PP
See \f(CW\*(C`xy\*(C'\fR and \f(CW\*(C`vec\*(C'\fR to get/set bits of the image itself.
.SS "\fBset()\fP"
.IX Subsection "set()"
.Vb 1
\& $i\->set( \-hotx => 120, \-hoty => 32 ) ;
.Ve
.PP
Set any of the object's attributes. Multiple attributes may be set in a single
call. Except for \f(CW\*(C`\-setch\*(C'\fR and \f(CW\*(C`\-unsetch\*(C'\fR all attributes are object
attributes; some attributes are read-only.
.PP
See \f(CW\*(C`xy\*(C'\fR and \f(CW\*(C`vec\*(C'\fR to get/set bits of the image itself.
.SS "class attributes"
.IX Subsection "class attributes"
.Vb 2
\& Image::Xbm\->set( \-setch => \*(AqX\*(Aq ) ;
\& $i\->set( \-setch => \*(Aq@\*(Aq, \-unsetch => \*(Aq*\*(Aq ) ;
.Ve
.ie n .IP """\-setch""" 4
.el .IP "\f(CW\-setch\fR" 4
.IX Item "-setch"
The character to print set bits as when using \f(CW\*(C`as_string\*(C'\fR, default is '#'.
This is a class attribute accessible from the class or an object via \f(CW\*(C`get\*(C'\fR
and \f(CW\*(C`set\*(C'\fR.
.ie n .IP """\-unsetch""" 4
.el .IP "\f(CW\-unsetch\fR" 4
.IX Item "-unsetch"
The character to print set bits as when using \f(CW\*(C`as_string\*(C'\fR, default is '\-'.
This is a class attribute accessible from the class or an object via \f(CW\*(C`get\*(C'\fR
and \f(CW\*(C`set\*(C'\fR.
.ie n .IP """\-sethotch""" 4
.el .IP "\f(CW\-sethotch\fR" 4
.IX Item "-sethotch"
The character to print set bits as when using \f(CW\*(C`as_string\*(C'\fR, default is 'H'.
This is a class attribute accessible from the class or an object via \f(CW\*(C`get\*(C'\fR
and \f(CW\*(C`set\*(C'\fR.
.ie n .IP """\-unsethotch""" 4
.el .IP "\f(CW\-unsethotch\fR" 4
.IX Item "-unsethotch"
The character to print set bits as when using \f(CW\*(C`as_string\*(C'\fR, default is 'h'.
This is a class attribute accessible from the class or an object via \f(CW\*(C`get\*(C'\fR
and \f(CW\*(C`set\*(C'\fR.
.SS "\fBxybit()\fP"
.IX Subsection "xybit()"
.Vb 2
\& $i\->xy( 4, 11, 1 ) ; # Set the bit at point 4,11
\& my $v = $i\->xy( 9, 17 ) ; # Get the bit at point 9,17
.Ve
.PP
Get/set bits using x, y coordinates; coordinates start at 0.
.SS "\fBxy()\fP"
.IX Subsection "xy()"
.Vb 2
\& $i\->xy( 4, 11, \*(Aqblack\*(Aq ) ; # Set the bit from a colour at point 4,11
\& my $v = $i\->xy( 9, 17 ) ; # Get the bit as a colour at point 9,17
.Ve
.PP
Get/set bits using colours using x, y coordinates; coordinates start at 0.
.PP
If set with a colour of 'black' or a numeric value > 0 or a string not
matching /^#0+$/ then the bit will be set, otherwise it will be cleared.
.PP
If you get a colour you will always get 'black' or 'white'.
.SS "\fBvec()\fP"
.IX Subsection "vec()"
.Vb 2
\& $i\->vec( 43, 0 ) ; # Unset the bit at offset 43
\& my $v = $i\->vec( 87 ) ; # Get the bit at offset 87
.Ve
.PP
Get/set bits using vector offsets; offsets start at 0.
.SS "\fBload()\fP"
.IX Subsection "load()"
.Vb 2
\& $i\->load ;
\& $i\->load( \*(Aqtest.xbm\*(Aq ) ;
.Ve
.PP
Load the image whose name is given, or if none is given load the image whose
name is in the \f(CW\*(C`\-file\*(C'\fR attribute.
.SS "\fBsave()\fP"
.IX Subsection "save()"
.Vb 2
\& $i\->save ;
\& $i\->save( \*(Aqtest.xbm\*(Aq ) ;
.Ve
.PP
Save the image using the name given, or if none is given save the image using
the name in the \f(CW\*(C`\-file\*(C'\fR attribute. The image is saved in xbm format, e.g.
.PP
.Vb 4
\& #define test_width 6
\& #define test_height 6
\& static unsigned char test_bits[] = {
\& 0x1f, 0x07, 0x07, 0x09, 0x11, 0x20 } ;
.Ve
.SS "\fBis_equal()\fP"
.IX Subsection "is_equal()"
.Vb 1
\& print "equal\en" if $i\->is_equal( $j ) ;
.Ve
.PP
Returns true (1) if the images are equal, false (0) otherwise. Note that
hotspots and filenames are ignored, so we compare width, height and the actual
bits only.
.SS "\fBas_string()\fP"
.IX Subsection "as_string()"
.Vb 1
\& print $i\->as_string ;
.Ve
.PP
Returns the image as a string, e.g.
.PP
.Vb 6
\& #####\-
\& ###\-\-\-
\& ###\-\-\-
\& #\-\-#\-\-
\& #\-\-\-#\-
\& \-\-\-\-\-#
.Ve
.PP
The characters used may be changed by \f(CW\*(C`set\*(C'\fRting the \f(CW\*(C`\-setch\*(C'\fR and \f(CW\*(C`\-unsetch\*(C'\fR
characters. If you give \f(CW\*(C`as_string\*(C'\fR a parameter it will print out the hotspot
if present using \f(CW\*(C`\-sethotch\*(C'\fR or \f(CW\*(C`\-unsethotch\*(C'\fR as appropriate, e.g.
.PP
.Vb 1
\& print $n\->as_string( 1 ) ;
\&
\& H##
\& #\-#
\& ###
.Ve
.SS "\fBas_binstring()\fP"
.IX Subsection "as_binstring()"
.Vb 1
\& print $i\->as_binstring ;
.Ve
.PP
Returns the image as a string of 0's and 1's, e.g.
.PP
.Vb 1
\& 1111101110001110001001001000100000010000
.Ve
.SH "CHANGES"
.IX Header "CHANGES"
2016/02/23 (Slaven Rezic)
.PP
Make sure macro/variable names are always sane.
.PP
More strict parsing of bits.
.PP
2000/11/09
.PP
Added Jerrad Pierce's patch to allow \fBload()\fR to accept filehandles or strings;
will document in next release.
.PP
2000/05/05
.PP
Added \fBnew_from_serialised()\fR and \fBserialise()\fR methods.
.PP
2000/05/04
.PP
Made \fBxy()\fR compatible with Image::Base, use \fBxybit()\fR for the earlier
functionality.
.PP
2000/05/01
.PP
Improved speed of \fBvec()\fR, \fBxy()\fR and \fBas_string()\fR.
.PP
Tried use integer to improve speed but according to Benchmark it made the code
slower so I dropped it; interestingly perl 5.6.0 was around 25% slower than
perl 5.004 with and without use integer.
.PP
2000/04/30
.PP
Created.
.SH "AUTHOR"
.IX Header "AUTHOR"
Mark Summerfield. I can be contacted as <summer@perlpress.com> \-
please include the word 'xbm' in the subject line.
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
Copyright (c) Mark Summerfield 2000. All Rights Reserved.
.PP
This module may be used/distributed/modified under the \s-1LGPL.\s0