Skip to content

Commit

Permalink
Made it a lot more simpler with a blend pixel formular
Browse files Browse the repository at this point in the history
  • Loading branch information
f0rodo committed Jun 18, 2010
1 parent f513211 commit 9ad7dbc
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions lib/Games/FrozenBubble/CStuff.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,13 +1386,11 @@ void overlook_(SDL_Surface * dest, SDL_Surface * orig, int step, int pivot)
{
int Bpp = dest->format->BytesPerPixel;

Uint8 Ar, Ag, Ab, Aa, Br, Bg, Bb, Ba, Cr, Cg, Cb, Ca, Dr, Dg, Db, Da;
int x_, y_;
Uint8 r, g, b, a;
double shading = 1 - CLAMP((double)step / 70, 0, 1);
double x_factor = 1 - (double)step / 700;
static double fade = 0.9;
double dx, dy;
Uint8 or, og, ob, oa, dr, dg, db, da;
if (orig->format->BytesPerPixel != 4) {
fprintf(stderr, "overlook: orig surface must be 32bpp\n");
abort();
Expand All @@ -1403,35 +1401,28 @@ void overlook_(SDL_Surface * dest, SDL_Surface * orig, int step, int pivot)
}
myLockSurface(orig);
myLockSurface(dest);


for (x = 0; x < dest->w; x++) {
double y_factor = 1 - ((double)step) / 150 * MIN(pivot, abs(x - pivot) + pivot/3) / pivot;
double x__ = pivot + (x - pivot) * x_factor;
x_ = floor(x__);


for (y = 0; y < dest->h; y++) {
double y__ = dest->h/2 + (y - dest->h/2) * y_factor;
Uint32 *A, *B, *C, *D;

y_ = floor(y__);
get_pixel(dest, x_, y_, &r, &g, &b, &a);
if (x_ < 0 || x_ > orig->w - 2 || y_ < 0 || y_ > orig->h - 2) {
// out of band
get_pixel(dest, x_, y_, &r, &g, &b, &a);
set_pixel(dest, x_, y_, r, g, b, (a *fade));
} else {
dx = x__ - x_;
dy = y__ - y_;

get_pixel(orig, x_, y_, &Ar, &Ag, &Ab, &Aa);
get_pixel(orig, (x_ + 1), y_, &Br, &Bg, &Bb, &Ba);
get_pixel(orig, x_ , (y_ + 1), &Cr, &Cg, &Cb, &Ca);
get_pixel(orig, (x_ + 1) , (y_ + 1), &Dr, &Dg, &Db, &Da);

Uint8 aa = ( (Aa * ( 1 - dx ) + Ba) * dx) * ( 1 - dy ) + (Ca * ( 1 - dx ) + Da * dx) * dy;
a = MAX(aa * shading, a * fade);
}
get_pixel(orig, x_, y_, &or, &og, &ob, &oa);
get_pixel(dest, x_, y_, &dr, &dg, &db, &da);
/* a better way to do this dst = (orig * A) + (dst * (1-A)) */


get_pixel(dest, x, y, &r, &g, &b, &Aa);
set_pixel(dest, x, y, r, g, b, a);
Uint8 aa = (oa * fade) + (da * (1-fade));
if( aa > 0 )
{
set_pixel(dest, x_, y_, dr, dg, db, 0);
}
}
}
myUnlockSurface(orig);
Expand Down

0 comments on commit 9ad7dbc

Please sign in to comment.