 |
Author |
Topic: AlphaImg customizing (Read 771 times) |
|
takashi mizohata
|
AlphaImg customizing
« on: Oct 27th, 2004, 5:36pm » |
|
I'm working on customizing "AlphaImg" class, which is made by toxi.. http://processing.org/learning/examples/alphamask.html I want that class give me back a blended-image as BImage. Does anyone has an idea? Or someone has already got the same thing??
|
|
|
|
toxi
|
Re: AlphaImg customizing
« Reply #1 on: Oct 27th, 2004, 6:43pm » |
|
takashi, you should have a look at all the functions in the BImage reference. the demo you're referring to is ancient, from times prior to these imaging functions to blend two images and store the result in one of them, simply do: Code:BImage a,b; a.blend(b,0,0,b.width,b.height,0,0,a.width,a.height,BLEND); |
| only that still requires that image B has an alpha channel. i guess a function to set the global alpha level of an image would be useful in future, but for now just put this in your code: Code:// set global opacity of an image // alpha value in range 0 (transparent) ... 255 (opaque) void setAlpha(BImage img, int alpha) { alpha<<=24; for(int i=0; i<img.pixels.length; i++) img.pixels[i]=img.pixels[i] & 0xffffff | alpha; } |
| hth!
|
http://toxi.co.uk/
|
|
|
kensuguro
|
Re: AlphaImg customizing
« Reply #2 on: Oct 27th, 2004, 7:41pm » |
|
on a similar note, is there any way where I can do a C=A*factor+B*factor type blend? (where source and desitination are factored)
|
|
|
|
toxi
|
Re: AlphaImg customizing
« Reply #3 on: Oct 27th, 2004, 9:19pm » |
|
here's an (untested) function to blend 2 images and store the result in a new one. no alpha channels are used, but you'll have to specify the blend factors: Code:// blend 2 equal sized images with specified factors // factors in range 0...255 // resulting image is fully opaque BImage mergeImages(BImage a, BImage b, int aFactor, int bFactor) { BImage c=new BImage(a.width,a.height); for(int i=0; i<c.pixels.length; i++) c.pixels[i]=blendColours(a.pixels[i],b.pixels[i],aFactor,bFactor); return c; } int blendColours(int a, int b, int fa, int fb) { // make sure there's no alpha info in colours a&=0xffffff; b&=0xffffff; return 0xff000000 | /* alpha */ mix(((a>>16)*fa)>>8,b>>16,fb)<<16 | /* red */ mix(((a>>8)*fa)>>8,b>>8,fb)<<8 | /* green */ mix(((a&0xff)*fa)>>8,b&0xff,fb); /* blue */ } int mix(int a, int b, int f) { return a + (((b - a) * f) >> 8); } |
|
|
http://toxi.co.uk/
|
|
|
takashi mizohata
|
Re: AlphaImg customizing
« Reply #4 on: Oct 31st, 2004, 7:00am » |
|
Thanks toxi, your reply is very helpful! Your code on this site also teaches me a lot. I actually am thinking that I will implement some image processing algorithm to understand it. So I might ask something stupid again.. Anyway thanks again.
|
|
|
|
|