Пример #1
0
        public ImageInfo Load(Stream ncgrStream, Stream nclrStream)
        {
            using var ncgrBr = new BinaryReaderX(ncgrStream);
            using var nclrBr = new BinaryReaderX(nclrStream);

            // Read generic headers
            _ncgrHeader = ncgrBr.ReadType <NitroHeader>();
            _nclrHeader = nclrBr.ReadType <NitroHeader>();

            // Read Char header
            _charHeader = ncgrBr.ReadType <NitroCharHeader>();

            // Read Ttlp header
            _ttlpHeader = nclrBr.ReadType <NitroTtlpHeader>();

            // Read palette data
            var paletteData = nclrBr.ReadBytes(_ttlpHeader.paletteSize);

            // Create image
            var dataLength = _charHeader.tileCountX < 0 ? _charHeader.tileDataSize : _charHeader.tileCountX * _charHeader.tileCountY;
            var data       = ncgrBr.ReadBytes(dataLength);
            var size       = GetImageSize(_charHeader);

            var imageInfo = new ImageInfo(data, _charHeader.imageFormat, size)
            {
                ImageFormat = _charHeader.imageFormat,

                PaletteData   = paletteData,
                PaletteFormat = 0
            };

            imageInfo.RemapPixels.With(context => new NitroSwizzle(context));

            return(imageInfo);
        }
Пример #2
0
        /// <summary>
        /// Reads the font from its associated file.
        /// </summary>
        public void Load()
        {
            byte[] fileData = StreamHelper.ReadFile(this.fileName);

            this.header = new NitroHeader("RTFN");
            this.header.ReadFrom(fileData, 0);

            this.finfChunk = new FontInfoSection();
            int finfOffset = this.header.Size;

            this.finfChunk.ReadFrom(fileData, finfOffset);

            this.cwdhChunk = new CharacterWidthChunk();
            this.cwdhChunk.ReadFrom(fileData, this.finfChunk.WidthSectionOffset);

            int characterCount = this.cwdhChunk.Widths.Count;

            this.cglpChunk = new CharacterGlyphChunk(characterCount);
            this.cglpChunk.ReadFrom(fileData, this.finfChunk.GlyphSectionOffset);

            int cmapCount  = this.header.SectionCount - 3;
            int cmapOffset = this.finfChunk.MapSectionOffset;

            this.cmapChunks    = new List <CharacterMapChunk>();
            this.characterSets = new List <CharacterSet>();
            for (int i = 0; i < cmapCount; i++)
            {
                CharacterMapChunk cmapChunk = new CharacterMapChunk();
                cmapChunk.ReadFrom(fileData, cmapOffset);
                cmapOffset = cmapChunk.NextChunkOffset;
                this.cmapChunks.Add(cmapChunk);
                this.characterSets.Add(new CharacterSet(cmapChunk, this.cwdhChunk, this.cglpChunk));
            }

            this.RebuildIndices();
        }