<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Monaco;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'>My application ray traces a 3D scene into a 2d array and then converts the result to a bitmap. The following code was producing colour shifted images<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              <span style='color:#0025FF'>byte</span> [] data = <span style='color:#0025FF'>new</span> <span style='color:#0025FF'>byte</span>[(width*<span style='color:#CC0ECB'>3</span>)*height] ;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              <span style='color:#0025FF'>var</span> ptr = <span style='color:#CC0ECB'>0</span>;<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              <span style='color:#0025FF'>for</span> (<span style='color:#0025FF'>int</span> y=<span style='color:#CC0ECB'>0</span>; y<height; y++)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                   <span style='color:#0025FF'>for</span> (<span style='color:#0025FF'>int</span> x=<span style='color:#CC0ECB'>0</span>; x<width; x++)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                   {<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        Rgba p = _pixels[x,y];<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        p.Clamp();<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        data[ptr++] = (<span style='color:#0025FF'>byte</span>)(p.values[<span style='color:#CC0ECB'>0</span>] * <span style='color:#CC0ECB'>255</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        data[ptr++] = (<span style='color:#0025FF'>byte</span>)(p.values[<span style='color:#CC0ECB'>1</span>] * <span style='color:#CC0ECB'>255</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        data[ptr++] = (<span style='color:#0025FF'>byte</span>)(p.values[<span style='color:#CC0ECB'>2</span>] * <span style='color:#CC0ECB'>255</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                   }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              }<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              Bitmap bmp = <span style='color:#0025FF'>new</span> System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              BitmapData bmpData = bmp.LockBits(<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                       <span style='color:#0025FF'>new</span> System.Drawing.Rectangle(<span style='color:#CC0ECB'>0</span>, <span style='color:#CC0ECB'>0</span>, width, height),   <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                       ImageLockMode.WriteOnly, <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                   bmp.PixelFormat);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'> <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                <span style='color:#339901'>//Copy the data from the byte array into BitmapData.Scan0<o:p></o:p></span></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                Marshal.Copy(data, <span style='color:#CC0ECB'>0</span>, bmpData.Scan0, data.Length);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                             <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                <span style='color:#339901'>//Unlock the pixels<o:p></o:p></span></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                bmp.UnlockBits(bmpData);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>              <span style='color:#0025FF'>return</span> bmp<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'>(values[0]..[2] is rgb)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'>When I changed it to <o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        data[ptr++] = (<span style='color:#0025FF'>byte</span>)(p.values[<span style='color:#CC0ECB'>2</span>] * <span style='color:#CC0ECB'>255</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        data[ptr++] = (<span style='color:#0025FF'>byte</span>)(p.values[<span style='color:#CC0ECB'>1</span>] * <span style='color:#CC0ECB'>255</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:Monaco'>                        data[ptr++] = (<span style='color:#0025FF'>byte</span>)(p.values[<span style='color:#CC0ECB'>0</span>] * <span style='color:#CC0ECB'>255</span>);<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'>It worked. It looks like 24bppRgb is being interpreted as 24bppBgr ???<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'>Has anyone seen this (or am I being an idiot and doing it wrong)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Helvetica","sans-serif"'>D</span><o:p></o:p></p></div></body></html>