2D ALPHA
BlitzPlus Forums/BlitzPlus Programming/2D ALPHA| 
 | ||
| Some time ago I saw a nice sample code to make an alpha effect with B+ , using a DLL (blend.dll) . It's fast, but is it possible to make it work with an image that has a mask ? In the sample, it is used a square.. if I need a circle, I must to mask a part of it, using MaskImage() . But it seems it doesn't care of mask colour. Any hints? Thank you. | 
| 
 | ||
| you must rewrite my DLL (source is included) - use DevCpp (older version is better) but i think this is faster: 1.) blend image+background to tmp-image 2.) use black/white shape and draw this masked to tmp-image 3.) draw tmp-image to background | 
| 
 | ||
| Thank you. Where can I find your DLL ? I know C/C++ and I could modify it. Please may you explain better better 1)2)3) steps ? | 
| 
 | ||
| http://www.blitzbasic.com/toolbox/toolbox.php?tool=38 1) load normal image and a second blask/white shape (=2 images) 2) copy background to tmp-image and blend normal image to tmp-image 3) draw black/white shape to tmp-image (now you have your blended and masked image) 4) draw tmp-image to background if you can c++ than modify my dll - i think it is easier (but i think not faster) | 
| 
 | ||
| This is the code based on 24/32bit source and destination, feel free to play. :) 		dest_bpp=dest_format;
		for(src_Y=src_Ystart, src_Yoff=src_Ystart*src_pitch, dest_Yoff=y*dest_pitch;
		src_Y<src_Yend;
		src_Y++, src_Yoff+=src_pitch, dest_Yoff+=dest_pitch){
			for(src_X=src_Xstart, src_Xoff=src_Yoff+(src_Xstart*src_bpp), dest_Xoff=dest_Yoff+(x*dest_bpp); 
			src_X<src_Xend; 
			src_Xoff+=src_bpp, dest_Xoff+=dest_bpp, src_X++){
				checkalpha=src_buffer[src_Xoff];
				if(src_alpha>0 && src_alpha<256){
					checkalpha=256-checkalpha;
					dest_buffer[dest_Xoff+2]=((dest_alpha * dest_buffer[dest_Xoff+2]) + (src_alpha * src_buffer[src_Xoff+2])) >> 8;
					dest_buffer[dest_Xoff+1]=((dest_alpha * dest_buffer[dest_Xoff+1]) + (src_alpha * src_buffer[src_Xoff+1])) >> 8;
					dest_buffer[dest_Xoff]=((dest_alpha * dest_buffer[dest_Xoff]) + (src_alpha * src_buffer[src_Xoff])) >> 8;
				}
				else if(src_alpha=0){
					dest_buffer[dest_Xoff+2]=src_buffer[src_Xoff+2];
					dest_buffer[dest_Xoff+1]=src_buffer[src_Xoff+1];
					dest_buffer[dest_Xoff]=src_buffer[src_Xoff];
				}
			}
		}
		break; | 
| 
 | ||
| Oh, if you didn't notice checkalpha is a dummy call since I was testing how much impact reading an alpha channel would cause. |