Skip to content

Commit

Permalink
Merge pull request #6256 from radarhere/furthestV
Browse files Browse the repository at this point in the history
Ensure that furthest v is set in quantize2
  • Loading branch information
hugovk committed May 17, 2022
2 parents 1a28662 + 44494a1 commit ef8cec6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/libImaging/Quant.c
Expand Up @@ -1519,7 +1519,7 @@ quantize(

typedef struct {
Pixel new;
Pixel furthest;
uint32_t furthestV;
uint32_t furthestDistance;
int secondPixel;
} DistanceData;
Expand All @@ -1536,7 +1536,7 @@ compute_distances(const HashTable *h, const Pixel pixel, uint32_t *dist, void *u
}
if (oldDist > data->furthestDistance) {
data->furthestDistance = oldDist;
data->furthest.v = pixel.v;
data->furthestV = pixel.v;
}
}

Expand Down Expand Up @@ -1577,10 +1577,11 @@ quantize2(
data.new.c.b = (int)(.5 + (double)mean[2] / (double)nPixels);
for (i = 0; i < nQuantPixels; i++) {
data.furthestDistance = 0;
data.furthestV = pixelData[0].v;
data.secondPixel = (i == 1) ? 1 : 0;
hashtable_foreach_update(h, compute_distances, &data);
p[i].v = data.furthest.v;
data.new.v = data.furthest.v;
p[i].v = data.furthestV;
data.new.v = data.furthestV;
}
hashtable_free(h);

Expand Down

0 comments on commit ef8cec6

Please sign in to comment.