EnttPong/src/libs/SDL2_gfx/SDL2_rotozoom.c
/*! 
\brief Internal 32 bit integer-factor averaging Shrinker.

Shrinks 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
Averages color and alpha values values of src pixels to calculate dst pixels.
Assumes src and dst surfaces are of 32 bit depth.
Assumes dst surface was allocated with the correct dimensions.

\param src The surface to shrink (input).
\param dst The shrunken surface (output).
\param factorx The horizontal shrinking ratio.
\param factory The vertical shrinking ratio.

\return 0 for success or -1 for error.
*/
\brief Internal 32 bit integer-factor averaging Shrinker.
Shrinks 32 bit RGBA/ABGR 'src' surface to 'dst' surface.
Averages color and alpha values values of src pixels to calculate dst pixels.
Assumes src and dst surfaces are of 32 bit depth.
Assumes dst surface was allocated with the correct dimensions.

\param src The surface to shrink (input).
\param dst The shrunken surface (output).
\param factorx The horizontal shrinking ratio.
\param factory The vertical shrinking ratio.

\return 0 for success or -1 for error.
\ brief Internal 32 bit integer - factor averaging Shrinker . Shrinks 32 bit RGBA / ABGR ' src ' surface to ' dst ' surface . Averages color and alpha values values of src pixels to calculate dst pixels . Assumes src and dst surfaces are of 32 bit depth . Assumes dst surface was allocated with the correct dimensions . \ param src The surface to shrink ( input ) . \ param dst The shrunken surface ( output ) . \ param factorx The horizontal shrinking ratio . \ param factory The vertical shrinking ratio . \ return 0 for success or - 1 for error .
int _shrinkSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
{
	int x, y, dx, dy, dgap, ra, ga, ba, aa;
	int n_average;
	tColorRGBA *sp, *osp, *oosp;
	tColorRGBA *dp;
	n_average = factorx*factory;
	sp = (tColorRGBA *) src->pixels;
	dp = (tColorRGBA *) dst->pixels;
	dgap = dst->pitch - dst->w * 4;
	for (y = 0; y < dst->h; y++) {
		osp=sp;
		for (x = 0; x < dst->w; x++) {
			oosp=sp;
			ra=ga=ba=aa=0;
			for (dy=0; dy < factory; dy++) {
				for (dx=0; dx < factorx; dx++) {
					ra += sp->r;
					ga += sp->g;
					ba += sp->b;
					aa += sp->a;
					sp++;
				} 
				sp = (tColorRGBA *)((Uint8*)sp + (src->pitch - 4*factorx)); 
			}
			sp = (tColorRGBA *)((Uint8*)oosp + 4*factorx);
			dp->r = ra/n_average;
			dp->g = ga/n_average;
			dp->b = ba/n_average;
			dp->a = aa/n_average;
			dp++;
		} 
		sp = (tColorRGBA *)((Uint8*)osp + src->pitch*factory);
		dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
	} 
	return (0);
}
int _shrinkSurfaceRGBA ( SDL_Surface * src , SDL_Surface * dst , int factorx , int factory ) { int x , y , dx , dy , dgap , ra , ga , ba , aa ; int n_average ; tColorRGBA * sp , * osp , * oosp ; tColorRGBA * dp ; n_average = factorx * factory ; sp = ( tColorRGBA * ) src -> pixels ; dp = ( tColorRGBA * ) dst -> pixels ; dgap = dst -> pitch - dst -> w * 4 ; for ( y = 0 ; y < dst -> h ; y ++ ) { osp = sp ; for ( x = 0 ; x < dst -> w ; x ++ ) { oosp = sp ; ra = ga = ba = aa = 0 ; for ( dy = 0 ; dy < factory ; dy ++ ) { for ( dx = 0 ; dx < factorx ; dx ++ ) { ra += sp -> r ; ga += sp -> g ; ba += sp -> b ; aa += sp -> a ; sp ++ ; } sp = ( tColorRGBA * ) ( ( Uint8 * ) sp + ( src -> pitch - 4 * factorx ) ) ; } sp = ( tColorRGBA * ) ( ( Uint8 * ) oosp + 4 * factorx ) ; dp -> r = ra / n_average ; dp -> g = ga / n_average ; dp -> b = ba / n_average ; dp -> a = aa / n_average ; dp ++ ; } sp = ( tColorRGBA * ) ( ( Uint8 * ) osp + src -> pitch * factory ) ; dp = ( tColorRGBA * ) ( ( Uint8 * ) dp + dgap ) ; } return ( 0 ) ; }
\brief Internal 32 bit integer-factor averaging Shrinker.
\ brief Internal 32 bit integer - factor averaging Shrinker .
/*
	* Averaging integer shrink
	*/ /* Precalculate division factor */ /*
	* Scan destination
	*/ /* Trace out source box and accumulate */ /* src dx loop */ // next y /* src dy loop */ /* next box-x */ /* Store result in destination */ /*
			* Advance destination pointer 
			*/ /* dst x loop */ /* next box-y */ /*
		* Advance destination pointers 
		*/ /* dst y loop */