예제 #1
0
        public Register(BinaryReader stream, PAL palette)
        {
            int graphId = stream.ReadInt32();

            stream.BaseStream.Position += sizeof(int); // Skip register size.
            string description = stream.ReadBytes(MAP.DESCRIPTION_LENGTH).ToASCIIString();

            this.filename = stream.ReadBytes(FILENAME_LENGTH).ToASCIIString();
            int width  = stream.ReadInt32();
            int height = stream.ReadInt32();

            this.map = new MAP(palette, (short)width, (short)height, graphId, description);

            int count = stream.ReadInt32(); // Control Points counter.

            for (int i = 0; i < count; i++)
            {
                var point = new ControlPoint(stream);
                if (point.x < 0 || point.y < 0)
                {
                    // If the control point has values under zero (x:-1, y:-1) means that this point has not defined values in DIV Games Studio MAP editor.
                    // DIV Games Studio read this values but when used for drawing a MAP this values are the MAP center coordintates.
                    point.x = (short)(width / 2);
                    point.y = (short)(height / 2);
                }
                this.map.ControlPoints.Add(point);
            }

            this.map.SetBitmapArray(stream.ReadBytes(width * height));
        }
예제 #2
0
        /// <summary>
        /// Loads a <see cref="FPG"/> file.
        /// </summary>
        /// <param name="buffer"><see cref="byte"/> array that contain the <see cref="FPG"/> file data to load.</param>
        public FPG(byte[] buffer)
            : this()
        {
            try
            {
                using (var stream = new BinaryReader(new MemoryStream(buffer)))
                {
                    if (FPG_FILE_HEADER.Validate(stream.ReadBytes(DIVFileHeader.SIZE)))
                    {
                        this.Palette = new PAL(new ColorPalette(stream.ReadBytes(ColorPalette.SIZE)),
                                               new ColorRangeTable(stream.ReadBytes(ColorRangeTable.SIZE)));

                        while (stream.BaseStream.Position < stream.BaseStream.Length)
                        {
                            this._registers.Add(new Register(stream, this.Palette));
                        }

                        this._registers.Sort(this.OrderByAsc);
                    }
                    else
                    {
                        throw new DIVFormatHeaderException();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new DIVFileFormatException <FPG>(ex);
            }
        }
예제 #3
0
        /// <summary>
        /// Creates new <see cref="PAL"/> instance from a supported image file.
        /// </summary>
        /// <param name="buffer">Memory buffer that contains a supported image file.</param>
        /// <param name="sortColors">Sort colors of the imported palette. By default is <see langword="false"/>.</param>
        /// <returns>Returns a new <see cref="PAL"/> instance.</returns>
        /// <remarks>Supported image formats are JPEG, PNG, BMP, GIF and TGA.
        /// Also supported 256 color PCX images, <see cref="MAP"/> and <see cref="FPG"/> files.</remarks>
        public static PAL FromImage(byte[] buffer, bool sortColors = false)
        {
            PAL pal = PaletteProcessor.ProcessPalette(buffer);

            if (sortColors)
            {
                pal.Sort();
            }

            return(pal);
        }
예제 #4
0
 /// <summary>
 /// Creates a new <see cref="FPG"/> instance.
 /// </summary>
 /// <param name="palette">The <see cref="PAL"/> instance used in this <see cref="FPG"/> instance.</param>
 public FPG(PAL palette)
     : this()
 {
     this.Palette = palette;
 }