Axiom.Media.Bitwise.IntWrite C# (CSharp) Method

IntWrite() public static method

public static IntWrite ( IntPtr dest, int n, uint value ) : void
dest System.IntPtr
n int
value uint
return void
		public static void IntWrite( IntPtr dest, int n, uint value )
		{
            unsafe
            {
                switch (n)
                {
                    case 1:
                        ((byte*)dest)[0] = (byte)value;
                        break;
                    case 2:
                        ((ushort*)dest)[0] = (ushort)value;
                        break;
                    case 3:
#if BIG_ENDIAN
                    ((byte*)dest)[0] = (byte)((value >> 16) & 0xFF);
                    ((byte*)dest)[1] = (byte)((value >> 8) & 0xFF);
                    ((byte*)dest)[2] = (byte)(value & 0xFF);
#else
                        ((byte*)dest)[2] = (byte)((value >> 16) & 0xFF);
                        ((byte*)dest)[1] = (byte)((value >> 8) & 0xFF);
                        ((byte*)dest)[0] = (byte)(value & 0xFF);
#endif
                        break;
                    case 4:
                        ((uint*)dest)[0] = (uint)value;
                        break;
                }
            }
		}

Usage Example

        ///*************************************************************************
        ///   Pixel packing/unpacking utilities
        ///*************************************************************************


        //           ///<summary>
        //           ///    Pack a color value to memory
        //           ///</summary>
        //           ///<param name="color">The color</param>
        //           ///<param name="format">Pixel format in which to write the color</param>
        //           ///<param name="dest">Destination memory location</param>
        //          public static void PackColor(System.Drawing.Color color, PixelFormat format,  IntPtr dest) {
        //              PackColor(color.r, color.g, color.b, color.a, format, dest);
        //          }

        ///<summary>
        ///    Pack a color value to memory
        ///</summary>
        ///<param name="r,g,b,a">The four color components, range 0x00 to 0xFF</param>
        ///<param name="format">Pixelformat in which to write the color</param>
        ///<param name="dest">Destination memory location</param>
        unsafe public void PackColor(uint r, uint g, uint b, uint a, PixelFormat format, byte *dest)
        {
            PixelFormatDescription des = PixelConverter.GetDescriptionFor(format);

            if ((des.flags & PixelFormatFlags.NativeEndian) != 0)
            {
                // Shortcut for integer formats packing
                uint value = (((Bitwise.FixedToFixed(r, 8, des.rbits) << des.rshift) & des.rmask) |
                              ((Bitwise.FixedToFixed(g, 8, des.gbits) << des.gshift) & des.gmask) |
                              ((Bitwise.FixedToFixed(b, 8, des.bbits) << des.bshift) & des.bmask) |
                              ((Bitwise.FixedToFixed(a, 8, des.abits) << des.ashift) & des.amask));
                // And write to memory
                Bitwise.IntWrite(dest, des.elemBytes, value);
            }
            else
            {
                // Convert to float
                PackColor((float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f, format, dest);
            }
        }
All Usage Examples Of Axiom.Media.Bitwise::IntWrite