Exemple #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;
        }
Exemple #2
0
        public Stream Decode()
        {
            m_input.Position = 0x40;
            using (var erif = new EriFile(m_input))
            {
                ReadHeader(erif);
                int total_bytes = m_info.AllSampleCount * BitsPerSample / 8;
                var output      = new MemoryStream(total_bytes);
                try
                {
                    var buffer  = new byte[0x10000];
                    var decoded = new byte[0x10000];
                    erif.BaseStream.Position = m_stream_pos;
                    while (total_bytes > 0)
                    {
                        var section = erif.ReadSection();
                        if (section.Id != "SoundStm")
                        {
                            break;
                        }
                        int stm_length = (int)section.Length;
                        if (stm_length > buffer.Length)
                        {
                            buffer = new byte[stm_length];
                        }
                        erif.Read(m_buffer, 0, stm_length);
                        int length = m_buffer.ToInt32(4) * m_lappedSubband;
                        if (length > decoded.Length)
                        {
                            decoded = new byte[length];
                        }

                        DecodeBlock(buffer, decoded);
                        length = Math.Min(length, total_bytes);
                        output.Write(decoded, 0, length);
                        total_bytes -= length;
                    }
                }
                catch (EndOfStreamException) { /* ignore EOF errors */ }
                output.Position = 0;
                return(output);
            }
        }
Exemple #3
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);
            }
        }
Exemple #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;
     }
 }