summaryrefslogtreecommitdiff
path: root/Wrapper/FreeImage.NET/cs/Library/Structs/FI4BIT.cs
blob: 0188c6d07ae2bb988a2d3b42cdc0f8ec3c8b4173 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace FreeImageAPI
{
	/// <summary>
	/// The <b>FI4BIT</b> structure represents the half of a <see cref="Byte"/>.
	/// It's valuerange is between <i>0</i> and <i>15</i>.
	/// </summary>
	[DebuggerDisplay("{value}"),
	Serializable]
	public struct FI4BIT
	{
		/// <summary>
		/// Represents the largest possible value of <see cref="FI4BIT"/>. This field is constant.
		/// </summary>
		public const byte MaxValue = 0x0F;

		/// <summary>
		/// Represents the smallest possible value of <see cref="FI4BIT"/>. This field is constant.
		/// </summary>
		public const byte MinValue = 0x00;

		/// <summary>
		/// The value of the structure.
		/// </summary>
		private byte value;

		/// <summary>
		/// Initializes a new instance based on the specified value.
		/// </summary>
		/// <param name="value">The value to initialize with.</param>
		private FI4BIT(byte value)
		{
			this.value = (byte)(value & MaxValue);
		}

		/// <summary>
		/// Converts the value of a <see cref="FI4BIT"/> structure to a <see cref="Byte"/> structure.
		/// </summary>
		/// <param name="value">A <see cref="FI4BIT"/> structure.</param>
		/// <returns>A new instance of <see cref="FI4BIT"/> initialized to <paramref name="value"/>.</returns>
		public static implicit operator byte(FI4BIT value)
		{
			return value.value;
		}

		/// <summary>
		/// Converts the value of a <see cref="Byte"/> structure to a <see cref="FI4BIT"/> structure.
		/// </summary>
		/// <param name="value">A <see cref="Byte"/> structure.</param>
		/// <returns>A new instance of <see cref="FI4BIT"/> initialized to <paramref name="value"/>.</returns>
		public static implicit operator FI4BIT(byte value)
		{
			return new FI4BIT(value);
		}

		/// <summary>
		/// Converts the numeric value of the <see cref="FI4BIT"/> object
		/// to its equivalent string representation.
		/// </summary>
		/// <returns>The string representation of the value of this instance.</returns>
		public override string ToString()
		{
			return value.ToString();
		}
	}
}