Created
May 10, 2012 02:42
-
-
Save warewolf/2650661 to your computer and use it in GitHub Desktop.
perl reading bmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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