Exemple #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);
        }
        public static void AddColorProfileReader(PipelineContext ctx)
        {
            var fmt = ctx.ImageFrame is IYccImageFrame?PixelFormat.FromGuid(PixelFormats.Bgr24bpp) : ctx.Source.Format;

            if (ctx.ImageFrame is WicImageFrame wicFrame)
            {
                ctx.WicContext.SourceColorContext = wicFrame.ColorProfileSource.WicColorContext;
                ctx.SourceColorProfile            = wicFrame.ColorProfileSource.ParsedProfile;
            }
            else
            {
                var profile = ColorProfile.Cache.GetOrAdd(ctx.ImageFrame.IccProfile);
                if (profile.IsValid && profile.IsCompatibleWith(fmt) && !profile.IsSrgb)
                {
                    ctx.WicContext.SourceColorContext = ctx.WicContext.AddRef(WicColorProfile.CreateContextFromProfile(profile.ProfileBytes));
                    ctx.SourceColorProfile            = profile;
                }
                else
                {
                    var wicProfile = WicColorProfile.GetDefaultFor(fmt);
                    ctx.WicContext.SourceColorContext = wicProfile.WicColorContext;
                    ctx.SourceColorProfile            = wicProfile.ParsedProfile;
                }
            }

            ctx.WicContext.DestColorContext = ctx.Settings.ColorProfileMode <= ColorProfileMode.NormalizeAndEmbed ? WicColorProfile.GetDefaultFor(fmt).WicColorContext : ctx.WicContext.SourceColorContext;
            ctx.DestColorProfile            = ctx.Settings.ColorProfileMode <= ColorProfileMode.NormalizeAndEmbed ? ColorProfile.GetDefaultFor(fmt) : ctx.SourceColorProfile;
        }