On 2/16/07, Frank Condello <[EMAIL PROTECTED]> wrote:
> Finally, there are even more subtle issues. I create an RGB image
> from raw pixel data by calling:
>
> sourceMap = GetGWorldPixMap( (GWorldPtr) sourceDes.pictureData);
> ...
> sourceData = (long*) GetPixBaseAddr( sourceMap ); // get the base addr
> of pix data
>
> then generate the 32 bit color (8 bits per color channel + alpha):
>
> sourceData[sourceLineAddrOffset+xCtr] = (redColor << 16) | (grnColor
> << 8) | (bluColor);
>
> where red/grn/bluColor vary from 0-255 depending on the pixel values.
> Even tho numerically the pixel values are correct on Intel, the color
> generated by the last statement is wrong: is that because
> red/grn/bluColor are shifted into the wrong byte positions because of
> Intel endianness (this was originally written for PPC)?
>
> This could break many plugin operations that perform direct byte-wise
> access of pointers.
Don't confuse pixel formats with endianess - these are related
problems but not the same thing! The LittleEndian property is of
little use unless you need to reverse a 4byte pixel wholesale: RGBA-
>ABGR isn't a common operation. Often you just have to reverse the
RGB byte order (RGBA->BGRA) or move the alpha byte to a different end
(RGBA->ARGB) rather than swap everything.
to answer my own question, and in case anyone else runs into this,
this is what you need to do and seems to work:
#if defined(__i386__)
sourceData[sourceLineAddrOffset+xCtr]
= (bluSample << 24) |
(grnSample << 16) | (redSample << 8); // Intel
#else
sourceData[sourceLineAddrOffset+xCtr]
= (redSample << 16) |
(grnSample << 8) | (bluSample); // PPC
#endif
--
-------------------------------------------------------------------------------
Peter K. Stys, MD
Professor of Medicine(Neurology), Senior Scientist
Ottawa Health Research Institute, Div. of Neuroscience
Ottawa Hospital / University of Ottawa
Ontario, CANADA
tel: (613)761-5444
fax: (613)761-5330
http://www.ohri.ca/profiles/stys.asp
-------------------------------------------------------------------------------
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>