Ejemplo n.º 1
0
        void ReadHeader(EriFile erif)
        {
            var section = erif.ReadSection();

            if (section.Id != "Header  " || section.Length <= 0 || section.Length > int.MaxValue)
            {
                return(null);
            }
            m_stream_pos = erif.BaseStream.Position + section.Length;
            section      = erif.ReadSection();
            if (section.Id != "FileHdr" || section.Length < 8)
            {
                return(null);
            }
            var file_hdr = new byte[section.Length];

            erif.Read(file_hdr, 0, file_hdr.Length);
            if (0 == (file_hdr[5] & 1))
            {
                return(null);
            }
            section = erif.ReadSection();
            if (section.Id != "SoundInf" || section.Length < 0x24)
            {
                return(null);
            }

            var info = new EmsacSoundInfo();

            info.Version        = erif.ReadInt32();
            info.Transformation = (CvType)erif.ReadInt32();
            info.Architecture   = (EriCode)erif.ReadInt32();
            info.ChannelCount   = erif.ReadInt32();
            info.SamplesPerSec  = erif.ReadUInt32();
            info.BlocksetCount  = erif.ReadUInt32();
            info.SubbandDegree  = erif.ReadInt32();
            info.AllSampleCount = erif.ReadInt32();
            info.LappedDegree   = erif.ReadInt32();
            SetSoundInfo(info);
            SetWaveFormat(info);

            erif.BaseStream.Position = m_stream_pos;
            var stream_size = erif.FindSection("Stream  ");

            m_stream_pos = erif.BaseStream.Position;
        }
Ejemplo n.º 2
0
        }                                                                  // 'Enti'

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            var header = stream.ReadHeader(0x40);

            if (0x03000100 != header.ToUInt32(8))
            {
                return(null);
            }
            if (!header.AsciiEqual(0x10, "Entis Rasterized Image") &&
                !header.AsciiEqual(0x10, "Moving Entis Image"))
            {
                return(null);
            }
            using (var reader = new EriFile(stream.AsStream))
            {
                var section = reader.ReadSection();
                if (section.Id != "Header  " || section.Length <= 0)
                {
                    return(null);
                }
                int           header_size = (int)section.Length;
                int           stream_pos  = 0x50 + header_size;
                EriFileHeader file_header = null;
                EriMetaData   info        = null;
                string        desc        = null;
                while (header_size > 0x10)
                {
                    section      = reader.ReadSection();
                    header_size -= 0x10;
                    if (section.Length <= 0 || section.Length > header_size)
                    {
                        break;
                    }
                    if ("FileHdr " == section.Id)
                    {
                        file_header = new EriFileHeader {
                            Version = reader.ReadInt32()
                        };
                        if (file_header.Version > 0x00020100)
                        {
                            throw new InvalidFormatException("Invalid ERI file version");
                        }
                        file_header.ContainedFlag = reader.ReadInt32();
                        file_header.KeyFrameCount = reader.ReadInt32();
                        file_header.FrameCount    = reader.ReadInt32();
                        file_header.AllFrameTime  = reader.ReadInt32();
                    }
                    else if ("ImageInf" == section.Id)
                    {
                        int version = reader.ReadInt32();
                        if (version != 0x00020100 && version != 0x00020200)
                        {
                            return(null);
                        }
                        info = new EriMetaData {
                            StreamPos = stream_pos, Version = version
                        };
                        info.Transformation = (CvType)reader.ReadInt32();
                        info.Architecture   = (EriCode)reader.ReadInt32();
                        info.FormatType     = (EriType)reader.ReadInt32();
                        int w = reader.ReadInt32();
                        int h = reader.ReadInt32();
                        info.Width           = (uint)Math.Abs(w);
                        info.Height          = (uint)Math.Abs(h);
                        info.VerticalFlip    = h < 0;
                        info.BPP             = reader.ReadInt32();
                        info.ClippedPixel    = reader.ReadInt32();
                        info.SamplingFlags   = (EriSampling)reader.ReadInt32();
                        info.QuantumizedBits = reader.ReadUInt64();
                        info.AllottedBits    = reader.ReadUInt64();
                        info.BlockingDegree  = reader.ReadInt32();
                        info.LappedBlock     = reader.ReadInt32();
                        info.FrameTransform  = reader.ReadInt32();
                        info.FrameDegree     = reader.ReadInt32();
                    }
                    else if ("descript" == section.Id)
                    {
                        if (0xFEFF == reader.PeekChar())
                        {
                            reader.Read();
                            var desc_chars = reader.ReadChars((int)section.Length / 2 - 1);
                            desc = new string (desc_chars);
                        }
                        else
                        {
                            var desc_chars = reader.ReadBytes((int)section.Length);
                            desc = Encoding.UTF8.GetString(desc_chars);
                        }
                    }
                    else
                    {
                        reader.BaseStream.Seek(section.Length, SeekOrigin.Current);
                    }
                    header_size -= (int)section.Length;
                }
                if (info != null)
                {
                    if (file_header != null)
                    {
                        info.Header = file_header;
                    }
                    if (desc != null)
                    {
                        info.Description = desc;
                    }
                }
                return(info);
            }
        }
Ejemplo n.º 3
0
        public MioInput(Stream file) : base(file)
        {
            file.Position = 0x40;
            using (var erif = new EriFile(file))
            {
                var section = erif.ReadSection();
                if (section.Id != "Header  " || section.Length <= 0 || section.Length > int.MaxValue)
                {
                    throw new InvalidFormatException();
                }
                m_stream_pos = 0x50 + section.Length;
                int header_size = (int)section.Length;
                while (header_size > 0x10)
                {
                    section      = erif.ReadSection();
                    header_size -= 0x10;
                    if (section.Length <= 0 || section.Length > header_size)
                    {
                        break;
                    }
                    if ("SoundInf" == section.Id)
                    {
                        m_info                = new MioInfoHeader();
                        m_info.Version        = erif.ReadInt32();
                        m_info.Transformation = (CvType)erif.ReadInt32();
                        m_info.Architecture   = (EriCode)erif.ReadInt32();
                        m_info.ChannelCount   = erif.ReadInt32();
                        m_info.SamplesPerSec  = erif.ReadUInt32();
                        m_info.BlocksetCount  = erif.ReadUInt32();
                        m_info.SubbandDegree  = erif.ReadInt32();
                        m_info.AllSampleCount = erif.ReadUInt32();
                        m_info.LappedDegree   = erif.ReadUInt32();
                        m_info.BitsPerSample  = erif.ReadUInt32();
                        break;
                    }
                    header_size -= (int)section.Length;
                    erif.BaseStream.Seek(section.Length, SeekOrigin.Current);
                }
                if (null == m_info)
                {
                    throw new InvalidFormatException("MIO sound header not found");
                }

                erif.BaseStream.Position = m_stream_pos;
                var stream_size = erif.FindSection("Stream  ");
                m_stream_pos = erif.BaseStream.Position;

                m_pmiod = new MioDecoder(m_info);
                if (EriCode.Nemesis != m_info.Architecture)
                {
                    m_pmioc = new HuffmanDecodeContext(0x10000);
                }
                else
                {
                    throw new NotImplementedException("MIO Nemesis encoding not implemented");
                }

                int pcm_bitrate = (int)(m_info.SamplesPerSec * BitsPerSample * ChannelCount);
                var format      = new GameRes.WaveFormat();
                format.FormatTag             = 1;
                format.Channels              = (ushort)ChannelCount;
                format.SamplesPerSecond      = m_info.SamplesPerSec;
                format.BitsPerSample         = (ushort)BitsPerSample;
                format.BlockAlign            = (ushort)(BitsPerSample / 8 * format.Channels);
                format.AverageBytesPerSecond = (uint)pcm_bitrate / 8;
                this.Format      = format;
                m_decoded_stream = LoadChunks(erif);

                if (0 != m_total_samples)
                {
                    m_bitrate = (int)(stream_size * 8 * m_info.SamplesPerSec / m_total_samples);
                }
                this.PcmSize = m_total_samples * ChannelCount * BitsPerSample / 8;
                m_decoded_stream.Position = 0;
            }
        }
Ejemplo n.º 4
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     byte[] header = new byte[0x40];
     if (header.Length != stream.Read (header, 0, header.Length))
         return null;
     if (0x03000100 != LittleEndian.ToUInt32 (header, 8))
         return null;
     if (!Binary.AsciiEqual (header, 0x10, "Entis Rasterized Image")
         && !Binary.AsciiEqual (header, 0x10, "Moving Entis Image"))
         return null;
     using (var reader = new EriFile (stream))
     {
         var section = reader.ReadSection();
         if (section.Id != "Header  " || section.Length <= 0)
             return null;
         int header_size = (int)section.Length;
         int stream_pos = 0x50 + header_size;
         EriFileHeader file_header = null;
         EriMetaData info = null;
         string desc = null;
         while (header_size > 0x10)
         {
             section = reader.ReadSection();
             header_size -= 0x10;
             if (section.Length <= 0 || section.Length > header_size)
                 break;
             if ("FileHdr " == section.Id)
             {
                 file_header = new EriFileHeader { Version = reader.ReadInt32() };
                 if (file_header.Version > 0x00020100)
                     throw new InvalidFormatException ("Invalid ERI file version");
                 file_header.ContainedFlag    = reader.ReadInt32();
                 file_header.KeyFrameCount    = reader.ReadInt32();
                 file_header.FrameCount       = reader.ReadInt32();
                 file_header.AllFrameTime     = reader.ReadInt32();
             }
             else if ("ImageInf" == section.Id)
             {
                 int version = reader.ReadInt32();
                 if (version != 0x00020100 && version != 0x00020200)
                     return null;
                 info = new EriMetaData { StreamPos = stream_pos, Version = version };
                 info.Transformation = (CvType)reader.ReadInt32();
                 info.Architecture = (EriCode)reader.ReadInt32();
                 info.FormatType = (EriType)reader.ReadInt32();
                 int w = reader.ReadInt32();
                 int h = reader.ReadInt32();
                 info.Width  = (uint)Math.Abs (w);
                 info.Height = (uint)Math.Abs (h);
                 info.VerticalFlip = h < 0;
                 info.BPP = reader.ReadInt32();
                 info.ClippedPixel = reader.ReadInt32();
                 info.SamplingFlags = (EriSampling)reader.ReadInt32();
                 info.QuantumizedBits = reader.ReadUInt64();
                 info.AllottedBits = reader.ReadUInt64();
                 info.BlockingDegree = reader.ReadInt32();
                 info.LappedBlock = reader.ReadInt32();
                 info.FrameTransform = reader.ReadInt32();
                 info.FrameDegree = reader.ReadInt32();
             }
             else if ("descript" == section.Id)
             {
                 if (0xFEFF == reader.PeekChar())
                 {
                     reader.Read();
                     var desc_chars = reader.ReadChars ((int)section.Length/2 - 1);
                     desc = new string (desc_chars);
                 }
                 else
                 {
                     var desc_chars = reader.ReadBytes ((int)section.Length);
                     desc = Encoding.UTF8.GetString (desc_chars);
                 }
             }
             else
             {
                 reader.BaseStream.Seek (section.Length, SeekOrigin.Current);
             }
             header_size -= (int)section.Length;
         }
         if (info != null)
         {
             if (file_header != null)
                 info.Header = file_header;
             if (desc != null)
                 info.Description = desc;
         }
         return info;
     }
 }