static public IColorTable FromFile(string path) { IColorTable ct = null; XmlReader r = null; try { r = XmlReader.Create(path); r.ReadToFollowing("ColorTable"); ColorTableType ctt = (ColorTableType)Enum.Parse(typeof(ColorTableType), r["Type"]); int cts = int.Parse(r["Size"]); ScalingAlgorithms sa = (ScalingAlgorithms)Enum.Parse(typeof(ScalingAlgorithms), r["Scale"]); double min = double.Parse(r["Minimum"]); double max = double.Parse(r["Maximum"]); ct = ColorTableFactory.Create(ctt); if (ct != null) { ct.ScalingAlgorithm = ScalingAlgorithmFactory.Create(sa); ct.Initialize(cts, min, max); } } finally { if (r != null) { r.Close(); } } return(ct); }
public static IColorTable Create(ColorTableType ctt) { IColorTable ct = null; switch (ctt) { case ColorTableType.ReducedColors: ct = new ReducedColorTable(); break; case ColorTableType.FullScale: ct = new FullScaledColorTable(); break; case ColorTableType.Indexed: ct = new IndexedColorTable(); break; } return(ct); }
public static extern int GetDIBits(IntPtr dc, IntPtr bmp, int startScan, int scanLineCount, [In, Out] byte[] data, IntPtr info, ColorTableType usage);
private void LoadColorTable(SubCode subCode, ColorTableType tableType) { Console.WriteLine("Loading {0} colors", tableType); List <byte> colors = new List <byte>(); switch (tableType) { case ColorTableType.High: foreach (byte color in subCode.Data) { colors.Add((byte)(color & 0x3F3F)); if (colors.Count == 8) { break; } } for (int i = 0; i < colors.Count; i++) { byte color = colors[i]; int red = (color & 0x3F3F) >> 2; int halfGreen = (color & 0x3) << 2; if (this.colorTable.Count < i) { this.colorTable.Add(Color.FromArgb(red, halfGreen, 0)); } else { int preRed = this.colorTable[i].R; int preGreen = this.colorTable[i].G; this.colorTable[i] = Color.FromArgb( preRed += (byte)red, preGreen += (byte)halfGreen, this.colorTable[i].B); } } break; case ColorTableType.Low: subCode.Data.Reverse(); foreach (byte color in subCode.Data) { colors.Add(color); if (colors.Count == 8) { break; } } subCode.Data.Reverse(); for (int i = 0; i < colors.Count; i++) { byte color = colors[i]; int halfGreen = (color & 0x3) >> 4; int blue = (color & 0x3F3F) << 2; if (this.colorTable.Count <= i) { this.colorTable.Add(Color.FromArgb(0, halfGreen, blue)); } else { int preGreen = this.colorTable[i].G; int preBlue = this.colorTable[i].B; if (preBlue + blue > 255) { int temp = (blue + preBlue) - 255; preGreen += temp; preBlue -= temp; } this.colorTable[i] = Color.FromArgb( this.colorTable[i].R, preGreen += (byte)halfGreen, preBlue += (byte)blue); } } break; } }