.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05) .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .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" '' '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 turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Xbm 3pm" .TH Xbm 3pm "2008-08-15" "perl v5.10.0" "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. .Sh "\fInew()\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. .Sh "\fInew_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. .Sh "\fInew_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. .Sh "\fIserialise()\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. .Sh "\fIget()\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. .Sh "\fIset()\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. .Sh "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. .Sh "\fIxybit()\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. .Sh "\fIxy()\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'. .Sh "\fIvec()\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. .Sh "\fIload()\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. .Sh "\fIsave()\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 .Sh "\fIis_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. .Sh "\fIas_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 .Sh "\fIas_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" 2000/11/09 .PP Added Jerrad Pierce's patch to allow \fIload()\fR to accept filehandles or strings; will document in next release. .PP 2000/05/05 .PP Added \fInew_from_serialised()\fR and \fIserialise()\fR methods. .PP 2000/05/04 .PP Made \fIxy()\fR compatible with Image::Base, use \fIxybit()\fR for the earlier functionality. .PP 2000/05/01 .PP Improved speed of \fIvec()\fR, \fIxy()\fR and \fIas_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 \- 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.