private static void CombineTextures(Texture baseTexture, IFileLocator locator, string filename) { Texture newTexture; using (Stream file = locator.Open(filename)) { newTexture = Texture.FromStream(file); newTexture.Name = Path.GetFileNameWithoutExtension(filename); } if (newTexture.Width != baseTexture.Width || newTexture.Height != baseTexture.Height) { return; } newTexture.Convert8To32(); int size = baseTexture.Width * baseTexture.Height; byte[] src = newTexture.ImageData; byte[] dst = baseTexture.ImageData; for (int i = 0; i < size; i++) { int a = src[i * 4 + 3]; dst[i * 4 + 0] = (byte)(dst[i * 4 + 0] * (255 - a) / 255 + src[i * 4 + 0] * a / 255); dst[i * 4 + 1] = (byte)(dst[i * 4 + 1] * (255 - a) / 255 + src[i * 4 + 1] * a / 255); dst[i * 4 + 2] = (byte)(dst[i * 4 + 2] * (255 - a) / 255 + src[i * 4 + 2] * a / 255); } }
/// <summary> /// Detects if the specified root from a locator is a disc. /// </summary> /// <param name="locator">The locator.</param> /// <param name="root">The root.</param> /// <param name="detect">The detection function.</param> /// <returns>A boolean.</returns> private static bool IsDisc(IFileLocator locator, string root, Func <Stream, bool> detect) { using (var file = locator.Open(root)) { return(detect(file)); } }
/// <summary> /// Initializes a new instance of the <see cref="ArchiveFileLocator"/> class. /// </summary> /// <param name="locator">A file locator.</param> /// <param name="root">The root path.</param> public ArchiveFileLocator(IFileLocator locator, string root) { if (locator != null) { this.fileStream = locator.Open(root); this.archive = ArchiveFactory.Open(this.fileStream); } else { this.archive = ArchiveFactory.Open(root); } }
/// <summary> /// Initializes a new instance of the <see cref="DiscFsFileLocator"/> class. /// </summary> /// <param name="locator">A file locator.</param> /// <param name="root">The root path.</param> /// <param name="create">The create function.</param> protected DiscFsFileLocator(IFileLocator locator, string root, Func <Stream, DiscFileSystem> create) { if (locator != null) { this.fileStream = locator.Open(root); } else { this.fileStream = File.OpenRead(root); } this.disc = create(this.fileStream); }
/// <summary> /// Write the files from a file locator. /// </summary> /// <param name="locator">A file locator.</param> /// <param name="root">The root path.</param> public void WriteAll(IFileLocator locator, string root) { if (locator == null) { throw new ArgumentNullException("locator"); } foreach (var file in locator.EnumerateFiles(root)) { using (var stream = locator.Open(file)) { this.Write(file, stream); } } }