Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Alpha Channel not Changing

$
0
0
Hi, I am pretty new to Processing, have been working on it for a few months. I have searched through the internet but my problem doesn't make sense. 
I have two videos playing and want to have a fade transition between them. I access directly each pixel but no matter what the alpha value is there is no change. For now I just have my code prepared to fade from a specific video to the other. If I can make it fade  from this video to the other I will be able to adapt and fade for the video that currently will be playing.
Here is my code:
  1. import processing.video.*;

  2. Movie movie1, movie2;
  3. float alpha;

  4. void setup() {
  5.   alpha = 255.0;
  6.   size(320, 240, P2D);
  7.   movie1 = new Movie(this, "Video1.mov");
  8.   movie2 = new Movie(this, "Video2.mov");
  9.   movie1.loop();
  10.   movie2.loop();
  11. }

  12. void movieEvent(Movie mov) {
  13.   mov.read();
  14. }

  15. void draw()  {
  16.   if (fade) { // Fade Transition
  17.     image(movie1, 0, 0, width, height);
  18.     fade(movie1, movie2, movie1Playing);
  19.   } else {
  20.     image(movie2, 0, 0, width, height);
  21.   }
  22. }

  23. void fade(Movie mov1, Movie mov2) {
  24.   float r = 0.0;
  25.   float g = 0.0;
  26.   float b = 0.0;

  27.   int x = 0;
  28.   int y = 0;
  29.   int pos = 0;
  30.   
  31.   loadPixels();
  32.   mov1.loadPixels();
  33.   mov2.loadPixels();
  34.     
  35.     if(alpha > 0) {
  36.       alpha--;
  37.     }
  38.     
  39.     for (x = 0; x < mov2.width; x++) {
  40.       for (y = 0; y < mov2.height; y++ ) {

  41.         pos = x + y*mov2.width;
  42.         
  43.         r = red(mov2.pixels[pos]);
  44.         g = green(mov2.pixels[pos]);
  45.         b = blue(mov2.pixels[pos]);
  46.   
  47.         color newColor = color(r,g,b, alpha);
  48.         pixels[pos] = newColor;
  49.       }
  50.     } 
  51.   
  52.   updatePixels();
  53. }

  54. void keyPressed() {
  55.   switch (key) {
  56.     case 'f':
  57.       fade = !fade;
  58.       break;
  59.   }
  60. }
For this work I can't use libraries or the tint function, I have to directly access the pixels and modify them.
I don't know why it's not working. I would appreciate any help you can give me.
Thanks in advance!

Viewing all articles
Browse latest Browse all 1768

Trending Articles