Exemplo n.º 1
0
        public static SCBGCollection LoadPngs(string[] files, bool tiled = true)
        {
            var scbgFiles = (
                from filePath in files
                let fileName = Path.GetFileNameWithoutExtension(filePath)
                               where int.TryParse(fileName, out var _)
                               let num = int.Parse(fileName)
                                         select(filePath, num))
                            .ToArray();

            int maxNum = scbgFiles.Max(i => i.num);
            var scbg   = new SCBG[maxNum + 1];

            Parallel.For(0, scbgFiles.Length, i =>
            {
                var(file, num) = scbgFiles[i];
                if (new FileInfo(file).Length == 0)
                {
                    Console.WriteLine("File of len 0 hit");
                    scbg[num] = null;
                }
                else
                {
                    scbg[num] = SCBG.LoadPng(file, tiled);
                }
            });
            return(new SCBGCollection {
                Items = scbg.ToList()
            });
        }
Exemplo n.º 2
0
        public static SCBGCollection Load(string scbgDataFile, string scbgInfoFile)
        {
            var scbgs = new List <SCBG>();

            using (var dataBr = new BinaryReader(File.OpenRead(scbgDataFile)))
            {
                using (var infoBr = new BinaryReader(File.OpenRead(scbgInfoFile)))
                {
                    int numItems = infoBr.ReadInt32();
                    int _        = infoBr.ReadInt32(); // length of the largest file
                    for (int i = 0; i < numItems; i++)
                    {
                        var offset = infoBr.ReadUInt32();
                        var len    = infoBr.ReadInt32();
                        if (len == 0)
                        {
                            scbgs.Add(null);
                        }
                        else
                        {
                            dataBr.BaseStream.Position = offset;
                            scbgs.Add(SCBG.Load(dataBr));
                        }
                    }

                    return(new SCBGCollection {
                        Items = scbgs
                    });
                }
            }
        }
Exemplo n.º 3
0
        public static SCBG Load(BinaryReader br)
        {
            var scbg = new SCBG();

            var magicNumber = br.ReadMagicNumber();

            if (magicNumber != MagicNumber)
            {
                throw new InvalidDataException($"Unexpected magic number '{magicNumber}'. (expected: {MagicNumber})");
            }
            scbg.Width  = br.ReadUInt16();
            scbg.Height = br.ReadUInt16();

            scbg.Palette = RawPalette.Decompress(br.ReadBytes(PaletteDataLength));
            scbg.Pixels  = br.ReadBytes(scbg.Width * scbg.Height);

            return(scbg);
        }