-
-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1586 from ynse01/ynse01/jpeg-grayscale
Grayscale Jpeg encoding
- Loading branch information
Showing
10 changed files
with
315 additions
and
98 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/ImageSharp/Formats/Jpeg/Components/Encoder/LuminanceForwardConverter{TPixel}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using SixLabors.ImageSharp.Advanced; | ||
using SixLabors.ImageSharp.PixelFormats; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder | ||
{ | ||
/// <summary> | ||
/// On-stack worker struct to efficiently encapsulate the TPixel -> L8 -> Y conversion chain of 8x8 pixel blocks. | ||
/// </summary> | ||
/// <typeparam name="TPixel">The pixel type to work on</typeparam> | ||
internal ref struct LuminanceForwardConverter<TPixel> | ||
where TPixel : unmanaged, IPixel<TPixel> | ||
{ | ||
/// <summary> | ||
/// The Y component | ||
/// </summary> | ||
public Block8x8F Y; | ||
|
||
/// <summary> | ||
/// Temporal 8x8 block to hold TPixel data | ||
/// </summary> | ||
private GenericBlock8x8<TPixel> pixelBlock; | ||
|
||
/// <summary> | ||
/// Temporal RGB block | ||
/// </summary> | ||
private GenericBlock8x8<L8> l8Block; | ||
|
||
public static LuminanceForwardConverter<TPixel> Create() | ||
{ | ||
var result = default(LuminanceForwardConverter<TPixel>); | ||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a 8x8 image area inside 'pixels' at position (x,y) placing the result members of the structure (<see cref="Y"/>) | ||
/// </summary> | ||
public void Convert(ImageFrame<TPixel> frame, int x, int y, ref RowOctet<TPixel> currentRows) | ||
{ | ||
this.pixelBlock.LoadAndStretchEdges(frame.PixelBuffer, x, y, ref currentRows); | ||
|
||
Span<L8> l8Span = this.l8Block.AsSpanUnsafe(); | ||
PixelOperations<TPixel>.Instance.ToL8(frame.GetConfiguration(), this.pixelBlock.AsSpanUnsafe(), l8Span); | ||
|
||
ref Block8x8F yBlock = ref this.Y; | ||
ref L8 l8Start = ref l8Span[0]; | ||
|
||
for (int i = 0; i < 64; i++) | ||
{ | ||
ref L8 c = ref Unsafe.Add(ref l8Start, i); | ||
yBlock[i] = c.PackedValue; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Jpeg | ||
{ | ||
/// <summary> | ||
/// Provides enumeration of available JPEG color types. | ||
/// </summary> | ||
public enum JpegColorType : byte | ||
{ | ||
/// <summary> | ||
/// YCbCr (luminance, blue chroma, red chroma) color as defined in the ITU-T T.871 specification. | ||
/// </summary> | ||
YCbCr = 0, | ||
|
||
/// <summary> | ||
/// Single channel, luminance. | ||
/// </summary> | ||
Luminance = 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.