Fix transparency issue with new color criterias (fix #4686)

Prior to this fix, the following particular conditions caused
an incorrect conversion of an opaque color to a transparent color
during RGBA->Indexed conversion:
- RGBA image with black color (#000000 a=255) painted on the canvas
- The black color is absent from the palette.
- The mask color is present in the palette
- Converts the sprite to indexed color mode using
  Sprite > Color Mode > More Options
- Select Advanced Options, select a Color Best Fit Criteria other than
  Default (for example CIELAB) and press OK
- The original black color becomes the mask color.
This commit is contained in:
Gaspar Capello 2024-10-04 10:37:28 -03:00
parent e5faac07b5
commit ff520c14d2

View File

@ -120,7 +120,7 @@ int RgbMapBase::findBestfit(int r, int g, int b, int a,
const double aDiff = double(a - rgba_geta(rgb)) / 128.0;
double diff = xDiff * xDiff + yDiff * yDiff + zDiff * zDiff + aDiff * aDiff;
if (diff < lowest) {
if (diff < lowest && i != mask_index) {
lowest = diff;
bestfit = i;
}