Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / MS / Internal / Ink / InkSerializedFormat / LZCodec.cs / 1 / LZCodec.cs
using MS.Utility;
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Globalization;
using System.Windows;
using System.Windows.Input;
using System.Windows.Ink;
using MS.Internal.Ink.InkSerializedFormat;
using MS.Internal.Ink;
using System.Collections.Generic;
using System.Diagnostics;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal.Ink.InkSerializedFormat
{
///
/// LZCodec
///
internal class LZCodec
{
///
/// LZCodec
///
internal LZCodec()
{
}
///
/// Uncompress
///
///
///
///
internal byte[] Uncompress(byte[] input, int inputIndex)
{
//first things first
Debug.Assert(input != null);
Debug.Assert(input.Length > 1);
Debug.Assert(inputIndex < input.Length);
Debug.Assert(inputIndex >= 0);
List output = new List();
BitStreamWriter writer = new BitStreamWriter(output);
BitStreamReader reader = new BitStreamReader(input, inputIndex);
//decode
int index = 0, countBytes = 0, start = 0;
byte byte1 = 0, byte2 = 0;
_maxMatchLength = FirstMaxMatchLength;
// initialize the ring buffer
for (index = 0; index < RingBufferLength - _maxMatchLength; index++)
{
_ringBuffer[index] = 0;
}
//initialize decoding globals
_flags = 0;
_currentRingBufferPosition = RingBufferLength - _maxMatchLength;
while (!reader.EndOfStream)
{
byte1 = reader.ReadByte(Native.BitsPerByte);
// High order byte counts the number of bits used in the low order
// byte.
if (((_flags >>= 1) & 0x100) == 0)
{
// Set bit mask describing the next 8 bytes.
_flags = (((int)byte1) | 0xff00);
byte1 = reader.ReadByte(Native.BitsPerByte);
}
if ((_flags & 1) != 0)
{
// Just store the literal byte in the buffer.
writer.Write(byte1, Native.BitsPerByte);
_ringBuffer[_currentRingBufferPosition++] = byte1;
_currentRingBufferPosition &= RingBufferLength - 1;
}
else
{
// Extract the offset and count to copy from the ring buffer.
byte2 = reader.ReadByte(Native.BitsPerByte);
countBytes = (int)byte2;
start = (countBytes & 0xf0) << 4 | (int)byte1;
countBytes = (countBytes & 0x0f) + MaxLiteralLength;
for (index = 0; index <= countBytes; index++)
{
byte1 = _ringBuffer[(start + index) & (RingBufferLength - 1)];
writer.Write(byte1, Native.BitsPerByte);
_ringBuffer[_currentRingBufferPosition++] = byte1;
_currentRingBufferPosition &= RingBufferLength - 1;
}
}
}
return output.ToArray();
}
///
/// Privates
///
private byte[] _ringBuffer = new byte[RingBufferLength];
private int _maxMatchLength = 0;
private int _flags = 0;
private int _currentRingBufferPosition = 0;
///
/// Statics / constants
///
private static readonly int FirstMaxMatchLength = 0x10;
private static readonly int RingBufferLength = 4069;
private static readonly int MaxLiteralLength = 2;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using MS.Utility;
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Globalization;
using System.Windows;
using System.Windows.Input;
using System.Windows.Ink;
using MS.Internal.Ink.InkSerializedFormat;
using MS.Internal.Ink;
using System.Collections.Generic;
using System.Diagnostics;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace MS.Internal.Ink.InkSerializedFormat
{
///
/// LZCodec
///
internal class LZCodec
{
///
/// LZCodec
///
internal LZCodec()
{
}
///
/// Uncompress
///
///
///
///
internal byte[] Uncompress(byte[] input, int inputIndex)
{
//first things first
Debug.Assert(input != null);
Debug.Assert(input.Length > 1);
Debug.Assert(inputIndex < input.Length);
Debug.Assert(inputIndex >= 0);
List output = new List();
BitStreamWriter writer = new BitStreamWriter(output);
BitStreamReader reader = new BitStreamReader(input, inputIndex);
//decode
int index = 0, countBytes = 0, start = 0;
byte byte1 = 0, byte2 = 0;
_maxMatchLength = FirstMaxMatchLength;
// initialize the ring buffer
for (index = 0; index < RingBufferLength - _maxMatchLength; index++)
{
_ringBuffer[index] = 0;
}
//initialize decoding globals
_flags = 0;
_currentRingBufferPosition = RingBufferLength - _maxMatchLength;
while (!reader.EndOfStream)
{
byte1 = reader.ReadByte(Native.BitsPerByte);
// High order byte counts the number of bits used in the low order
// byte.
if (((_flags >>= 1) & 0x100) == 0)
{
// Set bit mask describing the next 8 bytes.
_flags = (((int)byte1) | 0xff00);
byte1 = reader.ReadByte(Native.BitsPerByte);
}
if ((_flags & 1) != 0)
{
// Just store the literal byte in the buffer.
writer.Write(byte1, Native.BitsPerByte);
_ringBuffer[_currentRingBufferPosition++] = byte1;
_currentRingBufferPosition &= RingBufferLength - 1;
}
else
{
// Extract the offset and count to copy from the ring buffer.
byte2 = reader.ReadByte(Native.BitsPerByte);
countBytes = (int)byte2;
start = (countBytes & 0xf0) << 4 | (int)byte1;
countBytes = (countBytes & 0x0f) + MaxLiteralLength;
for (index = 0; index <= countBytes; index++)
{
byte1 = _ringBuffer[(start + index) & (RingBufferLength - 1)];
writer.Write(byte1, Native.BitsPerByte);
_ringBuffer[_currentRingBufferPosition++] = byte1;
_currentRingBufferPosition &= RingBufferLength - 1;
}
}
}
return output.ToArray();
}
///
/// Privates
///
private byte[] _ringBuffer = new byte[RingBufferLength];
private int _maxMatchLength = 0;
private int _flags = 0;
private int _currentRingBufferPosition = 0;
///
/// Statics / constants
///
private static readonly int FirstMaxMatchLength = 0x10;
private static readonly int RingBufferLength = 4069;
private static readonly int MaxLiteralLength = 2;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SecurityTokenProvider.cs
- WebServiceErrorEvent.cs
- VisualTreeUtils.cs
- cookiecontainer.cs
- TagPrefixInfo.cs
- ErrorsHelper.cs
- CodeMethodReturnStatement.cs
- OleDbSchemaGuid.cs
- XmlDocument.cs
- ScriptControlDescriptor.cs
- ExpandSegmentCollection.cs
- Int32.cs
- GrammarBuilderWildcard.cs
- KnownColorTable.cs
- FullTrustAssemblyCollection.cs
- HttpContext.cs
- SelfSignedCertificate.cs
- _BasicClient.cs
- OdbcCommand.cs
- Debug.cs
- TypedServiceOperationListItem.cs
- TrimSurroundingWhitespaceAttribute.cs
- CacheChildrenQuery.cs
- DatatypeImplementation.cs
- StorageAssociationSetMapping.cs
- BooleanFacetDescriptionElement.cs
- FontFamilyConverter.cs
- EntityDataSourceWrapperCollection.cs
- PersonalizationProviderCollection.cs
- HttpContext.cs
- FunctionUpdateCommand.cs
- SettingsAttributes.cs
- SymDocumentType.cs
- ListViewGroupItemCollection.cs
- DataReaderContainer.cs
- SqlTypeConverter.cs
- FamilyTypeface.cs
- TextServicesPropertyRanges.cs
- Camera.cs
- PolyQuadraticBezierSegment.cs
- ImmutableClientRuntime.cs
- XPathMultyIterator.cs
- NativeDirectoryServicesQueryAPIs.cs
- ACL.cs
- Viewport2DVisual3D.cs
- DataSourceControl.cs
- TableRowCollection.cs
- SqlDataSourceView.cs
- ResourceCodeDomSerializer.cs
- SoapIgnoreAttribute.cs
- RefType.cs
- WindowsBrush.cs
- DbException.cs
- DropSource.cs
- IdleTimeoutMonitor.cs
- RegionData.cs
- UInt32Storage.cs
- Qualifier.cs
- FormViewRow.cs
- DependencyPropertyChangedEventArgs.cs
- DataGridViewSelectedRowCollection.cs
- ObjectHandle.cs
- ThreadStartException.cs
- LinqDataSourceUpdateEventArgs.cs
- TypeBrowserDialog.cs
- MarkupObject.cs
- WizardSideBarListControlItem.cs
- CommandBinding.cs
- EditingMode.cs
- XmlSchemaElement.cs
- StringSorter.cs
- RouteParameter.cs
- ReturnValue.cs
- WebPartDescription.cs
- XmlHierarchicalEnumerable.cs
- Image.cs
- ProfileGroupSettings.cs
- PopOutPanel.cs
- DataGridRowsPresenter.cs
- ListViewInsertedEventArgs.cs
- CollectionType.cs
- XPathSelectionIterator.cs
- DirectoryRootQuery.cs
- TcpPortSharing.cs
- XMLDiffLoader.cs
- XmlDocumentFragment.cs
- Size.cs
- DirectoryNotFoundException.cs
- PeerCollaborationPermission.cs
- EncoderBestFitFallback.cs
- Transform3DCollection.cs
- HttpCookieCollection.cs
- IsolatedStorageFile.cs
- AuthenticationServiceManager.cs
- GcHandle.cs
- IPAddressCollection.cs
- XLinq.cs
- SafeMILHandleMemoryPressure.cs
- TraceHandlerErrorFormatter.cs
- FilePrompt.cs