Have you tried reading it as BigEndian (using the N template)? It kinda
looks like BigEndian to me, but I get easily turned around by endianness...

-Mike

Barry Brevik wrote:
> I am writing an app which, at a certain point, needs to read a .PNG
> graphics file.
>  
> The .PNG file is always small, so I read the whole file (binmode) into a
> scalar, and this works well.
>  
>   if ($gfilesize = -s $gfilespec)
>   {
>     $GRAPHFILE = "<$gfilespec";
>     if (open GRAPHFILE)
>     {
>       binmode GRAPHFILE;
>       read GRAPHFILE, $gbuffer, $gfilesize;
>       close GRAPHFILE;
> 
> The size of the file ($gfilesize) matches the size of the scalar
> ($gbuffer). This is good.
> 
> Then I proceed to paw through the buffer. The 1st 8 bytes of the file is
> a signature, which I read and deal with. Then, the file is a series of
> chunks where the 1st 4 bytes is a 32 bit number representing the size of
> the chunk, and the 2nd 4 bytes is an ASCII "chunk name", such as "IHDR".
> 
> So, after the signature, the next 8 bytes look like this:
>  
>   00 00 00 0d 49 48 44 52    . . . . I H D R
>  
> I am trying to decode this with the following:
>  
>   $bufptr = 8;
>   ($chunksize, $chunkname) = unpack "L a4", substr($gbuffer, $bufptr,
> 8);
>  
> Actually, I've tried every permutation of "unpack" template that I can
> think of.
> 
> The problem is that the 2nd scalar ($chunkname) comes out fine as
> "IHDR", but the first scalar comes out as "218103808" which is wrong as
> you can see above, it should be "13".
> 
> I thought I was starting to understand unpack, but what am I doing
> wrong??
> 
> Barry Brevik
> _______________________________________________
> ActivePerl mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to