Skip to content

Commit

Permalink
Feedback fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Oct 18, 2021
1 parent 88bb74f commit d5cea15
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
// If the color type was not specified by the user, preserve the color type of the input image.
if (!this.colorType.HasValue)
{
this.colorType = SetFallbackColorType(image);
this.colorType = GetFallbackColorType(image);
}

// Compute number of components based on color type in options.
Expand Down Expand Up @@ -162,31 +162,28 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
/// returns <see langword="null"/> defering the field assignment
/// to <see cref="InitQuantizationTables(int, JpegMetadata, out Block8x8F, out Block8x8F)"/>.
/// </summary>
private static JpegColorType? SetFallbackColorType<TPixel>(Image<TPixel> image)
private static JpegColorType? GetFallbackColorType<TPixel>(Image<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel>
{
// First inspect the image metadata.
JpegColorType? colorType = null;
JpegMetadata metadata = image.Metadata.GetJpegMetadata();
if (IsSupportedColorType(metadata.ColorType))
{
colorType = metadata.ColorType;
return metadata.ColorType;
}

// Secondly, inspect the pixel type.
// TODO: PixelTypeInfo should contain a component count!
if (colorType is null)
{
bool isGrayscale =
typeof(TPixel) == typeof(L8) || typeof(TPixel) == typeof(L16) ||
typeof(TPixel) == typeof(La16) || typeof(TPixel) == typeof(La32);
bool isGrayscale =
typeof(TPixel) == typeof(L8) || typeof(TPixel) == typeof(L16) ||
typeof(TPixel) == typeof(La16) || typeof(TPixel) == typeof(La32);

// We don't set multi-component color types here since we can set it based upon
// the quality in InitQuantizationTables.
if (isGrayscale)
{
colorType = JpegColorType.Luminance;
}
// We don't set multi-component color types here since we can set it based upon
// the quality in InitQuantizationTables.
if (isGrayscale)
{
colorType = JpegColorType.Luminance;
}

return colorType;
Expand Down

0 comments on commit d5cea15

Please sign in to comment.