We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Mask on multiple images
Page Index Toggle Pages: 1
Mask on multiple images (Read 1632 times)
Mask on multiple images
Jun 3rd, 2007, 2:08am
 
Hello, I have a question about an effects I'm trying to achieve: basically I need to use a single mask, static and with a fixed absolute position in the scene, on multiple moving images: that is to say, I need to have a scene with images floating around but then show just just a "slice" (the shape of the mask) of the whole scene. That means the mask cannot be applied to each single image normally because the position of the mask must be fixed and independent by the positions of the images, and we'll see the images (or parts of) only when they happen to pass where the mask is.
I can't figure out the best approach to achieve this.
Any idea/experience?

Thank you in anticipate to anyone who will take the time to read this post(and hopefully help)!!
Re: Mask on multiple images
Reply #1 - Jun 3rd, 2007, 3:09am
 
You can use a gif or png image with transparency representing the shape/mask.

Then if you want it in front of all your sketch layers, just add it at the end of draw()

Quote:
PImage Mymask;

void setup(){

...YOUR SETUP CODE HERE...

Mymask = loadImage("mymask.png")
}

void draw(){

...YOUR DRAW CODE HERE...

translate(0,0,100); // 100 will make the image() below to be displayed +100 pixels away on Z axys in front of the previous object/image.
image(Mymask,0,0,width,height);
}


The advantage of this is that it is compatible with OPENGL rendering.
Re: Mask on multiple images
Reply #2 - Jun 3rd, 2007, 3:34pm
 
Thanks jay, that's a smart approach (and it works!).
The only problem with me is this: I was trying to use a "real" mask because after having obtained the slice I'll have to make copies of what happens in that area. I mean, I really have to "cut" a part of a underneath(moving) scene and then replicate it. With this "3D window" approach it's not possible to replicate only that area because what is covered by the png image is still there.
What I'm trying to do is a kaleidoscope where everything that happens in a slice (which is a 30° section of the whole circle) is mirrored and then cloned and rotated 5 times to fill the entire circle with reflections.

Thank you for your help and you feel like having some other idea on the approach I could use, you are very welcome! Wink
Re: Mask on multiple images
Reply #3 - Jun 3rd, 2007, 4:44pm
 
flablo wrote on Jun 3rd, 2007, 3:34pm:
What I'm trying to do is a kaleidoscope


What you may want to do is have an offscreen PImage or PGraphics (whichever you need) and do all your initial drawing onto that.  Then apply your pie-slice mask to that image, then composite it onto the main drawing surface six times with desired rotation using image().
Re: Mask on multiple images
Reply #4 - Jun 6th, 2007, 3:59pm
 
Yes, in fact that's exactly what I did(and I'm glad that the solution I found is the right one!). It works perfectly, only I have a few issues/questions?
- Is PGraphics somehow faster than PImage or is it the same in terms of performance?
- I'm loading some video clips as well into the kaleidoscope, with RGBA channel, which works with JAVA2D but with P3D (which renders with better antialiasing) I loose the alpha information. Is this a typical issue with P3D or am I missing something?

Thank you for your support!!!
f
Re: Mask on multiple images
Reply #5 - Jun 7th, 2007, 7:57am
 
performance? at doing what? PGraphics extends PImage, so the functions it inherits are probably the same ...

PImage is for loading, working-with (holding) and saving images
PGraphics adds drawing and other image manipulations to that

i think processing assumes ARGB .. not sure why JAVA2D would detect that automatically. you might consider converting your videos before loading.

F
Re: Mask on multiple images
Reply #6 - Jun 7th, 2007, 9:38am
 
Thanks fjen, got it with PGraphics/PImage usage! It DOES work.

I created separate clips from the orgiginal clips'alpha converted as luma, loaded them and applied to the original clips as mask. Well, it worked and now I see right in P3D. The strange thing is: even if I shouldn't need anymore an alpha channel in the original clip (because I apply it expressely through the masking), so they could be RGB clip + mask clip, I saw that it doesn't work this way, the image disappears and sometime flickers in. It works only with ARGB clip + mask clip.

fjen, what do you mean exactly by "converting"? Separating RGA and alpha as I did? Or something else?

thanks!!!
f
Re: Mask on multiple images
Reply #7 - Apr 4th, 2008, 7:08am
 
Hey,

I've found out how to easily display .mov's with alpha transparency, Its like you mentioned above flablo, Although you only need one movie: RGBA then use the same movie as a mask and it works!! Weird, anyway heres an example:

import processing.video.*;

Movie myMovie;

void setup() {
 size(200, 200);
 frameRate(30);
 myMovie = new Movie(this, "RGBA.mov");
 myMovie.loop();
 myMovie.mask(myMovie);
}

void draw() {
 background(250);
 if(myMovie.available()){
   myMovie.read();
 }

 image(myMovie, 0, 0);
 myMovie.mask(myMovie);

}

tested with JAVA2D and P3D
Page Index Toggle Pages: 1