/// <summary>
 /// Initializes a new instance of the <see cref="ColorProfileConverter"/> class.
 /// </summary>
 public ColorProfileConverter()
 {
     documentProfile         = null;
     monitorProfile          = null;
     transform               = null;
     colorCorrectionRequired = false;
     disposed = false;
 }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (!disposed)
            {
                if (documentProfile != null)
                {
                    documentProfile.Dispose();
                    documentProfile = null;
                }
                if (monitorProfile != null)
                {
                    monitorProfile.Dispose();
                    monitorProfile = null;
                }
                if (transform != null)
                {
                    transform.Dispose();
                    transform = null;
                }

                disposed = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (!disposed)
            {
                if (documentProfile != null)
                {
                    documentProfile.Dispose();
                    documentProfile = null;
                }

                if (monitorProfile != null)
                {
                    monitorProfile.Dispose();
                    monitorProfile = null;
                }

                if (transform != null)
                {
                    transform.Dispose();
                    transform = null;
                }

                if (interleavedCMYKSurface != null)
                {
                    interleavedCMYKSurface.Dispose();
                    interleavedCMYKSurface = null;
                }

                if (interleavedRGBSurface != null)
                {
                    interleavedRGBSurface.Dispose();
                    interleavedRGBSurface = null;
                }

                disposed = true;
            }
        }
Esempio n. 4
0
 private static extern bool TranslateColors(SafeTransformHandle hTransform, IntPtr paInputColors, uint nColors, COLOR_TYPE ctInput, IntPtr paOutputColors, COLOR_TYPE ctOutput);
Esempio n. 5
0
 private static extern unsafe bool TranslateBitmapBits(SafeTransformHandle hTransform, void *pSrcBits, mscmsPxFormat bmFormat, uint dwWidth, uint dwHeight, uint dwInputStride, void *pDestBits, mscmsPxFormat bmOutput, uint dwOutputStride, IntPtr pfnCallBack, IntPtr lParam);
        private static int CreateColorTransform(SafeProfileHandle input, SafeProfileHandle output, out SafeTransformHandle handle)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }
#if DEBUG
            System.Diagnostics.Debug.Assert(!input.IsInvalid, "Input handle is invalid.");
            System.Diagnostics.Debug.Assert(!output.IsInvalid, "Output handle is invalid.");
#endif

            handle = null;

            int error = NativeConstants.ERROR_SUCCESS;

            bool inputNeedsRelease  = false;
            bool outputNeedsRelease = false;
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                input.DangerousAddRef(ref inputNeedsRelease);
                output.DangerousAddRef(ref outputNeedsRelease);

                IntPtr[] profiles = new IntPtr[2] {
                    input.DangerousGetHandle(), output.DangerousGetHandle()
                };
                uint[] intents = new uint[2]
                {
                    (uint)NativeEnums.Mscms.RenderingIntent.Perceptual,
                    (uint)NativeEnums.Mscms.RenderingIntent.Perceptual
                };

                handle = UnsafeNativeMethods.Mscms.CreateMultiProfileTransform(
                    profiles,
                    (uint)profiles.Length,
                    intents,
                    (uint)intents.Length,
                    NativeEnums.Mscms.TransformFlags.BestMode,
                    NativeConstants.CMM_FROM_PROFILE
                    );

                if (handle == null || handle.IsInvalid)
                {
                    error = Marshal.GetLastWin32Error();
                }
            }
            finally
            {
                if (inputNeedsRelease)
                {
                    input.DangerousRelease();
                }
                if (outputNeedsRelease)
                {
                    output.DangerousRelease();
                }
            }

            return(error);
        }