Re: [dev] Looking for simple, alpha supporting image format

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Wed, 16 Jul 2014 16:09:03 +0200

koneu wrote:
> On July 16, 2014 3:28:44 PM CEST, Markus Teich <markus.teich_AT_stusta.mhn.de> wrote:
> > *w = ntohs(hdr[9]);
> > *h = ntohs(hdr[11]);
>
> This will pass a char to ntohs; expanding it to a uint16_t, instead of passing
> ntohs two bytes from the header.

Heyho,

of course you are right.

ntohs(hdr[9] << 8 | hdr[10])

or

uint16_t *tw = hdr+9;
*w = ntohs(*tw);

should work.

> The proper way would involve some pointer casting or a header struct.

With a struct you get alignment issues, especially with the 9 byte magic, which
aligns to nothing but 1 byte boundaries.

--Markus
Received on Wed Jul 16 2014 - 16:09:03 CEST

This archive was generated by hypermail 2.3.0 : Wed Jul 16 2014 - 16:12:16 CEST