@@ -145,18 +145,15 @@ private int DitherPixel(int x, int y, Color c2, float beta)
145145 if ( palette . Length <= 4 && saliencies [ bidx ] > .2f && saliencies [ bidx ] < .25f )
146146 c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , beta * 2 / saliencies [ bidx ] , strength , x , y ) ;
147147 else if ( palette . Length <= 4 || CIELABConvertor . Y_Diff ( pixel , c2 ) < ( 2 * acceptedDiff ) ) {
148- if ( palette . Length <= 128 || BlueNoise . TELL_BLUE_NOISE [ bidx & 4095 ] > 0 )
148+ if ( palette . Length > 64 )
149149 {
150- if ( palette . Length > 64 )
151- {
152- var kappa = saliencies [ bidx ] < .6f ? beta * .15f / saliencies [ bidx ] : beta * .4f / saliencies [ bidx ] ;
153- c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , kappa , strength , x , y ) ;
154- }
155- else if ( palette . Length > 16 && weight < .005 )
156- c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , beta * NormalDistribution ( saliencies [ bidx ] , .5f ) + beta , strength , x , y ) ;
157- else
158- c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , beta * .5f / saliencies [ bidx ] , strength , x , y ) ;
150+ var kappa = saliencies [ bidx ] < .6f ? beta * .15f / saliencies [ bidx ] : beta * .4f / saliencies [ bidx ] ;
151+ c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , kappa , strength , x , y ) ;
159152 }
153+ else if ( palette . Length > 16 && weight < .005 )
154+ c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , beta * NormalDistribution ( saliencies [ bidx ] , .5f ) + beta , strength , x , y ) ;
155+ else
156+ c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , beta * .5f / saliencies [ bidx ] , strength , x , y ) ;
160157 }
161158
162159 var gamma = ( palette . Length <= 32 && weight < .01 && weight > .007 ) ? 1 - beta : beta ;
@@ -196,7 +193,7 @@ private int DitherPixel(int x, int y, Color c2, float beta)
196193 c2 = Color . FromArgb ( a_pix , r_pix , g_pix , b_pix ) ;
197194 if ( palette . Length > 32 && saliencies [ bidx ] > .95 )
198195 {
199- var kappa = beta * ( .75f - palette . Length / 128f ) * saliencies [ bidx ] ;
196+ var kappa = beta * Math . Max ( .05f , .75f - palette . Length / 128f ) * saliencies [ bidx ] ;
200197 c2 = BlueNoise . Diffuse ( pixel , palette [ qPixelIndex ] , kappa , strength , x , y ) ;
201198 }
202199
0 commit comments