Example #1
0
        public static uint IntRead(BufferBase src, int n)
        {
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                switch (n)
                {
                case 1:
                    return(src.ToBytePointer()[0]);

                case 2:
                    return(src.ToUShortPointer()[0]);

                case 3:
                    var s = src.ToBytePointer();
#if AXIOM_BIG_ENDIAN
                    return((uint)(s[0] << 16 |
                                  (s[1] << 8) |
                                  (s[2])));
#else
                    return((uint)(s[0] | (s[1] << 8) | (s[2] << 16)));
#endif
                case 4:
                    return(src.ToUIntPointer()[0]);
                }

                return(0); // ?
            }
        }
Example #2
0
        public static void IntWrite(BufferBase dest, int n, uint value)
        {
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                switch (n)
                {
                case 1:
                    dest.ToBytePointer()[0] = (byte)value;
                    break;

                case 2:
                    dest.ToUShortPointer()[0] = (ushort)value;
                    break;

                case 3:
                    var d = dest.ToBytePointer();
#if AXIOM_BIG_ENDIAN
                    d[0] = (byte)((value >> 16) & 0xFF);
                    d[1] = (byte)((value >> 8) & 0xFF);
                    d[2] = (byte)(value & 0xFF);
#else
                    d[2] = (byte)((value >> 16) & 0xFF);
                    d[1] = (byte)((value >> 8) & 0xFF);
                    d[0] = (byte)(value & 0xFF);
#endif
                    break;

                case 4:
                    dest.ToUIntPointer()[0] = value;
                    break;
                }
            }
        }
Example #3
0
        /// <summary>
        ///   Variant of ApplyGamma that operates on an unmanaged chunk of memory
        /// </summary>
        /// <param name="bufPtr"> </param>
        /// <param name="gamma"> </param>
        /// <param name="size"> </param>
        /// <param name="bpp"> </param>
        public static void ApplyGamma(BufferBase bufPtr, float gamma, int size, int bpp)
        {
            if (gamma == 1.0f)
            {
                return;
            }

            //NB only 24/32-bit supported
            if (bpp != 24 && bpp != 32)
            {
                return;
            }

            var stride = bpp >> 3;

#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                var srcBytes = bufPtr.ToBytePointer();

                for (int i = 0, j = size / stride, p = 0; i < j; i++, p += stride)
                {
                    float r, g, b;

                    r = (float)srcBytes[p + 0];
                    g = (float)srcBytes[p + 1];
                    b = (float)srcBytes[p + 2];

                    r = r * gamma;
                    g = g * gamma;
                    b = b * gamma;

                    float scale = 1.0f, tmp;

                    if (r > 255.0f && (tmp = (255.0f / r)) < scale)
                    {
                        scale = tmp;
                    }
                    if (g > 255.0f && (tmp = (255.0f / g)) < scale)
                    {
                        scale = tmp;
                    }
                    if (b > 255.0f && (tmp = (255.0f / b)) < scale)
                    {
                        scale = tmp;
                    }

                    r *= scale;
                    g *= scale;
                    b *= scale;

                    srcBytes[p + 0] = (byte)r;
                    srcBytes[p + 1] = (byte)g;
                    srcBytes[p + 2] = (byte)b;
                }
            }
        }
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToUShortPointer();
                    var outputPtr = output.ToBytePointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = (byte)(inp >> 8);
                }
            }
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToBytePointer();
                    var outputPtr = output.ToUShortPointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = (ushort)((((uint)inp) << 8) | (((uint)inp)));
                }
            }
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToBytePointer();
                    var outputPtr = output.ToUIntPointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = 0x000000FF | (((uint)inp) << 8) | (((uint)inp) << 16) | (((uint)inp) << 24);
                }
            }
            public void Convert(BufferBase input, BufferBase output, int offset)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    var inputPtr  = input.ToUIntPointer();
                    var outputPtr = output.ToBytePointer();
                    var inp       = inputPtr[offset];

                    outputPtr[offset] = (byte)((inp & 0x00FF0000) >> 16);
                }
            }
Example #8
0
        /// <summary>
        ///		Writes a specified number of bytes.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="count">Number of values to write.</param>
        /// <param name="src">Pointer that holds the values.</param>
        protected void WriteBytes(BinaryWriter writer, int count, BufferBase src)
        {
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                var pointer = src.ToBytePointer();

                for (var i = 0; i < count; i++)
                {
                    writer.Write(pointer[i]);
                }
            }
        }
Example #9
0
        private void _flipEndian(BufferBase pData, int size)
        {
#if AXIOM_BIG_ENDIAN
            byte swapByte;
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                var ptr = pData.ToBytePointer();
                for (var byteIndex = 0; byteIndex < size / 2; byteIndex++)
                {
                    swapByte                  = ptr[byteIndex];
                    ptr[byteIndex]            = ptr[size - byteIndex - 1];
                    ptr[size - byteIndex - 1] = swapByte;
                }
            }
#endif
        }
Example #10
0
        /// <summary>
        ///		Reads a specified number of floats and copies them into the destination pointer.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="count">Number of values to read.</param>
        /// <param name="dest">Pointer to copy the values into.</param>
        protected void ReadBytes(BinaryReader reader, int count, BufferBase dest)
        {
            // blast the data into the buffer
#if !AXIOM_SAFE_ONLY
            unsafe
#endif
            {
                var pointer = dest.ToBytePointer();
#if !(XBOX || XBOX360)
                for (var i = 0; i < count; i++)
                {
                    pointer[i] = reader.ReadByte();
                }
#else
                for (var i = 0; i < count; i += 4)
                {
                    pointer[i + 3] = reader.ReadByte();
                    pointer[i + 2] = reader.ReadByte();
                    pointer[i + 1] = reader.ReadByte();
                    pointer[i]     = reader.ReadByte();
                }
#endif
            }
        }
Example #11
0
		private void _flipEndian( BufferBase pData, int size )
		{
#if AXIOM_BIG_ENDIAN
			byte swapByte;
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				var ptr = pData.ToBytePointer();
				for ( var byteIndex = 0; byteIndex < size / 2; byteIndex++ )
				{
					swapByte = ptr[ byteIndex ];
					ptr[ byteIndex ] = ptr[ size - byteIndex - 1 ];
					ptr[ size - byteIndex - 1 ] = swapByte;
				}
			}
#endif
		}
Example #12
0
		/// <summary>
		///		Writes a specified number of bytes.
		/// </summary>
		/// <param name="writer"></param>
		/// <param name="count">Number of values to write.</param>
		/// <param name="src">Pointer that holds the values.</param>
		protected void WriteBytes( BinaryWriter writer, int count, BufferBase src )
		{
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				var pointer = src.ToBytePointer();

				for ( var i = 0; i < count; i++ )
				{
					writer.Write( pointer[ i ] );
				}
			}
		}
Example #13
0
		/// <summary>
		///		Reads a specified number of floats and copies them into the destination pointer.
		/// </summary>
		/// <param name="reader"></param>
		/// <param name="count">Number of values to read.</param>
		/// <param name="dest">Pointer to copy the values into.</param>
		protected void ReadBytes( BinaryReader reader, int count, BufferBase dest )
		{
			// blast the data into the buffer
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				var pointer = dest.ToBytePointer();
#if !(XBOX || XBOX360)
				for ( var i = 0; i < count; i++ )
				{
					pointer[ i ] = reader.ReadByte();
				}
#else
				for ( var i = 0; i < count; i += 4 )
				{
					pointer[ i + 3 ] = reader.ReadByte();
					pointer[ i + 2 ] = reader.ReadByte();
					pointer[ i + 1 ] = reader.ReadByte();
					pointer[ i ] = reader.ReadByte();
				}
#endif
			}
		}
Example #14
0
		public static uint IntRead( BufferBase src, int n )
		{
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				switch ( n )
				{
					case 1:
						return src.ToBytePointer()[ 0 ];

					case 2:
						return src.ToUShortPointer()[ 0 ];

					case 3:
						var s = src.ToBytePointer();
#if AXIOM_BIG_ENDIAN
						return (uint)( s[ 0 ] << 16 |
									   ( s[ 1 ] << 8 ) |
									   ( s[ 2 ] ) );
#else
						return (uint)( s[ 0 ] | ( s[ 1 ] << 8 ) | ( s[ 2 ] << 16 ) );
#endif
					case 4:
						return src.ToUIntPointer()[ 0 ];
				}

				return 0; // ?
			}
		}
Example #15
0
		public static void IntWrite( BufferBase dest, int n, uint value )
		{
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				switch ( n )
				{
					case 1:
						dest.ToBytePointer()[ 0 ] = (byte)value;
						break;

					case 2:
						dest.ToUShortPointer()[ 0 ] = (ushort)value;
						break;

					case 3:
						var d = dest.ToBytePointer();
#if AXIOM_BIG_ENDIAN
						d[ 0 ] = (byte)( ( value >> 16 ) & 0xFF );
						d[ 1 ] = (byte)( ( value >> 8 ) & 0xFF );
						d[ 2 ] = (byte)( value & 0xFF );
#else
						d[ 2 ] = (byte)( ( value >> 16 ) & 0xFF );
						d[ 1 ] = (byte)( ( value >> 8 ) & 0xFF );
						d[ 0 ] = (byte)( value & 0xFF );
#endif
						break;

					case 4:
						dest.ToUIntPointer()[ 0 ] = value;
						break;
				}
			}
		}
Example #16
0
		/// <summary>
		///   Variant of ApplyGamma that operates on an unmanaged chunk of memory
		/// </summary>
		/// <param name="bufPtr"> </param>
		/// <param name="gamma"> </param>
		/// <param name="size"> </param>
		/// <param name="bpp"> </param>
		public static void ApplyGamma( BufferBase bufPtr, float gamma, int size, int bpp )
		{
			if ( gamma == 1.0f )
			{
				return;
			}

			//NB only 24/32-bit supported
			if ( bpp != 24 && bpp != 32 )
			{
				return;
			}

			var stride = bpp >> 3;
#if !AXIOM_SAFE_ONLY
			unsafe
#endif
			{
				var srcBytes = bufPtr.ToBytePointer();

				for ( int i = 0, j = size/stride, p = 0; i < j; i++, p += stride )
				{
					float r, g, b;

					r = (float)srcBytes[ p + 0 ];
					g = (float)srcBytes[ p + 1 ];
					b = (float)srcBytes[ p + 2 ];

					r = r*gamma;
					g = g*gamma;
					b = b*gamma;

					float scale = 1.0f, tmp;

					if ( r > 255.0f && ( tmp = ( 255.0f/r ) ) < scale )
					{
						scale = tmp;
					}
					if ( g > 255.0f && ( tmp = ( 255.0f/g ) ) < scale )
					{
						scale = tmp;
					}
					if ( b > 255.0f && ( tmp = ( 255.0f/b ) ) < scale )
					{
						scale = tmp;
					}

					r *= scale;
					g *= scale;
					b *= scale;

					srcBytes[ p + 0 ] = (byte)r;
					srcBytes[ p + 1 ] = (byte)g;
					srcBytes[ p + 2 ] = (byte)b;
				}
			}
		}