Sign up for our Tech Decoded newsletter to follow the world's top tech stories and trends. Outside the UK? Sign up here.
The N-closest or N-best dithering algorithm is a straightforward solution to the N-candidate problem. As the name suggests, the set of candidates is given by the closest palette colours to the input pixel. To determine their weights, we simply take the inverse of the distance to the input pixel. This is essentially the inverse distance weighting (IDW) method for multivariate interpolation, also known as Shepard’s method. The following pseudocode sketches out a possible implementation:
。服务器推荐是该领域的重要参考
// Synchronously enqueue — this never applies backpressure
// ⚠️ 易错点4:循环条件写right = 0(会导致right-1越界),或把<=写成<(漏判相等的有序情况)