@@ -587,19 +587,17 @@ private static byte NearLosslessComponent(byte value, byte predict, byte boundar
587587
588588 return ( byte ) lower ;
589589 }
590- else
591- {
592- // upper is closer to residual than lower.
593- if ( residual <= boundaryResidual && upper > boundaryResidual )
594- {
595- // Halve quantization step to avoid crossing boundary. This midpoint is
596- // on the same side of boundary as residual because midpoint <= residual
597- // (since upper is closer than lower) and residual is below the boundary.
598- return ( byte ) ( lower + ( quantization >> 1 ) ) ;
599- }
600590
601- return ( byte ) ( upper & 0xff ) ;
591+ // upper is closer to residual than lower.
592+ if ( residual <= boundaryResidual && upper > boundaryResidual )
593+ {
594+ // Halve quantization step to avoid crossing boundary. This midpoint is
595+ // on the same side of boundary as residual because midpoint <= residual
596+ // (since upper is closer than lower) and residual is below the boundary.
597+ return ( byte ) ( lower + ( quantization >> 1 ) ) ;
602598 }
599+
600+ return ( byte ) ( upper & 0xff ) ;
603601 }
604602
605603 /// <summary>
@@ -1075,7 +1073,7 @@ private static double GetPredictionCostCrossColorBlue(
10751073 private static void CollectColorRedTransforms ( Span < uint > bgra , int stride , int tileWidth , int tileHeight , int greenToRed , Span < int > histo )
10761074 {
10771075#if SUPPORTS_RUNTIME_INTRINSICS
1078- if ( Avx2 . IsSupported && tileWidth > 16 )
1076+ if ( Avx2 . IsSupported && tileWidth >= 16 )
10791077 {
10801078 var multsg = Vector256 . Create ( LosslessUtils . Cst5b ( greenToRed ) ) ;
10811079 const int span = 16 ;
@@ -1182,7 +1180,7 @@ private static void CollectColorRedTransformsNoneVectorized(Span<uint> bgra, int
11821180 private static void CollectColorBlueTransforms ( Span < uint > bgra , int stride , int tileWidth , int tileHeight , int greenToBlue , int redToBlue , Span < int > histo )
11831181 {
11841182#if SUPPORTS_RUNTIME_INTRINSICS
1185- if ( Avx2 . IsSupported && tileWidth > 16 )
1183+ if ( Avx2 . IsSupported && tileWidth >= 16 )
11861184 {
11871185 const int span = 16 ;
11881186 Span < ushort > values = stackalloc ushort [ span ] ;
@@ -1219,12 +1217,12 @@ private static void CollectColorBlueTransforms(Span<uint> bgra, int stride, int
12191217 ++ histo [ values [ i ] ] ;
12201218 }
12211219 }
1220+ }
12221221
1223- int leftOver = tileWidth & ( span - 1 ) ;
1224- if ( leftOver > 0 )
1225- {
1226- CollectColorBlueTransformsNoneVectorized ( bgra . Slice ( tileWidth - leftOver ) , stride , leftOver , tileHeight , greenToBlue , redToBlue , histo ) ;
1227- }
1222+ int leftOver = tileWidth & ( span - 1 ) ;
1223+ if ( leftOver > 0 )
1224+ {
1225+ CollectColorBlueTransformsNoneVectorized ( bgra . Slice ( tileWidth - leftOver ) , stride , leftOver , tileHeight , greenToBlue , redToBlue , histo ) ;
12281226 }
12291227 }
12301228 else if ( Sse41 . IsSupported )
0 commit comments