public Reader(Stream stream, CmMetaData info) { m_input = stream; m_width = (int)info.Width; m_height = (int)info.Height; m_pixel_size = info.BPP / 8; m_compressed = info.IsCompressed; m_data_length = (int)info.DataLength; switch (m_pixel_size) { case 1: Format = PixelFormats.Indexed8; break; case 3: Format = PixelFormats.Bgr24; break; case 4: Format = PixelFormats.Bgr32; break; default: throw new InvalidFormatException("Invalid color depth"); } if (info.Colors > 0) { m_input.Position = 0x20; Palette = ImageFormat.ReadPalette(m_input, info.Colors, PaletteFormat.Bgr); } m_input.Position = info.DataOffset; int size = info.IsCompressed ? m_width * m_height * m_pixel_size : (int)info.DataLength; m_pixels = new byte[size]; }
public override ImageMetaData ReadMetaData(IBinaryStream stream) { if ('C' != stream.ReadByte() || 'M' != stream.ReadByte()) { return(null); } var header = stream.ReadBytes(0x1e); if (header.Length != 0x1e) { return(null); } if (1 != header[0x0c]) { return(null); } uint size = LittleEndian.ToUInt32(header, 0); if (size != stream.Length) { return(null); } var info = new CmMetaData(); info.Width = LittleEndian.ToUInt16(header, 4); info.Height = LittleEndian.ToUInt16(header, 6); info.Colors = LittleEndian.ToUInt16(header, 8); info.BPP = header[0x0a]; info.IsCompressed = 0 != header[0x0b]; info.DataOffset = LittleEndian.ToUInt32(header, 0x0e); info.DataLength = LittleEndian.ToUInt32(header, 0x12); if (info.DataLength > size) { return(null); } return(info); }
public Reader(Stream stream, CmMetaData info) { m_input = stream; m_width = (int)info.Width; m_height = (int)info.Height; m_pixel_size = info.BPP/8; m_compressed = info.IsCompressed; m_data_length = (int)info.DataLength; switch (m_pixel_size) { case 1: Format = PixelFormats.Indexed8; break; case 3: Format = PixelFormats.Bgr24; break; case 4: Format = PixelFormats.Bgr32; break; default: throw new InvalidFormatException ("Invalid color depth"); } if (info.Colors > 0) { m_input.Position = 0x20; Palette = RleDecoder.ReadPalette (m_input, info.Colors, 3); } m_input.Position = info.DataOffset; int size = info.IsCompressed ? m_width*m_height*m_pixel_size : (int)info.DataLength; m_pixels = new byte[size]; }
public override ImageMetaData ReadMetaData(Stream stream) { if ('C' != stream.ReadByte() || 'M' != stream.ReadByte()) return null; var header = new byte[0x1e]; if (header.Length != stream.Read (header, 0, header.Length)) return null; if (1 != header[0x0c]) return null; uint size = LittleEndian.ToUInt32 (header, 0); if (size != stream.Length) return null; var info = new CmMetaData(); info.Width = LittleEndian.ToUInt16 (header, 4); info.Height = LittleEndian.ToUInt16 (header, 6); info.Colors = LittleEndian.ToUInt16 (header, 8); info.BPP = header[0x0a]; info.IsCompressed = 0 != header[0x0b]; info.DataOffset = LittleEndian.ToUInt32 (header, 0x0e); info.DataLength = LittleEndian.ToUInt32 (header, 0x12); if (info.DataLength > size) return null; return info; }