Skip to content

Commit 574ec8a

Browse files
Merge branch 'main' into stefannikolei/arm/componentconverter
2 parents 4571325 + db49134 commit 574ec8a

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/ImageSharp/Formats/Jpeg/Components/Decoder/SpectralConverter{TPixel}.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,39 @@ public override void PrepareForDecoding()
184184

185185
MemoryAllocator allocator = this.Configuration.MemoryAllocator;
186186

187-
// color converter from RGB to TPixel
187+
// Color converter from RGB to TPixel
188188
JpegColorConverterBase converter = this.GetColorConverter(this.frame, this.jpegData);
189189
this.colorConverter = converter;
190190

191-
// resulting image size
191+
// Resulting image size
192192
Size pixelSize = CalculateResultingImageSize(this.frame.PixelSize, this.targetSize, out int blockPixelSize);
193193

194-
// iteration data
194+
// Iteration data
195195
int majorBlockWidth = this.frame.Components.Max((component) => component.SizeInBlocks.Width);
196196
int majorVerticalSamplingFactor = this.frame.Components.Max((component) => component.SamplingFactors.Height);
197197

198198
this.pixelRowsPerStep = majorVerticalSamplingFactor * blockPixelSize;
199199

200-
// pixel buffer for resulting image
200+
// Pixel buffer for resulting image
201201
this.pixelBuffer = allocator.Allocate2D<TPixel>(
202202
pixelSize.Width,
203203
pixelSize.Height,
204204
this.Configuration.PreferContiguousImageBuffers);
205205
this.paddedProxyPixelRow = allocator.Allocate<TPixel>(pixelSize.Width + 3);
206206

207-
// component processors from spectral to RGB
207+
// Component processors from spectral to RGB
208208
int bufferWidth = majorBlockWidth * blockPixelSize;
209-
int batchSize = converter.ElementsPerBatch;
210-
int batchRemainder = bufferWidth & (batchSize - 1);
211-
Size postProcessorBufferSize = new(bufferWidth + (batchSize - batchRemainder), this.pixelRowsPerStep);
209+
210+
// Converters process pixels in batches and require target buffer size to be divisible by a batch size
211+
// Corner case: image size including jpeg padding is already divisible by a batch size or remainder == 0
212+
int elementsPerBatch = converter.ElementsPerBatch;
213+
int batchRemainder = bufferWidth & (elementsPerBatch - 1);
214+
int widthComplementaryValue = batchRemainder == 0 ? 0 : elementsPerBatch - batchRemainder;
215+
216+
Size postProcessorBufferSize = new(bufferWidth + widthComplementaryValue, this.pixelRowsPerStep);
212217
this.componentProcessors = this.CreateComponentProcessors(this.frame, this.jpegData, blockPixelSize, postProcessorBufferSize);
213218

214-
// single 'stride' rgba32 buffer for conversion between spectral and TPixel
219+
// Single 'stride' rgba32 buffer for conversion between spectral and TPixel
215220
this.rgbBuffer = allocator.Allocate<byte>(pixelSize.Width * 3);
216221
}
217222

src/ImageSharp/Image.FromFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static async Task<IImageFormat> DetectFormatAsync(
8181
/// A return value indicates whether the operation succeeded.
8282
/// </summary>
8383
/// <param name="path">The image file to open and to read the header from.</param>
84-
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
84+
/// <returns>The <see cref="ImageInfo"/>.</returns>
8585
/// <exception cref="ArgumentNullException">The path is null.</exception>
8686
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
8787
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>

src/ImageSharp/Image.FromStream.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static IImageFormat DetectFormat(Stream stream)
2929
/// </summary>
3030
/// <param name="options">The general decoder options.</param>
3131
/// <param name="stream">The image stream to read the header from.</param>
32-
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
32+
/// <returns>The <see cref="IImageFormat"/>.</returns>
3333
/// <exception cref="ArgumentNullException">The options are null.</exception>
3434
/// <exception cref="ArgumentNullException">The stream is null.</exception>
3535
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
@@ -79,7 +79,7 @@ public static Task<IImageFormat> DetectFormatAsync(
7979
/// Reads the raw image information from the specified stream without fully decoding it.
8080
/// </summary>
8181
/// <param name="stream">The image stream to read the header from.</param>
82-
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
82+
/// <returns>The <see cref="ImageInfo"/>.</returns>
8383
/// <exception cref="ArgumentNullException">The stream is null.</exception>
8484
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
8585
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>

0 commit comments

Comments
 (0)