use strict; use warnings; my %Image = (); keys %Image = 4096 * 128; my $rdamt = 4096 * 6; my $buffer; # my $file = '249465.pprgb-srgb.absv.4000.cs.jpg'; # Original File downloaded my $file = '249465.pprgb-srgb.absv.4000.cs.jpg2'; # New File multiple copies my $compraw = -s $file; my $pixels = int ( $compraw / 6 ); open ( my $in, "<", "./$file") or die "$!\n"; while( 1 ) { my $size = sysread( $in, $buffer, $rdamt ); # No buffering if ( $size == 0 ) { last; } while( $buffer ) { if ( length( $buffer ) < 6 ) { last; } # Throw away odd number of pixels my $key = substr( $buffer, 0, 6, '' ); $Image{$key}++; } } close $in; my $uniq = keys %Image; my $factor = sprintf("%.2f", $uniq / $pixels ); print "Found $uniq colors in $pixels pixels $factor\%\n"; __END__