Exemplo n.º 1
0
        public static void AddColorspaceConverter(PipelineContext ctx)
        {
            if (ctx.SourceColorProfile is null || ctx.DestColorProfile is null || ctx.SourceColorProfile == ctx.DestColorProfile)
            {
                return;
            }

            if (ctx.SourceColorProfile.ProfileType > ColorProfileType.Matrix || ctx.DestColorProfile.ProfileType > ColorProfileType.Matrix)
            {
                AddExternalFormatConverter(ctx);

                ctx.WicContext.SourceColorContext ??= ctx.WicContext.AddRef(WicColorProfile.CreateContextFromProfile(ctx.SourceColorProfile.ProfileBytes));
                ctx.WicContext.DestColorContext ??= ctx.WicContext.AddRef(WicColorProfile.CreateContextFromProfile(ctx.DestColorProfile.ProfileBytes));

                WicTransforms.AddColorspaceConverter(ctx);

                return;
            }

            AddInternalFormatConverter(ctx, PixelValueEncoding.Linear);

            if (ctx.Source.Format.ColorRepresentation == PixelColorRepresentation.Bgr && ctx.SourceColorProfile is MatrixProfile srcProf && ctx.DestColorProfile is MatrixProfile dstProf)
            {
                var matrix = srcProf.Matrix * dstProf.InverseMatrix;
                if (matrix != default && !matrix.IsIdentity)
                {
                    ctx.Source = new ColorMatrixTransformInternal(ctx.Source, matrix);
                }
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        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;
        }