public override ImageMetaData ReadMetaData(IBinaryStream stream) { var header = stream.ReadHeader(0x14); int compression = header.ToUInt16(0xC); if (compression < 1 || compression > 3) { return(null); } int depth = header.ToInt16(0x10); var info = new CrxMetaData { Width = header.ToUInt16(8), Height = header.ToUInt16(10), OffsetX = header.ToInt16(4), OffsetY = header.ToInt16(6), BPP = 0 == depth ? 24 : 1 == depth ? 32 : 8, Compression = compression, CompressionFlags = header.ToUInt16(0xE), Colors = depth, Mode = header.ToUInt16(0x12), }; return(info); }
public Reader(IBinaryStream input, CrxMetaData info) { m_width = (int)info.Width; m_height = (int)info.Height; m_bpp = info.BPP; m_compression = info.Compression; m_flags = info.CompressionFlags; m_mode = info.Mode; switch (m_bpp) { case 24: Format = PixelFormats.Bgr24; break; case 32: Format = PixelFormats.Bgra32; break; case 8: Format = PixelFormats.Indexed8; break; default: throw new InvalidFormatException(); } m_stride = (m_width * m_bpp / 8 + 3) & ~3; m_output = new byte[m_height * m_stride]; m_input = input; m_input.Position = 0x14; if (8 == m_bpp) { ReadPalette(info.Colors); } }
} // 'CRXG' public override ImageMetaData ReadMetaData(Stream stream) { var header = new byte[0x14]; if (header.Length != stream.Read(header, 0, header.Length)) { return(null); } int depth = LittleEndian.ToInt16(header, 0x10); var info = new CrxMetaData { Width = LittleEndian.ToUInt16(header, 8), Height = LittleEndian.ToUInt16(header, 10), OffsetX = LittleEndian.ToInt16(header, 4), OffsetY = LittleEndian.ToInt16(header, 6), BPP = 0 == depth ? 24 : 1 == depth ? 32 : 8, Compression = LittleEndian.ToUInt16(header, 0xC), Colors = depth, Mode = LittleEndian.ToUInt16(header, 0x12), }; if (info.Compression != 1 && info.Compression != 2) { return(null); } return(info); }
public Reader(IBinaryStream input, CrxMetaData info) { m_width = (int)info.Width; m_height = (int)info.Height; m_bpp = info.BPP; m_compression = info.Compression; m_flags = info.CompressionFlags; m_mode = info.Mode; Format = CheckFormat(m_bpp); m_stride = (m_width * m_bpp / 8 + 3) & ~3; m_output = new byte[m_height * m_stride]; m_input = input; m_input.Position = 0x14; if (8 == m_bpp) { ReadPalette(info.Colors); } }
public Writer(byte[] input, BinaryWriter output, CrxMetaData info) { m_width = (int)info.Width; m_height = (int)info.Height; m_bpp = info.BPP; m_compression = info.Compression; m_flags = info.CompressionFlags; m_mode = info.Mode; Format = CheckFormat(m_bpp); m_stride = (m_width * m_bpp / 8 + 3) & ~3; m_input = input; m_output = output; m_output.Seek(0x14, SeekOrigin.Begin); if (8 == m_bpp) { ReadPalette(info.Colors); } }