:: New Mir3 Source discussion Thread ::

dida

Banned
Banned
Dedicated Member
Feb 17, 2013
31
0
32
USA
Not sure if I've released this before but Here's my OLD Optimized code. I have recently learned of a new technique which is faster, however I am able to create textures Extremely fast with the code below.

Code:
        public void CreateTexture(BinaryReader BReader)
        {
            byte[] Bytes = FullImageBytes(BReader);
            if (Bytes == null) return;

            LastAccess = Main.Time;
            ImageTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);

            GraphicsStream GS = ImageTexture.LockRectangle(0, LockFlags.Discard);
            GS.Write(Bytes);
            GS.Dispose();
            ImageTexture.UnlockRectangle(0);
        }

        private byte[] FullImageBytes(BinaryReader BReader)
        {
            byte[] Pixels = new byte[Size.Width * Size.Height * 4];
            byte[] FileBytes = BReader.ReadBytes(Length * 2);

            int End = 0, OffSet = 0, Count;

            for (int Y = 0; Y < Size.Height; Y++)
            {
                OffSet = End;
                End += (FileBytes[OffSet + 1] << 8 | FileBytes[OffSet]) * 2 + 2;
                OffSet += 2; //New line
                for (int X = 0; X < Size.Width; )
                    switch (FileBytes[OffSet])
                    {
                        case 192: //No Colour
                            X += FileBytes[OffSet + 3] << 8 | FileBytes[OffSet + 2];
                            OffSet += 4;
                            break;
                        case 193: //Solid Colour
                        case 194: //Overlay Colour
                        case 195: // ??
                            Count = FileBytes[OffSet + 3] << 8 | FileBytes[OffSet + 2];
                            OffSet += 4;
                            for (int I = 0; I < Count; I++)
                            {
                                int ColIndex = FileBytes[OffSet + 1] << 8 | FileBytes[OffSet];
                                OffSet += 2;
                                if (X >= Size.Width) continue;
                                Pixels[(Y * Size.Width + X) * 4 + 3] = 255;
                                Pixels[(Y * Size.Width + X) * 4 + 2] = (byte)((ColIndex / 2048) * 8 + 7);
                                Pixels[(Y * Size.Width + X) * 4 + 1] = (byte)(((ColIndex %= 2048) / 32) * 4);
                                Pixels[(Y * Size.Width + X) * 4] = (byte)((ColIndex % 32) * 8 + 7);
                                X++;
                            }
                            break;
                        default:
                            return null;
                    }
            }


            return Pixels;
        }
hi @Jamie/Hello i was wondering how could i convert pixels to Bitmap not texture? so sorry i have no idea with pixels wit texture or bitmap.
 

Jamie

LOMCN Developer
Developer
Mar 29, 2003
4,797
299
370
United Kingdom
hi @Jamie/Hello i was wondering how could i convert pixels to Bitmap not texture? so sorry i have no idea with pixels wit texture or bitmap.


Change:

Code:
 public void CreateTexture(BinaryReader BReader)
        {
            byte[] Bytes = FullImageBytes(BReader);
            if (Bytes == null) return;

            LastAccess = Main.Time;
            ImageTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed);

            GraphicsStream GS = ImageTexture.LockRectangle(0, LockFlags.Discard);
            GS.Write(Bytes);
            GS.Dispose();
            ImageTexture.UnlockRectangle(0);
        }

to

Code:
 public void CreateTexture(BinaryReader BReader)
        {
            byte[] Bytes = FullImageBytes(BReader);
            if (Bytes == null) return;


            Bitmap Image = new Bitmap(Size.Width, Size.Height);

            BitmapData Data = Image.LockBits(new Rectangle(0, 0, Size.Width, Size.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
            Marshal.Copy(Bytes, 0, Data.Scan0, Bytes.Length);
            Image.UnlockBits(Data);
        }
 

dida

Banned
Banned
Dedicated Member
Feb 17, 2013
31
0
32
USA
it works! lol , thinks alot!

---------- Post Merged on 16-10-2013 at 06:37 AM ---------- Previous Post was on 15-10-2013 at 12:13 PM ----------

nice thread.

---------- Post Merged on 16-10-2013 at 11:18 AM ---------- Previous Post was on 15-10-2013 at 12:13 PM ----------

could you tell me how to render map with directx? i konw how to read wil files now.