Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-24 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 24 June 2017 at 02:52:23 UTC, Felix wrote: I'm trying to read in just the first part of a .png file to peek at it's width and height without loading in the whole file. I'm using FreeImage for reading the whole file but since it doesn't have a function to let me peek at the image

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/24/17 1:18 AM, H. S. Teoh via Digitalmars-d-learn wrote: On Fri, Jun 23, 2017 at 10:10:22PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: On 06/23/2017 09:26 PM, Felix wrote: That works, thanks! I've just tried this, which seems cleaner: import std.stdio; import std.system; import

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-24 Thread Ali Çehreli via Digitalmars-d-learn
On 06/23/2017 10:18 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Fri, Jun 23, 2017 at 10:10:22PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: On 06/23/2017 09:26 PM, Felix wrote: That works, thanks! I've just tried this, which seems cleaner: import std.stdio; import std.system;

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 23, 2017 at 10:10:22PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 06/23/2017 09:26 PM, Felix wrote: > > That works, thanks! > > I've just tried this, which seems cleaner: > > import std.stdio; > import std.system; > import std.bitmanip; > > void ensureBigEndian(T)(ref T

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-23 Thread Ali Çehreli via Digitalmars-d-learn
On 06/23/2017 09:26 PM, Felix wrote: That works, thanks! I've just tried this, which seems cleaner: import std.stdio; import std.system; import std.bitmanip; void ensureBigEndian(T)(ref T value) { if (endian == Endian.littleEndian) { value = *cast(T*)nativeToBigEndian(value).ptr;

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-23 Thread Felix via Digitalmars-d-learn
That works, thanks!

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-23 Thread Ali Çehreli via Digitalmars-d-learn
On 06/23/2017 07:52 PM, Felix wrote: > So I'm guessing my ubytes are in the wrong order in the uint... how should I put them around the correct way so that my code won't break on another machine with different endianness? Yes, that would happen when your system is little-endian. (According to

Converting a ubyte[] to a struct with respect to endianness?

2017-06-23 Thread Felix via Digitalmars-d-learn
I'm trying to read in just the first part of a .png file to peek at it's width and height without loading in the whole file. I'm using FreeImage for reading the whole file but since it doesn't have a function to let me peek at the image size before loading it all in I'm rolling my own. I've