Skip to content

Commit 9e1b1d8

Browse files
committed
Add support for bt601 and bt709 grayscale methods
1 parent c717a6b commit 9e1b1d8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Synercoding.FileFormats.Pdf/GrayScaleMethod.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,13 @@ public enum GrayScaleMethod
2424
/// <summary>
2525
/// Use the average of the Red, Green and Blue channels.
2626
/// </summary>
27-
AverageOfRGBChannels
27+
AverageOfRGBChannels,
28+
/// <summary>
29+
/// The constants defined by ITU-R BT.601 are 0.299 red + 0.587 green + 0.114 blue.
30+
/// </summary>
31+
BT601,
32+
/// <summary>
33+
/// The constants defined by ITU-R BT.709 are 0.2126 red + 0.7152 green + 0.0722 blue.
34+
/// </summary>
35+
BT709,
2836
}

src/Synercoding.FileFormats.Pdf/Image.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ internal static Stream AsImageByteStream(Image<Rgba32> image, GrayScaleMethod gr
118118
GrayScaleMethod.GreenChannel => pixel.G,
119119
GrayScaleMethod.BlueChannel => pixel.B,
120120
GrayScaleMethod.AverageOfRGBChannels => (byte)( ( pixel.R + pixel.G + pixel.B ) / 3 ),
121+
GrayScaleMethod.BT601 => (byte)( ( pixel.R * 0.299 ) + ( pixel.G * 0.587 ) + ( pixel.B * 0.114 ) ),
122+
GrayScaleMethod.BT709 => (byte)( ( pixel.R * 0.2126 ) + ( pixel.G * 0.7152 ) + ( pixel.B * 0.0722 ) ),
121123
_ => throw new NotImplementedException()
122124
};
123125

0 commit comments

Comments
 (0)