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.SourceColorContext == null; WicTransforms.AddExifRotator(ctx); WicTransforms.AddPlanarCache(ctx); MagicTransforms.AddInternalFormatConverter(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.Height = (int)Math.Ceiling(ctx.Settings.Height / 2d); } if (subsample == ChromaSubsampleMode.Subsample420 || subsample == ChromaSubsampleMode.Subsample422) { ctx.Settings.Width = (int)Math.Ceiling(ctx.Settings.Width / 2d); } } MagicTransforms.AddInternalFormatConverter(ctx); MagicTransforms.AddHighQualityScaler(ctx); MagicTransforms.AddExternalFormatConverter(ctx); ctx.SwitchPlanarSource(WicPlane.Luma); if (!savePlanar) { WicTransforms.AddPlanarConverter(ctx); WicTransforms.AddColorspaceConverter(ctx); } } else { WicTransforms.AddNativeScaler(ctx); WicTransforms.AddExifRotator(ctx); WicTransforms.AddConditionalCache(ctx); WicTransforms.AddCropper(ctx); WicTransforms.AddPixelFormatConverter(ctx); WicTransforms.AddScaler(ctx, true); MagicTransforms.AddInternalFormatConverter(ctx); MagicTransforms.AddHighQualityScaler(ctx); MagicTransforms.AddMatte(ctx); MagicTransforms.AddUnsharpMask(ctx); MagicTransforms.AddExternalFormatConverter(ctx); WicTransforms.AddColorspaceConverter(ctx); } }