Skip to content

Commit d448321

Browse files
committed
fix SA1117
1 parent bd2d455 commit d448321

File tree

4 files changed

+82
-23
lines changed

4 files changed

+82
-23
lines changed

src/ImageSharp/Formats/Webp/AlphaEncoder.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ public static IMemoryOwner<byte> EncodeAlpha<TPixel>(
4343
{
4444
const WebpEncodingMethod effort = WebpEncodingMethod.Default;
4545
const int quality = 8 * (int)effort;
46-
using Vp8LEncoder lossLessEncoder = new Vp8LEncoder(memoryAllocator, configuration, width, height, quality,
47-
skipMetadata, effort, WebpTransparentColorMode.Preserve, false, 0);
46+
using Vp8LEncoder lossLessEncoder = new(
47+
memoryAllocator,
48+
configuration,
49+
width,
50+
height,
51+
quality,
52+
skipMetadata,
53+
effort,
54+
WebpTransparentColorMode.Preserve,
55+
false,
56+
0);
4857

4958
// The transparency information will be stored in the green channel of the ARGB quadruplet.
5059
// The green channel is allowed extra transformation steps in the specification -- unlike the other channels,

src/ImageSharp/Formats/Webp/Lossy/WebpLossyDecoder.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ public void Decode<TPixel>(Buffer2D<TPixel> pixels, int width, int height, WebpI
7676
Vp8Proba proba = new Vp8Proba();
7777
Vp8SegmentHeader vp8SegmentHeader = this.ParseSegmentHeader(proba);
7878

79-
using (Vp8Decoder decoder = new Vp8Decoder(info.Vp8FrameHeader, pictureHeader, vp8SegmentHeader, proba,
79+
using (Vp8Decoder decoder = new Vp8Decoder(
80+
info.Vp8FrameHeader,
81+
pictureHeader,
82+
vp8SegmentHeader,
83+
proba,
8084
this.memoryAllocator))
8185
{
8286
Vp8Io io = InitializeVp8Io(decoder, pictureHeader);
@@ -102,8 +106,13 @@ public void Decode<TPixel>(Buffer2D<TPixel> pixels, int width, int height, WebpI
102106

103107
if (info.Features?.Alpha == true)
104108
{
105-
using (AlphaDecoder alphaDecoder = new AlphaDecoder(width, height, alphaData,
106-
info.Features.AlphaChunkHeader, this.memoryAllocator, this.configuration))
109+
using (AlphaDecoder alphaDecoder = new AlphaDecoder(
110+
width,
111+
height,
112+
alphaData,
113+
info.Features.AlphaChunkHeader,
114+
this.memoryAllocator,
115+
this.configuration))
107116
{
108117
alphaDecoder.Decode();
109118
DecodePixelValues(width, height, decoder.Pixels.Memory.Span, pixels, alphaDecoder.Alpha);

src/ImageSharp/Formats/Webp/WebpDecoderCore.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,30 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
9191
{
9292
if (this.webImageInfo.Features is { Animation: true })
9393
{
94-
using WebpAnimationDecoder animationDecoder = new WebpAnimationDecoder(this.memoryAllocator,
95-
this.configuration, this.maxFrames, this.backgroundColorHandling);
94+
using WebpAnimationDecoder animationDecoder = new WebpAnimationDecoder(
95+
this.memoryAllocator,
96+
this.configuration,
97+
this.maxFrames,
98+
this.backgroundColorHandling);
9699
return animationDecoder.Decode<TPixel>(stream, this.webImageInfo.Features, this.webImageInfo.Width, this.webImageInfo.Height, fileSize);
97100
}
98101

99102
image = new Image<TPixel>(this.configuration, (int)this.webImageInfo.Width, (int)this.webImageInfo.Height, metadata);
100103
Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer();
101104
if (this.webImageInfo.IsLossless)
102105
{
103-
WebpLosslessDecoder losslessDecoder = new WebpLosslessDecoder(this.webImageInfo.Vp8LBitReader,
104-
this.memoryAllocator, this.configuration);
106+
WebpLosslessDecoder losslessDecoder = new WebpLosslessDecoder(
107+
this.webImageInfo.Vp8LBitReader,
108+
this.memoryAllocator,
109+
this.configuration);
105110
losslessDecoder.Decode(pixels, image.Width, image.Height);
106111
}
107112
else
108113
{
109-
WebpLossyDecoder lossyDecoder = new WebpLossyDecoder(this.webImageInfo.Vp8BitReader,
110-
this.memoryAllocator, this.configuration);
114+
WebpLossyDecoder lossyDecoder = new WebpLossyDecoder(
115+
this.webImageInfo.Vp8BitReader,
116+
this.memoryAllocator,
117+
this.configuration);
111118
lossyDecoder.Decode(pixels, image.Width, image.Height, this.webImageInfo, this.alphaData);
112119
}
113120

src/ImageSharp/Formats/Webp/WebpEncoderCore.cs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,35 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
129129

130130
if (lossless)
131131
{
132-
using Vp8LEncoder encoder = new Vp8LEncoder(this.memoryAllocator, this.configuration, image.Width,
133-
image.Height, this.quality, this.skipMetadata, this.method, this.transparentColorMode,
134-
this.nearLossless, this.nearLosslessQuality);
132+
using Vp8LEncoder encoder = new Vp8LEncoder(
133+
this.memoryAllocator,
134+
this.configuration,
135+
image.Width,
136+
image.Height,
137+
this.quality,
138+
this.skipMetadata,
139+
this.method,
140+
this.transparentColorMode,
141+
this.nearLossless,
142+
this.nearLosslessQuality);
135143

136144
bool hasAnimation = image.Frames.Count > 1;
137145
encoder.EncodeHeader(image, stream, hasAnimation);
138146
if (hasAnimation)
139147
{
140148
foreach (ImageFrame<TPixel> imageFrame in image.Frames)
141149
{
142-
using Vp8LEncoder enc = new Vp8LEncoder(this.memoryAllocator, this.configuration, image.Width,
143-
image.Height, this.quality, this.skipMetadata, this.method, this.transparentColorMode,
144-
this.nearLossless, this.nearLosslessQuality);
150+
using Vp8LEncoder enc = new Vp8LEncoder(
151+
this.memoryAllocator,
152+
this.configuration,
153+
image.Width,
154+
image.Height,
155+
this.quality,
156+
this.skipMetadata,
157+
this.method,
158+
this.transparentColorMode,
159+
this.nearLossless,
160+
this.nearLosslessQuality);
145161

146162
enc.Encode(imageFrame, stream, true);
147163
}
@@ -155,18 +171,36 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
155171
}
156172
else
157173
{
158-
using Vp8Encoder encoder = new Vp8Encoder(this.memoryAllocator, this.configuration, image.Width,
159-
image.Height, this.quality, this.skipMetadata, this.method, this.entropyPasses, this.filterStrength,
160-
this.spatialNoiseShaping, this.alphaCompression);
174+
using Vp8Encoder encoder = new Vp8Encoder(
175+
this.memoryAllocator,
176+
this.configuration,
177+
image.Width,
178+
image.Height,
179+
this.quality,
180+
this.skipMetadata,
181+
this.method,
182+
this.entropyPasses,
183+
this.filterStrength,
184+
this.spatialNoiseShaping,
185+
this.alphaCompression);
161186
if (image.Frames.Count > 1)
162187
{
163188
encoder.EncodeHeader(image, stream, false, true);
164189

165190
foreach (ImageFrame<TPixel> imageFrame in image.Frames)
166191
{
167-
using Vp8Encoder enc = new Vp8Encoder(this.memoryAllocator, this.configuration, image.Width,
168-
image.Height, this.quality, this.skipMetadata, this.method, this.entropyPasses,
169-
this.filterStrength, this.spatialNoiseShaping, this.alphaCompression);
192+
using Vp8Encoder enc = new Vp8Encoder(
193+
this.memoryAllocator,
194+
this.configuration,
195+
image.Width,
196+
image.Height,
197+
this.quality,
198+
this.skipMetadata,
199+
this.method,
200+
this.entropyPasses,
201+
this.filterStrength,
202+
this.spatialNoiseShaping,
203+
this.alphaCompression);
170204

171205
enc.EncodeAnimation(imageFrame, stream);
172206
}

0 commit comments

Comments
 (0)