public void NullPixels() { try { _e = new LzwEncoder( null ); } catch( ArgumentNullException ex ) { Assert.AreEqual( "pixels", ex.ParamName ); throw; } }
public void NullStream() { _e = new LzwEncoder( _ip ); try { _e.Encode( null ); } catch( ArgumentNullException ex ) { Assert.AreEqual( "outputStream", ex.ParamName ); throw; } }
/// <summary> /// Encodes _ip and decodes the encoded data, then compares the decoded /// data against the original. /// Also calculates the compression rate. /// </summary> private void TestIt() { MemoryStream s = new MemoryStream(); _e = new LzwEncoder( _ip ); _e.Encode( s ); int encodedByteCount = (int) s.Position; s.Seek( 0, SeekOrigin.Begin ); TableBasedImageData tbid = new TableBasedImageData( s, _ip.Count ); s.Seek( 0, SeekOrigin.Begin ); byte[] encodedBytes = new byte[encodedByteCount]; s.Read( encodedBytes, 0, encodedByteCount ); Assert.AreEqual( _ip.Count, tbid.Pixels.Count, "Pixel counts differ" ); for( int i = 0; i < _ip.Count; i++ ) { Assert.AreEqual( _ip[i], tbid.Pixels[i], "pixel index " + i ); } float compression = 100 - (100 * encodedByteCount / _ip.Count); WriteMessage( "Original byte count: " + _ip.Count + ". Encoded byte count: " + encodedByteCount + ". Compression rate: " + compression + "%" ); }
/// <summary> /// Encodes and writes pixel data to the supplied stream /// </summary> /// <param name="indexedPixels"> /// Collection of indices of the pixel colours within the active colour /// table. /// </param> /// <param name="outputStream"> /// The stream to write to. /// </param> private static void WritePixels( IndexedPixels indexedPixels, Stream outputStream ) { LzwEncoder encoder = new LzwEncoder( indexedPixels ); encoder.Encode( outputStream ); }