Added support for transparency in rotation code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5950 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Guillermo Rodriguez Garcia
2000-02-10 13:27:07 +00:00
parent b217783903
commit ad30de59f6

View File

@@ -2608,8 +2608,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxImageModule, wxModule)
unsigned long wxImage::CountColours( unsigned long stopafter )
{
wxHashTable h;
wxNode *node;
wxHNode *hnode;
wxObject dummy;
unsigned char r, g, b, *p;
unsigned long size, nentries, key;
@@ -2624,20 +2623,13 @@ unsigned long wxImage::CountColours( unsigned long stopafter )
b = *(p++);
key = (r << 16) | (g << 8) | b;
hnode = (wxHNode *) h.Get(key);
if (!hnode)
if (h.Get(key) == NULL)
{
h.Put(key, (wxObject *)(new wxHNode));
h.Put(key, &dummy);
nentries++;
}
}
// delete all HNodes
h.BeginFind();
while ((node = h.Next()) != NULL)
delete (wxHNode *)node->GetData();
return nentries;
}
@@ -2699,7 +2691,6 @@ struct wxRotationPoint
double x, y;
};
static const wxRotationPixel gs_BlankPixel = {0,0,0};
static const double gs_Epsilon = 1e-10;
static inline int wxCint (double x)
@@ -2741,7 +2732,8 @@ wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool i
data[i] = data[i - 1] + img.GetWidth();
}
// pre-compute coefficients for rotation formula (sine and cosine of the angle)
// pre-compute coefficients for rotation formula
// (sine and cosine of the angle)
const double cos_angle = cos(angle);
const double sin_angle = sin(angle);
@@ -2769,7 +2761,6 @@ wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool i
*offset_after_rotation = wxPoint (x1, y1);
}
wxRotationPixel ** result_data = new wxRotationPixel * [rotated.GetHeight()];
result_data[0] = (wxRotationPixel *) rotated.GetData();
@@ -2779,10 +2770,28 @@ wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool i
result_data[i] = result_data[i - 1] + rotated.GetWidth();
}
// GRG: if the original image has a mask, use its RGB values
// as the blank pixel, else, fall back to default (black).
//
wxRotationPixel blankPixel = {{ 0, 0, 0 }};
if (HasMask())
{
unsigned char r = GetMaskRed();
unsigned char g = GetMaskGreen();
unsigned char b = GetMaskBlue();
rotated.SetMaskColour( r, g, b );
blankPixel.rgb[0] = r;
blankPixel.rgb[1] = g;
blankPixel.rgb[2] = b;
}
// Now, for each point of the rotated image, find where it came from, by
// performing an inverse rotation (a rotation of -angle) and getting the
// pixel at those coordinates
// GRG: I'd suggest to take the (interpolating) test out of the loops
int x;
for (x = 0; x < rotated.GetWidth(); x++)
{
@@ -2854,7 +2863,7 @@ wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool i
}
else
{
result_data[y][x] = gs_BlankPixel;
result_data[y][x] = blankPixel;
}
}
else
@@ -2869,7 +2878,7 @@ wxImage wxImage::Rotate(double angle, const wxPoint & centre_of_rotation, bool i
}
else
{
result_data[y][x] = gs_BlankPixel;
result_data[y][x] = blankPixel;
}
}
}