Aus Weis nix
// Software Chroma Keying in an Immersive Virtual Environment
// Adapted by A. Schiffler from:
// F. van den Bergh , V. Lalioti!
// Department of Computer Science, University of Pretoria, South Africa, fvdbergh@cs.up.ac.za
// Department of Computer Science, University of Pretoria, South Africa, vlalioti@cs.up.ac.za
// http://www.makebelieve.gr/vl/Publications/SAICSIT99.pdf
//
// alpha_map [0..511]:
// is linar drop from 255 to 0 over the range 100-255
unsigned char alpha_map[512];
//
// Call before using chromakey()
void init_alpha_map() {
int i;
for (i=0; i<512; i++) {
if (i<128) {
alpha_map[i] = 255;
} else if (i<256) {
alpha_map[i] = 255-2*(i-127);
} else {
alpha_map[i] = 0;
}
}
}
//
// s points to the interleaved RGBA image
void chromakey(unsigned char *s, int imgsize) {
unsigned char *rp=s,*gp=s+1, *bp=s+2,*ap=s+3;
int i;
for (i = 0; i < imgsize; i++) {
if ( (*bp > *rp) && (*bp > *gp) ) {
*ap = alpha_map[ ( ( (unsigned int)(*bp - *rp) + (unsigned int)(*bp + *gp) ) & 0x000001ff) ];
} else {
*ap = 255;
}
rp += 4;
bp += 4;
gp += 4;
ap += 4;
}
}