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

Shrinks 8bit Y 'src' surface to 'dst' surface.
Averages color (brightness) values values of src pixels to calculate dst pixels.
Assumes src and dst surfaces are of 8 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 8 bit integer-factor averaging shrinker.
Shrinks 8bit Y 'src' surface to 'dst' surface.
Averages color (brightness) values values of src pixels to calculate dst pixels.
Assumes src and dst surfaces are of 8 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 8 bit integer - factor averaging shrinker . Shrinks 8bit Y ' src ' surface to ' dst ' surface . Averages color ( brightness ) values values of src pixels to calculate dst pixels . Assumes src and dst surfaces are of 8 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 _shrinkSurfaceY(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory)
{
	int x, y, dx, dy, dgap, a;
	int n_average;
	Uint8 *sp, *osp, *oosp;
	Uint8 *dp;
	n_average = factorx*factory;
	sp = (Uint8 *) src->pixels;
	dp = (Uint8 *) dst->pixels;
	dgap = dst->pitch - dst->w;
	for (y = 0; y < dst->h; y++) {    
		osp=sp;
		for (x = 0; x < dst->w; x++) {
			oosp=sp;
			a=0;
			for (dy=0; dy < factory; dy++) {
				for (dx=0; dx < factorx; dx++) {
					a += (*sp);
					sp++;
				} 
				sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx)); 
			} 
			sp = (Uint8 *)((Uint8*)oosp + factorx);
			*dp = a/n_average;
			dp++;
		} 
		sp = (Uint8 *)((Uint8*)osp + src->pitch*factory);
		dp = (Uint8 *)((Uint8 *)dp + dgap);
	} 
	return (0);
}
int _shrinkSurfaceY ( SDL_Surface * src , SDL_Surface * dst , int factorx , int factory ) { int x , y , dx , dy , dgap , a ; int n_average ; Uint8 * sp , * osp , * oosp ; Uint8 * dp ; n_average = factorx * factory ; sp = ( Uint8 * ) src -> pixels ; dp = ( Uint8 * ) dst -> pixels ; dgap = dst -> pitch - dst -> w ; for ( y = 0 ; y < dst -> h ; y ++ ) { osp = sp ; for ( x = 0 ; x < dst -> w ; x ++ ) { oosp = sp ; a = 0 ; for ( dy = 0 ; dy < factory ; dy ++ ) { for ( dx = 0 ; dx < factorx ; dx ++ ) { a += ( * sp ) ; sp ++ ; } sp = ( Uint8 * ) ( ( Uint8 * ) sp + ( src -> pitch - factorx ) ) ; } sp = ( Uint8 * ) ( ( Uint8 * ) oosp + factorx ) ; * dp = a / n_average ; dp ++ ; } sp = ( Uint8 * ) ( ( Uint8 * ) osp + src -> pitch * factory ) ; dp = ( Uint8 * ) ( ( Uint8 * ) dp + dgap ) ; } return ( 0 ) ; }
\brief Internal 8 bit integer-factor averaging shrinker.
\ brief Internal 8 bit integer - factor averaging shrinker .
/*
	* Averaging integer shrink
	*/ /* Precalculate division factor */ /*
	* Scan destination
	*/ /* Trace out source box and accumulate */ /* next x */ /* end src dx loop */ /* next y */ /* end src dy loop */ /* next box-x */ /* Store result in destination */ /*
			* Advance destination pointer 
			*/ /* end dst x loop */ /* next box-y */ /*
		* Advance destination pointers 
		*/ /* end dst y loop */