Endian, I hate you
I'm attempting to read a jpg file from the data provided here.
When I read the markers (start of image, jfif, etc, etc), where the marker is supposed to be FFD8 I read D8FF, and when I'm trying to read FFE0, I get E0FF.
Is this endianness stuffing me around? If so, does this mean I'm going to have to swap every two bytes that I read from the file.
I'm not sure if it was endianness, because it has happened so far with every jpg file that I've tried, and these are all wallpapers downloaded from the net.
Quote:Original post by ApochPiQ
Sounds like an endianness issue indeed. What architecture are you running on?
I'm running winXP, so, a little endian architecture, right?
Quote:Original post by igni ferroque
Yes, JPEG is a Big-endian format.
Damn. Does this mean that as I'm working on a little endian architecture, I have to swap around the bytes of every short and int that I read from the file before I actually use it?
When swapping, with a short, I just swap the 2 bytes, right?
And with an integer, or anything with 4 bytes, I have to swap bytes 0,3 together and bytes 1,2 together, right?
Welcome to the world of Xbox 360. I don't know how many bugs we've had thanks to endian issues on the 360 platorm. You'd think by this point in microprocessors we'd all be able to agree on something so low level.
Quote:Original post by EndarQuote:Original post by ApochPiQ
Sounds like an endianness issue indeed. What architecture are you running on?
I'm running winXP, so, a little endian architecture, right?Quote:Original post by igni ferroque
Yes, JPEG is a Big-endian format.
Damn. Does this mean that as I'm working on a little endian architecture, I have to swap around the bytes of every short and int that I read from the file before I actually use it?
When swapping, with a short, I just swap the 2 bytes, right?
And with an integer, or anything with 4 bytes, I have to swap bytes 0,3 together and bytes 1,2 together, right?
Correct. I suggest writing some small functions to automatically do it. Or write your own stream implementation [grin].
Quote:Original post by _goatQuote:Original post by Endar
I'm running winXP, so, a little endian architecture, right?Quote:Original post by igni ferroque
Yes, JPEG is a Big-endian format.
Damn. Does this mean that as I'm working on a little endian architecture, I have to swap around the bytes of every short and int that I read from the file before I actually use it?
When swapping, with a short, I just swap the 2 bytes, right?
And with an integer, or anything with 4 bytes, I have to swap bytes 0,3 together and bytes 1,2 together, right?
Correct. I suggest writing some small functions to automatically do it. Or write your own stream implementation [grin].
:D Hmmm, writing my own stream implementation ... tempting, but I think it would be a little overkill for a program that changes the windows wallpaper. [smile] Also, I would have no idea where to start.
Quote:Original post by Mike Bossy
Welcome to the world of Xbox 360. I don't know how many bugs we've had thanks to endian issues on the 360 platorm. You'd think by this point in microprocessors we'd all be able to agree on something so low level.
Do you do what _goat suggested and write a stream implementation to work with, or do you pre-process the data files? Or do you do something completely different?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement