Beispiel #1
0
        public Frame Split(EmguImage frame)
        {
            // Trim image
            Point startPos = TrimImage(ref frame);

            // Create objects
            List<Obj> objs = new List<Obj>();
            this.CreateObjects(frame, objs, 0, 0, frame.Height);

            // Update coordinates. Sets to absolute values.
            foreach (Obj obj in objs) {
                obj.CoordX = (short)(obj.CoordX + startPos.X);
                obj.CoordY = (sbyte)(obj.CoordY + startPos.Y);
            }

            // Return new frame
            Frame f = new Frame();
            f.SetObjects(objs.ToArray());
            f.VisibleArea = new Rectangle(startPos.X - 256, startPos.Y - 128, frame.Width - 1, frame.Height - 1);
            return f;
        }
Beispiel #2
0
            protected override void ReadData(Stream strIn)
            {
                BinaryReader br         = new BinaryReader(strIn);
                long         blockStart = strIn.Position;

                ushort numFrames = br.ReadUInt16();

                this.TypeFrame = br.ReadUInt16();
                uint frameOffset = br.ReadUInt32();

                this.TileSize = 1 << (5 + (int)(br.ReadUInt32() & 0xFF));
                int frameInfoSize = ((this.TypeFrame & 1) != 0) ? 0x10 : 0x08;

                this.UnknownOffset1 = br.ReadUInt32();                  // Offset to unknown block
                this.Unknown        = br.ReadUInt32();                  // Unknown
                this.UnknownOffset2 = br.ReadUInt32();                  // Unknown offset

#if VERBOSE
                if (this.UnknownOffset1 != 0)
                {
                    Console.WriteLine("\t* UnknownOffset1 -> {0:x8}", this.UnknownOffset1);
                }
                if (this.Unknown != 0)
                {
                    Console.WriteLine("\t* Unknown -> {0:x8}", this.Unknown);
                }
                if (this.UnknownOffset2 != 0)
                {
                    Console.WriteLine("\t* UnknownOffset2 -> {0:X8}", this.UnknownOffset2);
                }
#endif

                this.Frames = new Frame[numFrames];
                for (int i = 0; i < numFrames; i++)
                {
                    strIn.Position = blockStart + frameOffset + i * frameInfoSize;
                    Frame frame = new Frame();
                    frame.TileSize = this.TileSize;

                    ushort numObjs   = br.ReadUInt16();
                    ushort areaInfo  = br.ReadUInt16();
                    uint   objOffset = br.ReadUInt32();

                    // Get area info
                    bool      squareSizeFlag = ((areaInfo >> 11) & 1) == 0;
                    Rectangle frameArea      = new Rectangle();
                    if ((this.TypeFrame & 1) != 0 && !squareSizeFlag)
                    {
                        short xend   = br.ReadInt16();
                        short yend   = br.ReadInt16();
                        short xstart = br.ReadInt16();
                        short ystart = br.ReadInt16();

                        frameArea.Location = new Point(xstart, ystart);
                        frameArea.Width    = xend - xstart;
                        frameArea.Height   = yend - ystart;
                    }
                    else if (!squareSizeFlag)
                    {
                        throw new FormatException("Obj area info is square but areaInfo is set");
                    }
                    else
                    {
                        int squareSize = (areaInfo & 0x3F) << 2;
                        squareSize *= 2;

                        frameArea.Width  = squareSize;
                        frameArea.Height = squareSize;
                    }

                    // Read Objs
                    strIn.Position = blockStart + frameOffset + numFrames * frameInfoSize + objOffset;
                    Obj[] objs = new Obj[numObjs];
                    for (int j = 0; j < numObjs; j++)
                    {
                        objs[j]    = Obj.FromUshort(br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16());
                        objs[j].Id = (ushort)j;
                    }

                    // TODO: Detect frame position for square size

                    frame.SetObjects(objs);
                    frame.VisibleArea = frameArea;
                    this.Frames[i]    = frame;
                }
            }
Beispiel #3
0
            protected override void ReadData(Stream strIn)
            {
                BinaryReader br = new BinaryReader(strIn);
                long blockStart = strIn.Position;

                ushort numFrames  = br.ReadUInt16();
                this.TypeFrame    = br.ReadUInt16();
                uint frameOffset  = br.ReadUInt32();
                this.TileSize     = 1 << (5 + (int)(br.ReadUInt32() & 0xFF));
                int frameInfoSize = ((this.TypeFrame & 1) != 0) ? 0x10 : 0x08;

                this.UnknownOffset1 = br.ReadUInt32();	// Offset to unknown block
                this.Unknown        = br.ReadUInt32();	// Unknown
                this.UnknownOffset2 = br.ReadUInt32();	// Unknown offset

                #if VERBOSE
                if (this.UnknownOffset1 != 0)
                    Console.WriteLine("\t* UnknownOffset1 -> {0:x8}", this.UnknownOffset1);
                if (this.Unknown != 0)
                    Console.WriteLine("\t* Unknown -> {0:x8}", this.Unknown);
                if (this.UnknownOffset2 != 0)
                    Console.WriteLine("\t* UnknownOffset2 -> {0:X8}", this.UnknownOffset2);
                #endif

                this.Frames = new Frame[numFrames];
                for (int i = 0; i < numFrames; i++) {
                    strIn.Position = blockStart + frameOffset + i * frameInfoSize;
                    Frame frame    = new Frame();
                    frame.TileSize = this.TileSize;

                    ushort numObjs  = br.ReadUInt16();
                    ushort areaInfo = br.ReadUInt16();
                    uint objOffset  = br.ReadUInt32();

                    // Get area info
                    bool squareSizeFlag = ((areaInfo >> 11) & 1) == 0;
                    Rectangle frameArea = new Rectangle();
                    if ((this.TypeFrame & 1) != 0 && !squareSizeFlag) {
                        short xend = br.ReadInt16();
                        short yend = br.ReadInt16();
                        short xstart = br.ReadInt16();
                        short ystart = br.ReadInt16();

                        frameArea.Location = new Point(xstart, ystart);
                        frameArea.Width    = xend - xstart;
                        frameArea.Height   = yend - ystart;
                    } else if (!squareSizeFlag) {
                        throw new FormatException("Obj area info is square but areaInfo is set");
                    } else {
                        int squareSize = (areaInfo & 0x3F) << 2;
                        squareSize *= 2;

                        frameArea.Width  = squareSize;
                        frameArea.Height = squareSize;
                    }

                    // Read Objs
                    strIn.Position = blockStart + frameOffset + numFrames * frameInfoSize + objOffset;
                    Obj[] objs = new Obj[numObjs];
                    for (int j = 0; j < numObjs; j++) {
                        objs[j] = Obj.FromUshort(br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16());
                        objs[j].Id = (ushort)j;
                    }

                    // TODO: Detect frame position for square size

                    frame.SetObjects(objs);
                    frame.VisibleArea = frameArea;
                    this.Frames[i] = frame;
                }
            }