mirror of https://github.com/SixLabors/ImageSharp
8 changed files with 298 additions and 67 deletions
@ -0,0 +1,49 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.Runtime.CompilerServices; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder |
|||
{ |
|||
/// <summary>
|
|||
/// Provides 8-bit lookup tables for converting from L8 to Y colorspace.
|
|||
/// </summary>
|
|||
internal unsafe struct L8ToYConverter |
|||
{ |
|||
/// <summary>
|
|||
/// Initializes
|
|||
/// </summary>
|
|||
/// <returns>The initialized <see cref="L8ToYConverter"/></returns>
|
|||
public static L8ToYConverter Create() |
|||
{ |
|||
L8ToYConverter converter = default; |
|||
return converter; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Optimized method to allocates the correct y, cb, and cr values to the DCT blocks from the given r, g, b values.
|
|||
/// </summary>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|||
private void ConvertPixelInto( |
|||
int l, |
|||
ref Block8x8F yResult, |
|||
int i) => yResult[i] = l; |
|||
|
|||
public void Convert(Span<L8> l8Span, ref Block8x8F yBlock) |
|||
{ |
|||
ref L8 l8Start = ref l8Span[0]; |
|||
|
|||
for (int i = 0; i < 64; i++) |
|||
{ |
|||
ref L8 c = ref Unsafe.Add(ref l8Start, i); |
|||
|
|||
this.ConvertPixelInto( |
|||
c.PackedValue, |
|||
ref yBlock, |
|||
i); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
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>
|
|||
/// The converter
|
|||
/// </summary>
|
|||
private L8ToYConverter converter; |
|||
|
|||
/// <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>); |
|||
result.converter = L8ToYConverter.Create(); |
|||
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; |
|||
|
|||
this.converter.Convert(l8Span, ref yBlock); |
|||
} |
|||
} |
|||
} |
|||
@ -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 |
|||
} |
|||
} |
|||
Loading…
Reference in new issue