* fixed a bug with setting the transparent color

* changed behaviour when searching for the
  index of the specified to be transparent color:
  if there is no direct hit, the closest match
  is found and adjusted to the specified color,
  so that the transparency always works out


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14296 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-10-02 23:40:21 +00:00
parent f59edb4bf0
commit 8061ab77fa
3 changed files with 30 additions and 21 deletions
@@ -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 {
@@ -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
@@ -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);