Example #1
0
        public static unsafe void AddColorProfileReader(PipelineContext ctx)
        {
            var mode = ctx.Settings.ColorProfileMode;

            if (mode == ColorProfileMode.Ignore)
            {
                return;
            }

            var fmt = ctx.ImageFrame is IYccImageFrame ? PixelFormat.Bgr24Bpp : ctx.Source.Format;

            if (ctx.ImageFrame is WicImageFrame wicFrame)
            {
                var profile = WicColorProfile.GetSourceProfile(wicFrame.ColorProfileSource, mode);
                ctx.SourceColorProfile            = profile.ParsedProfile;
                ctx.WicContext.SourceColorContext = profile.WicColorContext;
                ctx.WicContext.DestColorContext   = WicColorProfile.GetDestProfile(wicFrame.ColorProfileSource, mode).WicColorContext;
            }
            else
            {
                var profile = ColorProfile.Cache.GetOrAdd(ctx.ImageFrame.IccProfile);
                ctx.SourceColorProfile = profile.IsValid && profile.IsCompatibleWith(fmt) ? ColorProfile.GetSourceProfile(profile, mode) : ColorProfile.GetDefaultFor(fmt);
            }

            ctx.DestColorProfile = ColorProfile.GetDestProfile(ctx.SourceColorProfile, mode);
        }