Log in

View Full Version : alpha channels


neily
23rd July 2003, 01:51
Hi,

I have 2 questions related to alpha channels. Firstly, is it possible to assign the alpha channel of one clip to another clip? Secondly, what is the simplest way to display the alpha channel of a clip. I seem to be able to do it but in a rather untidy way, whereby I white-out the clip using RGBAdjust (Levels seems to affect the alpha channel too), create a black BlankClip, and Layer the clip onto the BlankClip using "add" and level=255.

Wilbert
23rd July 2003, 09:39
Secondly, what is the simplest way to display the alpha channel of a clip.
clip3=Layer(clip2, clip, "add", 256) # clip2 is a black clip made with blankclip

Firstly, is it possible to assign the alpha channel of one clip to another clip?

Maskclip(clip4, clip3) # clip4 gets the alpha channel of clip

neily
23rd July 2003, 10:25
Wilbert,

Thanks for the reply, but neither of your replies seem quite what I was hoping for. Firstly, where does Maskclip come from? AVISynth v2.52 doesn't recognise it as a function. Secondly, the Layer example adds the visible image of "clip" to clip2 with a strength dependent on the values of the alpha channel, which is why in my original method I was whiting-out the clip first before layering. I was hoping there would be a better way.

Wilbert
23rd July 2003, 10:52
I meant the other way around, and Mask instead of Maskclip:

clip3=Layer(clip, clip2, "add", 256) # clip2 is a black clip made with blankclip
Maskclip(clip4, clip3) # clip4 gets the alpha channel of clip

I guess it gives the same problem ?

neily
23rd July 2003, 11:14
Wilbert,

My understanding is that Mask(clip,clip1) applies a greyscale version of the visible channels of clip1 as a mask to clip, ignoring the alpha channel of clip1.

In your revised layer example, the output is always just the original clip isn't it, as all it does is add zero value pixels?

It seems as if basing a BlankClip on a clip with an alpha channel does not make the BlankClip inherit the alpha channel.

It is curious also that the Levels function should affect the alpha channel.

I guess I am just too used to the way channels wotk in Photoshop, and expect AVISynth to work in roughly the same way.

Wilbert
23rd July 2003, 12:08
My understanding is that Mask(clip,clip1) applies a greyscale version of the visible channels of clip1 as a mask to clip, ignoring the alpha channel of clip1.

Correct.

It seems as if basing a BlankClip on a clip with an alpha channel does not make the BlankClip inherit the alpha channel.
Nb, (I think) clip3 doesn't have an alpha channel. In clip3 only the alpha channel of clip is visible. In the second line clip3 becomes the alpha channel of clip4. But I'm at work now, so I can't try it.

It is curious also that the Levels function should affect the alpha channel.
This shouldn't be happening, I guess. I will tell Sh0dan about it, when he's back.

WarpEnterprises
23rd July 2003, 15:34
* sadly many functions destroy the alpha values.
* copying the mask should be a separate new function or better an extension to Mask, like Mask(use_alpha = true)

neily
23rd July 2003, 21:07
Yes, I am discovering this. My original idea works if crudely, but whiting out the clip is problematic too. Using high values for RGBAdjust only works if none of the pixel values have a channel zero value. I tried layering on a white BlankClip, but for some reason this seems to be messing up the alpha channel of the original clip.

In the same way that one can mess around with audio channels and the YUV channels of YV12 clips, it would be nice if one could manipulate R, G, B, and a channels.

neily
24th July 2003, 09:32
More strangeness. Try this.

vid00=ColorBars(352,288).ConvertToRGB32.ResetMask
vid01=BlankClip(vid00,color=$FFFFFF).ResetMask
Layer(vid00,vid01,"lighten",level=255,threshold=0)

One would have thought that the output should be all white, but instead you get a mosaic of cyan!

WarpEnterprises
24th July 2003, 14:13
lighten and darken seem to be ok only for YUY2.
As the whole layer thing is written in assembler, I can't check anything :(

Kurosu
24th July 2003, 14:56
Originally posted by neily
More strangeness. Try this.

vid00=ColorBars(352,288).ConvertToRGB32.ResetMask
vid01=BlankClip(vid00,color=$FFFFFF).ResetMask
Layer(vid00,vid01,"lighten",level=255,threshold=0)

One would have thought that the output should be all white, but instead you get a mosaic of cyan!

Well, lighten does this by calculating luminance out of RGB, . A wild gues would be that RGB $FFFFFF is YUV $FF0000 (and maybe other stuff not in RGB), while maybe YUV $FFFFFF is needed. Therefore, using a RGB color that matches YUV $FFFFFF might help.

[edit]
The culprit *might* be the 2 inverted lines:
punpckldq mm2, mm2 ;mm2= 00aa*|00aa*|00aa*|00aa*
punpcklwd mm2, mm2 ;mm2= 0000|0000|00aa*|00aa*

which should read AFAIK:
punpcklwd mm2, mm2
punpckldq mm2, mm2

Not tested. But I think my first idea is now false. :)