예제 #1
0
 void ReadBaseImage()
 {
     try
     {
         string dir_name  = VFS.GetDirectoryName(m_info.FileName);
         string base_name = Path.ChangeExtension(m_info.BaseName, "qnt");
         base_name = VFS.CombinePath(dir_name, base_name);
         using (var base_file = VFS.OpenBinaryStream(base_name))
         {
             var base_info = Qnt.ReadMetaData(base_file) as QntMetaData;
             if (null != base_info && m_info.Width == base_info.Width && m_info.Height == base_info.Height)
             {
                 base_info.FileName = base_name;
                 var reader = new QntFormat.Reader(base_file.AsStream, base_info);
                 reader.Unpack();
                 m_base_bpp = reader.BPP;
                 m_base     = reader.Data;
             }
         }
     }
     catch (Exception X)
     {
         Trace.WriteLine(X.Message, "[DCF]");
     }
 }
예제 #2
0
파일: ImageDCF.cs 프로젝트: zxc120/GARbro
        public void Unpack()
        {
            long next_pos = m_info.DataOffset;

            for (;;)
            {
                m_input.Position = next_pos;
                uint id = m_input.ReadUInt32();
                next_pos += 8 + m_input.ReadUInt32();
                if (0x6C646664 == id) // 'dfdl'
                {
                    int unpacked_size = m_input.ReadInt32();
                    if (unpacked_size <= 0)
                    {
                        continue;
                    }
                    m_mask = new byte[unpacked_size];
                    using (var input = new ZLibStream(m_input.AsStream, CompressionMode.Decompress, true))
                        input.Read(m_mask, 0, unpacked_size);
                }
                else if (0x64676364 == id) // 'dcgd'
                {
                    break;
                }
            }
            long qnt_pos = m_input.Position;

            if (m_input.ReadUInt32() != Qnt.Signature)
            {
                throw new InvalidFormatException();
            }
            using (var reg = new StreamRegion(m_input.AsStream, qnt_pos, true))
                using (var qnt = new BinaryStream(reg, m_input.Name))
                {
                    var qnt_info = Qnt.ReadMetaData(qnt) as QntMetaData;
                    if (null == qnt_info)
                    {
                        throw new InvalidFormatException();
                    }

                    var overlay = new QntFormat.Reader(reg, qnt_info);
                    overlay.Unpack();
                    m_overlay_bpp = overlay.BPP;
                    if (m_mask != null)
                    {
                        ReadBaseImage();
                    }

                    if (m_base != null)
                    {
                        m_output = ApplyOverlay(overlay.Data);
                        SetFormat((int)m_info.Width, m_overlay_bpp);
                    }
                    else
                    {
                        m_output = overlay.Data;
                        SetFormat((int)qnt_info.Width, m_overlay_bpp);
                    }
                }
        }