Skip to content

Commit 5535823

Browse files
Fix last nullable issues
1 parent 2821506 commit 5535823

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/ImageSharp.Web/FormattedImage.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

5-
using System.Runtime.CompilerServices;
4+
using System.Diagnostics.CodeAnalysis;
65
using SixLabors.ImageSharp.Advanced;
76
using SixLabors.ImageSharp.Formats;
87
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
@@ -40,14 +39,15 @@ private FormattedImage(Image image, IImageFormat format, bool keepOpen)
4039
{
4140
this.Image = image;
4241
this.imageFormatsManager = image.GetConfiguration().ImageFormatsManager;
43-
this.Format = format;
42+
this.format = format;
43+
this.encoder = this.imageFormatsManager.GetEncoder(format);
4444
this.keepOpen = keepOpen;
4545
}
4646

4747
/// <summary>
4848
/// Gets the decoded image.
4949
/// </summary>
50-
public Image Image { get; private set; }
50+
public Image Image { get; }
5151

5252
/// <summary>
5353
/// Gets or sets the format.
@@ -105,7 +105,7 @@ internal static async Task<FormattedImage> LoadAsync<TPixel>(DecoderOptions opti
105105
// For example. If a resize command has been passed with no extra resampling options
106106
// then we should apply those changes on decode. This will allow memory savings and performance improvements.
107107
Image<TPixel> image = await Image.LoadAsync<TPixel>(options, source);
108-
return new FormattedImage(image, image.Metadata.DecodedImageFormat, false);
108+
return new FormattedImage(image, image.Metadata.DecodedImageFormat!, false);
109109
}
110110

111111
/// <summary>
@@ -117,7 +117,7 @@ internal static async Task<FormattedImage> LoadAsync<TPixel>(DecoderOptions opti
117117
internal static async Task<FormattedImage> LoadAsync(DecoderOptions options, Stream source)
118118
{
119119
Image image = await Image.LoadAsync(options, source);
120-
return new FormattedImage(image, image.Metadata.DecodedImageFormat, false);
120+
return new FormattedImage(image, image.Metadata.DecodedImageFormat!, false);
121121
}
122122

123123
/// <summary>
@@ -143,7 +143,7 @@ public bool TryGetExifOrientation(out ushort value)
143143
value = ExifOrientationMode.Unknown;
144144
if (this.Image.Metadata.ExifProfile != null)
145145
{
146-
if (!this.Image.Metadata.ExifProfile.TryGetValue(ExifTag.Orientation, out IExifValue<ushort> orientation))
146+
if (!this.Image.Metadata.ExifProfile.TryGetValue(ExifTag.Orientation, out IExifValue<ushort>? orientation))
147147
{
148148
return false;
149149
}
@@ -172,13 +172,12 @@ public void Dispose()
172172
if (!this.keepOpen)
173173
{
174174
this.Image?.Dispose();
175-
this.Image = null;
176175
}
177176
}
178177

179-
[MethodImpl(MethodImplOptions.NoInlining)]
178+
[DoesNotReturn]
180179
private static void ThrowNull(string name) => throw new ArgumentNullException(name);
181180

182-
[MethodImpl(MethodImplOptions.NoInlining)]
181+
[DoesNotReturn]
183182
private static void ThrowInvalid(string name) => throw new ArgumentException(name);
184183
}

src/ImageSharp.Web/Providers/FileProviderImageProvider.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ public virtual bool IsValidRequest(HttpContext context)
5252
/// <inheritdoc/>
5353
public Task<IImageResolver?> GetAsync(HttpContext context)
5454
{
55-
IFileInfo fileInfo = this.fileProvider.GetFileInfo(context.Request.Path.Value);
56-
if (!fileInfo.Exists)
55+
string? path = context.Request.Path.Value;
56+
if (path is not null)
5757
{
58-
return Task.FromResult<IImageResolver?>(null);
58+
IFileInfo fileInfo = this.fileProvider.GetFileInfo(path);
59+
if (fileInfo.Exists)
60+
{
61+
return Task.FromResult<IImageResolver?>(new FileProviderImageResolver(fileInfo));
62+
}
5963
}
6064

61-
return Task.FromResult<IImageResolver?>(new FileProviderImageResolver(fileInfo));
65+
return Task.FromResult<IImageResolver?>(null);
6266
}
6367
}

0 commit comments

Comments
 (0)