44using System ;
55using System . Runtime . CompilerServices ;
66using SixLabors . ImageSharp . Advanced ;
7- using SixLabors . ImageSharp . Formats ;
87using SixLabors . ImageSharp . Memory ;
98using SixLabors . ImageSharp . PixelFormats ;
109
@@ -17,12 +16,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
1716 internal class ResizeProcessor < TPixel > : TransformProcessor < TPixel > , IResamplingTransformImageProcessor < TPixel >
1817 where TPixel : unmanaged, IPixel < TPixel >
1918 {
19+ private readonly ResizeOptions options ;
2020 private readonly int destinationWidth ;
2121 private readonly int destinationHeight ;
2222 private readonly IResampler resampler ;
2323 private readonly Rectangle destinationRectangle ;
24- private readonly bool compand ;
25- private readonly bool premultiplyAlpha ;
2624 private Image < TPixel > destination ;
2725
2826 public ResizeProcessor ( Configuration configuration , ResizeProcessor definition , Image < TPixel > source , Rectangle sourceRectangle )
@@ -31,13 +29,12 @@ public ResizeProcessor(Configuration configuration, ResizeProcessor definition,
3129 this . destinationWidth = definition . DestinationWidth ;
3230 this . destinationHeight = definition . DestinationHeight ;
3331 this . destinationRectangle = definition . DestinationRectangle ;
34- this . resampler = definition . Sampler ;
35- this . premultiplyAlpha = definition . PremultiplyAlpha ;
36- this . compand = definition . Compand ;
32+ this . options = definition . Options ;
33+ this . resampler = definition . Options . Sampler ;
3734 }
3835
3936 /// <inheritdoc/>
40- protected override Size GetDestinationSize ( ) => new Size ( this . destinationWidth , this . destinationHeight ) ;
37+ protected override Size GetDestinationSize ( ) => new ( this . destinationWidth , this . destinationHeight ) ;
4138
4239 /// <inheritdoc/>
4340 protected override void BeforeImageApply ( Image < TPixel > destination )
@@ -62,8 +59,11 @@ public void ApplyTransform<TResampler>(in TResampler sampler)
6259 Image < TPixel > destination = this . destination ;
6360 Rectangle sourceRectangle = this . SourceRectangle ;
6461 Rectangle destinationRectangle = this . destinationRectangle ;
65- bool compand = this . compand ;
66- bool premultiplyAlpha = this . premultiplyAlpha ;
62+ bool compand = this . options . Compand ;
63+ bool premultiplyAlpha = this . options . PremultiplyAlpha ;
64+ bool shouldFill = ( this . options . Mode == ResizeMode . BoxPad || this . options . Mode == ResizeMode . Pad )
65+ && this . options . PadColor != default ;
66+ TPixel fillColor = this . options . PadColor . ToPixel < TPixel > ( ) ;
6767
6868 // Handle resize dimensions identical to the original
6969 if ( source . Width == destination . Width
@@ -91,6 +91,11 @@ public void ApplyTransform<TResampler>(in TResampler sampler)
9191 ImageFrame < TPixel > sourceFrame = source . Frames [ i ] ;
9292 ImageFrame < TPixel > destinationFrame = destination . Frames [ i ] ;
9393
94+ if ( shouldFill )
95+ {
96+ destinationFrame . Clear ( fillColor ) ;
97+ }
98+
9499 ApplyNNResizeFrameTransform (
95100 configuration ,
96101 sourceFrame ,
@@ -123,6 +128,11 @@ public void ApplyTransform<TResampler>(in TResampler sampler)
123128 ImageFrame < TPixel > sourceFrame = source . Frames [ i ] ;
124129 ImageFrame < TPixel > destinationFrame = destination . Frames [ i ] ;
125130
131+ if ( shouldFill )
132+ {
133+ destinationFrame . Clear ( fillColor ) ;
134+ }
135+
126136 ApplyResizeFrameTransform (
127137 configuration ,
128138 sourceFrame ,
0 commit comments