openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Openexr-devel] (no subject)


From: Richard Annema
Subject: Re: [Openexr-devel] (no subject)
Date: Tue, 4 Nov 2003 00:57:50 +0100

Hi James,

I checked with Steve (the coder), and basically the format of the packedRGBA
UINT that we optionally let our users store is of the following form :
AAAAAAAA BBBBBBBB GGGGGGGG RRRRRRRR

I.e. packed by method of converting each channel to a single BYTE in range 0
.. 255, then bitshifted into position like so :
unsigned int dest = (a<<24)+(b<<16)+(g<<8)+r

To get a channel out again, you just do the reverse :
unsigned int uint32 = (src[x] >> 16) & 0xff; // this is the blue channel,
for example

Basically bringing the format to :
GGGGGGGG RRRRRRRR AAAAAAAA BBBBBBBB // all bits shifted 16 to the right

And then killling off all the extraneous bits ( read that whichever way :) )
from the G, R and A channels by using a bitwise AND with the value 255
(0xff).
00000000 00000000 00000000 11111111 // value 255 in 32bit space
&
GGGGGGGG RRRRRRRR AAAAAAAA BBBBBBBB // all our channels
==
00000000 000000000 00000000 BBBBBBBB // blue channel with leading zeroes,
which never get stored
so you get
BBBBBBBB // the blue channel

After that, all you have to do is convert it back into float of range 0.0f
.. 1.0f by dividing the original values of range 0 .. 255 by 255.0
float b = (float) uint32 / 255.0f

And you should be all set.

One more note / tip from Steve. If you think you'll run into loading/saving
issues between floating point to integer and back operations, you may want
to use the "/QIfist" flag with the Intel compiler. Of course if you're
well-versed in assembly, you can just inline the significant code* when
using different compilers :)

Kindest regards,
Richard Annema
Director of Client Relations
SplutterFish, LLC

*
static float max_short_value = 65535.0f; // To convert to BYTEs, try using
"max_char_value = 255.0f" instead
inline WORD m_ftos(float v)
{
   int tmp;
   __asm {
      fld           dword ptr [v]
      fmul        dword ptr [max_short_value] // make sure you change this
reference if you use 'max_char_value'
      fistp        dword ptr [tmp]
   }
   return ((WORD)tmp);
}


----- Original Message ----- 
From: "James McPhail" <address@hidden>
To: <address@hidden>
Sent: Monday, November 03, 2003 18:50
Subject: [Openexr-devel] (no subject)


> Hello
>
> can one export, say, the Red channel in UINT format, or can these types
> of channels only be FLOAT or HALF? I ask because the Splutterfish EXR
> exporter for 3DSMax claims to be able to export RGBA as UINTs, although
> upon doing so neither my own nor the ExrDisplay program can find these
> channels in the file (they both just display solid black). Also, I tried
> to enable my program to export to RGBA as UINTS, and I got strange
> results. Does the UINT use 0-255 as the the black-white levels?
>
> Thanks in advance!
> James
>
>
>
>
> _______________________________________________
> Openexr-devel mailing list
> address@hidden
> http://mail.nongnu.org/mailman/listinfo/openexr-devel
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]