/// <summary> /// Reads hues.mul and fills <see cref="List"/> /// </summary> public static void Initialize() { string path = Files.GetFilePath("hues.mul"); int index = 0; List = new Hue[3000]; if (path != null) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { int blockCount = (int)fs.Length / 708; if (blockCount > 375) { blockCount = 375; } m_Header = new int[blockCount]; unsafe { int structsize = Marshal.SizeOf(typeof(HueDataMul)); byte[] buffer = new byte[blockCount * (4 + 8 * structsize)]; GCHandle gc = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { fs.Read(buffer, 0, buffer.Length); long currpos = 0; for (int i = 0; i < blockCount; ++i) { IntPtr ptrheader = new IntPtr((long)gc.AddrOfPinnedObject() + currpos); currpos += 4; m_Header[i] = (int)Marshal.PtrToStructure(ptrheader, typeof(int)); for (int j = 0; j < 8; ++j, ++index) { IntPtr ptr = new IntPtr((long)gc.AddrOfPinnedObject() + currpos); currpos += structsize; HueDataMul cur = (HueDataMul)Marshal.PtrToStructure(ptr, typeof(HueDataMul)); List[index] = new Hue(index, cur); } } } finally { gc.Free(); } } } } for (; index < List.Length; ++index) { List[index] = new Hue(index); } }
public Hue(int index, HueDataMul mulstruct) { Index = index; Colors = new short[32]; for (int i = 0; i < 32; ++i) { Colors[i] = (short)(mulstruct.colors[i] | 0x8000); } TableStart = (short)(mulstruct.tablestart | 0x8000); TableEnd = (short)(mulstruct.tableend | 0x8000); Name = NativeMethods.ReadNameString(mulstruct.name, 20); Name = Name.Replace("\n", " "); }
public Hue(int index, HueDataMul mulstruct) { Index = index; Colors = new short[32]; unsafe { for (int i = 0; i < 32; ++i) Colors[i] = (short)(mulstruct.colors[i] | 0x8000); TableStart = (short)(mulstruct.tablestart | 0x8000); TableEnd = (short)(mulstruct.tableend | 0x8000); Name = NativeMethods.ReadNameString(mulstruct.name, 20); Name = Name.Replace("\n", " "); } }