// This loads the image protected override void LocalLoadImage() { // Checks if (this.IsImageLoaded || width == 0 || height == 0) { return; } Graphics g = null; lock (this) { // 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.ZeroMemory(new IntPtr(pixels), width * height * sizeof(PixelColor)); bitmap.UnlockBits(bitmapdata); g = Graphics.FromImage(bitmap); } catch (Exception e) { // Unable to make bitmap General.ErrorLogger.Add(ErrorType.Error, "Unable to load texture image \"" + this.Name + "\". " + e.GetType().Name + ": " + e.Message); loadfailed = true; } int missingpatches = 0; //mxd if (patches.Count == 0) //mxd { //mxd. Empty image will suffice here, I suppose... if (nulltexture) { base.LocalLoadImage(); return; } // No patches! General.ErrorLogger.Add(ErrorType.Warning, "No patches are defined for texture \"" + this.Name + "\""); loadfailed = true; } else if (!loadfailed) { // 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); // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette); if (reader is UnknownImageReader) { //mxd. Probably that's a flat?.. if (General.Map.Config.MixTexturesFlats) { reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette); } if (reader is UnknownImageReader) { // Data is in an unknown format! if (!nulltexture) { General.ErrorLogger.Add((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 (!(reader is UnknownImageReader)) { // Get the patch mem.Seek(0, SeekOrigin.Begin); Bitmap patchbmp = null; try { patchbmp = reader.ReadAsBitmap(mem); } catch (InvalidDataException) { // Data cannot be read! if (!nulltexture) { General.ErrorLogger.Add((optional ? ErrorType.Warning : ErrorType.Error), "Patch lump \"" + 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(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) { if (!img.IsImageLoaded) { img.LoadImage(); } //mxd. Apply transformations from TexturePatch. We don't want to modify the original bitmap here, so make a copy Bitmap patchbmp = TransformPatch(p, new Bitmap(img.GetBitmap())); // 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) { General.ErrorLogger.Add((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) && (loadfailed || missingpatches >= patches.Count)) //mxd. We can still display texture if at least one of the patches was loaded { bitmap.Dispose(); bitmap = null; loadfailed = true; } // Pass on to base base.LocalLoadImage(); } }
// This loads the image protected override void LocalLoadImage() { // Leave when already loaded if (this.IsImageLoaded) { return; } lock (this) { // 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 IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMCOLORMAP, General.Map.Data.Palette); if (reader is UnknownImageReader) { // Data is in an unknown format! General.ErrorLogger.Add(ErrorType.Error, "Colormap lump \"" + Name + "\" data format could not be read. Does this lump contain valid colormap data at all?"); bitmap = null; } else { // Read data as bitmap mem.Seek(0, SeekOrigin.Begin); if (bitmap != null) { bitmap.Dispose(); } bitmap = reader.ReadAsBitmap(mem); } // Done mem.Dispose(); if (bitmap != null) { // Get width and height from image and set the scale width = bitmap.Size.Width; height = bitmap.Size.Height; scale.x = General.Map.Config.DefaultFlatScale; scale.y = General.Map.Config.DefaultFlatScale; } else { loadfailed = true; } } else { // Missing a patch lump! General.ErrorLogger.Add(ErrorType.Error, "Missing colormap lump \"" + Name + "\". Did you forget to include required resources?"); loadfailed = true; } // Pass on to base base.LocalLoadImage(); } }
// 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); // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(mem, (isFlat ? ImageDataFormat.DOOMFLAT : ImageDataFormat.DOOMPICTURE), General.Map.Data.Palette); if (!(reader is UnknownImageReader)) { // Load the image mem.Seek(0, SeekOrigin.Begin); try { bitmap = reader.ReadAsBitmap(mem); } catch (InvalidDataException) { // Data cannot be read! bitmap = null; } } // 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 void LocalLoadImage() { // Leave when already loaded if (this.IsImageLoaded) { return; } lock (this) { // Load file data if (bitmap != null) { bitmap.Dispose(); } bitmap = null; MemoryStream filedata = datareader.LoadFile(filepathname); //mxd isBadForLongTextureNames = false; if (filedata != null) { // Get a reader for the data IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette); if (!(reader is UnknownImageReader)) { // [ZZ] check for flat type if (reader is DoomFlatReader) { isBadForLongTextureNames = true; } // Load the image filedata.Seek(0, SeekOrigin.Begin); try { bitmap = reader.ReadAsBitmap(filedata); } catch (InvalidDataException) { // Data cannot be read! bitmap = null; } } // Not loaded? if (bitmap == null) { General.ErrorLogger.Add(ErrorType.Error, "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\""); loadfailed = true; } else { // Get width and height from image width = bitmap.Size.Width; height = bitmap.Size.Height; } filedata.Dispose(); } // Pass on to base base.LocalLoadImage(); } }
// This loads the image protected override void LocalLoadImage() { IImageReader reader; MemoryStream mem; byte[] membytes; Graphics g = null; // Checks if (this.IsImageLoaded) { return; } if ((width == 0) || (height == 0)) { return; } lock (this) { // 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.ZeroMemory(new IntPtr(pixels), width * height * sizeof(PixelColor)); bitmap.UnlockBits(bitmapdata); g = Graphics.FromImage(bitmap); } catch (Exception e) { // Unable to make bitmap General.ErrorLogger.Add(ErrorType.Error, "Unable to load texture image '" + this.Name + "'. " + e.GetType().Name + ": " + e.Message); loadfailed = true; } if (!loadfailed) { // Go for all patches foreach (TexturePatch p in patches) { // Get the patch data stream Stream patchdata = General.Map.Data.GetPatchData(p.lumpname); if (patchdata != null) { // Copy patch data to memory patchdata.Seek(0, SeekOrigin.Begin); membytes = new byte[(int)patchdata.Length]; patchdata.Read(membytes, 0, (int)patchdata.Length); mem = new MemoryStream(membytes); mem.Seek(0, SeekOrigin.Begin); // Get a reader for the data reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette); if (reader is UnknownImageReader) { // Data is in an unknown format! General.ErrorLogger.Add(ErrorType.Error, "Patch lump '" + p.lumpname + "' data format could not be read, while loading texture '" + this.Name + "'"); loadfailed = true; } else { // Get the patch mem.Seek(0, SeekOrigin.Begin); Bitmap patchbmp = null; try { patchbmp = reader.ReadAsBitmap(mem); } catch (InvalidDataException) { // Data cannot be read! General.ErrorLogger.Add(ErrorType.Error, "Patch lump '" + p.lumpname + "' data format could not be read, while loading texture '" + this.Name + "'"); loadfailed = true; } if (patchbmp != null) { // Adjust patch alpha if (p.alpha < 1.0f) { BitmapData bmpdata = null; try { bmpdata = patchbmp.LockBits(new Rectangle(0, 0, patchbmp.Size.Width, patchbmp.Size.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); } catch (Exception e) { General.ErrorLogger.Add(ErrorType.Error, "Cannot lock image '" + p.lumpname + "' for alpha adjustment. " + e.GetType().Name + ": " + e.Message); } if (bmpdata != null) { PixelColor *pixels = (PixelColor *)(bmpdata.Scan0.ToPointer()); int numpixels = bmpdata.Width * bmpdata.Height; for (PixelColor *cp = pixels + numpixels - 1; cp >= pixels; cp--) { cp->a = (byte)((((float)cp->a * PixelColor.BYTE_TO_FLOAT) * p.alpha) * 255.0f); } patchbmp.UnlockBits(bmpdata); } } // 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 { // Missing a patch lump! General.ErrorLogger.Add(ErrorType.Error, "Missing patch lump '" + p.lumpname + "' while loading texture '" + this.Name + "'"); loadfailed = true; } } } // Dispose bitmap if load failed if (loadfailed && (bitmap != null)) { bitmap.Dispose(); bitmap = null; } // Pass on to base base.LocalLoadImage(); } }