Exemplo n.º 1
0
        }                                                                 // 'AN10'

        public override List <Entry> GetFramesList(IBinaryStream file)
        {
            file.Position = 0x14;
            int frame_count = file.ReadInt16();

            file.Position = 0x18 + frame_count * 4;
            int count = file.ReadInt16();

            if (!IsSaneCount(count))
            {
                return(null);
            }
            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 channels   = file.ReadUInt32();
                uint image_size = channels * 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.º 2
0
        }                                                               // 'YGP'

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Position = 4;
            int  mask_pos = stream.ReadUInt16();        // 04
            byte type     = stream.ReadUInt8();         // 06

            if (type != 1 && type != 2)
            {
                return(null);
            }
            var info = new YgpMetaData {
                Type = type, BPP = 32
            };

            info.Flags = stream.ReadUInt8();            // 07
            int header_size = stream.ReadInt32();       // 08

            stream.Position = header_size;
            info.DataSize   = stream.ReadInt32();       // XX+00
            info.Width      = stream.ReadUInt16();      // XX+04
            info.Height     = stream.ReadUInt16();      // XX+06
            info.DataOffset = header_size + 8;
            if (0 != (info.Flags & 4))
            {
                stream.Position = 0x14;
                info.OffsetX    = stream.ReadInt16();
                info.OffsetY    = stream.ReadInt16();
            }
            return(info);
        }
Exemplo n.º 3
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            int c1 = file.ReadByte();
            int c2 = file.ReadByte();

            if ('B' != c1 || 'M' != c2)
            {
                return(null);
            }
            uint size = file.ReadUInt32();

            file.ReadUInt32();
            uint image_offset = file.ReadUInt32();
            uint header_size  = file.ReadUInt32();

            if (size < 14 + header_size)
            {
                // some otherwise valid bitmaps have size field set to zero
                if (size != 0 && size != 0xE || !file.AsStream.CanSeek)
                {
                    return(null);
                }
                size = (uint)file.Length;
            }
            else if (file.AsStream.CanSeek)
            {
                if (size > file.Length)
                {
                    size = (uint)file.Length;
                }
            }
            uint width, height;

            if (0xC == header_size)
            {
                width  = file.ReadUInt16();
                height = file.ReadUInt16();
            }
            else if (header_size < 40 || size - 14 < header_size)
            {
                return(null);
            }
            else
            {
                width  = file.ReadUInt32();
                height = file.ReadUInt32();
            }
            file.ReadInt16();
            int bpp = file.ReadInt16();

            return(new BmpMetaData {
                Width = width,
                Height = height,
                OffsetX = 0,
                OffsetY = 0,
                BPP = bpp,
                ImageLength = size,
                ImageOffset = image_offset,
            });
        }
Exemplo n.º 4
0
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            int width  = stream.ReadInt16();
            int height = stream.ReadInt16();

            if (width <= 0 || height <= 0)
            {
                return(null);
            }
            int bpp = stream.ReadInt32();

            if (24 != bpp && 32 != bpp && 8 != bpp)
            {
                return(null);
            }
            if (0 != stream.ReadInt64())
            {
                return(null);
            }
            return(new ImageMetaData
            {
                Width = (uint)width,
                Height = (uint)height,
                BPP = bpp,
            });
        }
Exemplo n.º 5
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            if (file.Length <= 0x408)
            {
                return(null);
            }
            int x = file.ReadInt16();
            int y = file.ReadInt16();

            if (x < 0 || y < 0 || x > 0x300 || y > 0x300)
            {
                return(null);
            }
            int w = file.ReadInt16();
            int h = file.ReadInt16();

            if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000)
            {
                return(null);
            }
            return(new ImageMetaData {
                Width = (uint)w,
                Height = (uint)h,
                BPP = 8,
            });
        }
Exemplo n.º 6
0
        public void Unpack()
        {
            m_input.Position = 0x1A;
            int  color_data_length = Binary.BigEndian(m_input.ReadInt32());
            long next_pos          = m_input.Position + color_data_length;

            if (0 != color_data_length)
            {
                if (8 == m_info.BPP)
                {
                    ReadPalette(color_data_length);
                }
                m_input.Position = next_pos;
            }
            next_pos        += 4 + Binary.BigEndian(m_input.ReadInt32());
            m_input.Position = next_pos; // skip Image Resources
            next_pos        += 4 + Binary.BigEndian(m_input.ReadInt32());
            m_input.Position = next_pos; // skip Layer and Mask Information

            int compression = Binary.BigEndian(m_input.ReadInt16());
            int remaining   = checked ((int)(m_input.Length - m_input.Position));

            byte[] pixels;
            if (0 == compression)
            {
                pixels = m_input.ReadBytes(remaining);
            }
            else if (1 == compression)
            {
                pixels = UnpackRLE();
            }
            else
            {
                throw new NotSupportedException("PSD files with ZIP compression not supported");
            }

            if (1 == m_info.Channels)
            {
                m_output = pixels;
                return;
            }
            int channels = Math.Min(4, m_info.Channels);

            m_output = new byte[channels * m_channel_size];
            int src = 0;

            for (int ch = 0; ch < channels; ++ch)
            {
                int dst = ChannelMap[ch];
                for (int i = 0; i < m_channel_size; ++i)
                {
                    m_output[dst] = pixels[src++];
                    dst          += channels;
                }
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 4;
            var meta = new ImageMetaData();

            meta.OffsetX = file.ReadInt16();
            meta.OffsetY = file.ReadInt16();
            meta.Width   = file.ReadUInt16();
            meta.Height  = file.ReadUInt16();
            meta.BPP     = 32;
            return(meta);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Setup reader endianness accordingly.
 /// </summary>
 public void SetupReaders(int format, bool is_little_endian)
 {
     m_format = format;
     if (is_little_endian)
     {
         ReadUInt16 = () => m_input.ReadUInt16();
         ReadUInt32 = () => m_input.ReadUInt32();
         ReadInt16  = () => m_input.ReadInt16();
         ReadInt32  = () => m_input.ReadInt32();
         ReadInt64  = () => m_input.ReadInt64();
     }
     else
     {
         ReadUInt16 = () => Binary.BigEndian(m_input.ReadUInt16());
         ReadUInt32 = () => Binary.BigEndian(m_input.ReadUInt32());
         ReadInt16  = () => Binary.BigEndian(m_input.ReadInt16());
         ReadInt32  = () => Binary.BigEndian(m_input.ReadInt32());
         ReadInt64  = () => Binary.BigEndian(m_input.ReadInt64());
     }
     if (m_format >= 14 || m_format == 9)
     {
         Align = () => {
             long pos = m_input.Position;
             if (0 != (pos & 3))
             {
                 m_input.Position = (pos + 3) & ~3L;
             }
         };
     }
     else
     {
         Align = () => {};
     }
     if (m_format >= 14)
     {
         ReadId = ReadInt64;
     }
     else
     {
         ReadId = () => ReadInt32();
     }
     if (m_format >= 22)
     {
         ReadOffset = ReadInt64;
     }
     else
     {
         ReadOffset = () => ReadUInt32();
     }
 }
Exemplo n.º 10
0
        internal static object ReadField(this IBinaryStream input, FieldInfo field)
        {
            var field_type = field.FieldType;
            var type_code  = Type.GetTypeCode(field_type);

            switch (type_code)
            {
            case TypeCode.SByte:    return(input.ReadInt8());

            case TypeCode.Byte:     return(input.ReadUInt8());

            case TypeCode.Int16:    return(input.ReadInt16());

            case TypeCode.UInt16:   return(input.ReadUInt16());

            case TypeCode.Int32:    return(input.ReadInt32());

            case TypeCode.UInt32:   return(input.ReadUInt32());

            case TypeCode.Int64:    return(input.ReadInt64());

            case TypeCode.UInt64:   return(input.ReadUInt64());

            case TypeCode.Char:     return((char)input.ReadInt16());

            case TypeCode.String:
                var cstring_attr = field.GetCustomAttribute <CStringAttribute>();
                if (cstring_attr != null)
                {
                    var encoding = cstring_attr.Encoding ?? Encodings.cp932;
                    if (cstring_attr.IsLengthDefined)
                    {
                        return(input.ReadCString(cstring_attr.Length, encoding));
                    }
                    else
                    {
                        return(input.ReadCString(encoding));
                    }
                }
                throw new FormatException("Serialization method for string field is not defined.");

            case TypeCode.Object:
                object val = Activator.CreateInstance(field_type);
                ReadStruct(input, field_type, ref val);  // FIXME check object graph for cycles
                return(val);

            default:
                throw new NotSupportedException("Not supported serialization type.");
            }
        }
Exemplo n.º 11
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            file.Position = 3;
            int bpp         = file.ReadByte();
            int x           = 0;
            int y           = 0;
            int type        = bpp;
            int header_size = 8;

            if (2 == type)
            {
                bpp         = file.ReadByte();
                header_size = 13;
            }
            else if (1 == type)
            {
                bpp         = file.ReadByte();
                x           = file.ReadInt16();
                y           = file.ReadInt16();
                header_size = 13;
            }
            else
            {
                type = 0;
            }
            if (8 != bpp && 24 != bpp && 32 != bpp)
            {
                return(null);
            }
            uint w = file.ReadUInt16();
            uint h = file.ReadUInt16();

            if (2 == type)
            {
                x = file.ReadInt16();
                y = file.ReadInt16();
            }
            return(new ElgMetaData
            {
                Width = w,
                Height = h,
                OffsetX = x,
                OffsetY = y,
                BPP = bpp,
                Type = type,
                HeaderSize = header_size,
            });
        }
Exemplo n.º 12
0
        bool UnpackAlpha(int length)
        {
            bool has_alpha = false;
            int  dst       = 3;

            while (length > 0)
            {
                int count = m_input.ReadInt16();
                length -= 2;
                if (count < 0)
                {
                    count = (count & 0x7FFF) + 1;
                    byte a = m_input.ReadUInt8();
                    has_alpha = has_alpha || a != 0;
                    length--;
                    for (int i = 0; i < count; ++i)
                    {
                        m_output[dst] = a;
                        dst          += 4;
                    }
                }
                else
                {
                    for (int i = 0; i < count; ++i)
                    {
                        byte a = m_input.ReadUInt8();
                        has_alpha     = has_alpha || a != 0;
                        m_output[dst] = a;
                        dst          += 4;
                    }
                    length -= count;
                }
            }
            return(has_alpha);
        }
Exemplo n.º 13
0
        }                                                                 // 'amp_'

        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            stream.Position = 4;
            int version = stream.ReadInt16();

            if (version != 1)
            {
                return(null);
            }
            int unpacked_size = stream.ReadInt32();
            int data_offset   = stream.ReadInt32();

            if (unpacked_size < 0x36 || data_offset < stream.Position)
            {
                return(null);
            }
            var header = new byte[0x20];

            stream.Position = data_offset;
            Unpack(stream.AsStream, header);
            Decrypt(header);
            if ('B' != header[0] || 'M' != header[1])
            {
                return(null);
            }
            return(new ZbmMetaData
            {
                Width = LittleEndian.ToUInt32(header, 0x12),
                Height = LittleEndian.ToUInt32(header, 0x16),
                BPP = LittleEndian.ToInt16(header, 0x1C),
                UnpackedSize = unpacked_size,
                DataOffset = data_offset,
            });
        }
Exemplo n.º 14
0
        public override ImageData Read(IBinaryStream file, ImageMetaData info)
        {
            var pixels = new short[info.Width * info.Height];

            file.Position = 0x20;
            int dst = 0;

            while (dst < pixels.Length && file.PeekByte() != -1)
            {
                short px = file.ReadInt16();
                if (px < 0)
                {
                    px &= 0x7FFF;
                    int count = file.ReadUInt8();
                    for (int i = 0; i < count; ++i)
                    {
                        pixels[dst++] = px;
                    }
                }
                else
                {
                    pixels[dst++] = px;
                }
            }
            return(ImageData.Create(info, PixelFormats.Bgr555, null, pixels));
        }
Exemplo n.º 15
0
        public override uint     Signature { get { return 0; } } // 'RIFF'

        public override ImageMetaData ReadMetaData (IBinaryStream file)
        {
            // 'RIFF' isn't included into signature to avoid auto-detection of the WAV files as IPH images.
            if (0x46464952 != file.Signature) // 'RIFF'
                return null;
            var header = file.ReadHeader (0x10);
            if (0x38 != header.ToInt32 (4))
                return null;
            var signature = header.ToInt32 (8);
            if (signature != 0x20485049 && signature != 0x00485049) // 'IPH'
                return null;
            if (0x20746D66 != header.ToInt32 (12)) // 'fmt '
                return null;
            file.Position = 0x38;
            if (0x20706D62 != file.ReadInt32()) // 'bmp '
                return null;
            var info = new IphMetaData();
            info.PackedSize = file.ReadInt32();
            info.Width  = file.ReadUInt16();
            info.Height = file.ReadUInt16();
            file.Position = 0x50;
            info.BPP = file.ReadUInt16();
            info.IsCompressed = 0 != file.ReadInt16();
            // XXX int16@[0x54] is a transparency color or 0xFFFF if image is not transparent
            return info;
        }
Exemplo n.º 16
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.º 17
0
        bool SkipFrameTable(IBinaryStream file)
        {
            file.Position = 4;
            int table_count = file.ReadInt16();

            file.Position = 8;
            for (int i = 0; i < table_count; ++i)
            {
                switch (file.ReadByte())
                {
                case 0: break;

                case 1: file.Seek(8, SeekOrigin.Current); break;

                case 2:
                case 3:
                case 4:
                case 5: file.Seek(4, SeekOrigin.Current); break;

                default: return(false);
                }
            }
            int count = file.ReadUInt16();

            file.Seek(count * 8, SeekOrigin.Current);
            return(true);
        }
Exemplo n.º 18
0
        void UnpackAlpha(int length)
        {
            int dst = 3;

            while (length > 0)
            {
                int count = m_input.ReadInt16();
                length -= 2;
                if (count < 0)
                {
                    count = (count & 0x7FFF) + 1;
                    byte a = (byte)~m_input.ReadUInt8();
                    length--;
                    for (int i = 0; i < count; ++i)
                    {
                        m_output[dst] = a;
                        dst          += 4;
                    }
                }
                else
                {
                    for (int i = 0; i < count; ++i)
                    {
                        m_output[dst] = (byte)~m_input.ReadUInt8();
                        dst          += 4;
                    }
                    length -= count;
                }
            }
        }
Exemplo n.º 19
0
        }                                                                 // 'AN20'

        public override List <Entry> GetFramesList(IBinaryStream file)
        {
            if (!SkipFrameTable(file))
            {
                return(null);
            }
            int count = file.ReadInt16();

            if (!IsSaneCount(count))
            {
                return(null);
            }
            long current_offset = file.Position + 0x10;
            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)
        {
            var header = file.ReadHeader(0x10);
            var info   = new CzMetaData {
                Width        = header.ToUInt16(8),
                Height       = header.ToUInt16(10),
                BPP          = header.ToUInt16(12),
                HeaderLength = header.ToUInt32(4),
                Version      = header[2] - '0',
            };

            if (info.HeaderLength > 0x18)
            {
                info.OffsetX = file.ReadInt16();
                info.OffsetY = file.ReadInt16();
            }
            return(info);
        }
Exemplo n.º 21
0
        private void Decode3Alt(IBinaryStream input, Stream output, int step)
        {
            int output_size = input.ReadInt32();
            int count       = input.ReadInt32();

            using (var buffer = new BinaryWriter(output, Encoding.ASCII, true))
            {
                short sample = input.ReadInt16();
                buffer.Write(sample);
                int output_count = 1;
                for (int i = 0; i < count; ++i)
                {
                    short v      = input.ReadInt16();
                    int   repeat = SizeTableAlt[v & 7];
                    output_count += repeat;
                    short end = (short)(v & 0xFFF8);
                    short inc = (short)((end - sample) / repeat);
                    for (int j = 0; j < repeat; ++j)
                    {
                        sample += inc;
                        buffer.Write(sample);
                        if (step != 0)
                        {
                            buffer.BaseStream.Seek(step, SeekOrigin.Current);
                        }
                    }
                    sample = end;
                }
                if (step != 0)
                {
                    output_size /= step;
                }
                while (output_count++ < output_size)
                {
                    sample = input.ReadInt16();
                    buffer.Write(sample);
                    if (step != 0)
                    {
                        buffer.BaseStream.Seek(step, SeekOrigin.Current);
                    }
                }
            }
        }
Exemplo n.º 22
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            if (!file.Name.HasExtension(".ggs"))
            {
                return(null);
            }
            int  x = file.ReadInt16();
            int  y = file.ReadInt16();
            uint w = file.ReadUInt16();
            uint h = file.ReadUInt16();

            if (0 == w || 0 == h || w > 0x4000 || h > 0x4000 || x < 0 || y < 0)
            {
                return(null);
            }
            return(new ImageMetaData {
                Width = w, Height = h, OffsetX = x, OffsetY = y, BPP = 24
            });
        }
Exemplo n.º 23
0
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            int name_count = stream.ReadInt16();

            if (name_count <= 0 || name_count > 1000)
            {
                return(null);
            }
            for (int i = 0; i < name_count; ++i)
            {
                int name_length = stream.ReadInt32();
                if (name_length <= 0 || name_length > 260)
                {
                    return(null);
                }
                stream.Seek(name_length, SeekOrigin.Current);
            }
            int tile_count = stream.ReadInt16();

            if (tile_count <= 0 || tile_count > 1000)
            {
                return(null);
            }
            var rect = new Rectangle(0, 0, 0, 0);

            for (int i = 0; i < tile_count; ++i)
            {
                int name_length = stream.ReadInt32();
                if (name_length <= 0 || name_length > 260)
                {
                    return(null);
                }
                stream.Seek(name_length + 0xC, SeekOrigin.Current);
                int x         = stream.ReadInt32();
                int y         = stream.ReadInt32();
                int w         = stream.ReadInt32() - x;
                int h         = stream.ReadInt32() - y;
                var part_rect = new Rectangle(x, y, w, h);
                rect = Rectangle.Union(rect, part_rect);
                stream.Seek(0x28, SeekOrigin.Current);
            }
            return(ReadCompressionMetaData(stream, rect));
        }
Exemplo n.º 24
0
        public override ImageMetaData ReadMetaData(IBinaryStream stream)
        {
            int count = stream.ReadInt16();

            if (count <= 0 || count >= 0x100)
            {
                return(null);
            }
            int offset;

            if (count > 1)
            {
                offset = stream.ReadInt32();
                if (offset != 2 + count * 4)
                {
                    return(null);
                }
            }
            else
            {
                offset = 2;
            }
            stream.Position = offset;
            int unpacked_size = stream.ReadInt32();
            int packed_size   = stream.ReadInt32();

            offset += 8;
            if (offset + packed_size > stream.Length)
            {
                return(null);
            }
            byte[] header = new byte[0x36];
            if (0x36 != MgrOpener.Decompress(stream.AsStream, header) ||
                header[0] != 'B' || header[1] != 'M')
            {
                return(null);
            }
            using (var bmp = new BinMemoryStream(header, stream.Name))
            {
                var info = Bmp.ReadMetaData(bmp);
                if (null == info)
                {
                    return(null);
                }
                return(new MgrMetaData
                {
                    Width = info.Width,
                    Height = info.Height,
                    BPP = info.BPP,
                    Offset = offset,
                    PackedSize = packed_size,
                    UnpackedSize = unpacked_size,
                });
            }
        }
Exemplo n.º 25
0
        }                                                                 // 'HG-2'

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

            if (0x25 == version)
            {
                info.HeaderSize = 0x58;
            }
            else if (0x20 == version)
            {
                info.HeaderSize = 0x50;
            }
            else if (0x10 == version)
            {
                info.HeaderSize = 0x30;
            }
            else
            {
                return(null);
            }
            info.Version = version;
            info.Width   = stream.ReadUInt32();
            info.Height  = stream.ReadUInt32();
            info.BPP     = stream.ReadInt16();
            info.Depth   = stream.ReadInt16();
            stream.Seek(8, SeekOrigin.Current);
            info.DataPacked   = stream.ReadInt32();
            info.DataUnpacked = stream.ReadInt32();
            info.CtlPacked    = stream.ReadInt32();
            info.CtlUnpacked  = stream.ReadInt32();
            if (info.HeaderSize > 0x30)
            {
                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.º 26
0
        public override ImageMetaData ReadMetaData(IBinaryStream input)
        {
            int x = input.ReadInt16();
            int y = input.ReadInt16();
            int w = input.ReadInt16();
            int h = input.ReadInt16();

            if (w <= 0 || w > 0x1000 || h <= 0 || h > 0x1000 ||
                x < 0 || x > 0x800 || y < 0 || y > 0x800)
            {
                return(null);
            }
            return(new ImageMetaData {
                Width = (uint)w,
                Height = (uint)h,
                OffsetX = x,
                OffsetY = y,
                BPP = 8,
            });
        }
Exemplo n.º 27
0
        private void Decode3(IBinaryStream input, Stream output, int step)
        {
            input.ReadInt32(); // unpacked_size
            int count = input.ReadInt32();

            using (var buffer = new BinaryWriter(output, Encoding.ASCII, true))
            {
                short sample = input.ReadInt16();
                buffer.Write(sample);
                for (int i = 0; i < count; ++i)
                {
                    if (count - 300 == i)
                    {
                        sample = 0;
                    }
                    ushort v = input.ReadUInt8();
                    if (0 != (v & 1))
                    {
                        ushort v14 = (ushort)((v >> 1) & 0x7F);
                        if (0 != (v14 & 0x40))
                        {
                            sample = (short)(v14 << 10);
                        }
                        else
                        {
                            sample += (short)SampleTable2[v14];
                        }
                        buffer.Write(sample);
                        if (step != 0)
                        {
                            buffer.BaseStream.Seek(step, SeekOrigin.Current);
                        }
                    }
                    else
                    {
                        v |= (ushort)(input.ReadUInt8() << 8);
                        int    repeat = SizeTable[(v >> 1) & 7];
                        short  end    = (short)(v & 0xFFF0);
                        double inc    = (end - sample) / (double)repeat;
                        double v8     = sample;
                        for (int j = 0; j < repeat; ++j)
                        {
                            v8 += inc;
                            buffer.Write((short)v8);
                            if (step != 0)
                            {
                                buffer.BaseStream.Seek(step, SeekOrigin.Current);
                            }
                        }
                        sample = end;
                    }
                }
            }
        }
Exemplo n.º 28
0
        public override ImageMetaData ReadMetaData(IBinaryStream file)
        {
            if (!file.Name.HasExtension(".gga"))
            {
                return(null);
            }
            int  x             = file.ReadInt16();
            int  y             = file.ReadInt16();
            uint w             = file.ReadUInt16();
            uint h             = file.ReadUInt16();
            int  unpacked_size = file.ReadInt32();

            if (0 == w || 0 == h || w > 0x7FFF || h > 0x7FFF || x < 0 || y < 0 ||
                3 * w * h != unpacked_size)
            {
                return(null);
            }
            return(new GgaMetaData {
                Width = w, Height = h, OffsetX = x, OffsetY = y, BPP = 24,
                UnpackedSize = unpacked_size,
            });
        }
Exemplo n.º 29
0
 internal override ImageMetaData GetBaseInfo(IBinaryStream input)
 {
     SkipFrameTable(input);
     input.ReadInt16();
     return(new ImageMetaData
     {
         OffsetX = input.ReadInt32(),
         OffsetY = input.ReadInt32(),
         Width = input.ReadUInt32(),
         Height = input.ReadUInt32(),
         BPP = 32,
     });
 }
Exemplo n.º 30
0
        internal bool ReadBmpInfo(IBinaryStream file, IpfMetaData info)
        {
            if (0x20706D62 != file.ReadInt32()) // 'bmp '
            {
                return(false);
            }
            int bmp_size = file.ReadInt32();

            if (bmp_size <= 0x20)
            {
                return(false);
            }
            info.BmpOffset = file.Position + 0x18;
            info.Width     = file.ReadUInt16();
            info.Height    = file.ReadUInt16();
            file.ReadUInt32();
            info.OffsetX = file.ReadInt16();
            info.OffsetY = file.ReadInt16();
            file.Seek(6, SeekOrigin.Current);
            info.IsCompressed = 0 != (file.ReadByte() & 1);
            return(true);
        }