diff --git a/src/add-ons/translators/giftranslator/GIFSave.cpp b/src/add-ons/translators/giftranslator/GIFSave.cpp index 4ea1d4e06f..12d808d7eb 100644 --- a/src/add-ons/translators/giftranslator/GIFSave.cpp +++ b/src/add-ons/translators/giftranslator/GIFSave.cpp @@ -104,20 +104,13 @@ GIFSave::GIFSave(BBitmap *bitmap, BPositionIO *output) if (debug) printf("GIFSave::GIFSave() - Using transparent index %d\n", palette->TransparentIndex()); } else { - bool found = palette->SetTransparentColor((uint8)prefs->transparentred, - (uint8)prefs->transparentred, - (uint8)prefs->transparentblue); - if (found) { - if (debug) { - printf("GIFSave::GIFSave() - Found transparent color %d,%d,%d at index %d\n", - prefs->transparentred, prefs->transparentgreen, prefs->transparentblue, - palette->TransparentIndex()); - } - } else { - if (debug) { - printf("GIFSave::GIFSave() - Did not find color %d,%d,%d - deactivating transparency\n", - prefs->transparentred, prefs->transparentgreen, prefs->transparentblue); - } + palette->SetTransparentColor((uint8)prefs->transparentred, + (uint8)prefs->transparentgreen, + (uint8)prefs->transparentblue); + if (debug) { + printf("GIFSave::GIFSave() - Found transparent color %d,%d,%d at index %d\n", + prefs->transparentred, prefs->transparentgreen, prefs->transparentblue, + palette->TransparentIndex()); } } } else { diff --git a/src/add-ons/translators/giftranslator/SavePalette.cpp b/src/add-ons/translators/giftranslator/SavePalette.cpp index 02feb912c1..164e442928 100644 --- a/src/add-ons/translators/giftranslator/SavePalette.cpp +++ b/src/add-ons/translators/giftranslator/SavePalette.cpp @@ -229,9 +229,9 @@ touch_color_item(SFHash& hash, unsigned int key, uint8 r, uint8 g, uint8 b) } else { ci->count++; // use brightest color - ci->red = max_c(ci->red, r); +/* ci->red = max_c(ci->red, r); ci->green = max_c(ci->green, g); - ci->blue = max_c(ci->blue, b); + ci->blue = max_c(ci->blue, b);*/ } return true; } @@ -404,11 +404,12 @@ SavePalette::SetTransparentIndex(int index) } // SetTransparentColor -bool +void SavePalette::SetTransparentColor(uint8 red, uint8 green, uint8 blue) { bool found = false; + // try direct hit first for (int i = 0; i < fSize; i++) { if (pal[i].red == red && pal[i].green == green && @@ -421,10 +422,25 @@ SavePalette::SetTransparentColor(uint8 red, uint8 green, uint8 blue) } } if (!found) { - fTransparentIndex = 0; - fUseTransparent = false; + // find closest match + fTransparentIndex = IndexForColor(red, green, blue); + // NOTE: This is a tough decision: + // -> the exact color might be contained within the image + // but have slipped through the net and is now not in the + // palette, the user still wants those pixels to be + // transparent of course, so it is best to match up a + // color from the palette + // -> on the other hand, the setting might still be there + // from some previous image and the color might not + // even appear in the current image at all... but I guess + // handling it like below is the lesser evil. + // match up color at index to provided transparent color, + // to make sure it actually works + pal[fTransparentIndex].red = red; + pal[fTransparentIndex].green = green; + pal[fTransparentIndex].blue = blue; + found = true; } - return found; } // GetColors diff --git a/src/add-ons/translators/giftranslator/SavePalette.h b/src/add-ons/translators/giftranslator/SavePalette.h index 2420e55005..9dba0ea0d6 100644 --- a/src/add-ons/translators/giftranslator/SavePalette.h +++ b/src/add-ons/translators/giftranslator/SavePalette.h @@ -47,7 +47,7 @@ class SavePalette { void SetTransparentIndex(int index); inline int TransparentIndex() const { return fTransparentIndex; } - bool SetTransparentColor(uint8 red, + void SetTransparentColor(uint8 red, uint8 green, uint8 blue);