Skip to content

Instantly share code, notes, and snippets.

@warewolf
Created May 10, 2012 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warewolf/2650661 to your computer and use it in GitHub Desktop.
Save warewolf/2650661 to your computer and use it in GitHub Desktop.
perl reading bmp
#!/usr/bin/perl
use strict;
use warnings;
use Data::ParseBinary;
use Data::ParseBinary::Graphics::BMP qw{$bmp_parser};
use Data::Dumper;
my $filename = shift @ARGV;
open(my $fh,"<",$filename) or die "Couldn't open $filename for reading! ($!)";
my $data = $bmp_parser->parse(CreateStreamReader(File => $fh));
my $pixels = $data->{pixels};
my $counter = 0;
STOPME: foreach my $row (@$pixels) {
foreach my $column (@$row) {
my ($blue,$green,$red) = (@$column);
printf("%02x %02x %02x\n",$blue,$green,$red);
last STOPME if ($counter++ == 10);
}
}
#print Data::Dumper->Dump([$pixels],[qw($pixels)]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment