コード例 #1
0
        unsafe void ReadStaticTexture(int index, out Texture2D texture)
        {
            texture = null;
            int  length, extra;
            bool is_patched;
            // get a reader inside Art.Mul
            BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out is_patched);

            if (reader == null)
            {
                return;
            }
            reader.ReadInt(); // don't need this, see Art.mul file format.
            // get the dimensions of the texture
            int width  = reader.ReadShort();
            int height = reader.ReadShort();

            if (width <= 0 || height <= 0)
            {
                return;
            }
            // read the texture data!
            ushort[] lookups = reader.ReadUShorts(height);
            ushort[] data    = reader.ReadUShorts(length - lookups.Length * 2 - 8);
            Metrics.ReportDataRead(sizeof(ushort) * (data.Length + lookups.Length + 2));
            ushort[] pixels = new ushort[width * height];
            fixed(ushort *pData = pixels)
            {
                ushort *dataRef = pData;
                int     i;

                for (int y = 0; y < height; y++, dataRef += width)
                {
                    i = lookups[y];

                    ushort *start = dataRef;

                    int count, offset;

                    while (((offset = data[i++]) + (count = data[i++])) != 0)
                    {
                        start += offset;
                        ushort *end = start + count;

                        while (start < end)
                        {
                            ushort color   = data[i++];
                            *      start++ = (ushort)(color | 0x8000);
                        }
                    }
                }
            }

            texture = new Texture2D(m_Graphics, width, height, false, SurfaceFormat.Bgra5551);
            texture.SetData(pixels);
            m_StaticPicking.Set(index, width, height, pixels);
            return;
        }
コード例 #2
0
        unsafe Texture2D ReadLandTexture(int index)
        {
            int              length, extra;
            bool             is_patched;
            BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out is_patched);

            if (reader == null)
            {
                return(null);
            }
            ushort[] pixels = new ushort[44 * 44];
            ushort[] data   = reader.ReadUShorts(23 * 44); // land tile textures store only opaque pixels
            Metrics.ReportDataRead(data.Length);
            int i = 0;

            fixed(ushort *pData = pixels)
            {
                ushort *dataRef = pData;
                // fill the top half of the tile
                int count  = 2;
                int offset = 21;

                for (int y = 0; y < 22; y++, count += 2, offset--, dataRef += 44)
                {
                    ushort *start = dataRef + offset;
                    ushort *end   = start + count;
                    while (start < end)
                    {
                        ushort color   = data[i++];
                        *      start++ = (ushort)(color | 0x8000);
                    }
                }
                // file the bottom half of the tile
                count  = 44;
                offset = 0;
                for (int y = 0; y < 22; y++, count -= 2, offset++, dataRef += 44)
                {
                    ushort *start = dataRef + offset;
                    ushort *end   = start + count;
                    while (start < end)
                    {
                        ushort color   = data[i++];
                        *      start++ = (ushort)(color | 0x8000);
                    }
                }
            }

            Texture2D texture = new Texture2D(m_Graphics, 44, 44, false, SurfaceFormat.Bgra5551);

            texture.SetData(pixels);


            return(texture);
        }
コード例 #3
0
        private unsafe Texture2D readTexmapTexture(int index)
        {
            int  length, extra;
            bool is_patched;

            BinaryFileReader reader = m_Index.Seek(index, out length, out extra, out is_patched);

            if (reader == null)
            {
                return(null);
            }
            if (reader.Stream.Length == 0)
            {
                Tracer.Warn("Requested texmap texture #{0} does not exist. Replacing with 'unused' graphic.", index);
                return(null);
            }

            int metrics_dataread_start = (int)reader.Position;

            int textureSize = (extra == 0) ? 64 : 128;

            ushort[] pixelData = new ushort[textureSize * textureSize];
            ushort[] fileData  = reader.ReadUShorts(textureSize * textureSize);

            fixed(ushort *pData = pixelData)
            {
                ushort *pDataRef = pData;

                int count = 0;
                int max   = textureSize * textureSize;

                while (count < max)
                {
                    ushort color      = (ushort)(fileData[count] | 0x8000);
                    *      pDataRef++ = color;
                    count++;
                }
            }

            Texture2D texture = new Texture2D(m_Graphics, textureSize, textureSize, false, SurfaceFormat.Bgra5551);

            texture.SetData <ushort>(pixelData);

            Metrics.ReportDataRead((int)reader.Position - metrics_dataread_start);

            return(texture);
        }
コード例 #4
0
ファイル: TexmapData.cs プロジェクト: ViWinfii/UltimaXNA
        private static unsafe Texture2D readTexmapTexture(int index)
        {
            int  length, extra;
            bool is_patched;

            BinaryFileReader reader = m_Index.Seek(index, out length, out extra, out is_patched);

            if (reader == null)
            {
                return(null);
            }

            int metrics_dataread_start = (int)reader.Position;

            int textureSize = (extra == 0) ? 64 : 128;

            uint[]   pixelData = new uint[textureSize * textureSize];
            ushort[] fileData  = reader.ReadUShorts(textureSize * textureSize);

            fixed(uint *pData = pixelData)
            {
                uint *pDataRef = pData;

                int count = 0;
                int max   = textureSize * textureSize;

                while (count < max)
                {
                    uint color      = fileData[count];
                    *    pDataRef++ = 0xFF000000 + (
                        ((((color >> 10) & 0x1F) * multiplier)) |
                        ((((color >> 5) & 0x1F) * multiplier) << 8) |
                        (((color & 0x1F) * multiplier) << 16)
                        );
                    count++;
                }
            }

            Texture2D texture = new Texture2D(m_graphics, textureSize, textureSize);

            texture.SetData <uint>(pixelData);

            Metrics.ReportDataRead((int)reader.Position - metrics_dataread_start);

            return(texture);
        }
コード例 #5
0
        public unsafe Texture2D GetGumpXNA(int index, bool replaceMask080808 = false)
        {
            if (index < 0)
            {
                return(null);
            }

            if (m_TextureCache[index] == null)
            {
                int  length, extra;
                bool patched;

                BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out patched);
                if (reader == null)
                {
                    return(null);
                }

                int width  = (extra >> 16) & 0xFFFF;
                int height = extra & 0xFFFF;

                int metrics_dataread_start = (int)reader.Position;

                int[]    lookups  = reader.ReadInts(height);
                ushort[] fileData = reader.ReadUShorts(length - (height * 2));

                ushort[] pixels = new ushort[width * height];

                fixed(ushort *line = &pixels[0])
                {
                    fixed(ushort *data = &fileData[0])
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            ushort *dataRef = data + (lookups[y] - height) * 2;

                            ushort *cur = line + (y * width);
                            ushort *end = cur + width;

                            while (cur < end)
                            {
                                ushort  color = *dataRef++;
                                ushort *next  = cur + *dataRef++;

                                if (color == 0)
                                {
                                    cur = next;
                                }
                                else
                                {
                                    color |= 0x8000;
                                    while (cur < next)
                                    {
                                        *cur++ = color;
                                    }
                                }
                            }
                        }
                    }
                }

                Metrics.ReportDataRead(length);

                if (replaceMask080808)
                {
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        if (pixels[i] == 0x8421)
                        {
                            pixels[i] = 0xFC1F;
                        }
                    }
                }

                Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Bgra5551);
                texture.SetData(pixels);
                m_TextureCache[index] = texture;
            }
            return(m_TextureCache[index]);
        }
コード例 #6
0
        public unsafe Texture2D GetGumpTexture(int textureID, bool replaceMask080808 = false)
        {
            if (textureID < 0)
            {
                return(null);
            }

            if (m_TextureCache[textureID] == null)
            {
                int              length, extra;
                bool             patched;
                BinaryFileReader reader = m_FileIndex.Seek(textureID, out length, out extra, out patched);
                if (reader == null)
                {
                    return(null);
                }
                int width  = (extra >> 16) & 0xFFFF;
                int height = extra & 0xFFFF;
                if (width == 0 || height == 0)
                {
                    return(null);
                }
                int shortsToRead = length - (height * 2);
                if (reader.Stream.Length - reader.Position < (shortsToRead * 2))
                {
                    Tracer.Error($"Could not read gump {textureID:X4}: not enough data. Gump texture file truncated?");
                    return(null);
                }
                int[]    lookups = reader.ReadInts(height);
                int      metrics_dataread_start = (int)reader.Position;
                ushort[] fileData = reader.ReadUShorts(shortsToRead);
                ushort[] pixels   = new ushort[width * height];
                fixed(ushort *line = &pixels[0])
                {
                    fixed(ushort *data = &fileData[0])
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            ushort *dataRef = data + (lookups[y] - height) * 2;
                            ushort *cur     = line + (y * width);
                            ushort *end     = cur + width;
                            while (cur < end)
                            {
                                ushort  color = *dataRef++;
                                ushort *next  = cur + *dataRef++;
                                if (color == 0)
                                {
                                    cur = next;
                                }
                                else
                                {
                                    color |= 0x8000;
                                    while (cur < next)
                                    {
                                        *cur++ = color;
                                    }
                                }
                            }
                        }
                    }
                }

                Metrics.ReportDataRead(length);
                if (replaceMask080808)
                {
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        if (pixels[i] == 0x8421)
                        {
                            pixels[i] = 0xFC1F;
                        }
                    }
                }
                Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Bgra5551);
                texture.SetData(pixels);
                m_TextureCache[textureID] = texture;
                m_Picking.Set(textureID, width, height, pixels);
            }
            return(m_TextureCache[textureID]);
        }
コード例 #7
0
ファイル: GumpData.cs プロジェクト: ViWinfii/UltimaXNA
        public unsafe static Texture2D GetGumpXNA(int index)
        {
            if (index < 0)
            {
                return(null);
            }
            if (m_cache[index] == null)
            {
                int  length, extra;
                bool patched;

                BinaryFileReader reader = m_FileIndex.Seek(index, out length, out extra, out patched);
                if (reader == null)
                {
                    return(null);
                }

                int width  = (extra >> 16) & 0xFFFF;
                int height = extra & 0xFFFF;

                int metrics_dataread_start = (int)reader.Position;

                int[]    lookups  = reader.ReadInts(height);
                ushort[] fileData = reader.ReadUShorts(length - (height * 2));

                uint[] pixels = new uint[width * height];

                fixed(uint *line = &pixels[0])
                {
                    fixed(ushort *data = &fileData[0])
                    {
                        for (int y = 0; y < height; ++y)
                        {
                            ushort *dataRef = data + (lookups[y] - height) * 2;

                            uint *cur = line + (y * width);
                            uint *end = cur + width;

                            while (cur < end)
                            {
                                uint  color = *dataRef++;
                                uint *next  = cur + *dataRef++;

                                if (color == 0)
                                {
                                    cur = next;
                                }
                                else
                                {
                                    uint color32 = 0xFF000000 + (
                                        ((((color >> 10) & 0x1F) * multiplier)) |
                                        ((((color >> 5) & 0x1F) * multiplier) << 8) |
                                        (((color & 0x1F) * multiplier) << 16)
                                        );
                                    while (cur < next)
                                    {
                                        *cur++ = color32;
                                    }
                                }
                            }
                        }
                    }
                }

                Metrics.ReportDataRead(length);

                Texture2D texture = new Texture2D(m_graphicsDevice, width, height, false, SurfaceFormat.Color);
                texture.SetData(pixels);
                m_cache[index] = texture;
            }
            return(m_cache[index]);
        }
コード例 #8
0
        private static unsafe Texture2D readLandTexture(int index)
        {
            int  length, extra;
            bool is_patched;

            BinaryFileReader reader = m_Index.Seek(index, out length, out extra, out is_patched);

            if (reader == null)
            {
                return(null);
            }

            uint[] data = new uint[44 * 44];

            ushort[] fileData = reader.ReadUShorts(((44 + 2) / 2) * 44);
            int      i        = 0;

            int count  = 2;
            int offset = 21;

            fixed(uint *pData = data)
            {
                uint *dataRef = pData;

                for (int y = 0; y < 22; y++, count += 2, offset--, dataRef += 44)
                {
                    uint *start = dataRef + offset;
                    uint *end   = start + count;

                    Metrics.ReportDataRead(count * 2);

                    while (start < end)
                    {
                        uint color   = fileData[i++];
                        *    start++ = 0xFF000000 + (
                            ((((color >> 10) & 0x1F) * multiplier)) |
                            ((((color >> 5) & 0x1F) * multiplier) << 8) |
                            (((color & 0x1F) * multiplier) << 16)
                            );
                    }
                }

                count  = 44;
                offset = 0;

                for (int y = 0; y < 22; y++, count -= 2, offset++, dataRef += 44)
                {
                    uint *start = dataRef + offset;
                    uint *end   = start + count;

                    Metrics.ReportDataRead(count * 2);

                    while (start < end)
                    {
                        uint color   = fileData[i++];
                        *    start++ = 0xFF000000 + (
                            ((((color >> 10) & 0x1F) * multiplier)) |
                            ((((color >> 5) & 0x1F) * multiplier) << 8) |
                            (((color & 0x1F) * multiplier) << 16)
                            );
                    }
                }
            }

            Texture2D texture = new Texture2D(m_graphics, 44, 44);

            texture.SetData <uint>(data);

            return(texture);
        }
コード例 #9
0
        private static unsafe Texture2D readStaticTexture(int index)
        {
            int  length, extra;
            bool is_patched;

            BinaryFileReader reader = m_Index.Seek(index, out length, out extra, out is_patched);

            reader.ReadInt(); // this data is discarded. Why?

            int width  = reader.ReadShort();
            int height = reader.ReadShort();

            if (width <= 0 || height <= 0)
            {
                return(null);
            }

            if (m_dimensions[index - 0x4000] == null)
            {
                m_dimensions[index - 0x4000] = new ushort[] { (ushort)width, (ushort)height };
            }


            ushort[] lookups = reader.ReadUShorts(height);

            int dataStart  = (int)reader.Position + (height * 2);
            int readLength = (getMaxLookup(lookups) + width * 2); // we don't know the length of the last line, so we read width * 2, anticipating worst case compression.

            if (dataStart + readLength * 2 > reader.Stream.Length)
            {
                readLength = ((int)reader.Stream.Length - dataStart) >> 1;
            }
            ushort[] fileData  = reader.ReadUShorts(readLength);
            uint[]   pixelData = new uint[width * height];

            fixed(uint *pData = pixelData)
            {
                uint *dataRef = pData;
                int   i;

                for (int y = 0; y < height; y++, dataRef += width)
                {
                    i = lookups[y];

                    uint *start = dataRef;

                    int count, offset;

                    while (((offset = fileData[i++]) + (count = fileData[i++])) != 0)
                    {
                        start += offset;
                        uint *end = start + count;

                        while (start < end)
                        {
                            uint color   = fileData[i++];
                            *    start++ = 0xFF000000 + (
                                ((((color >> 10) & 0x1F) * multiplier)) |
                                ((((color >> 5) & 0x1F) * multiplier) << 8) |
                                (((color & 0x1F) * multiplier) << 16)
                                );
                        }
                    }
                }
            }

            Metrics.ReportDataRead(sizeof(ushort) * (fileData.Length + lookups.Length + 2));

            Texture2D texture = new Texture2D(m_graphics, width, height);

            texture.SetData <uint>(pixelData);

            return(texture);
        }