MESSAGE
DATE | 2016-12-07 |
FROM | ruben safir
|
SUBJECT | Subject: [Learn] Fwd: Re: png data format
|
From learn-bounces-at-nylxs.com Wed Dec 7 23:27:31 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 970AE161312; Wed, 7 Dec 2016 23:27:30 -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 86C91160E77 for ; Wed, 7 Dec 2016 23:27:19 -0500 (EST) References: To: learn-at-nylxs.com From: ruben safir X-Forwarded-Message-Id: Message-ID: <81b38449-b920-8578-43fb-de7b6db1431b-at-mrbrklyn.com> Date: Wed, 7 Dec 2016 23:27:19 -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: Subject: [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"
-------- Forwarded Message -------- Subject: Re: png data format Date: Tue, 6 Dec 2016 21:41:26 +0100 From: David Brown Organization: A noiseless patient Spider Newsgroups: comp.lang.c++ References:
On 06/12/16 20:33, ruben safir wrote: > On 12/06/2016 02:05 PM, Scott Lurndal wrote: >> ruben safir writes: >>> On 12/06/2016 10:10 AM, Scott Lurndal wrote: >>>> ruben safir writes: >>>>> Hello >>>>> >>>>> 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 >>>>> >>>> >>>> https://en.wikipedia.org/wiki/Endianness >>>> >>> >>> >>> that doesn't help >> >> And nobody here is obligated to help you - you should learn to >> help yourself, and the link referenced above should be your starting >> point. >> > > no it is not really. Like most wikipedia articles it is written poorly > and leaves of coherent details. Your under no obligation to post, if > you don't want to contribute. Being an ass isn't helpful though and > treating me like I'm stupid makes me resentful >
The Wikipedia article there is reasonably written, and full of useful information. But you may not have made the connection as to why it is relevant to your problem.
Numbers bigger than single bytes in computing can be stored in two basic formats - big endian with the most significant byte first, and little endian with the least significant byte first. Some processors use one format, other processors use the other. Some file formats and protocols use one format, others use the other. If the processor and the file format do not match, then you need to convert when reading or writing the format.
x86 uses little endian format, so 13 is stored as 0b 00 00 00 as a 32-bit integer. PNG, like many network-related formats, uses big endian. So it stores 32-bit 13 as 00 00 00 0b. (Incidentally, use hex for this sort of thing - octal had no place in computing outside of "chmod" since the 1970's.)
Assuming you are trying to learn and understand this, rather than copy-and-paste working code, then this should be enough to get you going.
_______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|