MESSAGE
DATE | 2016-12-12 |
FROM | Ruben Safir
|
SUBJECT | Re: [Learn] Fwd: Re: png data format
|
From learn-bounces-at-nylxs.com Mon Dec 12 12:04:35 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id 06AF9161312; Mon, 12 Dec 2016 12:04:35 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id 331EB160E77; Mon, 12 Dec 2016 12:04:33 -0500 (EST) To: Samir Iabbassen , learn-at-nylxs.com References: <885db5b8-cd28-1647-d931-d18f4bfb5e5a-at-mrbrklyn.com> <1481484196598.70353-at-liu.edu> From: Ruben Safir Message-ID: <5318dcc5-5ed2-9012-b42b-3c16a8a7a83f-at-mrbrklyn.com> Date: Mon, 12 Dec 2016 12:04:33 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: <1481484196598.70353-at-liu.edu> Subject: Re: [Learn] Fwd: Re: png data format X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
On 12/11/2016 02:23 PM, Samir Iabbassen wrote: > I think the number you are getting is not huge as it's less than 2^31 - 1. > did you use the following formula to calculate the value you are getting? > uint32_t len = ((bytes[0] * 256 + bytes[1]) * 256 + bytes[2]) * 256 + bytes[3];
Right, it is not too large for the byte size, but it is larger than the size of the entire image ;)
This post came from the PNG working group and includes am decent endian explanation, so I forwarded it. What confuses me is that BYTEs are bytes regardless of endianess. That makes no sense to me
> ________________________________________ > From: Learn on behalf of ruben safir > Sent: Sunday, December 11, 2016 12:39 AM > To: learn-at-nylxs.com > Subject: [Learn] Fwd: Re: png data format > > -------- Forwarded Message -------- > Subject: Re: png data format > Date: 7 Dec 2016 19:49:12 GMT > From: Jens Thoms Toerring > Organization: Freie Universitaet Berlin > Newsgroups: comp.unix.programmer > References: > > ruben safir wrote: >> I'm having trouble with this imput of data from a PNG image. The >> specification says that "chunks" have a 4 byte field that is the length of >> the attached data segment. I tried to read the length in for a chunk that >> has a length of 13, which was confirmed in a hexdump > >> 0000000 211 120 116 107 015 012 032 012 -->>000 000 000 015<<-- 111 110 104 122 >> 0000010 000 000 041 215 000 000 007 165 010 006 000 000 001 206 055 074 >> 0000020 336 000 000 000 004 147 101 115 101 000 000 261 217 013 374 141 > >> I am storing the data in a uint32_t variable using the following code, but >> the value keeps showing up with a huge number 218103808 which happens to be >> the number that is evaluated by iostream for the value of the whole chunk > > >> done reading header > >> Sizeof Chunk 4 >> Raw Chunk Number 0: 218103808 >> ***LENGTH**** >> Length value => 218103808 > > The data are stored in big-endian order, i.e. with the most > significant byte coming first, but you seem to have read it > in as a 32-bit integer on a machine using little-endian byte > order, e.g. with a machine with an Intel processor, where > the least-significant byte comes first in memory. That's > also what they expect when reading in binary data from a > file. So simply read in the four bytes separately into e. > g. an array > > uint8_t bytes[4] > > with the first byte you read from the file going into > the first array element etc. Then do > > uint32_t len = ((bytes[0] * 256 + bytes[1]) * 256 + bytes[2]) * 256 + > bytes[3]; > > and you should get the correct value. The same applies, of > course, also for other fields containing values that occupy > multiple bytes! This then will work correctly on both big- > and little-endian machines. > Regards, Jens > -- > \ Jens Thoms Toerring ___ jt-at-toerring.de > \__________________________ http://toerring.de > _______________________________________________ > Learn mailing list > Learn-at-nylxs.com > http://lists.mrbrklyn.com/mailman/listinfo/learn > >
-- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013 _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|