@@ -81,7 +81,7 @@ private GilbertCurve(int width, int height, int[] pixels, Color[] palette, int[]
8181 beta = ( float ) ( weight > boundary ? Math . Max ( .25 , beta - palette . Length * weight ) : Math . Min ( 1.5 , beta + palette . Length * weight ) ) ;
8282 if ( palette . Length > 16 && palette . Length <= 32 && weight < .003 )
8383 beta += .075f ;
84- else if ( palette . Length > 32 && palette . Length < 256 )
84+ else if ( weight < .0015 || ( palette . Length > 32 && palette . Length < 256 ) )
8585 beta += .1f ;
8686 if ( palette . Length >= 64 && ( weight > .012 && weight < .0125 ) || ( weight > .025 && weight < .03 ) )
8787 beta *= 2 ;
@@ -131,11 +131,12 @@ private int DitherPixel(int x, int y, Color c2, float beta)
131131 }
132132
133133 if ( palette . Length < 3 || margin > 6 ) {
134- var delta = ( weight > .0015 && weight < .0025 ) ? beta : Math . PI ;
135- if ( palette . Length > 4 && CIELABConvertor . Y_Diff ( pixel , c2 ) > ( delta * acceptedDiff ) ) {
136- var kappa = saliencies [ bidx ] < .4f ? beta * .4f / saliencies [ bidx ] : beta * .4f / saliencies [ bidx ] ;
137- var c1 = saliencies [ bidx ] < .6f ? pixel : Color . FromArgb ( a_pix , r_pix , g_pix , b_pix ) ;
138- c2 = BlueNoise . Diffuse ( c1 , palette [ qPixelIndex ] , kappa , strength , x , y ) ;
134+ if ( palette . Length > 4 && CIELABConvertor . Y_Diff ( pixel , c2 ) > ( beta * acceptedDiff ) ) {
135+ var kappa = saliencies [ bidx ] < .4f ? beta * .4f * saliencies [ bidx ] : beta * .4f / saliencies [ bidx ] ;
136+ var c1 = Color . FromArgb ( a_pix , r_pix , g_pix , b_pix ) ;
137+ if ( weight >= .0015 && saliencies [ bidx ] < .6 )
138+ c1 = pixel ;
139+ c2 = BlueNoise . Diffuse ( c1 , palette [ qPixelIndex ] , kappa , strength , x , y ) ;
139140 }
140141 }
141142 else if ( palette . Length > 4 && ( CIELABConvertor . Y_Diff ( pixel , c2 ) > ( beta * acceptedDiff ) || CIELABConvertor . U_Diff ( pixel , c2 ) < acceptedDiff ) ) {
0 commit comments