예제 #1
0
        /// <summary>
        /// Создание анимации из файла *.avi (при этом палитра если возможно берется из одноименного файла *.pal) (TODO: поддрежка формата *.gif)
        /// </summary>
        /// <param name="file"></param>
        public void ImportFromFile(string file)
        {
            if (!File.Exists(file))
            {
                return;
            }
            //Palette = new ushort[0x100];
            //Frames = new List<FrameEdit>();
            //idxextra = 0x00000000; // хз

            ClearFrames();
            switch (Path.GetExtension(file))
            {
            case ".avi":
                var filename = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file));
                var avi      = new AviManager(filename + ".avi", true);
                var stream   = avi.GetVideoStream();
                stream.GetFrameOpen();
                var frames = new Bitmap[stream.CountFrames];
                for (int pos = 0; pos < stream.CountFrames; ++pos)
                {
                    frames[pos] = stream.GetBitmap(pos);
                }
                stream.GetFrameClose();
                avi.Close();

                if (File.Exists(filename + ".pal"))
                {
                    this.GetPalPalette(filename + ".pal");
                }
                else
                {
                    this.GetImagePalette(frames);
                }

                if (Frames == null)
                {
                    Frames = new List <FrameEdit>();
                }
                foreach (var frame in frames)
                {
                    Frames.Add(new FrameEdit(frame, FrameEdit.GetSingleRect(frame), Palette, frame.Width / 2, -frame.Height / 4));
                }
                //this.AddFrame(frame);

                break;

            case ".gif":
                throw new NotImplementedException();
                break;

            default: throw new FileFormatException();
            }
        }
 public void ReplaceFrame(Bitmap bit, int index)
 {
     if ((Frames == null) || (Frames.Count == 0))
     {
         return;
     }
     if (index > Frames.Count)
     {
         return;
     }
     Frames[index] = new FrameEdit(bit, Palette, ((FrameEdit)Frames[index]).Center.X, ((FrameEdit)Frames[index]).Center.Y);
 }
예제 #3
0
 public void ReplaceFrame(Bitmap bit, int index)
 {
     if ((Frames == null) || (Frames.Count == 0))
     {
         return;
     }
     if (index > Frames.Count)
     {
         return;
     }
     Frames[index] = new FrameEdit(bit, Rectangle.FromLTRB(0, 0, bit.Width, bit.Height), Palette, ((FrameEdit)Frames[index]).Center.X, ((FrameEdit)Frames[index]).Center.Y);
 }
예제 #4
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);
        }
예제 #5
0
 public void ReplaceFrame(Bitmap bit, int index)
 {
     if ((Frames == null) || (Frames.Count == 0))
         return;
     if (index > Frames.Count)
         return;
     Frames[index] = new FrameEdit(bit, Palette, ((FrameEdit)Frames[index]).Center.X, ((FrameEdit)Frames[index]).Center.Y);
 }
예제 #6
0
 //My Soulblighter Modification
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         if (FileType != 0)
         {
             AnimIdx edit = Ultima.AnimationEdit.GetAnimation(FileType, CurrBody, CurrAction, CurrDir);
             if (edit != null)
             {
                 if (edit.Frames.Count >= trackBar2.Value)
                 {
                     FrameEdit[] frame = new FrameEdit[edit.Frames.Count];
                     for (int Index = 0; Index < edit.Frames.Count; Index++)
                     {
                         frame[Index] = edit.Frames[Index];
                         frame[Index].ChangeCenter((int)numericUpDownCx.Value, (int)numericUpDownCy.Value);
                         Options.ChangedUltimaClass["Animations"] = true;
                         pictureBox1.Invalidate();
                     }
                 }
             }
         }
     }
     catch (System.NullReferenceException) { }
 }
예제 #7
0
 public void ReplaceFrame(Bitmap bit, int index)
 {
     if ((Frames == null) || (Frames.Count == 0))
         return;
     if (index > Frames.Count)
         return;
     Frames[index] = new FrameEdit(bit, Rectangle.FromLTRB(0, 0, bit.Width, bit.Height), Palette, ((FrameEdit)Frames[index]).Center.X, ((FrameEdit)Frames[index]).Center.Y);
 }
예제 #8
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);
        }