Пример #1
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = (NgpMetaData)info;
            using (var input = new StreamRegion (stream, 0x104, meta.PackedSize, true))
            using (var z = new ZLibStream (input, CompressionMode.Decompress))
            {
                var pixels = new byte[meta.UnpackedSize];
                if (pixels.Length != z.Read (pixels, 0, pixels.Length))
                    throw new EndOfStreamException();
                PixelFormat format;
                if (32 == meta.BPP)
                    format = PixelFormats.Bgra32;
                else if (24 == meta.BPP)
                    format = PixelFormats.Bgr24;
                else if (8 == meta.BPP)
                    format = PixelFormats.Gray8;
                else
                    throw new System.NotSupportedException ("Not supported NGP image color depth");

                return ImageData.Create (info, format, null, pixels);
            }
        }
Пример #2
0
 void UnpackZlib()
 {
     m_input.Position = 0x38;
     using (var z = new ZLibStream (m_input, CompressionMode.Decompress, true))
         if (m_info.UnpackedSize1 != z.Read (m_output, 0, m_info.UnpackedSize1))
             throw new EndOfStreamException();
     m_input.Position = 0x38 + m_info.CompressedSize1;
     using (var z = new ZLibStream (m_input, CompressionMode.Decompress, true))
         if (m_info.UnpackedSize2 != z.Read (m_output, m_info.UnpackedSize1, m_info.UnpackedSize2))
             throw new EndOfStreamException();
 }
Пример #3
0
 uint ReadSysenvSeed(ArcView file, IEnumerable<Entry> dir, uint key)
 {
     var entry = dir.FirstOrDefault (e => e.Name.Equals ("sysenv.tbl", StringComparison.InvariantCultureIgnoreCase));
     if (null == entry)
         return key;
     var data = file.View.ReadBytes (entry.Offset, entry.Size);
     if (data.Length <= 4)
         throw new InvalidFormatException ("Invalid sysenv.tbl size");
     Decrypt (data, entry.Offset, key);
     uint adler32 = LittleEndian.ToUInt32 (data, 0);
     if (adler32 != Adler32.Compute (data, 4, data.Length-4))
         throw new InvalidEncryptionScheme();
     using (var input = new MemoryStream (data, 4, data.Length-4))
     using (var sysenv_stream = new ZLibStream (input, CompressionMode.Decompress))
     {
         var seed = new byte[0x10];
         if (0x10 != sysenv_stream.Read (seed, 0, 0x10))
             throw new InvalidFormatException ("Invalid sysenv.tbl size");
         return EncryptionScheme.GenerateContentKey (seed);
     }
 }
Пример #4
0
 public override Stream OpenEntry(ArcFile arc, Entry entry)
 {
     var hzc = (HzcArchive)arc;
     using (var input = arc.File.CreateStream (0xC+hzc.ImageInfo.HeaderSize))
     using (var z = new ZLibStream (input, CompressionMode.Decompress))
     {
         uint frame_size = entry.Size - 0x12;
         var pixels = new byte[frame_size];
         uint offset = 0;
         for (;;)
         {
             if (pixels.Length != z.Read (pixels, 0, pixels.Length))
                 break;
             if (offset >= entry.Offset)
                 break;
             offset += frame_size;
         }
         if (4 == hzc.ImageInfo.Type)
         {
             for (int i = 0; i < pixels.Length; ++i)
                 if (1 == pixels[i])
                     pixels[i] = 0xFF;
         }
         return TgaStream.Create (hzc.ImageInfo, pixels);
     }
 }
Пример #5
0
 public Reader(Stream stream, QntMetaData info)
 {
     m_width = (int)info.Width;
     m_height = (int)info.Height;
     int w = (m_width + 1) & ~1;
     int h = (m_height + 1) & ~1;
     int rgb_size = h * w * 3;
     m_bpp = info.AlphaSize != 0 ? 4 : 3;
     m_input = new byte[rgb_size];
     var alpha_pos = stream.Position + info.RGBSize;
     using (var zstream = new ZLibStream (stream, CompressionMode.Decompress, true))
         if (rgb_size != zstream.Read (m_input, 0, rgb_size))
             throw new InvalidFormatException ("Unexpected end of file");
     if (info.AlphaSize != 0)
     {
         int alpha_size = w * m_height;
         m_alpha = new byte[alpha_size];
         stream.Position = alpha_pos;
         using (var zstream = new ZLibStream (stream, CompressionMode.Decompress, true))
             if (alpha_size != zstream.Read (m_alpha, 0, alpha_size))
                 throw new InvalidFormatException ("Unexpected end of file");
     }
     m_output = new byte[info.Width*info.Height*m_bpp];
 }
Пример #6
0
 void UnpackV0()
 {
     byte[] channel = new byte[m_width*m_height];
     long start_pos = m_input.Position;
     for (int i = 0; i < 4; ++i)
     {
         if (0 == m_channel[StreamMap[i]])
             continue;
         m_input.Position = start_pos + 4; // skip crc32
         using (var input = new ZLibStream (m_input, CompressionMode.Decompress, true))
         {
             int channel_size = input.Read (channel, 0, channel.Length);
             int dst = ChannelMap[i];
             for (int j = 0; j < channel_size; ++j)
             {
                 m_output[dst] = channel[j];
                 dst += 4;
             }
         }
         start_pos += m_channel[StreamMap[i]];
     }
 }