コード例 #1
0
        // 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));
        }
コード例 #2
0
        // 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));
        }
コード例 #3
0
        // 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);
                }
            }));
        }
コード例 #4
0
        // 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

                if (filedata != null)
                {
                    // Get a reader for the data
                    IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette);
                    if (!(reader is UnknownImageReader))
                    {
                        // 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();
            }
        }
コード例 #5
0
        // 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
                IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMFLAT, General.Map.Data.Palette);
                if (reader is UnknownImageReader)
                {
                    // 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?";
                    bitmap = null;
                }
                else
                {
                    // Read data as bitmap
                    mem.Seek(0, SeekOrigin.Begin);
                    bitmap = reader.ReadAsBitmap(mem);
                }

                // 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;
            }));
        }
コード例 #6
0
        // 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);

                // Get a reader for the data
                IImageReader reader = ImageDataFormat.GetImageReader(mem, 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(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));
        }
コード例 #7
0
        // 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
                IImageReader reader = ImageDataFormat.GetImageReader(mem, ImageDataFormat.DOOMCOLORMAP, General.Map.Data.Palette);
                if (reader is UnknownImageReader)
                {
                    // 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?";
                    bitmap = null;
                }
                else
                {
                    // Read data as bitmap
                    mem.Seek(0, SeekOrigin.Begin);
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                    bitmap = reader.ReadAsBitmap(mem);
                }

                // 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;
            }));
        }
コード例 #8
0
        // 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
                IImageReader reader = ImageDataFormat.GetImageReader(lumpdata, ImageDataFormat.DOOMPICTURE, General.Map.Data.Palette);
                if (reader is UnknownImageReader)
                {
                    // 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?";
                    bitmap = null;
                }
                else
                {
                    // Read data as bitmap
                    lumpdata.Seek(0, SeekOrigin.Begin);
                    if (bitmap != null)
                    {
                        bitmap.Dispose();
                    }
                    bitmap = reader.ReadAsBitmap(lumpdata, out offsetx, out offsety);
                }

                // 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);
                }
            }));
        }
コード例 #9
0
        // 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
                IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette);
                if (!(reader is UnknownImageReader))
                {
                    // 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)
                {
                    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));
        }
コード例 #10
0
        // 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
                IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette);
                if (!(reader is UnknownImageReader))
                {
                    // 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)
                {
                    error = "Image file \"" + filepathname + "\" data format could not be read, while loading texture \"" + this.Name + "\"";
                }

                filedata.Dispose();
            }

            return(new LocalLoadResult(bitmap, error));
        }
コード例 #11
0
        // 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;

                // Set the offset if the offset was not given
                if ((offsetx == int.MinValue) || (offsety == int.MinValue))
                {
                    offsetx = offsety = 0;
                }
            }));
        }
コード例 #12
0
        // This loads the image
        protected override void LocalLoadImage()
        {
            // Checks
            if (this.IsImageLoaded)
            {
                return;
            }

            lock (this)
            {
                // Get the patch data stream
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
                bitmap = 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);

                    // Get a reader for the data
                    IImageReader reader = ImageDataFormat.GetImageReader(mem, 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)
                    {
                        General.ErrorLogger.Add(ErrorType.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?");
                        loadfailed = true;
                    }
                    else
                    {
                        // Get width and height from image
                        width  = bitmap.Size.Width;
                        height = bitmap.Size.Height;
                    }

                    // Done
                    mem.Dispose();
                }
                else
                {
                    General.ErrorLogger.Add(ErrorType.Error, "Image lump \"" + lumpname + "\" could not be found, while loading texture \"" + this.Name + "\". Did you forget to include required resources?");
                    loadfailed = true;
                }

                // Pass on to base
                base.LocalLoadImage();
            }
        }
コード例 #13
0
        // 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();
            }
        }
コード例 #14
0
        // 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;

                bool isBadForLongTextureNames = false;

                MemoryStream filedata = null;
                try
                {
                    filedata = new MemoryStream(File.ReadAllBytes(filepathname));
                }
                catch (IOException)
                {
                    General.ErrorLogger.Add(ErrorType.Error, "Image file \"" + filepathname + "\" could not be read, while loading image \"" + this.Name + "\". Consider reloading resources.");
                    loadfailed = true;
                }

                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 doom flat, always short name for these
                        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 image \"" + this.Name + "\". Is this a valid picture file at all?");
                        loadfailed = true;
                    }
                    else
                    {
                        // Get width and height
                        width  = bitmap.Size.Width;
                        height = bitmap.Size.Height;
                    }

                    filedata.Dispose();
                }

                // [ZZ] validate disabled long texture names for flats. (and enabled for everything else, if our guessed format was wrong)
                SetName(_c_name, _c_filepathname, General.Map.Config.UseLongTextureNames, isBadForLongTextureNames ? -1 : (isinternal ? 1 : 0));

                // Pass on to base
                base.LocalLoadImage();
            }
        }
コード例 #15
0
        // This loads the image
        protected override void LocalLoadImage()
        {
            // Checks
            if (this.IsImageLoaded)
            {
                return;
            }

            lock (this)
            {
                // Get the patch data stream
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
                bitmap = 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)
                    {
                        General.ErrorLogger.Add(ErrorType.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?");
                        loadfailed = true;
                    }
                    else
                    {
                        // Get width and height from image
                        width  = bitmap.Size.Width;
                        height = bitmap.Size.Height;

                        // 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);
                        }
                    }

                    // Done
                    mem.Dispose();
                }
                else
                {
                    General.ErrorLogger.Add(ErrorType.Error, "Image lump \"" + shortname + "\" could not be found, while loading HiRes texture \"" + this.Name + "\". Did you forget to include required resources?");
                    loadfailed = true;
                }

                // Pass on to base
                base.LocalLoadImage();
            }
        }
コード例 #16
0
        // 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));
        }
コード例 #17
0
        // This loads the image
        protected override void LocalLoadImage()
        {
            // Leave when already loaded
            if (this.IsImageLoaded)
            {
                return;
            }

            lock (this)
            {
                // Get the lump data stream
                string spritelocation = string.Empty;                 //mxd
                Stream lumpdata       = General.Map.Data.GetSpriteData(Name, ref spritelocation);
                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
                    IImageReader 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, "Sprite lump \"" + Path.Combine(spritelocation, Name) + "\" data format could not be read. Does this lump contain valid picture data at all?");
                        bitmap = null;
                    }
                    else
                    {
                        // Read data as bitmap
                        mem.Seek(0, SeekOrigin.Begin);
                        if (bitmap != null)
                        {
                            bitmap.Dispose();
                        }
                        bitmap = reader.ReadAsBitmap(mem, out offsetx, out offsety);
                    }

                    // Done
                    mem.Dispose();

                    if (bitmap != null)
                    {
                        // Get width and height from image
                        width   = bitmap.Size.Width;
                        height  = bitmap.Size.Height;
                        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);
                        }
                    }
                    else
                    {
                        loadfailed = true;
                    }
                }
                else
                {
                    // Missing a patch lump!
                    General.ErrorLogger.Add(ErrorType.Error, "Missing sprite lump \"" + Name + "\". Forgot to include required resources?");
                }

                // Pass on to base
                base.LocalLoadImage();
            }
        }
コード例 #18
0
        // This loads the image
        protected override void LocalLoadImage()
        {
            // Checks
            if (this.IsImageLoaded || width == 0 || height == 0)
            {
                return;
            }

            BitmapData  bitmapdata = null;
            PixelColor *pixels     = (PixelColor *)0;

            lock (this)
            {
                // 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
                    General.ErrorLogger.Add(ErrorType.Error, "Unable to load texture image \"" + this.Name + "\". " + e.GetType().Name + ": " + e.Message);
                    loadfailed = true;
                }

                int missingpatches = 0;                 //mxd

                if (!loadfailed)
                {
                    // 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)
                        {
                            // 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!
                                    General.ErrorLogger.Add(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?");
                                    loadfailed = true;
                                    missingpatches++;                                     //mxd
                                }
                            }

                            if (!(reader is UnknownImageReader))
                            {
                                // Draw the patch
                                mem.Seek(0, SeekOrigin.Begin);
                                try { reader.DrawToPixelData(mem, pixels, width, height, p.X, p.Y); }
                                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 + "\". Does this lump contain valid picture data at all?");
                                    loadfailed = true;
                                    missingpatches++;                                     //mxd
                                }
                            }

                            // Done
                            mem.Dispose();
                        }
                        else
                        {
                            // Missing a patch lump!
                            General.ErrorLogger.Add(ErrorType.Error, "Missing patch lump \"" + p.LumpName + "\" while loading texture \"" + this.Name + "\". Did you forget to include required resources?");
                            loadfailed = true;
                            missingpatches++;                             //mxd
                        }
                    }

                    // Done
                    bitmap.UnlockBits(bitmapdata);
                }

                // Dispose bitmap if load failed
                if ((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();
            }
        }
コード例 #19
0
        // This loads the image
        protected override void LocalLoadImage()
        {
            Stream       lumpdata;
            MemoryStream mem;
            IImageReader reader;

            byte[] membytes;

            // Leave when already loaded
            if (this.IsImageLoaded)
            {
                return;
            }

            lock (this)
            {
                // Get the lump data stream
                lumpdata = General.Map.Data.GetColormapData(Name);
                if (lumpdata != null)
                {
                    // Copy lump data to memory
                    lumpdata.Seek(0, SeekOrigin.Begin);
                    membytes = new byte[(int)lumpdata.Length];
                    lumpdata.Read(membytes, 0, (int)lumpdata.Length);
                    mem = new MemoryStream(membytes);
                    mem.Seek(0, SeekOrigin.Begin);

                    // Get a reader for the data
                    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();
            }
        }
コード例 #20
0
        // 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));
        }
コード例 #21
0
ファイル: TextureImage.cs プロジェクト: volte/doombuilderx
        // This loads the image
        protected override void LocalLoadImage()
        {
            IImageReader reader;
            BitmapData   bitmapdata = null;
            MemoryStream mem;
            PixelColor * pixels = (PixelColor *)0;
            Stream       patchdata;

            byte[] membytes;

            // 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 = 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
                    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
                        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 + "'. Does this lump contain valid picture data at all?");
                                loadfailed = true;
                            }
                            else
                            {
                                // Draw the patch
                                mem.Seek(0, SeekOrigin.Begin);
                                try { reader.DrawToPixelData(mem, pixels, width, height, p.x, p.y); }
                                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 + "'. Does this lump contain valid picture data at all?");
                                    loadfailed = true;
                                }
                            }

                            // Done
                            mem.Dispose();
                        }
                        else
                        {
                            // Missing a patch lump!
                            General.ErrorLogger.Add(ErrorType.Error, "Missing patch lump '" + p.lumpname + "' while loading texture '" + this.Name + "'. Did you forget to include required resources?");
                            loadfailed = true;
                        }
                    }

                    // Done
                    bitmap.UnlockBits(bitmapdata);
                }

                // Dispose bitmap if load failed
                if (loadfailed && (bitmap != null))
                {
                    bitmap.Dispose();
                    bitmap = null;
                }

                // Pass on to base
                base.LocalLoadImage();
            }
        }