Did you look at http://www.w3.org/TR/PNG/ ?
The GD module does what you want, but you also need to install the GD library for that. There should be a windows version available I think.
| [reply] |
Wow, useful reference. If it's concise enough that may be useful to help me write my own loader, yes.
GD wouldn't be useful since it only creates images and doesn't read them.
| [reply] |
#! perl -slw
use strict;
use GD;
my $img = GD::Image->new( $ARGV[ 0 ] );
my( $w, $h ) = $img->getBounds;
print "The image '$ARGV[ 0 ]' is $w x $h pixels.";
printf "The color of the pixel in the middle is: [0x%02x:0x%02x:0x%02x
+].\n",
$img->rgb( $img->getPixel( $w/2, $h/2 ) );
__DATA__
c:\test>junk5 694790clustered.png
The image '694790clustered.png' is 800 x 800 pixels.
The color of the pixel in the middle is: [0xfc:0xfe:0xfc].
c:\test>junk5 img\worldx2-2.jpg
The image 'img\worldx2-2.jpg' is 5400 x 2700 pixels.
The color of the pixel in the middle is: [0x04:0x0c:0x11].
c:\test>junk5 img\gradient.gif
The image 'img\gradient.gif' is 108 x 108 pixels.
The color of the pixel in the middle is: [0xff:0xff:0xff].
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
I've written code that generated PNG files by hand. Reading a PNG file isn't much harder. Both GD and ImageMagick do this quite nicely. There is a pureperl solution on CPAN, but I don't remember what it is. I found it a year ago when I was doing this, but it wasn't fast enough for my specialized use. (Turned out that my hand-tuned code was faster for my very specialized use than general purpose C code.)
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |
As mentioned above: GD seems to be for creating only. ImageMagick might do it, but i'm really leery of using such a huge package, since i need to include all the necessary dlls and such in the package of the project i'm working on.
Speed is not a matter though.
| [reply] |
Oh? GD's docs are horrid, so I can see why you missed the following:
my $image = GD::Image->newFromPng($filename);
my ($height, $width) = $image->getBounds;
foreach my $x ( 0 .. $width ) {
foreach my $y ( 0 .. $height ) {
my ($index) = $image->getPixel($x,$y);
my ($r,$g,$b) = $image->rgb($index);
print "($x,$y) -> ($r,$g,$b)\n";
}
}
That will print out the RGB value for every XY coordinate, row-first. There's a ton of other information you can extract. You just have to spend a few hours reading ALL the docs. It's well worth the effort.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] [d/l] |
Before you try to reinvent the wheel:
You might want to look at how Gtk2 loads images. See pixbufloader
muppet wrote a color snooper script that displays pixel information with the pixbuf, and shows the complexities that need to be accounted for.
Also, (and you may already know this), PNGS, come in 2 types, DirectClass and PseudoClass, where direct is true color, and pseudo allows you to define colors and store the colormap in the image. You need to handle them differently. Whether you have an alpha transparency layer must be considered too.
| [reply] |