Axiom.Media.PixelConverter.UnpackColor C# (CSharp) Method

UnpackColor() public static method

Unpack a color value from memory
This function returns the color components in 8 bit precision, this will lose precision when coming from A2R10G10B10 or floating point formats.
public static UnpackColor ( byte &r, byte &g, byte &b, byte &a, PixelFormat pf, IntPtr src ) : void
r byte The color is returned here (as byte)
g byte The color is returned here (as byte)
b byte The color is returned here (as byte)
a byte The color is returned here (as byte)
pf PixelFormat Pixelformat in which to read the color
src System.IntPtr Source memory location
return void
		public static void UnpackColor( ref byte r, ref byte g, ref byte b, ref byte a, PixelFormat pf, IntPtr src )
		{
			PixelFormatDescription des = GetDescriptionFor( pf );
			if ( ( des.flags & PixelFormatFlags.NativeEndian ) != 0 )
			{
				// Shortcut for integer formats unpacking
				uint value = Bitwise.IntRead( src, des.elemBytes );
				if ( ( des.flags & PixelFormatFlags.Luminance ) != 0 )
					// Luminance format -- only rbits used
					r = g = b = (byte)Bitwise.FixedToFixed( ( value & des.rmask ) >> des.rshift, des.rbits, 8 );
				else
				{
					r = (byte)Bitwise.FixedToFixed( ( value & des.rmask ) >> des.rshift, des.rbits, 8 );
					g = (byte)Bitwise.FixedToFixed( ( value & des.gmask ) >> des.gshift, des.gbits, 8 );
					b = (byte)Bitwise.FixedToFixed( ( value & des.bmask ) >> des.bshift, des.bbits, 8 );
				}
				if ( ( des.flags & PixelFormatFlags.HasAlpha ) != 0 )
				{
					a = (byte)Bitwise.FixedToFixed( ( value & des.amask ) >> des.ashift, des.abits, 8 );
				}
				else
					a = 255; // No alpha, default a component to full
			}
			else
			{
				// Do the operation with the more generic floating point
				float rr, gg, bb, aa;
				UnpackColor( out rr, out gg, out bb, out aa, pf, src );
				r = Bitwise.FloatToByteFixed( rr );
				g = Bitwise.FloatToByteFixed( gg );
				b = Bitwise.FloatToByteFixed( bb );
				a = Bitwise.FloatToByteFixed( aa );
			}
		}
        /// <summary>

Same methods

PixelConverter::UnpackColor ( PixelFormat pf, IntPtr src ) : ColorEx
PixelConverter::UnpackColor ( float &r, float &g, float &b, float &a, PixelFormat pf, IntPtr src ) : void

Usage Example

Beispiel #1
0
        private void Unpack(ref ColorEx dst, int x, int y, int z, PixelFormat format, BufferBase src, PixelBox srcbox,
                            int elemsize)
        {
            var data = src + (elemsize * ((x) + (y) * srcbox.RowPitch + (z) * srcbox.SlicePitch));

            dst = PixelConverter.UnpackColor(format, data);
        }
All Usage Examples Of Axiom.Media.PixelConverter::UnpackColor