Пример #1
0
        public static Rectangle Measure(int itemid)
        {
            ArtData data = GetStatic(itemid);

            return(new Rectangle(0, 0, data.Width, data.Height));
        }
Пример #2
0
        public unsafe static ArtData GetStatic(int itemId)
        {
            FileStream artFile;

            itemId += 0x4000;

            if (m_Cache == null)
            {
                m_Cache = new Dictionary <int, ArtData>();
            }

            if (m_Cache.ContainsKey(itemId))
            {
                return(m_Cache[itemId]);
            }

            string fileName = Path.Combine(m_DataPath, "art.mul");

            if (m_isUOPFormat)
            {
                fileName = Path.Combine(m_DataPath, "artLegacyMUL.uop");
            }

            artFile = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            if (artFile == null)
            {
                return(new ArtData(0, 0, null, null, new Rectangle(0, 0, 0, 0)));
            }

            Entry3D entry = m_Index[itemId];

            artFile.Seek(entry.Lookup, SeekOrigin.Begin);

            using (BinaryReader reader = new BinaryReader(artFile))
            {
                reader.ReadInt32();

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

                if (width <= 0 || height <= 0)
                {
                    return(new ArtData(0, 0, null, null, new Rectangle(0, 0, 0, 0)));
                }

                int[] lookups = new int[height];

                int start = (int)reader.BaseStream.Position + (height * 2);

                for (int i = 0; i < height; i++)
                {
                    lookups[i] = (start + reader.ReadUInt16() * 2);
                }

                Bitmap bmp = new Bitmap(width, height, PixelFormat.Format16bppArgb1555);

                BitmapData bd = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);

                ushort *line  = (ushort *)bd.Scan0;
                int     delta = bd.Stride >> 1;

                int smallestX, largestX = 0;
                smallestX = width;
                int smallestY, largestY = 0;
                smallestY = height;

                for (int y = 0; y < height; y++, line += delta)
                {
                    reader.BaseStream.Seek(lookups[y], SeekOrigin.Begin);

                    ushort *cur = line;
                    ushort *end;

                    int xOffset, xRun;
                    int x = 0;

                    if (y > largestY)
                    {
                        largestY = y + 1;
                    }

                    if (y < smallestY)
                    {
                        smallestY = y;
                    }

                    while (((xOffset = reader.ReadUInt16()) + (xRun = reader.ReadUInt16())) != 0)
                    {
                        cur += xOffset;
                        end  = cur + xRun;
                        x   += xOffset;

                        if (x < smallestX)
                        {
                            smallestX = x;
                        }

                        while (cur < end)
                        {
                            *cur++ = (ushort)(reader.ReadUInt16() ^ 0x8000);
                            x++;
                        }

                        if (x > largestX)
                        {
                            largestX = x;
                        }
                    }
                }

                bmp.UnlockBits(bd);

                ArtData imageData = new ArtData(width, height, bmp, Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height)), new Rectangle(smallestX, smallestY, largestX, largestY));
                if (!m_Cache.ContainsKey(itemId))
                {
                    m_Cache.Add(itemId, imageData);
                }

                return(imageData);
            }
        }
Пример #3
0
        public static unsafe ArtData GetStatic( int itemId )
        {
            FileStream artFile;
            itemId += 0x4000;

            if (m_Cache == null)
                m_Cache = new Dictionary<int, ArtData>();

            if (m_Cache.ContainsKey( itemId ))
                return m_Cache[itemId];

            string fileName = Path.Combine( m_DataPath, "art.mul" );

            if (m_isUOPFormat)
                fileName = Path.Combine( m_DataPath, "artLegacyMUL.uop" );

            artFile = File.Open( fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite );

            if (artFile == null)
                return new ArtData( 0, 0, null, null, new Rectangle(0, 0, 0, 0) );

            Entry3D entry = m_Index[itemId];

            artFile.Seek( entry.Lookup, SeekOrigin.Begin );

            using (BinaryReader reader = new BinaryReader( artFile ))
            {
                reader.ReadInt32();

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

                if (width <= 0 || height <= 0)
                    return new ArtData( 0, 0, null, null, new Rectangle(0, 0, 0, 0) );

                int[] lookups = new int[height];

                int start = (int) reader.BaseStream.Position + ( height * 2 );

                for (int i = 0; i < height; i++)
                    lookups[i] = ( start + reader.ReadUInt16() * 2 );

                Bitmap bmp = new Bitmap( width, height, PixelFormat.Format16bppArgb1555 );

                BitmapData bd = bmp.LockBits( new Rectangle( 0, 0, width, height ), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555 );

                ushort* line = (ushort*) bd.Scan0;
                int delta = bd.Stride >> 1;

                int smallestX, largestX = 0;
                smallestX = width;
                int smallestY, largestY = 0;
                smallestY = height;

                for (int y = 0; y < height; y++, line += delta)
                {
                    reader.BaseStream.Seek( lookups[y], SeekOrigin.Begin );

                    ushort* cur = line;
                    ushort* end;

                    int xOffset, xRun;
                    int x = 0;

                    if (y > largestY)
                        largestY = y + 1;

                    if (y < smallestY)
                        smallestY = y;

                    while (( ( xOffset = reader.ReadUInt16() ) + ( xRun = reader.ReadUInt16() ) ) != 0)
                    {
                        cur += xOffset;
                        end = cur + xRun;
                        x += xOffset;

                        if (x < smallestX)
                            smallestX = x;

                        while (cur < end)
                        {
                            *cur++ = (ushort) ( reader.ReadUInt16() ^ 0x8000 );
                            x++;
                        }

                        if (x > largestX)
                            largestX = x;
                    }
                }

                bmp.UnlockBits( bd );

                ArtData imageData = new ArtData( width, height, bmp, Imaging.CreateBitmapSourceFromHBitmap( bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight( bmp.Width, bmp.Height ) ), new Rectangle(smallestX, smallestY, largestX, largestY) );
                if (!m_Cache.ContainsKey( itemId ))
                    m_Cache.Add( itemId, imageData );

                return imageData;
            }
        }