// xImalpha.cpp : Alpha channel functions /* 07/08/2001 v1.00 - ing.davide.pizzolato@libero.it * CxImage version 5.71 25/Apr/2003 */ #include "ximage.h" #if CXIMAGE_SUPPORT_ALPHA //////////////////////////////////////////////////////////////////////////////// void CxImage::AlphaClear() { if (pAlpha) memset(pAlpha,0,head.biWidth * head.biHeight); } //////////////////////////////////////////////////////////////////////////////// void CxImage::AlphaSet(BYTE level) { if (pAlpha) memset(pAlpha,level,head.biWidth * head.biHeight); } //////////////////////////////////////////////////////////////////////////////// void CxImage::AlphaCreate() { AlphaDelete(); pAlpha = (BYTE*)calloc(head.biWidth * head.biHeight, 1); } //////////////////////////////////////////////////////////////////////////////// void CxImage::AlphaDelete() { if (pAlpha) { free(pAlpha); pAlpha=0; } } //////////////////////////////////////////////////////////////////////////////// void CxImage::AlphaInvert() { if (pAlpha) { BYTE *iSrc=pAlpha; long n=head.biHeight*head.biWidth; for(long i=0; i < n; i++){ *iSrc=(BYTE)~(*(iSrc)); iSrc++; } } } //////////////////////////////////////////////////////////////////////////////// bool CxImage::AlphaCopy(CxImage &from) { if (from.pAlpha == NULL || head.biWidth != from.head.biWidth || head.biWidth != from.head.biWidth) return false; if (pAlpha==NULL) pAlpha = (BYTE*)malloc(head.biWidth * head.biHeight); memcpy(pAlpha,from.pAlpha,head.biWidth * head.biHeight); info.nAlphaMax=from.info.nAlphaMax; return true; } //////////////////////////////////////////////////////////////////////////////// bool CxImage::AlphaSet(CxImage &from) { if (!from.IsGrayScale() || head.biWidth != from.head.biWidth || head.biWidth != from.head.biWidth) return false; if (pAlpha==NULL) pAlpha = (BYTE*)malloc(head.biWidth * head.biHeight); BYTE* src = from.info.pImage; BYTE* dst = pAlpha; for (long y=0; yTransfer(tmp); return true; } //////////////////////////////////////////////////////////////////////////////// bool CxImage::AlphaPaletteSplit(CxImage *dest) { if (!AlphaPaletteIsValid() || !dest) return false; CxImage tmp(head.biWidth,head.biHeight,8); for(long y=0; yTransfer(tmp); return true; } //////////////////////////////////////////////////////////////////////////////// #endif //CXIMAGE_SUPPORT_ALPHA