示例#1
0
        public unsafe Bitmap[] GetFrames()
        {
            if ((Frames == null) || (Frames.Count == 0))
            {
                return(null);
            }

            var bits = new Bitmap[Frames.Count];

            for (int i = 0; i < bits.Length; ++i)
            {
                FrameEdit frame  = Frames[i];
                int       width  = frame.width;
                int       height = frame.height;
                if (height == 0 || width == 0)
                {
                    continue;
                }

                var        bmp   = new Bitmap(width, height, PixelFormat.Format16bppArgb1555);
                BitmapData bd    = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
                var        line  = (ushort *)bd.Scan0;
                int        delta = bd.Stride >> 1;

                int xBase = frame.Center.X - 0x200;
                int yBase = frame.Center.Y + height - 0x200;

                line += xBase;
                line += yBase * delta;

                for (int j = 0; j < frame.RawData.Length; ++j)
                {
                    FrameEdit.Raw raw = frame.RawData[j];

                    ushort *cur = line + (((raw.offsetY) * delta) + ((raw.offsetX) & 0x3FF));
                    ushort *end = cur + (raw.run);

                    int ii = 0;
                    while (cur < end)
                    {
                        *cur++ = Palette[raw.data[ii++]];
                    }
                }

                bmp.UnlockBits(bd);
                bits[i] = bmp;
            }

            return(bits);
        }
示例#2
0
        public unsafe Bitmap[] GetFrames(bool centred = false)
        {
            if ((Frames == null) || (Frames.Count == 0))
            {
                return(null);
            }
            Bitmap[] bits = new Bitmap[Frames.Count];
            int      _width = 0, _height = 0;

            if (centred)
            {
                for (int i = 0; i < bits.Length; ++i)
                {
                    _width  = Math.Max(2 * Math.Max(Frames[i].Center.X, Frames[i].width - Frames[i].Center.X), _width);
                    _height = Math.Max(Math.Max(-4 * Frames[i].Center.Y, (Frames[i].height + Frames[i].Center.Y) * 4 / 3), _height);
                }
                _width  = (int)(Math.Max(1.2, (1.6 - _width / 640)) * _width);
                _height = (int)(Math.Max(1.2, (1.6 - _height / 640)) * _height);

                if (_width <= 64)
                {
                    _width = 64;
                }
                else if (_width <= 96)
                {
                    _width = 96;
                }
                else if (_width <= 128)
                {
                    _width = 128;
                }
                else if (_width <= 192)
                {
                    _width = 192;
                }
                else if (_width <= 256)
                {
                    _width = 256;
                }
                else if (_width <= 384)
                {
                    _width = 384;
                }
                else if (_width <= 512)
                {
                    _width = 512;
                }
                else if (_width <= 768)
                {
                    _width = 768;
                }
                else if (_width <= 1024)
                {
                    _width = 1024;
                }

                if (_height <= 64)
                {
                    _width = 64;
                }
                else if (_height <= 96)
                {
                    _height = 96;
                }
                else if (_height <= 128)
                {
                    _height = 128;
                }
                else if (_height <= 192)
                {
                    _height = 192;
                }
                else if (_height <= 256)
                {
                    _height = 256;
                }
                else if (_height <= 384)
                {
                    _height = 384;
                }
                else if (_height <= 512)
                {
                    _height = 512;
                }
                else if (_height <= 768)
                {
                    _height = 768;
                }
                else if (_height <= 1024)
                {
                    _width = 1024;
                }
            }

            for (int i = 0; i < bits.Length; ++i)
            {
                FrameEdit frame  = (FrameEdit)Frames[i];
                int       width  = centred ? _width  : frame.width;
                int       height = centred ? _height : frame.height;
                if (height == 0 || width == 0)
                {
                    continue;
                }
                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 xBase = centred ? (width / 2 - 0x200) : (frame.Center.X - 0x200);
                int yBase = centred ? (height * 3 / 4 - 0x200) : (frame.Center.Y + height - 0x200);

                line += xBase;
                line += yBase * delta;
                for (int j = 0; j < frame.RawData.Length; ++j)
                {
                    FrameEdit.Raw raw = frame.RawData[j];

                    ushort *cur = line + (((raw.offy) * delta) + ((raw.offx) & 0x3FF));
                    ushort *end = cur + (raw.run);

                    int ii = 0;
                    while (cur < end)
                    {
                        *cur++ = Palette[raw.data[ii++]];
                    }
                }
                bmp.UnlockBits(bd);
                bits[i] = bmp;
            }
            return(bits);
        }