BrianP

I downloaded the file, but it was in '.jpg' format and not a raw file. I used it in the following script, and then I copied it until the file size was larger than 217MB. The result of the 2 runs are below. I may be wrong but I don't think you need to convert to an integer and then use pack. The result will be the same as the raw 6 bytes ( 48 bits ) for the pixel.

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 bufferi +ng 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__

This is the results of run1, almost all unique pixels. About 1 second.

> time pyrperl uniqcolors.plx Found 153601 colors in 153606 pixels 1.00% ( File size: 921,638 ) real 0m0.098s user 0m0.092s sys 0m0.008s

This is using the larger file. We got some more uniques since the '.jpg' file was not a multiple of 6 bytes. About 15-16 seconds.

> time pyrperl uniqcolors.plx Found 460775 colors in 41473710 pixels 0.01% ( File size: 248,842,260 + ) real 0m15.015s user 0m14.937s sys 0m0.080s

Try it on your real data and let us know if it helps.

Regards...Ed

"Well done is better than well said." - Benjamin Franklin


In reply to Re: Perl Hashes in C? by flexvault
in thread Perl Hashes in C? by BrianP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.