示例#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);
                }
            }
        }
示例#2
0
        internal ProcessingPipeline(PipelineContext ctx)
        {
            Context = ctx;
            source  = new Lazy <IPixelSource>(() => {
                MagicTransforms.AddExternalFormatConverter(Context);
                WicTransforms.AddPixelFormatConverter(Context, false);

                return(Context.Source.AsIPixelSource());
            });
        }