public Reader(Stream stream, QntMetaData info) { m_width = (int)info.Width; m_height = (int)info.Height; int w = (m_width + 1) & ~1; int h = (m_height + 1) & ~1; int rgb_size = h * w * 3; m_bpp = info.AlphaSize != 0 ? 4 : 3; m_input = new byte[rgb_size]; var alpha_pos = stream.Position + info.RGBSize; using (var zstream = new ZLibStream(stream, CompressionMode.Decompress, true)) if (rgb_size != zstream.Read(m_input, 0, rgb_size)) { throw new InvalidFormatException("Unexpected end of file"); } if (info.AlphaSize != 0) { int alpha_size = w * m_height; m_alpha = new byte[alpha_size]; stream.Position = alpha_pos; using (var zstream = new ZLibStream(stream, CompressionMode.Decompress, true)) if (alpha_size != zstream.Read(m_alpha, 0, alpha_size)) { throw new InvalidFormatException("Unexpected end of file"); } } m_output = new byte[info.Width * info.Height * m_bpp]; }
public Reader(Stream stream, QntMetaData info) { m_width = (int)info.Width; m_height = (int)info.Height; int w = (m_width + 1) & ~1; int h = (m_height + 1) & ~1; int rgb_size = h * w * 3; m_bpp = info.AlphaSize != 0 ? 4 : 3; m_input = new byte[rgb_size]; var alpha_pos = stream.Position + info.RGBSize; using (var zstream = new ZLibStream (stream, CompressionMode.Decompress, true)) if (rgb_size != zstream.Read (m_input, 0, rgb_size)) throw new InvalidFormatException ("Unexpected end of file"); if (info.AlphaSize != 0) { int alpha_size = w * m_height; m_alpha = new byte[alpha_size]; stream.Position = alpha_pos; using (var zstream = new ZLibStream (stream, CompressionMode.Decompress, true)) if (alpha_size != zstream.Read (m_alpha, 0, alpha_size)) throw new InvalidFormatException ("Unexpected end of file"); } m_output = new byte[info.Width*info.Height*m_bpp]; }