prev1_yoff = 1;
void Scale_2xSaI	(	Source_pixel *source,	// ->source pixels.	int srcx, int srcy,		// Start of rectangle within src.	int srcw, int srch,		// Dims. of rectangle.	int sline_pixels,		// Pixels (words)/line for source.	int sheight,			// Source height.	Dest_pixel *dest,		// ->dest pixels.	int dline_pixels,		// Pixels (words)/line for dest.	const Manip_pixels& manip	// Manipulator methods.	){	Source_pixel *srcPtr = source + (srcx + srcy*sline_pixels);	Dest_pixel *dstPtr = dest + (2*srcy*dline_pixels + 2*srcx);	if (srcx + srcw >= sline_pixels)	{		srcw = sline_pixels - srcx;	}					// Init offset to prev. line, next 2.    int prev1_yoff = srcy ? sline_pixels : 0;    int next1_yoff = sline_pixels, next2_yoff = 2*sline_pixels;					// Figure threshholds for counters.    int ybeforelast = sheight - 2 - srcy;    int xbeforelast = sline_pixels - 2 - srcx;    for (int y = 0; y < srch; y++, prev1_yoff = sline_pixels)	{		if (y >= ybeforelast)	// Last/next-to-last row?			if (y == ybeforelast)				next2_yoff = sline_pixels;			else		// Very last line?				next2_yoff = next1_yoff = 0;		Source_pixel *bP = srcPtr;		Dest_pixel *dP = dstPtr;		int prev1_xoff = srcx ? 1 : 0;		int next1_xoff = 1, next2_xoff = 2;		for (int x = 0; x < srcw; x++)		{			Source_pixel colorA, colorB;			Source_pixel colorC, colorD,				   colorE, colorF, colorG, colorH,				   colorI, colorJ, colorK, colorL,				   colorM, colorN, colorO, colorP;			Dest_pixel product, product1, product2, orig;				// Last/next-to-last row?			if (x >= xbeforelast)				if (x == xbeforelast)					next2_xoff = 1;				else					next2_xoff = next1_xoff = 0;			//---------------------------------------			// Map of the pixels:                    I|E F|J			//                                       G|A B|K			//                                       H|C D|L			//                                       M|N O|P			colorI = *(bP- prev1_yoff - prev1_xoff);			colorE = *(bP- prev1_yoff);			colorF = *(bP- prev1_yoff + next1_xoff);			colorJ = *(bP- prev1_yoff + next2_xoff);			colorG = *(bP - prev1_xoff);			colorA = *(bP);			colorB = *(bP + next1_xoff);			colorK = *(bP + next2_xoff);			colorH = *(bP + next1_yoff - prev1_xoff);			colorC = *(bP + next1_yoff);			colorD = *(bP + next1_yoff + next1_xoff);			colorL = *(bP + next1_yoff + next2_xoff);			colorM = *(bP + next2_yoff - prev1_xoff);			colorN = *(bP + next2_yoff);			colorO = *(bP + next2_yoff + next1_xoff);			colorP = *(bP + next2_yoff + next2_xoff);			if ((colorA == colorD) && (colorB != colorC))			{			   if ( ((colorA == colorE) && (colorB == colorL)) ||					((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ)) )			   {				  //product = colorA;					manip.copy(product, colorA);			   }			   else			   {				  //product = INTERPOLATE(colorA, colorB);				  product = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorB, manip);			   }			   if (((colorA == colorG) && (colorC == colorO)) ||				   ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM)) )			   {				  //product1 = colorA;					manip.copy(product1, colorA);			   }			   else			   {				  //product1 = INTERPOLATE(colorA, colorC);				  product1 = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorC, manip);			   }			   //product2 = colorA;			   manip.copy(product2, colorA);			}			else			if ((colorB == colorC) && (colorA != colorD))			{			   if (((colorB == colorF) && (colorA == colorH)) ||				   ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI)) )			   {				  //product = colorB;				  manip.copy(product, colorB);			   }			   else			   {				  //product = INTERPOLATE(colorA, colorB);				  product = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorB, manip);			   }			   if (((colorC == colorH) && (colorA == colorF)) ||				   ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI)) )			   {				  //product1 = colorC;				  manip.copy(product1, colorC);			   }			   else			   {				  //product1 = INTERPOLATE(colorA, colorC);				  product1 = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorC, manip);			   }			   //product2 = colorB;			   manip.copy(product2, colorB);			}			else			if ((colorA == colorD) && (colorB == colorC))			{			   if (colorA == colorB)			   {				  //product = colorA;				  manip.copy(product, colorA);				  //product1 = colorA;				  manip.copy(product1, colorA);				  //product2 = colorA;				  manip.copy(product2, colorA);			   }			   else			   {				  register int r = 0;				  //product1 = INTERPOLATE(colorA, colorC);				  product1 = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorC, manip);				  //product = INTERPOLATE(colorA, colorB);				  product = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorB, manip);				  r += GetResult1 <Source_pixel>(colorA, colorB, colorG, colorE);				  r += GetResult2 <Source_pixel>(colorB, colorA, colorK, colorF);				  r += GetResult2 <Source_pixel>(colorB, colorA, colorH, colorN);				  r += GetResult1 <Source_pixel>(colorA, colorB, colorL, colorO);				  if (r > 0)					  //product2 = colorA;					  manip.copy(product2, colorA);				  else				  if (r < 0)					  //product2 = colorB;					  manip.copy(product2, colorB);				  else				  {					  //product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);					  product2 = QInterpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorB, colorC, colorD, manip);				  }			   }			}			else			{			   //product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);			   product2 = QInterpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorB, colorC, colorD, manip);			   if ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ))			   {				  //product = colorA;				  manip.copy(product, colorA);			   }			   else			   if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))			   {				  //product = colorB;				  manip.copy(product, colorB);			   }			   else			   {				  //product = INTERPOLATE(colorA, colorB);				  product = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorB, manip);			   }			   if ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM))			   {				  //product1 = colorA;				  manip.copy(product1, colorA);			   }			   else			   if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI))			   {				  //product1 = colorC;				  manip.copy(product1, colorC);			   }			   else			   {				  //product1 = INTERPOLATE(colorA, colorC);				  product1 = Interpolate_2xSaI< Source_pixel,  Dest_pixel,  Manip_pixels>(colorA, colorC, manip);			   }			}			//product = colorA | (product << 16);			//product1 = product1 | (product2 << 16);			manip.copy(orig, colorA);			*dP = orig;			*(dP+1) = product;			*(dP+dline_pixels) = product1;			*(dP+dline_pixels+1) = product2;			bP += 1;			dP += 2;		}//end of for ( finish= width etc..)		srcPtr += sline_pixels;		dstPtr += 2*dline_pixels;	};}