// This loads the image protected override LocalLoadResult LocalLoadImage() { // Load file data Bitmap bitmap = null; string error = null; MemoryStream filedata = datareader.LoadFile(filepathname); //mxd isBadForLongTextureNames = false; if (filedata != null) { // Get a reader for the data bitmap = ImageDataFormat.TryLoadImage(filedata, probableformat, General.Map.Data.Palette); // Not loaded? if (bitmap == null) { error = "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\""; } filedata.Dispose(); } return(new LocalLoadResult(bitmap, error)); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Load file data Bitmap bitmap = null; string error = null; MemoryStream filedata = null; try { filedata = new MemoryStream(File.ReadAllBytes(filepathname)); } catch (IOException) { error = "Image file \"" + filepathname + "\" could not be read, while loading image \"" + this.Name + "\". Consider reloading resources."; } if (filedata != null) { // Get a reader for the data bitmap = ImageDataFormat.TryLoadImage(filedata, probableformat, General.Map.Data.Palette); // Not loaded? if (bitmap == null) { error = "Image file \"" + filepathname + "\" data format could not be read, while loading image \"" + this.Name + "\". Is this a valid picture file at all?"; } filedata.Dispose(); } return(new LocalLoadResult(bitmap, error)); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Get the patch data stream Bitmap bitmap = null; string error = null; string sourcelocation = string.Empty; Stream data = General.Map.Data.GetHiResTextureData(shortname, ref sourcelocation); if (data != null) { // Copy patch data to memory byte[] membytes = new byte[(int)data.Length]; lock (data) //mxd { data.Seek(0, SeekOrigin.Begin); data.Read(membytes, 0, (int)data.Length); } MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); bitmap = ImageDataFormat.TryLoadImage(mem, (isFlat ? ImageDataFormat.DOOMFLAT : ImageDataFormat.DOOMPICTURE), General.Map.Data.Palette); // Not loaded? if (bitmap == null) { error = "Image lump \"" + Path.Combine(sourcelocation, filepathname.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)) + "\" data format could not be read, while loading HiRes texture \"" + this.Name + "\". Does this lump contain valid picture data at all?"; } // Done mem.Dispose(); } else { error = "Image lump \"" + shortname + "\" could not be found, while loading HiRes texture \"" + this.Name + "\". Did you forget to include required resources?"; } return(new LocalLoadResult(bitmap, error, () => { // Apply source overrides? if (!sourcesize.IsEmpty) { scale = new Vector2D(ScaledWidth / width, ScaledHeight / height); } else { if (overridesettingsapplied) { General.ErrorLogger.Add(ErrorType.Warning, "Unable to get source texture dimensions while loading HiRes texture \"" + this.Name + "\"."); } // Use our own size... sourcesize = new Size(width, height); } })); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { Bitmap bitmap = null; string error = null; // Get the lump data stream string flatlocation = string.Empty; //mxd Stream lumpdata = General.Map.Data.GetFlatData(Name, hasLongName, ref flatlocation); if (lumpdata != null) { // Copy lump data to memory byte[] membytes = new byte[(int)lumpdata.Length]; lock (lumpdata) //mxd { lumpdata.Seek(0, SeekOrigin.Begin); lumpdata.Read(membytes, 0, (int)lumpdata.Length); } MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); // Get a reader for the data bitmap = ImageDataFormat.TryLoadImage(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette); if (bitmap == null) { // Data is in an unknown format! error = "Flat lump \"" + Path.Combine(flatlocation, Name) + "\" data format could not be read. Does this lump contain valid picture data at all?"; } // Done mem.Dispose(); } else { // Missing a patch lump! error = "Missing flat lump \"" + Name + "\". Did you forget to include required resources?"; } return(new LocalLoadResult(bitmap, error, () => { scale.x = General.Map.Config.DefaultFlatScale; scale.y = General.Map.Config.DefaultFlatScale; })); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Get the lump data stream Bitmap bitmap = null; string error = null; string spritelocation = string.Empty; //mxd Stream lumpdata = General.Map.Data.GetSpriteData(Name, ref spritelocation); if (lumpdata != null) { // Get a reader for the data bitmap = ImageDataFormat.TryLoadImage(lumpdata, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette, out offsetx, out offsety); if (bitmap == null) { // Data is in an unknown format! error = "Sprite lump \"" + Path.Combine(spritelocation, Name) + "\" data format could not be read. Does this lump contain valid picture data at all?"; } // Done lumpdata.Close(); } else { // Missing a patch lump! error = "Missing sprite lump \"" + Name + "\". Forgot to include required resources?"; } return(new LocalLoadResult(bitmap, error, () => { scale.x = 1.0f; scale.y = 1.0f; // Make offset corrections if the offset was not given if ((offsetx == int.MinValue) || (offsety == int.MinValue)) { offsetx = (int)((width * scale.x) * 0.5f); offsety = (int)(height * scale.y); } })); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { Bitmap bitmap = null; string error = null; // Get the lump data stream Stream lumpdata = General.Map.Data.GetColormapData(Name); if (lumpdata != null) { // Copy lump data to memory lumpdata.Seek(0, SeekOrigin.Begin); byte[] membytes = new byte[(int)lumpdata.Length]; lumpdata.Read(membytes, 0, (int)lumpdata.Length); MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); // Get a reader for the data bitmap = ImageDataFormat.TryLoadImage(mem, ImageDataFormat.DOOMCOLORMAP, General.Map.Data.Palette); if (bitmap == null) { // Data is in an unknown format! error = "Colormap lump \"" + Name + "\" data format could not be read. Does this lump contain valid colormap data at all?"; } // Done mem.Dispose(); } else { // Missing a patch lump! error = "Missing colormap lump \"" + Name + "\". Did you forget to include required resources?"; } return(new LocalLoadResult(bitmap, error, () => { scale.x = General.Map.Config.DefaultFlatScale; scale.y = General.Map.Config.DefaultFlatScale; })); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Get the patch data stream Bitmap bitmap = null; string error = null; string patchlocation = string.Empty; //mxd Stream patchdata = General.Map.Data.GetTextureData(lumpname, hasLongName, ref patchlocation); if (patchdata != null) { // Copy patch data to memory byte[] membytes = new byte[(int)patchdata.Length]; lock (patchdata) //mxd { patchdata.Seek(0, SeekOrigin.Begin); patchdata.Read(membytes, 0, (int)patchdata.Length); } MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); bitmap = ImageDataFormat.TryLoadImage(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette); // Not loaded? if (bitmap == null) { error = "Image lump \"" + Path.Combine(patchlocation, lumpname) + "\" data format could not be read, while loading texture \"" + this.Name + "\". Does this lump contain valid picture data at all?"; } // Done mem.Dispose(); } else { error = "Image lump \"" + lumpname + "\" could not be found, while loading texture \"" + this.Name + "\". Did you forget to include required resources?"; } return(new LocalLoadResult(bitmap, error)); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Checks if (width == 0 || height == 0) { return(new LocalLoadResult(null)); } Graphics g = null; Bitmap bitmap = null; List <LogMessage> messages = new List <LogMessage>(); // Create texture bitmap try { if (bitmap != null) { bitmap.Dispose(); } bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); PixelColor *pixels = (PixelColor *)bitmapdata.Scan0.ToPointer(); General.ZeroPixels(pixels, width * height); bitmap.UnlockBits(bitmapdata); g = Graphics.FromImage(bitmap); } catch (Exception e) { // Unable to make bitmap messages.Add(new LogMessage(ErrorType.Error, "Unable to load texture image \"" + this.Name + "\". " + e.GetType().Name + ": " + e.Message)); } int missingpatches = 0; //mxd if (patches.Count == 0) //mxd { //mxd. Empty image will suffice here, I suppose... if (nulltexture) { return(new LocalLoadResult(bitmap, messages)); } // No patches! messages.Add(new LogMessage(ErrorType.Error, "No patches are defined for texture \"" + this.Name + "\"")); } else if (!messages.Any(x => x.Type == ErrorType.Error)) { // Go for all patches foreach (TexturePatch p in patches) { //mxd. Some patches (like "TNT1A0") should be skipped if (p.Skip) { continue; } // Get the patch data stream string patchlocation = string.Empty; //mxd Stream patchdata = General.Map.Data.GetPatchData(p.LumpName, p.HasLongName, ref patchlocation); if (patchdata != null) { // Copy patch data to memory byte[] membytes = new byte[(int)patchdata.Length]; lock (patchdata) //mxd { patchdata.Seek(0, SeekOrigin.Begin); patchdata.Read(membytes, 0, (int)patchdata.Length); } MemoryStream mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); Bitmap patchbmp = ImageDataFormat.TryLoadImage(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette); if (patchbmp == null) { //mxd. Probably that's a flat?.. if (General.Map.Config.MixTexturesFlats) { patchbmp = ImageDataFormat.TryLoadImage(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette); } if (patchbmp == null) { // Data is in an unknown format! if (!nulltexture) { messages.Add(new LogMessage(optional ? ErrorType.Warning : ErrorType.Error, "Patch lump \"" + Path.Combine(patchlocation, p.LumpName) + "\" data format could not be read, while loading texture \"" + this.Name + "\"")); } missingpatches++; //mxd } } if (patchbmp != null) { //mxd. Apply transformations from TexturePatch patchbmp = TransformPatch(bitmap, p, patchbmp); // Draw the patch on the texture image Rectangle tgtrect = new Rectangle(p.X, p.Y, patchbmp.Size.Width, patchbmp.Size.Height); g.DrawImageUnscaledAndClipped(patchbmp, tgtrect); patchbmp.Dispose(); } // Done mem.Dispose(); } else { //mxd. ZDoom can use any known graphic as patch if (General.Map.Config.MixTexturesFlats) { ImageData img = General.Map.Data.GetTextureImage(p.LumpName); if (!(img is UnknownImage) && img != this) { //mxd. Apply transformations from TexturePatch. We don't want to modify the original bitmap here, so make a copy Bitmap bmp = new Bitmap(img.LocalGetBitmap()); Bitmap patchbmp = TransformPatch(bitmap, p, bmp); // Draw the patch on the texture image Rectangle tgtrect = new Rectangle(p.X, p.Y, patchbmp.Size.Width, patchbmp.Size.Height); g.DrawImageUnscaledAndClipped(patchbmp, tgtrect); patchbmp.Dispose(); continue; } } // Missing a patch lump! if (!nulltexture) { messages.Add(new LogMessage(optional ? ErrorType.Warning : ErrorType.Error, "Missing patch lump \"" + p.LumpName + "\" while loading texture \"" + this.Name + "\"")); } missingpatches++; //mxd } } } // Dispose bitmap if load failed if (!nulltexture && (bitmap != null) && (messages.Any(x => x.Type == ErrorType.Error) || missingpatches >= patches.Count)) //mxd. We can still display texture if at least one of the patches was loaded { bitmap.Dispose(); bitmap = null; } return(new LocalLoadResult(bitmap, messages)); }
// This loads the image protected override LocalLoadResult LocalLoadImage() { // Checks if (width == 0 || height == 0) { return(new LocalLoadResult(null)); } BitmapData bitmapdata = null; PixelColor *pixels = (PixelColor *)0; Bitmap bitmap = null; List <LogMessage> messages = new List <LogMessage>(); // Create texture bitmap try { if (bitmap != null) { bitmap.Dispose(); } bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); pixels = (PixelColor *)bitmapdata.Scan0.ToPointer(); General.ZeroMemory(new IntPtr(pixels), width * height * sizeof(PixelColor)); } catch (Exception e) { // Unable to make bitmap messages.Add(new LogMessage(ErrorType.Error, "Unable to load texture image \"" + this.Name + "\". " + e.GetType().Name + ": " + e.Message)); } int missingpatches = 0; //mxd if (!messages.Any(x => x.Type == ErrorType.Error)) { // Go for all patches foreach (TexturePatch p in patches) { // Get the patch data stream string patchlocation = string.Empty; //mxd Stream patchdata = General.Map.Data.GetPatchData(p.LumpName, p.HasLongName, ref patchlocation); if (patchdata != null) { // Get a reader for the data Bitmap patchbmp = ImageDataFormat.TryLoadImage(patchdata, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette); if (patchbmp == null) { //mxd. Probably that's a flat?.. if (General.Map.Config.MixTexturesFlats) { patchbmp = ImageDataFormat.TryLoadImage(patchdata, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette); } if (patchbmp == null) { // Data is in an unknown format! messages.Add(new LogMessage(ErrorType.Error, "Patch lump \"" + Path.Combine(patchlocation, p.LumpName) + "\" data format could not be read, while loading texture \"" + this.Name + "\". Does this lump contain valid picture data at all?")); missingpatches++; //mxd } } if (patchbmp != null) { // Draw the patch DrawToPixelData(patchbmp, pixels, width, height, p.X, p.Y); patchbmp.Dispose(); } // Done patchdata.Dispose(); } else { // Missing a patch lump! messages.Add(new LogMessage(ErrorType.Error, "Missing patch lump \"" + p.LumpName + "\" while loading texture \"" + this.Name + "\". Did you forget to include required resources?")); missingpatches++; //mxd } } // Done bitmap.UnlockBits(bitmapdata); } // Dispose bitmap if load failed if ((bitmap != null) && (messages.Any(x => x.Type == ErrorType.Error) || missingpatches >= patches.Count)) //mxd. We can still display texture if at least one of the patches was loaded { bitmap.Dispose(); bitmap = null; } return(new LocalLoadResult(bitmap, messages)); }