/// <summary> Loads a TrigradCompressed image from a stream. </summary> public TrigradCompressed(Stream s) { using (BZip2InputStream dezipper = new BZip2InputStream(s)) using (BinaryReader reader = new BinaryReader(dezipper)) { Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); uint count = reader.ReadUInt32(); Point[] points = new Point[count]; for (int i = 0; i < count; i++) points[i].X = reader.ReadUInt16(); for (int i = 0; i < count; i++) points[i].Y = reader.ReadUInt16(); ColorStruct[] colors = new ColorStruct[count]; for (int i = 0; i < count; i++) colors[i].R = reader.ReadByte(); for (int i = 0; i < count; i++) colors[i].G = reader.ReadByte(); for (int i = 0; i < count; i++) colors[i].B = reader.ReadByte(); for (int i = 0; i < count; i++) { SampleTable.Add(points[i],colors[i].Color); } uint meshCount = reader.ReadUInt32(); SampleTri[] tris = new SampleTri[meshCount]; for (int i = 0; i < meshCount; i++) tris[i] = new SampleTri(); for (int i = 0; i < meshCount; i++) tris[i].U = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black)); for (int i = 0; i < meshCount; i++) tris[i].V = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black)); for (int i = 0; i < meshCount; i++) tris[i].W = new Sample(points[reader.ReadInt32()], new Pixel(Color.Black)); foreach (var tri in tris) { tri.U.Color = SampleTable[tri.U.Point]; tri.V.Color = SampleTable[tri.V.Point]; tri.W.Color = SampleTable[tri.W.Point]; } Mesh = tris.ToList(); } }
/// <summary> /// Initializes a new instance of the <see cref="Window"/> class. /// </summary> /// <param name="id"> /// The window id. /// </param> /// <param name="fontHeight"> /// Font height. /// </param> /// <param name="fontWidth"> /// Font width. /// </param> /// <param name="background"> /// Background colour. /// </param> /// <param name="foreground"> /// Foreground colour. /// </param> internal Window(ushort id, byte fontHeight, byte fontWidth, ColorStruct background, ColorStruct foreground) { this.id = id; this.Attributes = WindowAttributes.BufferingEnabled; this.Column = 1; this.Row = 1; this.CursorColumn = 1; this.CursorRow = 1; this.FontNumber = 1; this.FontHeight = fontHeight; this.FontWidth = fontWidth; this.Background = background; this.Foreground = foreground; }
public Color this[int x, int y] { get { ColorStruct[,] pixels = new ColorStruct[Height, Width]; GL.BindTexture(TextureTarget.Texture2D, tex); GL.GetTexImage(TextureTarget.Texture2D, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixels); var c = pixels[y, x]; return new Color(c.r / 255.0, c.g / 255.0, c.b / 255.0, c.a / 255.0); } set { ColorStruct[,] pixels = new ColorStruct[1, 1]; pixels[0, 0] = new ColorStruct(value); GL.BindTexture(TextureTarget.Texture2D, tex); GL.TexSubImage2D(TextureTarget.Texture2D, 0, x, y, 1, 1, PixelFormat.Rgba, PixelType.UnsignedByte, pixels); } }
/// <summary> /// Get colour number from colour. /// </summary> /// <param name="colour"> /// True colour. /// </param> /// <returns> /// Colour number. /// </returns> protected byte ColorToColorNumber(ColorStruct colour) { for (byte colourNumber = 0; colourNumber < this.customColours.Length; colourNumber++) { var definedColour = this.customColours[colourNumber]; if (definedColour.HasValue && colour.Equals(definedColour.Value)) { return colourNumber; } } var result = this.nextCustomColourNumber; this.customColours[result] = colour; if (++this.nextCustomColourNumber == 0) { this.nextCustomColourNumber = 16; } return result; }
/// <summary> /// Converts true colour to 15-bit. /// </summary> /// <param name="colour"> /// True colour. /// </param> /// <returns> /// 15-bit colour. /// </returns> protected static short ColorToFifteenBit(ColorStruct colour) { return (byte)((colour.RedComponent >> 3) + ((colour.GreenComponent >> 3) << 5) + ((colour.BlueComponent >> 3) << 10)); }
/// <summary> /// Determines whether two colours are equal. /// </summary> /// <param name="color"> /// The colour to compare. /// </param> /// <returns> /// A value indicating whether two colours are equal. /// </returns> internal bool Equals(ColorStruct color) { return this.redComponent == color.redComponent && this.greenComponent == color.greenComponent && this.blueComponent == color.blueComponent && this.alphaComponent == color.alphaComponent; }
/// <summary> /// Blends two colours. /// </summary> /// <param name="color"> /// The colour to add. /// </param> /// <param name="alpha"> /// The alpha transparency. /// </param> /// <returns> /// The blended colour. /// </returns> internal ColorStruct Blend(ColorStruct color, byte alpha) { // todo: Handle transparent. var originalFactor = ~alpha; var r = (byte)(((this.redComponent * originalFactor) + (color.redComponent * alpha)) / byte.MaxValue); var g = (byte)(((this.greenComponent * originalFactor) + (color.greenComponent * alpha)) / byte.MaxValue); var b = (byte)(((this.blueComponent * originalFactor) + (color.blueComponent * alpha)) / byte.MaxValue); return new ColorStruct(r, g, b); }