use strict; use warnings; use GD::Simple; use MCE; my $png = GD::Image->newFromPng('test.png'); my ($bx,$by) = $png->getBounds; my @col; # foreground colors for (0..$png->colorsTotal) { my ($r,$g,$b) = $png->rgb($_); push (@col,$_) unless ($b>128 || $r>128); } my $pdata = ''; MCE->new( max_workers => 4, chunk_size => 1, input_data => \@col, init_relay => 1, # loads MCE::Relay gather => sub { # this runs inside the parent $pdata |= $_[0]; }, user_func => sub { # run parallel my $val = ~$png->wbmp($_); # send the val to the parent process # relay makes it run serially and orderly MCE::relay { MCE->gather($val); }; } )->run(); our $zlen = int(($bx + 7) / 8); # number of Bytes per line my $pos = 6; my $y = 0; # position after Header of WBMP my @sw; while ($pos < length($pdata)) { $sw[$y] = ''; for (1..$zlen) { # convert binary data into string $sw[$y] .= sprintf("%08b",ord(substr($pdata,$pos++,1))); } # print $sw[$y], "\n"; $y++; }