Пример #1
0
        private byte[] TextureToPng(Microsoft.Xna.Framework.Graphics.Texture2D tex)
        {
            var bmp = new Bitmap(tex.Width, tex.Height, PixelFormat.Format32bppArgb);

            var    bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
            IntPtr ptr     = bmpData.Scan0;

            var data = new byte[tex.Width * tex.Height * 4];

            tex.GetData(data);

            for (int i = 0; i < data.Length; i += 4)
            {
                var swap = data[i];
                data[i]     = data[i + 2];
                data[i + 2] = swap;
            }

            Marshal.Copy(data, 0, ptr, bmpData.Stride * bmpData.Height);
            bmp.UnlockBits(bmpData);

            using (var mem = new MemoryStream())
            {
                bmp.Save(mem, ImageFormat.Png);
                return(mem.ToArray());
            }
        }
Пример #2
0
        internal void fillUIWithMob(DoomDef.mobj_t mo)
        {
            lblMobType.Text = mo.type.ToString();
            int lump;

            r_local.spritedef_t   sprdef;
            r_local.spriteframe_t sprframe;
            info.mobjinfo_t       mobT = info.mobjinfo[(int)mo.type];
            sprdef   = r_thing.sprites[(int)mo.sprite];
            sprframe = sprdef.spriteframes[mo.frame & DoomDef.FF_FRAMEMASK];
            lump     = sprframe.lump[0];
            Microsoft.Xna.Framework.Graphics.Texture2D texture = w_wad.W_CacheLumpNum(lump + r_data.firstspritelump, DoomDef.PU_CACHE).cache as Microsoft.Xna.Framework.Graphics.Texture2D;

            byte[] pixels = new byte[texture.Width * texture.Height * 4];
            texture.GetData <byte>(pixels);

            for (int i = 0; i < texture.Width * texture.Height; ++i)
            {
                byte tmp = pixels[i * 4 + 0];
                pixels[i * 4 + 0] = pixels[i * 4 + 2];
                pixels[i * 4 + 2] = tmp;
            }

            Bitmap bmp = new Bitmap(texture.Width, texture.Height, texture.Width * 4, PixelFormat.Format32bppArgb,
                                    GCHandle.Alloc(pixels, GCHandleType.Pinned).AddrOfPinnedObject());

            picMobSprite.Image = bmp;

            if (mobT.light == null)
            {
                btnRemoveColor.Text = "Add Light";
            }
            else
            {
                btnRemoveColor.Text        = "Remove Light";
                sldRadius.Value            = (int)mobT.light.radius;
                sldHue.Value               = mobT.light.hue;
                sldSaturation.Value        = mobT.light.saturation;
                txtMultiplier.Text         = mobT.light.brightness.ToString();
                chkCastShadow.Checked      = mobT.light.castShadow;
                cboLightType.SelectedIndex = mobT.light.type;
            }

            sldBottomIllumination.Value = (int)(mobT.selfIllumB * 100.0f);
            sldTopIllumination.Value    = (int)(mobT.selfIllumT * 100.0f);
        }
Пример #3
0
        public void load_bmp(Microsoft.Xna.Framework.Graphics.Texture2D InputTexture, ref CCL_Map2D FirstImage)
        {
            byte        i;
            int         x, y;
            Colorstruct Col;

            if (InputTexture == null)
            {
                return;                                       // Bitmap laod failed so exit
            }
            if ((InputTexture.Width > 32765) || (InputTexture.Height > 32765))
            {               // Bitmap is too big to vectorize (outside int range)
                return;     // Fail return
            }
            FirstImage = CreateCCLMap2D((ushort)(InputTexture.Width + 2),
                                        (ushort)(InputTexture.Height + 2), 0);         // Create a CCL map (IT IS BLANK HERE)

            Colorstruct[] TextureData = new Colorstruct[InputTexture.Width * InputTexture.Height];
            InputTexture.GetData(TextureData);

            for (y = 0; y < InputTexture.Height; y++)
            {                                                      // For each y height scanline
                for (x = 0; x < InputTexture.Width; x++)
                {                                                  // For each x pixel
                    Col = TextureData[x + y * InputTexture.Width]; // Fetch the pixel colour
                    if (Col.A > 10)
                    {
                        i = 1;
                    }
                    else
                    {
                        i = 0;                        // Convert to B/W depending colour
                    }
                    FirstImage.map[y + 1][x + 1] = i; // Set B/W colour to CCL Map
                }
            }
        }
Пример #4
0
 public override void GetData <T>(T[] data)
 {
     texture.GetData(data);
 }
Пример #5
0
        internal void fillUIWithSector(r_local.sector_t sector)
        {
            m_sector = sector;

            {
                Microsoft.Xna.Framework.Graphics.Texture2D texture = Game1.instance.floorTexturesById[r_data.texturetranslation[sector.floorpic]];

                byte[] pixels = new byte[texture.Width * texture.Height * 4];
                texture.GetData <byte>(pixels);

                for (int i = 0; i < texture.Width * texture.Height; ++i)
                {
                    byte tmp = pixels[i * 4 + 0];
                    pixels[i * 4 + 0] = pixels[i * 4 + 2];
                    pixels[i * 4 + 2] = tmp;
                }

                Bitmap bmp = new Bitmap(texture.Width, texture.Height, texture.Width * 4, PixelFormat.Format32bppArgb,
                                        GCHandle.Alloc(pixels, GCHandleType.Pinned).AddrOfPinnedObject());
                picFloor.Image = bmp;
            }
            {
                Microsoft.Xna.Framework.Graphics.Texture2D texture = sector.ceilingBatch.texture;

                byte[] pixels = new byte[texture.Width * texture.Height * 4];
                texture.GetData <byte>(pixels);

                for (int i = 0; i < texture.Width * texture.Height; ++i)
                {
                    byte tmp = pixels[i * 4 + 0];
                    pixels[i * 4 + 0] = pixels[i * 4 + 2];
                    pixels[i * 4 + 2] = tmp;
                }

                Bitmap bmp = new Bitmap(texture.Width, texture.Height, texture.Width * 4, PixelFormat.Format32bppArgb,
                                        GCHandle.Alloc(pixels, GCHandleType.Pinned).AddrOfPinnedObject());
                picCeil.Image = bmp;
            }

            {
                Bitmap bmp = new Bitmap(picSector.Width, picSector.Height, PixelFormat.Format24bppRgb);

                Pen yellowPen = new Pen(Color.Yellow, 2);

                float bbminX = 100000;
                float bbminY = 100000;
                float bbmaxX = -100000;
                float bbmaxY = -100000;

                sector.floorBatch.boundingBox(ref bbminX, ref bbminY, ref bbmaxX, ref bbmaxY);

                float biggest = Math.Max(bbmaxX - bbminX, bbmaxY - bbminY);
                int   padding = 4;
                float scale   = (float)(picSector.Width - padding * 2) / biggest;

                bbminX -= (biggest - (bbmaxX - bbminX)) * .5f;
                bbminY -= (biggest - (bbmaxY - bbminY)) * .5f;

                // Draw lines to screen
                Graphics graphics = Graphics.FromImage(bmp);

                foreach (r_local.seg_t seg in p_setup.segs)
                {
                    if (seg.frontsector == sector)
                    {
                        Microsoft.Xna.Framework.Vector2 vp1 = new Microsoft.Xna.Framework.Vector2(
                            seg.v1.x >> DoomDef.FRACBITS,
                            -seg.v1.y >> DoomDef.FRACBITS);
                        Microsoft.Xna.Framework.Vector2 vp2 = new Microsoft.Xna.Framework.Vector2(
                            seg.v2.x >> DoomDef.FRACBITS,
                            -seg.v2.y >> DoomDef.FRACBITS);

                        vp1.X -= bbminX;
                        vp2.X -= bbminX;
                        vp1.Y -= bbminY;
                        vp2.Y -= bbminY;

                        vp1 *= scale;
                        vp2 *= scale;

                        graphics.DrawLine(yellowPen,
                                          (int)vp1.X + padding,
                                          (int)vp1.Y + padding,
                                          (int)vp2.X + padding,
                                          (int)vp2.Y + padding);
                    }
                }

                picSector.Image = bmp;
            }
        }