Example #1
0
        public IarImage(IarArchive iarc, Entry entry)
        {
            int flags = iarc.File.View.ReadUInt16(entry.Offset);
            int bpp;

            switch (flags & 0x3E)
            {
            case 0x02:  bpp = 8; break;

            case 0x1C:  bpp = 24; break;

            case 0x3C:  bpp = 32; break;

            default:    throw new NotSupportedException("Not supported IAR image format");
            }
            var offset = entry.Offset;

            m_info = new IarImageInfo
            {
                Flags        = flags,
                BPP          = bpp,
                Compressed   = iarc.File.View.ReadByte(offset + 3) != 0,
                Width        = iarc.File.View.ReadUInt32(offset + 0x20),
                Height       = iarc.File.View.ReadUInt32(offset + 0x24),
                Stride       = iarc.File.View.ReadInt32(offset + 0x28),
                OffsetX      = iarc.File.View.ReadInt32(offset + 0x18),
                OffsetY      = iarc.File.View.ReadInt32(offset + 0x1C),
                UnpackedSize = iarc.File.View.ReadInt32(offset + 8),
                PaletteSize  = iarc.File.View.ReadUInt32(offset + 0xC),
                PackedSize   = iarc.File.View.ReadInt32(offset + 0x10),
            };
            uint header_size = 1 == iarc.Version ? 0x30u : iarc.Version < 4 ? 0x40u : 0x48u;

            offset += header_size;
            uint input_size = entry.Size - header_size;

            if (m_info.PaletteSize > 0)
            {
                m_palette = new byte[m_info.PaletteSize];
                iarc.File.View.Read(offset, m_palette, 0, m_info.PaletteSize);
                offset     += m_info.PaletteSize;
                input_size -= m_info.PaletteSize;
            }
            m_output = new byte[m_info.UnpackedSize];
            using (var input = iarc.File.CreateStream(offset, input_size))
            {
                if (m_info.Compressed)
                {
                    using (var reader = new IarDecompressor(input))
                        reader.Unpack(m_output);
                }
                else
                {
                    input.Read(m_output, 0, m_output.Length);
                }
            }
        }
Example #2
0
 public IarImage(IarImageInfo info, byte[] pixels, byte[] palette = null)
 {
     m_info    = info;
     m_output  = pixels;
     m_palette = palette;
 }
Example #3
0
 public IarImage(IarImageInfo info, byte[] pixels, byte[] palette = null)
 {
     m_info = info;
     m_output = pixels;
     m_palette = palette;
 }
Example #4
0
        public IarImage(IarArchive iarc, Entry entry)
        {
            int flags = iarc.File.View.ReadUInt16 (entry.Offset);
            int bpp;
            switch (flags & 0x3E)
            {
            case 0x02:  bpp = 8; break;
            case 0x1C:  bpp = 24; break;
            case 0x3C:  bpp = 32; break;
            default:    throw new NotSupportedException ("Not supported IAR image format");
            }
            var offset = entry.Offset;
            m_info = new IarImageInfo
            {
                Flags   = flags,
                BPP     = bpp,
                Compressed = iarc.File.View.ReadByte (offset+3) != 0,
                Width   = iarc.File.View.ReadUInt32 (offset+0x20),
                Height  = iarc.File.View.ReadUInt32 (offset+0x24),
                Stride  = iarc.File.View.ReadInt32 (offset+0x28),
                OffsetX = iarc.File.View.ReadInt32 (offset+0x18),
                OffsetY = iarc.File.View.ReadInt32 (offset+0x1C),
                UnpackedSize = iarc.File.View.ReadInt32 (offset+8),
                PaletteSize = iarc.File.View.ReadUInt32 (offset+0xC),
                PackedSize = iarc.File.View.ReadInt32 (offset+0x10),
            };
            uint header_size = 1 == iarc.Version ? 0x30u : iarc.Version < 4 ? 0x40u : 0x48u;
            offset += header_size;
            uint input_size = entry.Size - header_size;

            if (m_info.PaletteSize > 0)
            {
                m_palette = new byte[m_info.PaletteSize];
                iarc.File.View.Read (offset, m_palette, 0, m_info.PaletteSize);
                offset += m_info.PaletteSize;
                input_size -= m_info.PaletteSize;
            }
            m_output = new byte[m_info.UnpackedSize];
            using (var input = iarc.File.CreateStream (offset, input_size))
            {
                if (m_info.Compressed)
                {
                    using (var reader = new IarDecompressor (input))
                        reader.Unpack (m_output);
                }
                else
                    input.Read (m_output, 0, m_output.Length);
            }
        }