Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / System / Windows / Media / ColorTransformHelper.cs / 1 / ColorTransformHelper.cs
//------------------------------------------------------------------------------
// Microsoft Windows Client Platform
// Copyright (c) Microsoft Corporation, 2001, 2002, 2003
//
// File: ColorTransformHelper.cs
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using MS.Internal;
using MS.Win32;
using System.Security;
using System.Security.Permissions;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Win32.SafeHandles;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods;
namespace System.Windows.Media
{
#region ColorTransformHandle
internal class ColorTransformHandle : SafeHandleZeroOrMinusOneIsInvalid
{
///
/// Use this constructor if the handle exists at construction time.
///
///
/// Critical: The ctor of the base class requires SecurityPermission
///
[SecurityCritical]
internal ColorTransformHandle()
: base(true)
{
}
///
/// Use this constructor if the handle exists at construction time.
///
///
/// Critical: The ctor of the base class requires SecurityPermission
/// This code calls SetHandle
///
[SecurityCritical]
internal ColorTransformHandle(IntPtr profile)
: base(true)
{
SetHandle(profile);
}
///
/// Critical - calls unmanaged code, not treat as safe because you must
/// validate that handle is a valid color transform handle.
///
[SecurityCritical]
protected override bool ReleaseHandle()
{
if (!UnsafeNativeMethods.Mscms.DeleteColorTransform(handle))
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
return true;
}
}
#endregion
#region ColorTransformHelper
///
/// Class to call into MSCMS color transform APIs
///
internal class ColorTransformHelper
{
/// Constructor
internal ColorTransformHelper()
{
}
/// Creates an ICM Profile Transform
/// Retrieves a standard color space profile
///
/// SecurityCritical: Calls unmanaged code, accepts SafeHandles as input.
///
[SecurityCritical]
internal void CreateTransform(SafeProfileHandle sourceProfile, SafeProfileHandle destinationProfile)
{
if (sourceProfile == null || sourceProfile.IsInvalid)
{
throw new ArgumentNullException("sourceProfile");
}
if (destinationProfile == null || destinationProfile.IsInvalid)
{
throw new ArgumentNullException("destinationProfile");
}
IntPtr[] handles = new IntPtr[2];
bool success = true;
sourceProfile.DangerousAddRef(ref success);
Debug.Assert(success);
destinationProfile.DangerousAddRef(ref success);
Debug.Assert(success);
try
{
handles[0] = sourceProfile.DangerousGetHandle();
handles[1] = destinationProfile.DangerousGetHandle();
UInt32[] dwIntents = new UInt32[2] {INTENT_PERCEPTUAL, INTENT_PERCEPTUAL};
// No need to get rid of the old handle as it will get GC'ed
_transformHandle = UnsafeNativeMethods.Mscms.CreateMultiProfileTransform(
handles,
(UInt32)handles.Length,
dwIntents,
(UInt32)dwIntents.Length,
BEST_MODE | USE_RELATIVE_COLORIMETRIC,
0
);
}
finally
{
sourceProfile.DangerousRelease();
destinationProfile.DangerousRelease();
}
if (_transformHandle == null || _transformHandle.IsInvalid)
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
}
/// Translates the colors
/// Retrieves a standard color space profile
///
/// SecurityCritical: Calls unmanaged code, accepts IntPtr/unverified data.
///
[SecurityCritical]
internal void TranslateColors(IntPtr paInputColors, UInt32 numColors, UInt32 inputColorType, IntPtr paOutputColors, UInt32 outputColorType)
{
if (_transformHandle == null || _transformHandle.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.Image_ColorTransformInvalid));
}
HRESULT.Check(UnsafeNativeMethods.Mscms.TranslateColors(
_transformHandle,
paInputColors,
numColors,
inputColorType,
paOutputColors,
outputColorType));
}
#region Data members
/// Handle for the ICM Color Transform
private ColorTransformHandle _transformHandle;
/// Intents
private const UInt32 INTENT_PERCEPTUAL = 0;
private const UInt32 INTENT_RELATIVE_COLORIMETRIC = 1;
private const UInt32 INTENT_SATURATION = 2;
private const UInt32 INTENT_ABSOLUTE_COLORIMETRIC = 3;
/// Flags for create color transform
private const UInt32 PROOF_MODE = 0x00000001;
private const UInt32 NORMAL_MODE = 0x00000002;
private const UInt32 BEST_MODE = 0x00000003;
private const UInt32 ENABLE_GAMUT_CHECKING = 0x00010000;
private const UInt32 USE_RELATIVE_COLORIMETRIC = 0x00020000;
private const UInt32 FAST_TRANSLATE = 0x00040000;
#endregion
}
#endregion
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// Microsoft Windows Client Platform
// Copyright (c) Microsoft Corporation, 2001, 2002, 2003
//
// File: ColorTransformHelper.cs
//-----------------------------------------------------------------------------
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using MS.Internal;
using MS.Win32;
using System.Security;
using System.Security.Permissions;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Win32.SafeHandles;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods;
namespace System.Windows.Media
{
#region ColorTransformHandle
internal class ColorTransformHandle : SafeHandleZeroOrMinusOneIsInvalid
{
///
/// Use this constructor if the handle exists at construction time.
///
///
/// Critical: The ctor of the base class requires SecurityPermission
///
[SecurityCritical]
internal ColorTransformHandle()
: base(true)
{
}
///
/// Use this constructor if the handle exists at construction time.
///
///
/// Critical: The ctor of the base class requires SecurityPermission
/// This code calls SetHandle
///
[SecurityCritical]
internal ColorTransformHandle(IntPtr profile)
: base(true)
{
SetHandle(profile);
}
///
/// Critical - calls unmanaged code, not treat as safe because you must
/// validate that handle is a valid color transform handle.
///
[SecurityCritical]
protected override bool ReleaseHandle()
{
if (!UnsafeNativeMethods.Mscms.DeleteColorTransform(handle))
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
return true;
}
}
#endregion
#region ColorTransformHelper
///
/// Class to call into MSCMS color transform APIs
///
internal class ColorTransformHelper
{
/// Constructor
internal ColorTransformHelper()
{
}
/// Creates an ICM Profile Transform
/// Retrieves a standard color space profile
///
/// SecurityCritical: Calls unmanaged code, accepts SafeHandles as input.
///
[SecurityCritical]
internal void CreateTransform(SafeProfileHandle sourceProfile, SafeProfileHandle destinationProfile)
{
if (sourceProfile == null || sourceProfile.IsInvalid)
{
throw new ArgumentNullException("sourceProfile");
}
if (destinationProfile == null || destinationProfile.IsInvalid)
{
throw new ArgumentNullException("destinationProfile");
}
IntPtr[] handles = new IntPtr[2];
bool success = true;
sourceProfile.DangerousAddRef(ref success);
Debug.Assert(success);
destinationProfile.DangerousAddRef(ref success);
Debug.Assert(success);
try
{
handles[0] = sourceProfile.DangerousGetHandle();
handles[1] = destinationProfile.DangerousGetHandle();
UInt32[] dwIntents = new UInt32[2] {INTENT_PERCEPTUAL, INTENT_PERCEPTUAL};
// No need to get rid of the old handle as it will get GC'ed
_transformHandle = UnsafeNativeMethods.Mscms.CreateMultiProfileTransform(
handles,
(UInt32)handles.Length,
dwIntents,
(UInt32)dwIntents.Length,
BEST_MODE | USE_RELATIVE_COLORIMETRIC,
0
);
}
finally
{
sourceProfile.DangerousRelease();
destinationProfile.DangerousRelease();
}
if (_transformHandle == null || _transformHandle.IsInvalid)
{
HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
}
/// Translates the colors
/// Retrieves a standard color space profile
///
/// SecurityCritical: Calls unmanaged code, accepts IntPtr/unverified data.
///
[SecurityCritical]
internal void TranslateColors(IntPtr paInputColors, UInt32 numColors, UInt32 inputColorType, IntPtr paOutputColors, UInt32 outputColorType)
{
if (_transformHandle == null || _transformHandle.IsInvalid)
{
throw new InvalidOperationException(SR.Get(SRID.Image_ColorTransformInvalid));
}
HRESULT.Check(UnsafeNativeMethods.Mscms.TranslateColors(
_transformHandle,
paInputColors,
numColors,
inputColorType,
paOutputColors,
outputColorType));
}
#region Data members
/// Handle for the ICM Color Transform
private ColorTransformHandle _transformHandle;
/// Intents
private const UInt32 INTENT_PERCEPTUAL = 0;
private const UInt32 INTENT_RELATIVE_COLORIMETRIC = 1;
private const UInt32 INTENT_SATURATION = 2;
private const UInt32 INTENT_ABSOLUTE_COLORIMETRIC = 3;
/// Flags for create color transform
private const UInt32 PROOF_MODE = 0x00000001;
private const UInt32 NORMAL_MODE = 0x00000002;
private const UInt32 BEST_MODE = 0x00000003;
private const UInt32 ENABLE_GAMUT_CHECKING = 0x00010000;
private const UInt32 USE_RELATIVE_COLORIMETRIC = 0x00020000;
private const UInt32 FAST_TRANSLATE = 0x00040000;
#endregion
}
#endregion
}
// 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
- PropertyValueChangedEvent.cs
- AutomationIdentifierGuids.cs
- WindowsServiceElement.cs
- ArrayExtension.cs
- FixedSOMContainer.cs
- StrokeNodeOperations.cs
- SamlAuthorizationDecisionStatement.cs
- MetadataSerializer.cs
- LinqDataSourceInsertEventArgs.cs
- InkCanvasAutomationPeer.cs
- DefaultValueTypeConverter.cs
- MetadataArtifactLoaderResource.cs
- NodeCounter.cs
- ClientFactory.cs
- UpdateManifestForBrowserApplication.cs
- IDReferencePropertyAttribute.cs
- NumericPagerField.cs
- HtmlInputFile.cs
- XamlTemplateSerializer.cs
- BindingList.cs
- CommandValueSerializer.cs
- LogAppendAsyncResult.cs
- QilIterator.cs
- TableCell.cs
- SwitchLevelAttribute.cs
- JoinGraph.cs
- PaginationProgressEventArgs.cs
- UniqueIdentifierService.cs
- ImageIndexEditor.cs
- QueryContinueDragEvent.cs
- LinqDataView.cs
- DashStyle.cs
- FileDialog.cs
- DataRowCollection.cs
- VirtualDirectoryMappingCollection.cs
- CaretElement.cs
- DBAsyncResult.cs
- SerialErrors.cs
- Canvas.cs
- FixedSOMImage.cs
- TextElementEditingBehaviorAttribute.cs
- WebPartZone.cs
- GuidelineCollection.cs
- ProcessStartInfo.cs
- ConstraintConverter.cs
- OneOfTypeConst.cs
- KeyGestureConverter.cs
- AuthenticatedStream.cs
- TypeBuilderInstantiation.cs
- DataControlFieldCell.cs
- PerformanceCounterManager.cs
- X509SubjectKeyIdentifierClause.cs
- MarkupCompiler.cs
- SerializationStore.cs
- FlowDocumentPaginator.cs
- localization.cs
- AppLevelCompilationSectionCache.cs
- ExpressionBuilderContext.cs
- ObjectPersistData.cs
- RootCodeDomSerializer.cs
- MetafileHeaderWmf.cs
- HighContrastHelper.cs
- TokenBasedSetEnumerator.cs
- SqlWorkflowInstanceStoreLock.cs
- BlurBitmapEffect.cs
- OleDragDropHandler.cs
- LinqMaximalSubtreeNominator.cs
- TextServicesDisplayAttributePropertyRanges.cs
- ToolStripGrip.cs
- Adorner.cs
- EncodingTable.cs
- MessageFilter.cs
- CdpEqualityComparer.cs
- WinFormsUtils.cs
- Pointer.cs
- ExpressionSelection.cs
- Directory.cs
- RestClientProxyHandler.cs
- LockedHandleGlyph.cs
- StreamInfo.cs
- GenericsInstances.cs
- Base64Encoding.cs
- Component.cs
- CommandDevice.cs
- ExpressionEvaluator.cs
- ModelPerspective.cs
- TextPattern.cs
- ParameterCollection.cs
- SqlDataSourceSummaryPanel.cs
- InvalidOperationException.cs
- WpfWebRequestHelper.cs
- CodeConstructor.cs
- AutoCompleteStringCollection.cs
- OdbcReferenceCollection.cs
- SecurityRuntime.cs
- WindowsNonControl.cs
- MessageDecoder.cs
- QueryableDataSourceHelper.cs
- ObservableCollection.cs
- ArcSegment.cs