Exemplo n.º 1
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 3;
            byte id        = file.ReadUInt8();
            uint data_size = file.ReadUInt32();
            uint width     = file.ReadUInt32();
            uint height    = file.ReadUInt32();
            uint stride    = file.ReadUInt32();

            if (stride < width)
            {
                throw new NotSupportedException();
            }
            if (stride * height != data_size)
            {
                return(null);
            }
            return(new MfgMetaData
            {
                Width = width,
                Height = height,
                BPP = (int)(stride * 8 / width),
                Type = id,
                Stride = (int)stride,
            });
        }
Exemplo n.º 2
0
        public override SoundInput TryOpen(IBinaryStream file)
        {
            var header = file.ReadHeader(0x24);

            if (!header.AsciiEqual(0, "RIFF") || !header.AsciiEqual(8, "PCMWFMT "))
            {
                return(null);
            }
            uint data_pos = header.ToUInt32(0x10) + 0x14;

            file.Position = data_pos;
            if (file.ReadUInt32() != 0x61746164) // 'data'
            {
                return(null);
            }
            uint data_size = file.ReadUInt32();
            var  format    = new WaveFormat {
                FormatTag             = header.ToUInt16(0x14),
                Channels              = header.ToUInt16(0x16),
                SamplesPerSecond      = header.ToUInt32(0x18),
                AverageBytesPerSecond = header.ToUInt32(0x1C),
                BlockAlign            = header.ToUInt16(0x20),
                BitsPerSample         = header.ToUInt16(0x22),
            };
            var pcm = new StreamRegion(file.AsStream, data_pos + 8, data_size);

            return(new RawPcmInput(pcm, format));
        }
Exemplo n.º 3
0
        List <Entry> ReadIndexV1(IBinaryStream file)
        {
            var max_offset = file.Length;

            file.Position = 8;
            var key_gen = new KeyGenerator(0xDEADCAFE);
            var dir     = new List <Entry>();

            while (file.PeekByte() != -1)
            {
                uint name_length = file.ReadUInt32() ^ key_gen.GetNext();
                var  name_bytes  = file.ReadBytes((int)name_length);
                var  name        = DecryptName(name_bytes, key_gen);
                var  entry       = FormatCatalog.Instance.Create <RgssEntry> (name);
                entry.Size   = file.ReadUInt32() ^ key_gen.GetNext();
                entry.Offset = file.Position;
                entry.Key    = key_gen.Current;
                if (!entry.CheckPlacement(max_offset))
                {
                    return(null);
                }
                dir.Add(entry);
                file.Seek(entry.Size, SeekOrigin.Current);
            }
            return(dir);
        }
Exemplo n.º 4
0
        List <Entry> ReadIndexV3(IBinaryStream file)
        {
            var max_offset = file.Length;

            file.Position = 8;
            uint key = file.ReadUInt32() * 9 + 3;
            var  dir = new List <Entry>();

            while (file.PeekByte() != -1)
            {
                uint offset = file.ReadUInt32() ^ key;
                if (0 == offset)
                {
                    break;
                }
                uint size        = file.ReadUInt32() ^ key;
                uint entry_key   = file.ReadUInt32() ^ key;
                uint name_length = file.ReadUInt32() ^ key;
                var  name_bytes  = file.ReadBytes((int)name_length);
                var  name        = DecryptName(name_bytes, key);
                var  entry       = FormatCatalog.Instance.Create <RgssEntry> (name);
                entry.Offset = offset;
                entry.Size   = size;
                entry.Key    = entry_key;
                if (!entry.CheckPlacement(max_offset))
                {
                    return(null);
                }
                dir.Add(entry);
            }
            return(dir);
        }
Exemplo n.º 5
0
        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);
                    }
                }
        }
Exemplo n.º 6
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var  info           = new AkbMetaData();
            bool is_incremental = '+' == (file.ReadUInt32() >> 24);

            info.Width       = file.ReadUInt16();
            info.Height      = file.ReadUInt16();
            info.Flags       = file.ReadUInt32();
            info.BPP         = 0 == (info.Flags & 0x40000000) ? 32 : 24;
            info.Background  = file.ReadBytes(4);
            info.OffsetX     = file.ReadInt32();
            info.OffsetY     = file.ReadInt32();
            info.InnerWidth  = file.ReadInt32() - info.OffsetX;
            info.InnerHeight = file.ReadInt32() - info.OffsetY;
            if (info.InnerWidth > info.Width || info.InnerHeight > info.Height)
            {
                return(null);
            }
            if (is_incremental)
            {
                info.BaseFileName = file.ReadCString(0x20);
            }
            info.DataOffset = (uint)file.Position;
            return(info);
        }
Exemplo n.º 7
0
        public string LoadRioTypeCore(out uint signature)
        {
            signature = m_input.ReadUInt32();
            if (!CoreSignatures.Contains(signature))
            {
                throw new InvalidFormatException("[RIO] invalid signature");
            }
            int version = ReadUInt16();

            if (version >= 0x10 && version <= 0x3FFF)
            {
                Schema = version;
                if (version >= 0x11)
                {
                    m_field_4C &= 0xFFFF;
                    m_field_4C |= ReadUInt16() << 16;
                }
            }
            else
            {
                m_input.Seek(-2, SeekOrigin.Current);
            }
            if (EncryptedSignature == signature)
            {
                m_field_4C |= 0xC;
            }

            return(ReadClass());
        }
Exemplo n.º 8
0
        public void Parse(IBinaryStream index)
        {
            index.Position = 16;
            int segment_count = Binary.BigEndian(index.ReadInt32());

            m_segments = new List <BundleSegment> (segment_count);
            long packed_offset   = m_data_offset;
            long unpacked_offset = 0;

            for (int i = 0; i < segment_count; ++i)
            {
                var segment = new BundleSegment();
                segment.Offset         = packed_offset;
                segment.UnpackedOffset = unpacked_offset;
                segment.UnpackedSize   = Binary.BigEndian(index.ReadUInt32());
                segment.PackedSize     = Binary.BigEndian(index.ReadUInt32());
                segment.Compression    = Binary.BigEndian(index.ReadUInt16());
                m_segments.Add(segment);
                packed_offset   += segment.PackedSize;
                unpacked_offset += segment.UnpackedSize;
            }
            int count = Binary.BigEndian(index.ReadInt32());

            m_bundles = new List <BundleEntry> (count);
            for (int i = 0; i < count; ++i)
            {
                var entry = new BundleEntry();
                entry.Offset = Binary.BigEndian(index.ReadInt64());
                entry.Size   = (uint)Binary.BigEndian(index.ReadInt64());
                entry.Flags  = Binary.BigEndian(index.ReadUInt32());
                entry.Name   = index.ReadCString(Encoding.UTF8);
                m_bundles.Add(entry);
            }
        }
Exemplo n.º 9
0
        int PrepareBmpHeader(IBinaryStream input, byte[] output)
        {
            input.ReadInt32();
            uint h1     = ~input.ReadUInt32();
            uint h2     = ~input.ReadUInt32();
            uint h3     = ~input.ReadUInt32();
            uint width  = Binary.BigEndian((ushort)h1);
            uint height = Binary.BigEndian((ushort)(h1 >> 16));

            output[0] = (byte)'B';
            output[1] = (byte)'M';
            LittleEndian.Pack(output.Length, output, 2);
            output[10] = 54; // offset to the body
            output[14] = 40; // header size
            LittleEndian.Pack(width, output, 18);
            LittleEndian.Pack(height, output, 22);
            output[26] = 1;                            // planes
            output[28] = Binary.RotByteL((byte)h2, 4); // bpp
            LittleEndian.Pack(Binary.RotL(h3, 16), output, 34);
            LittleEndian.Pack(0xB12, output, 38);
            LittleEndian.Pack(0xB12, output, 42);
            LittleEndian.Pack((uint)Binary.RotByteL((byte)(h2 >> 16), 4), output, 46);
            LittleEndian.Pack((uint)Binary.RotByteL((byte)(h2 >> 24), 4), output, 50);
            return(54);
        }
Exemplo n.º 10
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            uint size = file.ReadUInt32();

            if (size != file.Length)
            {
                return(null);
            }
            uint width      = file.ReadUInt32();
            uint height     = file.ReadUInt32();
            int  compressed = file.ReadInt32();

            if (compressed > 1 || 0 == compressed && (width * height + 0x410) != size)
            {
                return(null);
            }
            return(new CmMetaData {
                Width = width,
                Height = height,
                BPP = 8,
                IsCompressed = 1 == compressed,
                DataOffset = 0x10,
                DataLength = size,
            });
        }
Exemplo n.º 11
0
        }                                                                 // 'dcf '

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Seek(4, SeekOrigin.Current);
            uint header_size = stream.ReadUInt32();
            long data_pos    = stream.Position + header_size;

            if (stream.ReadInt32() != 1)
            {
                return(null);
            }
            uint width       = stream.ReadUInt32();
            uint height      = stream.ReadUInt32();
            int  bpp         = stream.ReadInt32();
            int  name_length = stream.ReadInt32();

            if (name_length <= 0)
            {
                return(null);
            }
            int shift     = (name_length % 7) + 1;
            var name_bits = stream.ReadBytes(name_length);

            for (int i = 0; i < name_length; ++i)
            {
                name_bits[i] = Binary.RotByteL(name_bits[i], shift);
            }
            return(new DcfMetaData
            {
                Width = width,
                Height = height,
                BPP = bpp,
                BaseName = Encodings.cp932.GetString(name_bits),
                DataOffset = data_pos,
            });
        }
Exemplo n.º 12
0
        }                                                                 // 'TYP1'

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Position = 4;
            int  bpp         = stream.ReadByte();
            bool has_palette = stream.ReadByte() != 0;
            var  info        = new Typ1MetaData {
                BPP = bpp
            };

            info.Width  = stream.ReadUInt16();
            info.Height = stream.ReadUInt16();
            uint packed_size  = stream.ReadUInt32();
            uint palette_size = 8 == bpp ? 0x400u : 0u;

            if (packed_size + palette_size + 0xE == stream.Length)
            {
                info.SeparateChannels = false;
                info.HasPalette       = palette_size > 0;
                info.PackedSize       = packed_size;
            }
            else
            {
                info.SeparateChannels = true;
                info.HasPalette       = has_palette;
                info.Channel[0]       = stream.ReadUInt32();
                info.Channel[1]       = stream.ReadUInt32();
                info.Channel[2]       = stream.ReadUInt32();
                info.Channel[3]       = stream.ReadUInt32();
            }
            return(info);
        }
Exemplo n.º 13
0
        public override ImageMetaData ReadMetaData(IBinaryStream input)
        {
            input.Position = 4;
            uint width  = Binary.BigEndian(input.ReadUInt32());
            uint height = Binary.BigEndian(input.ReadUInt32());

            if (0 == width || 0 == height)
            {
                return(null);
            }
            int bpp        = input.ReadByte();
            int color_type = input.ReadByte();

            switch (color_type)
            {
            case 2: bpp *= 3; break;

            case 4: bpp *= 2; break;

            case 6: bpp *= 4; break;

            case 3:
            case 0: break;

            default: return(null);
            }
            return(new ImageMetaData
            {
                Width = width,
                Height = height,
                BPP = bpp,
            });
        }
Exemplo n.º 14
0
        internal ApsMetaData ReadCompressionMetaData(IBinaryStream reader, Rectangle rect)
        {
            int compression = reader.ReadInt16();
            var info        = new ApsMetaData
            {
                Width    = (uint)rect.Width,
                Height   = (uint)rect.Height,
                BPP      = 32,
                IsPacked = 0 != compression,
            };

            if (0 == compression)
            {
                info.UnpackedSize = reader.ReadUInt32();
            }
            else if (1 == compression)
            {
                info.PackedSize   = reader.ReadUInt32();
                info.UnpackedSize = reader.ReadUInt32();
            }
            else
            {
                return(null);
            }
            info.DataOffset = (uint)reader.Position;
            return(info);
        }
Exemplo n.º 15
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            var info = new EpaMetaData();

            info.Mode      = file.ReadInt32() >> 24;
            info.ColorType = file.ReadInt32() & 0xff;
            switch (info.ColorType)
            {
            case 0: info.BPP = 8; break;

            case 1: info.BPP = 24; break;

            case 2: info.BPP = 32; break;

            case 3: info.BPP = 15; break;

            case 4: info.BPP = 8; break;

            default: return(null);
            }
            info.Width  = file.ReadUInt32();
            info.Height = file.ReadUInt32();
            if (2 == info.Mode)
            {
                info.OffsetX = file.ReadInt32();
                info.OffsetY = file.ReadInt32();
            }
            return(info);
        }
Exemplo n.º 16
0
        }                                                                 // 'hiz'

        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 4;
            int n = file.ReadInt32();

            if (100 != n)
            {
                return(null);
            }
            uint right    = file.ReadUInt32() ^ 0xAA5A5A5A;
            uint bottom   = file.ReadUInt32() ^ 0xAC9326AF;
            int  unknown1 = file.ReadInt32(); // @0x10

            if (unknown1 == 0x375A8436)
            {
                return(null);
            }
            uint unpacked_size = file.ReadUInt32() ^ 0x19739D6A; // @0x14

            if (unpacked_size != right * bottom * 4)
            {
                return(null);
            }
            return(new HizMetaData
            {
                Width = right,
                Height = bottom,
                BPP = 32,
                IsPacked = true,
                DataOffset = 0x4c,
                UnpackedSize = unpacked_size,
            });
        }
Exemplo n.º 17
0
        public string LoadRioTypeCore(out uint signature)
        {
            signature = m_input.ReadUInt32();
            if (!CoreSignatures.Contains(signature))
            {
                throw new InvalidFormatException("[RIO] invalid signature");
            }
            int version = ReadUInt16();

            if (version < 0x10 || version > 0x3FFF)
            {
                throw new InvalidFormatException("[RIO] invalid version");
            }
            if (version >= 0x11)
            {
                m_field_4C &= 0xFFFF;
                m_field_4C |= ReadUInt16() << 16;
            }
            if (EncryptedSignature == signature)
            {
                m_field_4C |= 0xC;
            }

            return(ReadClass());
        }
Exemplo n.º 18
0
 public List <Entry> Read(IBinaryStream input, int count)
 {
     m_dir.Clear();
     if (m_dir.Capacity < count)
     {
         m_dir.Capacity = count;
     }
     try
     {
         for (int i = 0; i < count; ++i)
         {
             uint offset = input.ReadUInt32();
             uint size   = input.ReadUInt32();
             var  name   = input.ReadCString(0x18);
             var  entry  = FormatCatalog.Instance.Create <Entry> (name);
             entry.Offset = offset;
             entry.Size   = size;
             if (!entry.CheckPlacement(m_arc_length))
             {
                 return(null);
             }
             m_dir.Add(entry);
         }
         return(m_dir);
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 19
0
        public override List <Entry> GetFramesList(IBinaryStream file)
        {
            file.Position = 4;
            int count = file.ReadInt16();

            if (!IsSaneCount(count))
            {
                return(null);
            }
            file.Position = 0x16;
            var current_offset = file.Position;
            var dir            = new List <Entry> (count);

            for (int i = 0; i < count; ++i)
            {
                file.Position = current_offset + 8;
                uint width      = file.ReadUInt32();
                uint height     = file.ReadUInt32();
                uint depth      = file.ReadUInt32();
                uint image_size = depth * width * height;
                var  entry      = new AnmEntry
                {
                    Offset          = current_offset,
                    Size            = 0x14 + image_size,
                    ImageDataOffset = current_offset + 0x14,
                    ImageDataSize   = image_size,
                };
                dir.Add(entry);
                current_offset += entry.Size;
            }
            return(dir);
        }
Exemplo n.º 20
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 4;
            int  frames = file.ReadUInt16();
            int  bpp    = file.ReadUInt16();
            uint width  = file.ReadUInt32();
            uint height = file.ReadUInt32();
            int  x      = file.ReadInt32();
            int  y      = file.ReadInt32();

            file.ReadInt32(); // 0
            uint frame_size = file.ReadUInt32();

            if (24 != bpp && 8 != bpp)
            {
                Trace.WriteLine("unsupported bpp", "WipFormat");
                return(null);
            }
            return(new WipMetaData
            {
                Width = width,
                Height = height,
                OffsetX = x,
                OffsetY = y,
                BPP = bpp,
                FrameCount = frames,
                FrameSize = frame_size,
            });
        }
Exemplo n.º 21
0
        public WadyInput(IBinaryStream input) : base(new MemoryStream())
        {
            input.Seek(5, SeekOrigin.Begin);
            MulValue = input.ReadUInt8();
            input.Seek(6, SeekOrigin.Current);
            int src_size = input.ReadInt32();

            input.Seek(16, SeekOrigin.Current);
            var format = new WaveFormat();

            format.FormatTag             = input.ReadUInt16();
            format.Channels              = input.ReadUInt16();
            format.SamplesPerSecond      = input.ReadUInt32();
            format.AverageBytesPerSecond = input.ReadUInt32();
            format.BlockAlign            = input.ReadUInt16();
            format.BitsPerSample         = input.ReadUInt16();
            format.ExtraSize             = 0;
            this.Format = format;
            int remaining = (int)(input.Length - input.Position);

            if (remaining == src_size)
            {
                (Source as MemoryStream).Capacity = src_size * 2;
                Decode(input, src_size, Source);
            }
            else
            {
                Decode2(input, Source);
            }
            Source.Position = 0;
            this.PcmSize    = Source.Length;
            input.Dispose();
        }
Exemplo n.º 22
0
        }                                                               // 'CHD'

        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 4;
            int count = file.ReadInt32();

            if (count < 0 || count > 0xFFFFF)
            {
                return(null);
            }
            file.ReadInt32();
            uint first_offset = 0;

            for (int i = 0; i < count && 0 == first_offset; ++i)
            {
                first_offset = file.ReadUInt32();
            }
            if (0 == first_offset)
            {
                return(null);
            }
            file.Position = first_offset;
            var info = new ChdMetaData();

            info.Width       = file.ReadUInt32();
            info.Height      = file.ReadUInt32();
            info.OffsetX     = file.ReadInt32();
            info.OffsetY     = file.ReadInt32();
            info.FirstOffset = first_offset + 0x10;
            info.BPP         = 32;
            return(info);
        }
Exemplo n.º 23
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            int type = file.ReadInt32();

            if (type < 0 || type > 3)
            {
                return(null);
            }
            if (-1 != file.ReadInt32())
            {
                return(null);
            }
            int  x           = file.ReadInt32();
            int  y           = file.ReadInt32();
            uint width       = file.ReadUInt32();
            uint height      = file.ReadUInt32();
            int  comp_size   = file.ReadInt32();
            int  uncomp_size = file.ReadInt32();

            if (uncomp_size != width * height * 3u)
            {
                return(null);
            }
            return(new Pt1MetaData {
                Width = width,
                Height = height,
                OffsetX = x,
                OffsetY = y,
                BPP = 3 == type ? 32 : 24,
                Type = type,
                PackedSize = comp_size,
                UnpackedSize = uncomp_size
            });
        }
Exemplo n.º 24
0
        }                                                                 // 'HG-2'

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Position = 8;
            var info = new Hg2MetaData();
            int type = stream.ReadInt32();

            if (0x25 == type)
            {
                info.HeaderSize = 0x58;
            }
            else if (0x20 == type)
            {
                info.HeaderSize = 0x50;
            }
            else
            {
                return(null);
            }
            info.Width  = stream.ReadUInt32();
            info.Height = stream.ReadUInt32();
            info.BPP    = stream.ReadInt32();
            stream.Seek(8, SeekOrigin.Current);
            info.DataPacked   = stream.ReadInt32();
            info.DataUnpacked = stream.ReadInt32();
            info.CtlPacked    = stream.ReadInt32();
            info.CtlUnpacked  = stream.ReadInt32();
            stream.Seek(8, SeekOrigin.Current);
            info.CanvasWidth  = stream.ReadUInt32();
            info.CanvasHeight = stream.ReadUInt32();
            info.OffsetX      = stream.ReadInt32();
            info.OffsetY      = stream.ReadInt32();
            return(info);
        }
Exemplo n.º 25
0
        List <Entry> ReadIndex(IBinaryStream index, long max_offset, int align)
        {
            var index_length = index.Length;
            int index_pos    = 0;
            var dir          = new List <Entry>();

            while (index_pos < index_length)
            {
                index.Position = index_pos;
                uint offset = index.ReadUInt32();
                if (0 == offset)
                {
                    break;
                }
                uint size        = index.ReadUInt32();
                byte name_length = index.ReadUInt8();
                var  name        = index.ReadCString(name_length);
                index_pos += ((align + 1 + name_length) & -align) + 8;
//                index_pos += ((9 + name_length) & ~7) + 8;
//                index_pos += ((5 + name_length) & ~3) + 8;

                var entry = FormatCatalog.Instance.Create <Entry> (name);
                entry.Offset = offset;
                entry.Size   = size;
                if (!entry.CheckPlacement(max_offset))
                {
                    return(null);
                }
                dir.Add(entry);
            }
            return(dir);
        }
Exemplo n.º 26
0
        public void Unpack()
        {
            m_input.Position = m_info.DataOffset;
            uint name_length = m_input.ReadUInt32();

            m_input.Seek(name_length, SeekOrigin.Current);
            uint mask = m_input.ReadUInt32();

            m_input.Seek(9, SeekOrigin.Current);
            int layer_count = m_input.ReadInt32();

            if (layer_count < 1)
            {
                throw new InvalidFormatException();
            }

            // XXX only first frame is interpreted.

            var frame = new Frame(layer_count);

            frame.Width  = m_input.ReadInt32();
            frame.Height = m_input.ReadInt32();
            frame.BPP    = m_input.ReadInt32();
            if (frame.BPP <= 0)
            {
                throw new InvalidFormatException();
            }
            if (frame.BPP <= 8)
            {
                frame.Palette = ImageFormat.ReadColorMap(m_input.AsStream, 1 << frame.BPP);
            }
            frame.SetStride();
            m_frames.Add(frame);
            for (int i = 0; i < layer_count; ++i)
            {
                m_input.ReadInt32();    // left
                m_input.ReadInt32();    // top
                m_input.ReadByte();     // visibility
                m_input.ReadInt32();    // (-1) TransColor
                m_input.ReadInt32();    // (0xFF) alpha
                m_input.ReadByte();     // AlphaOn
                name_length = m_input.ReadUInt32();
                m_input.Seek(name_length, SeekOrigin.Current);
                if (m_info.Version >= 107)
                {
                    m_input.ReadByte(); // lock
                }
                var layer      = new Layer();
                int layer_size = m_input.ReadInt32();
                layer.Pixels = UnpackLayer(frame, layer_size);
                int alpha_size = m_input.ReadInt32();
                if (alpha_size != 0)
                {
                    layer.Alpha = UnpackLayer(frame, alpha_size, true);
                }
                frame.Layers.Add(layer);
            }
            Flatten(0);
        }
Exemplo n.º 27
0
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Position = 4;
            int id = stream.ReadByte();

            if (0x54 != id)
            {
                return(null);
            }
            int encryption = stream.ReadByte();

            if (encryption != 0x43 && encryption != 0x53)
            {
                return(null);
            }
            bool is_encrypted = 0x53 == encryption;
            int  version      = stream.ReadByte();

            if (0x30 != version)
            {
                return(null);
            }
            version = stream.ReadByte() - 0x30;
            if (version != 0 && version != 1)
            {
                return(null);
            }

            uint width           = stream.ReadUInt32();
            uint height          = stream.ReadUInt32();
            int  data_size       = stream.ReadInt32();
            int  additional_size = 0;

            if (1 == version)
            {
                additional_size = stream.ReadUInt16();
            }
            if (width > 0x8000 || height > 0x8000)
            {
                return(null);
            }

            return(new RctMetaData
            {
                Width = width,
                Height = height,
                OffsetX = 0,
                OffsetY = 0,
                BPP = 24,
                Version = version,
                IsEncrypted = is_encrypted,
                DataOffset = (uint)stream.Position,
                DataSize = data_size,
                BaseNameLength = additional_size,
            });
        }
Exemplo n.º 28
0
 public override ImageMetaData ReadMetaData(IBinaryStream file)
 {
     file.Position = 4;
     return(new ImageMetaData
     {
         Width = file.ReadUInt32(),
         Height = file.ReadUInt32(),
         BPP = 32,
     });
 }
Exemplo n.º 29
0
        public DscDecoder(IBinaryStream input) : base(input.AsStream)
        {
            m_magic        = (uint)input.ReadUInt16() << 16;
            input.Position = 0x10;
            m_key          = input.ReadUInt32();
            int output_size = input.ReadInt32();

            m_dec_count = input.ReadUInt32();
            m_output    = new byte[output_size];
        }
Exemplo n.º 30
0
        public byte[] Decode(IBinaryStream input)
        {
            m_dst = 0;
            if (1 == Channels)
            {
                var adp = new AdpDecoder();
                while (input.PeekByte() != -1)
                {
                    short sample = input.ReadInt16();
                    PutSample(sample);
                    int quant_idx = input.ReadUInt16() & 0xFF;
                    adp.Reset(sample, quant_idx);

                    for (int j = 0; j < BytesPerChunk - 4; ++j)
                    {
                        byte octet = input.ReadUInt8();
                        PutSample(adp.DecodeSample(octet));
                        PutSample(adp.DecodeSample(octet >> 4));
                    }
                }
            }
            else
            {
                var first             = new AdpDecoder();
                var second            = new AdpDecoder();
                int samples_per_chunk = (BytesPerChunk - 8) / 8;
                while (input.PeekByte() != -1)
                {
                    short sample = input.ReadInt16();
                    PutSample(sample);
                    int quant_idx = input.ReadUInt16() & 0xFF;
                    first.Reset(sample, quant_idx);

                    sample = input.ReadInt16();
                    PutSample(sample);
                    quant_idx = input.ReadUInt16() & 0xFF;
                    second.Reset(sample, quant_idx);

                    for (int j = 0; j < samples_per_chunk; ++j)
                    {
                        uint first_code  = input.ReadUInt32();
                        uint second_code = input.ReadUInt32();
                        for (int i = 0; i < 8; ++i)
                        {
                            PutSample(first.DecodeSample((byte)first_code));
                            PutSample(second.DecodeSample((byte)second_code));
                            first_code  >>= 4;
                            second_code >>= 4;
                        }
                    }
                }
            }
            return(m_output);
        }