Axiom.Media.PixelConverter.UnpackColor C# (CSharp) Метод

UnpackColor() публичный статический Метод

Unpack a color value from memory
public static UnpackColor ( float &r, float &g, float &b, float &a, PixelFormat pf, IntPtr src ) : void
r float The color is returned here (as float)
g float The color is returned here (as float)
b float The color is returned here (as float)
a float The color is returned here (as float)
pf PixelFormat Pixelformat in which to read the color
src System.IntPtr Source memory location
Результат void
		public static void UnpackColor( out float r, out float g, out float b, out float 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 = Bitwise.FixedToFloat(
						( value & des.rmask ) >> des.rshift, des.rbits );
				}
				else
				{
					r = Bitwise.FixedToFloat( ( value & des.rmask ) >> des.rshift, des.rbits );
					g = Bitwise.FixedToFloat( ( value & des.gmask ) >> des.gshift, des.gbits );
					b = Bitwise.FixedToFloat( ( value & des.bmask ) >> des.bshift, des.bbits );
				}
				if ( ( des.flags & PixelFormatFlags.HasAlpha ) != 0 )
					a = Bitwise.FixedToFloat( ( value & des.amask ) >> des.ashift, des.abits );
				else
					a = 1.0f; // No alpha, default a component to full
			}
			else
			{
                unsafe{
                    switch (pf)
                    {
                        case PixelFormat.FLOAT32_R:
                            r = g = b = ((float*)src)[0];
                            a = 1.0f;
                            break;
                        case PixelFormat.FLOAT32_RGB:
                            r = ((float*)src)[0];
                            g = ((float*)src)[1];
                            b = ((float*)src)[2];
                            a = 1.0f;
                            break;
                        case PixelFormat.FLOAT32_RGBA:
                            r = ((float*)src)[0];
                            g = ((float*)src)[1];
                            b = ((float*)src)[2];
                            a = ((float*)src)[3];
                            break;
                        case PixelFormat.FLOAT16_R:
                            r = g = b = Bitwise.HalfToFloat(((ushort*)src)[0]);
                            a = 1.0f;
                            break;
                        case PixelFormat.FLOAT16_RGB:
                            r = Bitwise.HalfToFloat(((ushort*)src)[0]);
                            g = Bitwise.HalfToFloat(((ushort*)src)[1]);
                            b = Bitwise.HalfToFloat(((ushort*)src)[2]);
                            a = 1.0f;
                            break;
                        case PixelFormat.FLOAT16_RGBA:
                            r = Bitwise.HalfToFloat(((ushort*)src)[0]);
                            g = Bitwise.HalfToFloat(((ushort*)src)[1]);
                            b = Bitwise.HalfToFloat(((ushort*)src)[2]);
                            a = Bitwise.HalfToFloat(((ushort*)src)[3]);
                            break;
                        case PixelFormat.SHORT_RGBA:
                            r = Bitwise.FixedToFloat(((ushort*)src)[0], 16);
                            g = Bitwise.FixedToFloat(((ushort*)src)[1], 16);
                            b = Bitwise.FixedToFloat(((ushort*)src)[2], 16);
                            a = Bitwise.FixedToFloat(((ushort*)src)[3], 16);
                            break;
                        case PixelFormat.BYTE_LA:
                            r = g = b = Bitwise.FixedToFloat(((byte*)src)[0], 8);
                            a = Bitwise.FixedToFloat(((byte*)src)[1], 8);
                            break;
                        default:
                            // Not yet supported
                            throw new Exception("Unpack from " + pf + " not implemented, in PixelUtil.UnpackColor");
                    }
				}
			}
		}

Same methods

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

Usage Example

Пример #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