@@ -106,15 +106,23 @@ public GrayscaleLevelsRowOperation(
106106 }
107107
108108 /// <inheritdoc/>
109+ #if NETSTANDARD2_0
110+ // https://github.com/SixLabors/ImageSharp/issues/1204
111+ [ MethodImpl ( MethodImplOptions . NoOptimization ) ]
112+ #else
109113 [ MethodImpl ( InliningOptions . ShortMethod ) ]
114+ #endif
110115 public void Invoke ( int y )
111116 {
112117 ref int histogramBase = ref MemoryMarshal . GetReference ( this . histogramBuffer . GetSpan ( ) ) ;
113118 ref TPixel pixelBase = ref MemoryMarshal . GetReference ( this . source . GetPixelRowSpan ( y ) ) ;
119+ int levels = this . luminanceLevels ;
114120
115121 for ( int x = 0 ; x < this . bounds . Width ; x ++ )
116122 {
117- int luminance = GetLuminance ( Unsafe . Add ( ref pixelBase , x ) , this . luminanceLevels ) ;
123+ // TODO: We should bulk convert here.
124+ var vector = Unsafe . Add ( ref pixelBase , x ) . ToVector4 ( ) ;
125+ int luminance = ImageMaths . GetBT709Luminance ( ref vector , levels ) ;
118126 Unsafe . Add ( ref histogramBase , luminance ) ++ ;
119127 }
120128 }
@@ -147,18 +155,27 @@ public CdfApplicationRowOperation(
147155 }
148156
149157 /// <inheritdoc/>
158+ #if NETSTANDARD2_0
159+ // https://github.com/SixLabors/ImageSharp/issues/1204
160+ [ MethodImpl ( MethodImplOptions . NoOptimization ) ]
161+ #else
150162 [ MethodImpl ( InliningOptions . ShortMethod ) ]
163+ #endif
151164 public void Invoke ( int y )
152165 {
153166 ref int cdfBase = ref MemoryMarshal . GetReference ( this . cdfBuffer . GetSpan ( ) ) ;
154167 ref TPixel pixelBase = ref MemoryMarshal . GetReference ( this . source . GetPixelRowSpan ( y ) ) ;
168+ int levels = this . luminanceLevels ;
169+ float noOfPixelsMinusCdfMin = this . numberOfPixelsMinusCdfMin ;
155170
156171 for ( int x = 0 ; x < this . bounds . Width ; x ++ )
157172 {
173+ // TODO: We should bulk convert here.
158174 ref TPixel pixel = ref Unsafe . Add ( ref pixelBase , x ) ;
159- int luminance = GetLuminance ( pixel , this . luminanceLevels ) ;
160- float luminanceEqualized = Unsafe . Add ( ref cdfBase , luminance ) / this . numberOfPixelsMinusCdfMin ;
161- pixel . FromVector4 ( new Vector4 ( luminanceEqualized , luminanceEqualized , luminanceEqualized , pixel . ToVector4 ( ) . W ) ) ;
175+ var vector = pixel . ToVector4 ( ) ;
176+ int luminance = ImageMaths . GetBT709Luminance ( ref vector , levels ) ;
177+ float luminanceEqualized = Unsafe . Add ( ref cdfBase , luminance ) / noOfPixelsMinusCdfMin ;
178+ pixel . FromVector4 ( new Vector4 ( luminanceEqualized , luminanceEqualized , luminanceEqualized , vector . W ) ) ;
162179 }
163180 }
164181 }
0 commit comments