diff src/filters/simple2x.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/filters/simple2x.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,189 @@
     1.4 +#include "../Port.h"
     1.5 +
     1.6 +void Simple2x16(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
     1.7 +                u8 *dstPtr, u32 dstPitch, int width, int height)
     1.8 +{
     1.9 +	u8 *nextLine, *finish;
    1.10 +
    1.11 +	nextLine = dstPtr + dstPitch;
    1.12 +
    1.13 +	do
    1.14 +	{
    1.15 +		u32 *bP = (u32 *) srcPtr;
    1.16 +		u32 *dP = (u32 *) dstPtr;
    1.17 +		u32 *nL = (u32 *) nextLine;
    1.18 +		u32	 currentPixel;
    1.19 +
    1.20 +		finish		 = (u8 *) bP + ((width + 2) << 1);
    1.21 +		currentPixel = *bP++;
    1.22 +
    1.23 +		do
    1.24 +		{
    1.25 +#ifdef WORDS_BIGENDIAN
    1.26 +			u32 color = currentPixel >> 16;
    1.27 +#else
    1.28 +			u32 color = currentPixel & 0xffff;
    1.29 +#endif
    1.30 +
    1.31 +			color = color | (color << 16);
    1.32 +
    1.33 +			*(dP) = color;
    1.34 +			*(nL) = color;
    1.35 +
    1.36 +#ifdef WORDS_BIGENDIAN
    1.37 +			color = currentPixel & 0xffff;
    1.38 +#else
    1.39 +			color = currentPixel >> 16;
    1.40 +#endif
    1.41 +			color	  = color | (color << 16);
    1.42 +			*(dP + 1) = color;
    1.43 +			*(nL + 1) = color;
    1.44 +
    1.45 +			currentPixel = *bP++;
    1.46 +
    1.47 +			dP += 2;
    1.48 +			nL += 2;
    1.49 +		}
    1.50 +		while ((u8 *) bP < finish);
    1.51 +
    1.52 +		srcPtr	 += srcPitch;
    1.53 +		dstPtr	 += dstPitch << 1;
    1.54 +		nextLine += dstPitch << 1;
    1.55 +	}
    1.56 +	while (--height);
    1.57 +}
    1.58 +
    1.59 +void Simple2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
    1.60 +                u8 *dstPtr, u32 dstPitch, int width, int height)
    1.61 +{
    1.62 +	u8 *nextLine, *finish;
    1.63 +
    1.64 +	nextLine = dstPtr + dstPitch;
    1.65 +
    1.66 +	do
    1.67 +	{
    1.68 +		u32 *bP = (u32 *) srcPtr;
    1.69 +		u32 *dP = (u32 *) dstPtr;
    1.70 +		u32 *nL = (u32 *) nextLine;
    1.71 +		u32	 currentPixel;
    1.72 +
    1.73 +		finish		 = (u8 *) bP + ((width + 1) << 2);
    1.74 +		currentPixel = *bP++;
    1.75 +
    1.76 +		do
    1.77 +		{
    1.78 +			u32 color = currentPixel;
    1.79 +
    1.80 +			*(dP)	  = color;
    1.81 +			*(dP + 1) = color;
    1.82 +			*(nL)	  = color;
    1.83 +			*(nL + 1) = color;
    1.84 +
    1.85 +			currentPixel = *bP++;
    1.86 +
    1.87 +			dP += 2;
    1.88 +			nL += 2;
    1.89 +		}
    1.90 +		while ((u8 *) bP < finish);
    1.91 +
    1.92 +		srcPtr	 += srcPitch;
    1.93 +		dstPtr	 += dstPitch << 1;
    1.94 +		nextLine += dstPitch << 1;
    1.95 +	}
    1.96 +	while (--height);
    1.97 +}
    1.98 +
    1.99 +#if 0
   1.100 +// generic Simple Nx magnification filter
   1.101 +template <int magnification, typename ColorType>
   1.102 +void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
   1.103 +              u8 *dstPtr, u32 dstPitch, int width, int height)
   1.104 +{
   1.105 +	srcPitch = srcPitch / sizeof(ColorType) - width;
   1.106 +	u32 dstNextP = dstPitch / sizeof(ColorType);
   1.107 +	u32 dstNextL = (dstNextP - width) * magnification;  // skip to the next magnificated 'line'
   1.108 +	dstNextP -= magnification;
   1.109 +
   1.110 +	u32 offset = (dstPitch + sizeof(ColorType)) * magnification - dstPitch;
   1.111 +
   1.112 +	ColorType *src = (ColorType *)srcPtr;
   1.113 +	ColorType *dst = (ColorType *)dstPtr;
   1.114 +
   1.115 +	do // per src line
   1.116 +	{
   1.117 +		u8 *finishP = (u8 *)dst + offset;
   1.118 +		for (int x = 0; x < width; ++x) // per pixel in line
   1.119 +		{
   1.120 +			ColorType  col	   = *src;
   1.121 +			ColorType *dst2	   = dst;
   1.122 +			u8 *	   finishM = (u8 *)(dst + magnification);
   1.123 +			do // dst magnificated pixel
   1.124 +			{
   1.125 +				do
   1.126 +				{
   1.127 +					*dst2 = col;
   1.128 +				}
   1.129 +				while ((u8 *)++dst2 < finishM);
   1.130 +				dst2	+= dstNextP;
   1.131 +				finishM += dstPitch;
   1.132 +			}
   1.133 +			while ((u8 *)dst2 < finishP);
   1.134 +
   1.135 +			++src;
   1.136 +			dst		+= magnification;
   1.137 +			finishP += magnification * sizeof(ColorType);
   1.138 +		}
   1.139 +		src += srcPitch;
   1.140 +		dst += dstNextL;
   1.141 +	}
   1.142 +	while (--height);
   1.143 +}
   1.144 +
   1.145 +#else
   1.146 +
   1.147 +// generic Simple Nx magnification filter
   1.148 +template <int magnification, typename ColorType>
   1.149 +void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
   1.150 +              u8 *dstPtr, u32 dstPitch, int width, int height)
   1.151 +{
   1.152 +	srcPitch  = srcPitch / sizeof(ColorType) - width;
   1.153 +	dstPitch /= sizeof(ColorType);
   1.154 +	u32 dstBlank = (dstPitch - width) * magnification; // skip to the next magnificated 'line'
   1.155 +	dstPitch -= magnification;
   1.156 +
   1.157 +	ColorType *src = (ColorType *)srcPtr;
   1.158 +	ColorType *dst = (ColorType *)dstPtr;
   1.159 +
   1.160 +	do // per src line
   1.161 +	{
   1.162 +		for (int x = 0; x < width; ++x) // per pixel in src line
   1.163 +		{
   1.164 +			ColorType  col	= *src;
   1.165 +			ColorType *dst2 = dst;
   1.166 +			for (int dy = 0; dy < magnification; ++dy) // dst magnificated pixel
   1.167 +			{
   1.168 +				for (int dx = 0; dx < magnification; ++dx)
   1.169 +				{
   1.170 +					*dst2 = col;
   1.171 +					++dst2;
   1.172 +				}
   1.173 +				dst2 += dstPitch;
   1.174 +			}
   1.175 +
   1.176 +			++src;
   1.177 +			dst += magnification;
   1.178 +		}
   1.179 +		src += srcPitch;
   1.180 +		dst += dstBlank;
   1.181 +	}
   1.182 +	while (--height);
   1.183 +}
   1.184 +
   1.185 +#endif
   1.186 +
   1.187 +typedef void (*SimpleNxFP)(u8 *, u32, u8 *, u8 *, u32, int, int);
   1.188 +
   1.189 +SimpleNxFP Simple3x16 = SimpleNx<3, u16>;
   1.190 +SimpleNxFP Simple3x32 = SimpleNx<3, u32>;
   1.191 +SimpleNxFP Simple4x16 = SimpleNx<4, u16>;
   1.192 +SimpleNxFP Simple4x32 = SimpleNx<4, u32>;