public override ImageMetaData ReadMetaData(IBinaryStream stream) { if ('A' != stream.ReadByte() || 'M' != stream.ReadByte()) { return(null); } var header = new byte[0x30]; if (0x2e != stream.Read(header, 2, 0x2e)) { return(null); } uint size = LittleEndian.ToUInt32(header, 2); if (size != stream.Length) { return(null); } int am_type = header[0x16]; if (am_type != 2 && am_type != 1 || header[0x18] != 1) { return(null); } var info = new AmMetaData(); info.Width = LittleEndian.ToUInt16(header, 6); info.Height = LittleEndian.ToUInt16(header, 8); info.MaskWidth = LittleEndian.ToUInt16(header, 0x0a); info.MaskHeight = LittleEndian.ToUInt16(header, 0x0c); info.Colors = LittleEndian.ToUInt16(header, 0x12); info.BPP = header[0x14]; info.IsCompressed = 0 != header[0x15]; info.DataOffset = LittleEndian.ToUInt32(header, 0x1a); info.DataLength = LittleEndian.ToUInt32(header, 0x1e); info.MaskOffset = LittleEndian.ToUInt32(header, 0x22); info.MaskLength = LittleEndian.ToUInt32(header, 0x26); info.IsMaskCompressed = 0 != header[0x2a]; if (checked (info.DataLength + info.MaskLength) > size) { return(null); } return(info); }
public Reader(Stream stream, AmMetaData info) { m_input = stream; m_info = info; m_width = (int)info.Width; m_height = (int)info.Height; m_pixel_size = info.BPP / 8; if (m_pixel_size != 3 && m_pixel_size != 4 && m_pixel_size != 1) { throw new InvalidFormatException("Invalid color depth"); } Format = PixelFormats.Bgra32; int size = info.IsCompressed ? m_width * m_height * m_pixel_size : (int)info.DataLength; m_output = new byte[size]; uint mask_size = info.IsMaskCompressed ? info.MaskWidth * info.MaskHeight : info.MaskLength; m_alpha = new byte[mask_size]; m_pixels = new byte[m_width * m_height * 4]; }
public override ImageMetaData ReadMetaData(IBinaryStream stream) { var header = stream.ReadHeader(0x30); if ('A' != header[0] || 'M' != header[1]) { return(null); } uint size = header.ToUInt32(2); if (size != stream.Length) { return(null); } int am_type = header[0x16]; if (am_type != 2 && am_type != 1 || header[0x18] != 1) { return(null); } var info = new AmMetaData { Width = header.ToUInt16(6), Height = header.ToUInt16(8), MaskWidth = header.ToUInt16(0x0A), MaskHeight = header.ToUInt16(0x0C), Colors = header.ToUInt16(0x12), BPP = header[0x14], IsCompressed = 0 != header[0x15], DataOffset = header.ToUInt32(0x1A), DataLength = header.ToUInt32(0x1E), MaskOffset = header.ToUInt32(0x22), MaskLength = header.ToUInt32(0x26), IsMaskCompressed = 0 != header[0x2A], }; if (checked (info.DataLength + info.MaskLength) > size) { return(null); } return(info); }
public override ImageMetaData ReadMetaData(Stream stream) { if ('A' != stream.ReadByte() || 'M' != stream.ReadByte()) return null; var header = new byte[0x30]; if (0x2e != stream.Read (header, 2, 0x2e)) return null; uint size = LittleEndian.ToUInt32 (header, 2); if (size != stream.Length) return null; int am_type = header[0x16]; if (am_type != 2 && am_type != 1 || header[0x18] != 1) return null; var info = new AmMetaData(); info.Width = LittleEndian.ToUInt16 (header, 6); info.Height = LittleEndian.ToUInt16 (header, 8); info.MaskWidth = LittleEndian.ToUInt16 (header, 0x0a); info.MaskHeight = LittleEndian.ToUInt16 (header, 0x0c); info.Colors = LittleEndian.ToUInt16 (header, 0x12); info.BPP = header[0x14]; info.IsCompressed = 0 != header[0x15]; info.DataOffset = LittleEndian.ToUInt32 (header, 0x1a); info.DataLength = LittleEndian.ToUInt32 (header, 0x1e); info.MaskOffset = LittleEndian.ToUInt32 (header, 0x22); info.MaskLength = LittleEndian.ToUInt32 (header, 0x26); info.IsMaskCompressed = 0 != header[0x2a]; if (checked(info.DataLength + info.MaskLength) > size) return null; return info; }
public Reader(Stream stream, AmMetaData info) { m_input = stream; m_info = info; m_width = (int)info.Width; m_height = (int)info.Height; m_pixel_size = info.BPP/8; if (m_pixel_size != 3 && m_pixel_size != 4 && m_pixel_size != 1) throw new InvalidFormatException ("Invalid color depth"); Format = PixelFormats.Bgra32; int size = info.IsCompressed ? m_width*m_height*m_pixel_size : (int)info.DataLength; m_output = new byte[size]; uint mask_size = info.IsMaskCompressed ? info.MaskWidth*info.MaskHeight : info.MaskLength; m_alpha = new byte[mask_size]; m_pixels = new byte[m_width*m_height*4]; }