Exemplo n.º 1
0
        internal ProcessingPipeline(WicProcessingContext ctx)
        {
            Context = ctx;
            source  = new Lazy <IPixelSource>(() => {
                MagicTransforms.AddExternalFormatConverter(Context);
                WicTransforms.AddPixelFormatConverter(Context, false);

                return(Context.Source.AsIPixelSource());
            });
        }
Exemplo n.º 2
0
#pragma warning restore 1573

        internal static ProcessImageResult WriteOutput(PipelineContext ctx, Stream ostm)
        {
            MagicTransforms.AddExternalFormatConverter(ctx);
            WicTransforms.AddIndexedColorConverter(ctx);

            var enc = new WicEncoder(ctx, ostm.AsIStream());

            enc.WriteSource(ctx);

            return(new ProcessImageResult(ctx.UsedSettings, ctx.Stats));
        }
Exemplo n.º 3
0
        private static ProcessImageResult executePipeline(WicProcessingContext ctx, Stream ostm)
        {
            MagicTransforms.AddExternalFormatConverter(ctx);
            WicTransforms.AddIndexedColorConverter(ctx);

            var enc = new WicEncoder(ctx, ostm.AsIStream());

            enc.WriteSource(ctx);

            return(new ProcessImageResult {
                Settings = ctx.UsedSettings, Stats = ctx.Stats
            });
        }
Exemplo n.º 4
0
        /// <summary>Adds a new transform filter to the pipeline.  Because a filter may alter dimensions or pixel format of an image, filters may not be added once the <see cref="PixelSource" /> has been retrieved.</summary>
        /// <param name="transform">The <see cref="IPixelTransform" /> that implements the filter.</param>
        public void AddTransform(IPixelTransform transform)
        {
            if (source.IsValueCreated)
            {
                throw new NotSupportedException("A Transform cannot be added once the Pipeline Source is materialized");
            }

            if (transform is IPixelTransformInternal tint)
            {
                tint.Init(Context);
                return;
            }

            MagicTransforms.AddExternalFormatConverter(Context);

            transform.Init(Context.Source.AsIPixelSource());
            Context.Source = transform.AsPixelSource();
        }
Exemplo n.º 5
0
        private static void buildPipeline(WicProcessingContext ctx, bool outputPlanar = true)
        {
            var frm = new WicFrameReader(ctx, EnablePlanarPipeline);

            WicTransforms.AddMetadataReader(ctx);

            ctx.FinalizeSettings();
            ctx.Settings.UnsharpMask       = ctx.UsedSettings.UnsharpMask;
            ctx.Settings.JpegQuality       = ctx.UsedSettings.JpegQuality;
            ctx.Settings.JpegSubsampleMode = ctx.UsedSettings.JpegSubsampleMode;

            if (ctx.DecoderFrame.SupportsPlanarPipeline)
            {
                bool savePlanar = outputPlanar &&
                                  ctx.Settings.SaveFormat == FileFormat.Jpeg &&
                                  ctx.Settings.InnerRect == ctx.Settings.OuterRect &&
                                  ctx.SourceColorContext is null;

                WicTransforms.AddExifRotator(ctx);
                WicTransforms.AddPlanarCache(ctx);

                MagicTransforms.AddHighQualityScaler(ctx);
                MagicTransforms.AddUnsharpMask(ctx);
                MagicTransforms.AddExternalFormatConverter(ctx);

                ctx.SwitchPlanarSource(WicPlane.Chroma);

                if (savePlanar)
                {
                    var subsample = ctx.Settings.JpegSubsampleMode;
                    if (subsample == ChromaSubsampleMode.Subsample420)
                    {
                        ctx.Settings.InnerRect.Height = (int)Math.Ceiling(ctx.Settings.InnerRect.Height / 2d);
                    }

                    if (subsample == ChromaSubsampleMode.Subsample420 || subsample == ChromaSubsampleMode.Subsample422)
                    {
                        ctx.Settings.InnerRect.Width = (int)Math.Ceiling(ctx.Settings.InnerRect.Width / 2d);
                    }
                }

                MagicTransforms.AddHighQualityScaler(ctx);
                MagicTransforms.AddExternalFormatConverter(ctx);

                ctx.SwitchPlanarSource(WicPlane.Luma);

                if (!savePlanar)
                {
                    WicTransforms.AddPlanarConverter(ctx);
                    MagicTransforms.AddColorspaceConverter(ctx);
                    MagicTransforms.AddPad(ctx);
                }
            }
            else
            {
                WicTransforms.AddNativeScaler(ctx);
                WicTransforms.AddExifRotator(ctx);
                WicTransforms.AddConditionalCache(ctx);
                WicTransforms.AddCropper(ctx);
                MagicTransforms.AddHighQualityScaler(ctx, true);
                WicTransforms.AddPixelFormatConverter(ctx);
                WicTransforms.AddScaler(ctx, true);
                MagicTransforms.AddHighQualityScaler(ctx);
                MagicTransforms.AddColorspaceConverter(ctx);
                MagicTransforms.AddMatte(ctx);
                MagicTransforms.AddUnsharpMask(ctx);
                MagicTransforms.AddPad(ctx);
            }
        }