better magic blocks effect

This commit is contained in:
Albert Cahalan 2004-12-06 20:03:28 +00:00
parent 7e99dd8554
commit b20d3f1d75
2 changed files with 37 additions and 18 deletions

View file

@ -8,6 +8,10 @@ http://www.newbreedsoftware.com/tuxpaint/
2004.December.5 (0.9.15) 2004.December.5 (0.9.15)
* Magic blocks effect now gamma-aware and using all 16 (not just 4)
source pixels.
Albert Cahalan <albert@users.sf.net>
* More range for stamp sizes. Can't hang off edge in both dimensions. * More range for stamp sizes. Can't hang off edge in both dimensions.
Albert Cahalan <albert@users.sf.net> Albert Cahalan <albert@users.sf.net>

View file

@ -4114,24 +4114,39 @@ static void blit_magic(int x, int y)
{ {
for (xx = x - 8; xx < x + 8; xx = xx + 4) for (xx = x - 8; xx < x + 8; xx = xx + 4)
{ {
/* Get average color around here: */ Uint32 pix[16];
Uint32 p_or = 0;
SDL_GetRGB(getpixel(last, xx, yy), last->format, Uint32 p_and = ~0;
&r1, &g1, &b1); unsigned i = 16;
while(i--)
SDL_GetRGB(getpixel(last, xx + 2, yy), last->format, {
&r2, &g2, &b2); Uint32 p_tmp;
p_tmp = getpixel(last, xx+(i>>2), yy+(i&3));
SDL_GetRGB(getpixel(last, xx, yy + 2), last->format, p_or |= p_tmp;
&r3, &g3, &b3); p_and &= p_tmp;
pix[i] = p_tmp;
SDL_GetRGB(getpixel(last, xx + 2, yy + 2), last->format, }
&r4, &g4, &b4); if(p_or==p_and) // if all pixels the same already
{
r = (r1 + r2 + r3 + r4) / 4; SDL_GetRGB(p_or, last->format, &r, &g, &b);
g = (g1 + g2 + g3 + g4) / 4; }
b = (b1 + b2 + b3 + b4) / 4; else // nope, must average them
{
double r_sum = 0.0;
double g_sum = 0.0;
double b_sum = 0.0;
i = 16;
while(i--)
{
SDL_GetRGB(pix[i], last->format, &r, &g, &b);
r_sum += sRGB_to_linear_table[r];
g_sum += sRGB_to_linear_table[g];
b_sum += sRGB_to_linear_table[b];
}
r = linear_to_sRGB(r_sum/16.0);
g = linear_to_sRGB(g_sum/16.0);
b = linear_to_sRGB(b_sum/16.0);
}
/* Draw block: */ /* Draw block: */