Re: Something I don't understand about Resource Byte-swapping
Re: Something I don't understand about Resource Byte-swapping
- Subject: Re: Something I don't understand about Resource Byte-swapping
- From: Verizon <email@hidden>
- Date: Fri, 26 Oct 2012 08:25:22 -0400
- Importance: Normal
Hello Stephen,
Well Apple was a bit inconsistent on Byte-Swapping. I think, like you, went
the fast route and decided there were too many routines that took PICT
resources in Big-Endian mode and therefore left the data in that format.
Jeremy
-----Original Message-----
From: Stephen Kay
Sent: Thursday, October 25, 2012 10:12 PM
To: email@hidden
Subject: Something I don't understand about Resource Byte-swapping
There's something I need to understand about Resource byte-swapping in Intel
versions of software...
Background: porting an old Carbon PPC application (CW, PowerPlant) that is
heavily resource-based, and only had a PPC version, that runs fine on 10.4
to 10.6.8 (w/Rosetta). The goal is to get an Intel version with no new
features, just the capability to run on Intel machines - at least at first.
I've actually gotten all the byte-swapping to work, and the app now compiles
and looks normal on 10.4.11 Intel. (I have a Windows version of the
software, and I already had byte-swapping code for every resource type under
the sun including all of PowerPlant's resource types, and my custom
resources, so it was relatively easy to integrate that code on the Mac side,
without using the swap-big-to-host functions that are in Foundation and
CoreFoundation.)
What I don't quite get is this: apparently, Mac OS X automatically
byte-swaps data for *some* resources (standard ones like MENU, PICT, etc.)
So when I was doing my own byte-swapping on these standard resources, they
were getting double-swapped and PICTs (for example) would not display
correctly.
However, this code uses a lot of GWorlds, and while I know that I could
likely get rid of them on OS X since windows are double-buffered, the goal
here is the fastest possible transition to a shippable update that works on
Intel, so I want to just leave it as is for now.
The problem was: lets say you've got the following:
PicHandle ph = ::GetPicture(128);
and then you create a GWorld based on the size of the PicHandle's rect:
Rect bounds = (*ph)->picFrame;
NewGWorld(&myGWorld, 0, &bounds, 0L, 0L, kNativeEndianPixMap);
When I view the returned PicHandle in the debugger, the data looks wrong,
like it needs byte-swapping. The size field is flipped; the dimensions of
the rect are flipped. And if I pass this to the NewGWorld call, it will
return an error since the dimensions of the Rect are whacked.
So, I tried byte-swapping the PICT data. Now, it looks absolutely correct in
the debugger. Now, the creation of the GWorld gets the correct Rect size and
no error. But the picture doesn't draw (blank white area, or sometimes
garbage).
After much head-scratching, I had to do this: (get the PICT resource, do NOT
byte-swap it even though it looks wrong in the debugger, but byte-swap the
Rect when creating the GWorld) - and everything works!
PicHandle ph = ::GetPicture(128);
Rect bounds = (*ph)->picFrame;
#ifdef MAC_VERSION && defined(__LITTLE_ENDIAN__)
ByteSwap_Rect(&bounds);
#endif //MAC_VERSION && defined(__LITTLE_ENDIAN__)
NewGWorld(&myGWorld, 0, &bounds, 0L, 0L, kNativeEndianPixMap);
While my app now compiles and seems to be working on Intel, I'd love to
understand this. :-)
And apologies for being 8 years behind everyone else!
- Stephen
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Stephen Kay
Karma-Lab :: developers of KARMA
http://www.karma-lab.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden