_ALPHA BLENDING GRAPHIC IMAGES_ by Tim Wittenburg Listing One void memImage::smoothX3NN(){ int x, y; BYTE HUGE *myTemp = bytes; for (y = 1; y <= imageHeight; y++){ for (x = 1; x < imageWidth; x++){ if(x == 1 && *myTemp > 0){ *myTemp = (*(myTemp)+ *(myTemp+1))*0.5; } else if(x == imageWidth && *myTemp > 0){ *myTemp = (*(myTemp-1) + *(myTemp))*0.5; } else if(x > 1 && x < imageWidth && *myTemp > 0){ *myTemp = (*(myTemp-1) + *(myTemp)+ *(myTemp+1))*0.33333; } myTemp++; } myTemp+=pads; } } void memImage::smoothY3NN(){ int x, y, y1, y2, y3, result; for (x = 1; x <= imageWidth; x++){ for (y = 1; y <= imageHeight; y++){ if(y > 1) y1 = getMPixel(x, y - 1); y2 = getMPixel(x, y); if(y < imageHeight) y3 = getMPixel(x, y + 1); result = 0; if(y == 1 && y2 > 0) result = (y2 + y3) * 0.5; if(y > 1 && y < imageHeight && y2 > 0) result = (y1 + y2 + y3) * 0.33333; if(y == imageHeight && y2 > 0) result = (y1 + y2) * 0.5; setMPixel(x, y, (BYTE)result); } } } Listing Two short blend(memImage *inImage, memImage *alphaImage, memImage *outImage, float alphaScale, short xOffset, short yOffset){ // // Blend over the common area in input and mask images // short inputRows = inImage->getHeight(); short inputCols = inImage->getWidth(); short maskRows = maskImage->getHeight(); short maskCols = maskImage->getWidth(); short commonRows = min(inputRows, maskRows); short commonCols = min(inputCols, maskCols); // // each memImage is assumed to be opened for random access short x, y; BYTE maskPixel, inPixel, outPixel, addedPixel; float inWeight, outWeight; for(y = 1; y <= commonRows; y++){ for(x = 1; x <= commonCols; x++){ maskPixel = maskImage->getMPixel(x, y); if(maskPixel > 0){ inPixel = inImage->getMPixel(x, y); outPixel = outImage->getMPixel(x + xOffset, y + yOffset); inWeight = (float)maskPixel / 255.0 * alphaScale; outWeight = 1.0 - inWeight; if(alphaScale > 0.0) addedPixel = (inWeight * (float)inPixel) + (outWeight *(float)outPixel) + 0.5; else{ addedPixel = (float)outPixel + (inWeight *(float)inPixel) + 0.5; // make certain shadows won't produce negative values if (addedPixel > outPixel) addedPixel = outPixel; } if (addedPixel < 1) addedPixel = 1; if (alphaScale == 0.0) addedPixel = 0; outImage->setMPixel(x + xOffset, y + yOffset, addedPixel); } } } return 0; }