Beispiel #1
0
        private static ProcessImageResult processImage(WicDecoder dec, WicProcessingContext ctx, Stream ostm)
        {
            var frm = new WicFrameReader(ctx);

            WicTransforms.AddMetadataReader(ctx);

            ctx.FinalizeSettings();

            WicTransforms.AddNativeScaler(ctx);
            WicTransforms.AddExifRotator(ctx);
            WicTransforms.AddConditionalCache(ctx);
            WicTransforms.AddCropper(ctx);
            WicTransforms.AddPixelFormatConverter(ctx);
            WicTransforms.AddScaler(ctx);
            WicTransforms.AddColorspaceConverter(ctx);
            MagicTransforms.AddMatte(ctx);
            MagicTransforms.AddPad(ctx);
            WicTransforms.AddIndexedColorConverter(ctx);

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

            enc.WriteSource(ctx);

            return(new ProcessImageResult {
                Settings = ctx.UsedSettings, Stats = ctx.Stats
            });
        }
Beispiel #2
0
        private void loadInfo(WicDecoder dec, WicProcessingContext ctx)
        {
            ContainerType = ctx.Decoder.ContainerFormat;
            Frames        = new FrameInfo[ctx.Decoder.FrameCount];
            for (int i = 0; i < ctx.Decoder.FrameCount; i++)
            {
                ctx.Settings.FrameIndex = i;
                var frm = new WicFrameReader(ctx);
                WicTransforms.AddMetadataReader(ctx, basicOnly: true);

                int width  = (int)(frm.ExifOrientation.RequiresDimensionSwap() ? ctx.Source.Height : ctx.Source.Width);
                int height = (int)(frm.ExifOrientation.RequiresDimensionSwap() ? ctx.Source.Width : ctx.Source.Height);
                Frames[i] = new FrameInfo(width, height, ctx.Source.Format.AlphaRepresentation != PixelAlphaRepresentation.None, frm.ExifOrientation);
            }
        }
Beispiel #3
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);
            }
        }