| 133 |
void wxImageExt::ReconstructColors(const wxColour& bgColor) |
void wxImageExt::ReconstructColors(const wxColour& bgColor) |
| 134 |
{ |
{ |
| 135 |
// restore the color of edge texels by guessing correct non-background color |
// restore the color of edge texels by guessing correct non-background color |
|
wxImageExt result; |
|
| 136 |
|
|
|
result.Create(GetWidth(), GetHeight()); |
|
|
result.InitAlpha(); |
|
| 137 |
for (int x = 0; x < GetWidth(); x++) { |
for (int x = 0; x < GetWidth(); x++) { |
| 138 |
for (int y = 0; y < GetHeight(); y++) { |
for (int y = 0; y < GetHeight(); y++) { |
| 139 |
if (GetAlpha(x, y) == 0) { |
if (GetAlpha(x, y) == 0) { |
| 140 |
result.SetAlpha(x, y, 0); |
SetAlpha(x, y, 0); |
| 141 |
result.SetRGB(x, y, bgColor.Red(), bgColor.Green(), bgColor.Blue()); |
SetRGB(x, y, bgColor.Red(), bgColor.Green(), bgColor.Blue()); |
| 142 |
} else if (GetAlpha(x, y) == 0xff) { |
} else if (GetAlpha(x, y) == 0xff) { |
| 143 |
result.SetAlpha(x, y, 0xff); |
SetAlpha(x, y, 0xff); |
| 144 |
result.SetRGB(x, y, GetRed(x, y), GetGreen(x, y), GetBlue(x, y)); |
SetRGB(x, y, GetRed(x, y), GetGreen(x, y), GetBlue(x, y)); |
| 145 |
} else { |
} else { |
| 146 |
float blend_factor = GetAlpha(x, y) / 255.0f; |
float blend_factor = GetAlpha(x, y) / 255.0f; |
| 147 |
result.SetAlpha(x, y, GetAlpha(x, y)); |
SetAlpha(x, y, GetAlpha(x, y)); |
| 148 |
short rDiff = GetRed(x, y) - bgColor.Red(); |
short rDiff = GetRed(x, y) - bgColor.Red(); |
| 149 |
short gDiff = GetGreen(x, y) - bgColor.Green(); |
short gDiff = GetGreen(x, y) - bgColor.Green(); |
| 150 |
short bDiff = GetBlue(x, y) - bgColor.Blue(); |
short bDiff = GetBlue(x, y) - bgColor.Blue(); |
| 151 |
|
|
| 152 |
result.SetRGB(x, y, PIN(bgColor.Red() + (int) (rDiff * (1.0f / blend_factor)), 0, 255), PIN(bgColor.Green() + (int) (gDiff * (1.0f / blend_factor)), 0, 255), PIN(bgColor.Blue() + (int) (bDiff * (1.0f / blend_factor)), 0, 255)); |
SetRGB(x, y, PIN(bgColor.Red() + (int) (rDiff * (1.0f / blend_factor)), 0, 255), PIN(bgColor.Green() + (int) (gDiff * (1.0f / blend_factor)), 0, 255), PIN(bgColor.Blue() + (int) (bDiff * (1.0f / blend_factor)), 0, 255)); |
| 153 |
} |
} |
| 154 |
} |
} |
| 155 |
} |
} |
| 156 |
|
|
|
*this = result; |
|
| 157 |
} |
} |
| 158 |
|
|
| 159 |
void wxImageExt::UnpremultiplyAlpha() |
void wxImageExt::UnpremultiplyAlpha() |