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 / Codec.cs / 1 / Codec.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 SR = MS.Internal.PresentationCore.SR; using SRID = MS.Internal.PresentationCore.SRID; namespace MS.Internal.Ink.InkSerializedFormat { ////// A Math helper class. /// internal static class MathHelper { ////// Returns the absolute value of a 32-bit signed integer. /// Unlike Math.Abs, this method doesn't throw OverflowException /// when the signed integer equals int.MinValue (-2,147,483,648/0x80000000). /// It will return the same value (-2,147,483,648). /// In this case, value can be casted to unsigned value which will be positive (2,147,483,648) /// /// ///internal static int AbsNoThrow(int data) { // This behavior is desired for ISF decoder. Please refer to the below macro in old native code (codec.h). // template{typename DataType} // inline DataType Abs(DataType data) { return (data < 0) ? -data : data; }; return (data < 0) ? -data : data; } /// /// Returns the absolute value of a 64-bit signed integer. /// Unlike Math.Abs, this method doesn't throw OverflowException /// when the signed integer equals int.MinValue (-9,223,372,036,854,775,808/0x8000000000000000). /// It will return the same value -9,223,372,036,854,775,808 instead. /// In this case, value can be casted to unsigned value which will be positive (9,223,372,036,854,775,808) /// /// ///internal static long AbsNoThrow(long data) { // This behavior is desired for ISF decoder. Please refer to the below macro in old native code (codec.h). // template{typename DataType} // inline DataType Abs(DataType data) { return (data < 0) ? -data : data; }; return (data < 0) ? -data : data; } } /// /// Abstact base class for DeltaDelta and some others /// internal abstract class DataXform { internal abstract void Transform(int data, ref int xfData, ref int extra); internal abstract void ResetState(); internal abstract int InverseTransform(int xfData, int extra); } ////// Oddly named because we have unmanged code we keep in [....] with this that /// has this name. /// internal class DeltaDelta : DataXform { private long _d_i_1 = 0; private long _d_i_2 = 0; internal DeltaDelta() { } ////// Your guess is as good as mine /// /// /// /// internal override void Transform(int data, ref int xfData, ref int extra) { // Find out the delta delta of the number // Its absolute value could potentially be more than LONG_MAX long llxfData = (data + _d_i_2 - (_d_i_1 << 1)); // Save the state info for next number _d_i_2 = _d_i_1; _d_i_1 = data; // Most of the cases, the delta delta will be less than LONG_MAX if ( Int32.MaxValue >= MathHelper.AbsNoThrow(llxfData) ) { // In those cases, we set 0 to nExtra and // assign the delta delta to xfData extra = 0; xfData = (int)llxfData; } else { long absLxfData = MathHelper.AbsNoThrow(llxfData); // Additional bits in most significant 32 bits extra = (int)(absLxfData >> (sizeof(int) << 3)); // Left sift one bit and append sign bit the the LSB extra = (extra << 1) | ((llxfData < 0) ? 1 : 0); // Save least significant 32 bits in xfData xfData = (int)((unchecked((uint)~0 & absLxfData))); } } ////// /// internal override void ResetState() { _d_i_1 = 0; _d_i_2 = 0; } ////// Your guess is as good as mine /// /// /// ///internal override int InverseTransform(int xfData, int extra) { long llxfData; // Find out whether the original delta delta exceeded the limit if (0 != extra) { // Yes, we had |delta delta| more than LONG_MAX // Find out the original delta delta was negative bool negative = ((extra & 0x01) != 0); // Construct the |DelDel| from xfData and nExtra llxfData = (((long)extra >> 1) << (sizeof(int) << 3)) | (unchecked((uint)~0) & xfData); // Do the sign adjustment llxfData = (negative) ? -llxfData : llxfData; } else { llxfData = xfData; } // Reconstruct the number from delta delta long orgData = (llxfData - _d_i_2 + (_d_i_1 << 1)); _d_i_2 = _d_i_1; _d_i_1 = orgData; // Typecast to LONG and return it return (int)orgData; } } } // 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 SR = MS.Internal.PresentationCore.SR; using SRID = MS.Internal.PresentationCore.SRID; namespace MS.Internal.Ink.InkSerializedFormat { /// /// A Math helper class. /// internal static class MathHelper { ////// Returns the absolute value of a 32-bit signed integer. /// Unlike Math.Abs, this method doesn't throw OverflowException /// when the signed integer equals int.MinValue (-2,147,483,648/0x80000000). /// It will return the same value (-2,147,483,648). /// In this case, value can be casted to unsigned value which will be positive (2,147,483,648) /// /// ///internal static int AbsNoThrow(int data) { // This behavior is desired for ISF decoder. Please refer to the below macro in old native code (codec.h). // template{typename DataType} // inline DataType Abs(DataType data) { return (data < 0) ? -data : data; }; return (data < 0) ? -data : data; } /// /// Returns the absolute value of a 64-bit signed integer. /// Unlike Math.Abs, this method doesn't throw OverflowException /// when the signed integer equals int.MinValue (-9,223,372,036,854,775,808/0x8000000000000000). /// It will return the same value -9,223,372,036,854,775,808 instead. /// In this case, value can be casted to unsigned value which will be positive (9,223,372,036,854,775,808) /// /// ///internal static long AbsNoThrow(long data) { // This behavior is desired for ISF decoder. Please refer to the below macro in old native code (codec.h). // template{typename DataType} // inline DataType Abs(DataType data) { return (data < 0) ? -data : data; }; return (data < 0) ? -data : data; } } /// /// Abstact base class for DeltaDelta and some others /// internal abstract class DataXform { internal abstract void Transform(int data, ref int xfData, ref int extra); internal abstract void ResetState(); internal abstract int InverseTransform(int xfData, int extra); } ////// Oddly named because we have unmanged code we keep in [....] with this that /// has this name. /// internal class DeltaDelta : DataXform { private long _d_i_1 = 0; private long _d_i_2 = 0; internal DeltaDelta() { } ////// Your guess is as good as mine /// /// /// /// internal override void Transform(int data, ref int xfData, ref int extra) { // Find out the delta delta of the number // Its absolute value could potentially be more than LONG_MAX long llxfData = (data + _d_i_2 - (_d_i_1 << 1)); // Save the state info for next number _d_i_2 = _d_i_1; _d_i_1 = data; // Most of the cases, the delta delta will be less than LONG_MAX if ( Int32.MaxValue >= MathHelper.AbsNoThrow(llxfData) ) { // In those cases, we set 0 to nExtra and // assign the delta delta to xfData extra = 0; xfData = (int)llxfData; } else { long absLxfData = MathHelper.AbsNoThrow(llxfData); // Additional bits in most significant 32 bits extra = (int)(absLxfData >> (sizeof(int) << 3)); // Left sift one bit and append sign bit the the LSB extra = (extra << 1) | ((llxfData < 0) ? 1 : 0); // Save least significant 32 bits in xfData xfData = (int)((unchecked((uint)~0 & absLxfData))); } } ////// /// internal override void ResetState() { _d_i_1 = 0; _d_i_2 = 0; } ////// Your guess is as good as mine /// /// /// ///internal override int InverseTransform(int xfData, int extra) { long llxfData; // Find out whether the original delta delta exceeded the limit if (0 != extra) { // Yes, we had |delta delta| more than LONG_MAX // Find out the original delta delta was negative bool negative = ((extra & 0x01) != 0); // Construct the |DelDel| from xfData and nExtra llxfData = (((long)extra >> 1) << (sizeof(int) << 3)) | (unchecked((uint)~0) & xfData); // Do the sign adjustment llxfData = (negative) ? -llxfData : llxfData; } else { llxfData = xfData; } // Reconstruct the number from delta delta long orgData = (llxfData - _d_i_2 + (_d_i_1 << 1)); _d_i_2 = _d_i_1; _d_i_1 = orgData; // Typecast to LONG and return it return (int)orgData; } } } // 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
- formatter.cs
- ConfigurationException.cs
- Authorization.cs
- TailPinnedEventArgs.cs
- SqlDataSourceQueryEditor.cs
- WebZone.cs
- Point3DCollectionValueSerializer.cs
- SqlWriter.cs
- InkSerializer.cs
- PeerNearMe.cs
- LocalizedNameDescriptionPair.cs
- SecurityKeyIdentifierClause.cs
- ListenerConnectionDemuxer.cs
- ImageConverter.cs
- BitmapCodecInfo.cs
- PageBreakRecord.cs
- MenuBase.cs
- selecteditemcollection.cs
- OracleMonthSpan.cs
- safesecurityhelperavalon.cs
- recordstatefactory.cs
- GridViewRowPresenterBase.cs
- connectionpool.cs
- autovalidator.cs
- HttpCacheVaryByContentEncodings.cs
- ScrollBar.cs
- ReadOnlyDataSourceView.cs
- _HeaderInfo.cs
- TrackingWorkflowEventArgs.cs
- SizeAnimation.cs
- RadioButtonBaseAdapter.cs
- ScriptReferenceBase.cs
- VarRefManager.cs
- BamlRecordReader.cs
- StringAnimationUsingKeyFrames.cs
- DesignerSerializerAttribute.cs
- RtfToXamlReader.cs
- DrawingGroup.cs
- ModelEditingScope.cs
- DataColumn.cs
- XmlArrayItemAttribute.cs
- MailAddress.cs
- LinqDataSource.cs
- SemanticBasicElement.cs
- Visual.cs
- OdbcTransaction.cs
- Help.cs
- ProviderConnectionPoint.cs
- DockPattern.cs
- FlowDecisionLabelFeature.cs
- DropShadowBitmapEffect.cs
- UrlMappingsSection.cs
- ValueExpressions.cs
- ImageCodecInfo.cs
- FileStream.cs
- TypedTableBaseExtensions.cs
- PolicyUnit.cs
- ProfileModule.cs
- UnrecognizedPolicyAssertionElement.cs
- ComEventsMethod.cs
- RemoteWebConfigurationHostStream.cs
- BinaryParser.cs
- HelpKeywordAttribute.cs
- SettingsPropertyValueCollection.cs
- CornerRadius.cs
- SamlAttribute.cs
- StackOverflowException.cs
- InputElement.cs
- ChannelManager.cs
- DesignerAttribute.cs
- RequiredAttributeAttribute.cs
- ISAPIWorkerRequest.cs
- ExpressionLexer.cs
- OneOfTypeConst.cs
- HiddenField.cs
- SafeBitVector32.cs
- SecurityContextSecurityToken.cs
- AtomMaterializer.cs
- KeyBinding.cs
- RegistryConfigurationProvider.cs
- _NegoState.cs
- ResolveMatchesApril2005.cs
- PeerPresenceInfo.cs
- NetMsmqSecurityElement.cs
- ConstructorBuilder.cs
- DetailsViewCommandEventArgs.cs
- wgx_exports.cs
- SQLRoleProvider.cs
- SqlCacheDependencyDatabase.cs
- OracleTimeSpan.cs
- PasswordDeriveBytes.cs
- FullTextLine.cs
- PagerSettings.cs
- VScrollProperties.cs
- ComboBox.cs
- DataExchangeServiceBinder.cs
- DataTableReader.cs
- MarshalByValueComponent.cs
- ClientProxyGenerator.cs
- Int32Collection.cs