gimcdan has asked for the wisdom of the Perl Monks concerning the following question:

Fairly new to perl and am trying to decipher older code. I thought this was a simple question that I could find in documentation but eludes me. I am looking at the following:

my $bitsDown = pack("b9" x 13, ".........", ".........", ".........", ".........", ".........", "..#####..", "...###...", "....#....", ".........", ".........", ".........", ".........", ".........");

I thought only '1' or '.' were acceptable to set or not set the pixels?

Replies are listed 'Best First'.
Re: bitmap and pack
by BrowserUk (Patriarch) on May 13, 2015 at 20:39 UTC
    I thought only '1' or '.' were acceptable to set or not set the pixels?

    pack template 'b', only considers the low bit of each byte, thus all these produce the same results:

    print unpack 'b8', pack 'b8', '01010101';; 01010101 print unpack 'b8', pack 'b8', 'babababa';; 01010101 print unpack 'b8', pack 'b8', "\x00\x01\x00\x01\x00\x01\x00\x01";; 01010101 print unpack 'b8', pack 'b8', "()()()()";; 01010101 print unpack 'b8', pack 'b8', "@?@?@?@?";; 01010101 print unpack 'b8', pack 'b8', 'dcdcdcdc';; 01010101

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
    .
Re: bitmap and pack
by Discipulus (Canon) on May 14, 2015 at 07:32 UTC
    hello gimcdan,
    aside from pack, the mention of pixel let me think you are inspecting a template for an image: my little experience with bitmap was due to my project about Tartaglia's triangle.

    As far as i remember in the image you have some header where you declare the size of the bitmap (x and y), the number of colors used and a fourth parameter i dont know..
    Then you can declare a map between char and colors. In the example below the space is the background (mapped to black) and the # is mapped to red.This is mentioned in Mastering PerlTk also.

    So, if you are talking about bitmap, any char is acceptable to set a pixel because it sets it's color.

    sub tart_icon { return <<EOI /* XPM */ static char * Icon_xpm[] = { "32 32 4 1", " c #000000000000", "g c #00FF00", "X c #FF0000", "D c #FFFF00", " ", " ", " ", " ", " ", " ", " XXXXXXXXXXXXXXXX ", " XXXXXXXXXXXXXXXX ", " ", " ", " XX ", " XX ", " XXXX ", " XXXX ", " XXXXXX ", " XXXXXX ", " XXXXXXXX ", " XXXXXXXX ", " XXXXXXXXXX ", " XXXXXXXXXX ", " XXXXXXXXXXXX ", " XXXXXXXXXXXX ", " XXXXXXXXXXXXXX ", " XXXXXXXXXXXXXX ", " ", " ", " ", " ", " ", " ", " ", " ",}; EOI }
    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: bitmap and pack (Image::Xbm)
by Anonymous Monk on May 13, 2015 at 22:41 UTC
    See Image::Xbm
    use Image::Xbm; my $bits = pack 'b*', Image::Xbm->new_from_string( $str )->as_binstring ;
Re: bitmap and pack
by gimcdan (Acolyte) on May 14, 2015 at 13:50 UTC

    Thanx Monks!