/// <summary> /// Creates a new instance of the <see cref="CC_ExecuteMethod"/> class /// </summary> /// <param name="method">The method to execute</param> public CC_ExecuteMethod(TransformToDelegate method) { if (method == null) { throw new ArgumentNullException(nameof(method)); } MethodTTo = method; }
/// <summary> /// Creates a new instance of the <see cref="ConversionData"/> class /// </summary> /// <param name="inColor">The input color</param> /// <param name="outColor">The output color</param> public ConversionData(Color inColor, Color outColor) { if (inColor == null || outColor == null) { throw new ArgumentNullException(); } Type inColorType = inColor.GetType(); Type outColorType = inColor.GetType(); Colorspace inSpace = inColor.Space; Colorspace outSpace = outColor.Space; Type inSpaceType = inSpace.GetType(); Type outSpaceType = outSpace.GetType(); IsCARequired = !inSpace.Equals(outSpace); IsDifferentWP = inSpace.ReferenceWhite != outSpace.ReferenceWhite; InTransform = inSpace.GetTransformation(true); OutTransform = outSpace.GetTransformation(false); _InSpaceData = inSpace.GetData(true); _OutSpaceData = outSpace.GetData(false); if (_InSpaceData != null) { InSpaceData = _InSpaceData.DataPointer; } if (_OutSpaceData != null) { OutSpaceData = _OutSpaceData.DataPointer; } ColVars1Handle = GCHandle.Alloc(ColVars1Array, GCHandleType.Pinned); ColVars2Handle = GCHandle.Alloc(ColVars2Array, GCHandleType.Pinned); VarsHandle = GCHandle.Alloc(VarsArray, GCHandleType.Pinned); InWPHandle = GCHandle.Alloc(inSpace.ReferenceWhite.XYZ, GCHandleType.Pinned); OutWPHandle = GCHandle.Alloc(outSpace.ReferenceWhite.XYZ, GCHandleType.Pinned); InWPCrHandle = GCHandle.Alloc(inSpace.ReferenceWhite.Cxy, GCHandleType.Pinned); OutWPCrHandle = GCHandle.Alloc(outSpace.ReferenceWhite.Cxy, GCHandleType.Pinned); ColVars1 = (double *)ColVars1Handle.AddrOfPinnedObject(); ColVars2 = (double *)ColVars2Handle.AddrOfPinnedObject(); Vars = (double *)VarsHandle.AddrOfPinnedObject(); InWP = (double *)InWPHandle.AddrOfPinnedObject(); OutWP = (double *)OutWPHandle.AddrOfPinnedObject(); InWPCr = (double *)InWPCrHandle.AddrOfPinnedObject(); OutWPCr = (double *)OutWPCrHandle.AddrOfPinnedObject(); AdditionalDataHandle = new List <ArrayData>(); }
/// <summary> /// Releases all allocated resources /// </summary> /// <param name="managed">True if called by user, false if called by finalizer</param> protected virtual void Dispose(bool managed) { if (!IsDisposed) { if (managed) { InTransform = null; OutTransform = null; VarsArray = null; } _CAData?.Dispose(); _InSpaceData?.Dispose(); _OutSpaceData?.Dispose(); _InICCData?.Dispose(); _OutICCData?.Dispose(); if (ColVars1Handle.IsAllocated) { ColVars1Handle.Free(); } if (ColVars2Handle.IsAllocated) { ColVars2Handle.Free(); } if (VarsHandle.IsAllocated) { VarsHandle.Free(); } if (InWPHandle.IsAllocated) { InWPHandle.Free(); } if (OutWPHandle.IsAllocated) { OutWPHandle.Free(); } if (InWPCrHandle.IsAllocated) { InWPCrHandle.Free(); } if (OutWPCrHandle.IsAllocated) { OutWPCrHandle.Free(); } if (CAMatrixHandle.IsAllocated) { CAMatrixHandle.Free(); } if (AdditionalDataPointer != IntPtr.Zero) { Marshal.FreeHGlobal(AdditionalDataPointer); } if (AdditionalDataHandle != null) { foreach (var data in AdditionalDataHandle) { data?.Dispose(); } } _IsDisposed = true; } }