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 & HelpSyntax Questions › alpha channel strange behavior
Page Index Toggle Pages: 1
alpha channel strange behavior (Read 1117 times)
alpha channel strange behavior
Jun 18th, 2005, 3:34pm
 
I'm wonder why this two scripts behave in a very different way.

I have a PImage with an alpha channel assigned in this way once:

Code:

overlay.pixels[(y*w)+x]=(overlay.pixels[(y*w)+x] & 0xffffff) | (dark_mask[y][p] << 24);


if in the draw handler I draw the image in this way:

Code:
image(overlay,0,0); 



it works perfectly, but if I want to save performance drawing in this way something weird happens:

Code:
for(int i=0; i<npixels; i++) pixels[i]=overlay.pixels[i]; 



It seems that the alpha channel of overlay becomes overwritten everytime increasing the contrast and becoming at 1 bit.

Can someone explain me why?


Thanks to everyone, chr
Re: alpha channel strange behavior
Reply #1 - Jun 18th, 2005, 6:27pm
 
does overlay.pixels[] have its alpha channel set properly?
Re: alpha channel strange behavior
Reply #2 - Jun 19th, 2005, 1:30am
 
it is set in this way:

Code:
dark_mask[y][x]=(int)(random(255));
overlay.pixels[(w*y)+x]=color(0);
overlay.pixels[(y*w)+x]=(overlay.pixels[(y*w)+x] & 0xffffff) | (dark_mask[y][p] << 24);


thx, chr
Re: alpha channel strange behavior
Reply #3 - Jun 19th, 2005, 12:21pm
 
p in the last row?? Perhaps you mean x.
Re: alpha channel strange behavior
Reply #4 - Jun 19th, 2005, 12:47pm
 
unfortunately now my code is totally changed but anyway I'm sure it was the same value of "x".

If I'll find the time I'll prepare a simple example. Mine project was a bit more complex, so I cut and paste parts of it.


thanks, chr
Re: alpha channel strange behavior
Reply #5 - Jun 20th, 2005, 10:24pm
 
I made a small example in p5 (mine was on eclipse) and it works... of course I was making some mistakes somewhere, anyway the working code is:

Code:
int w;
int h;
int npixels;

PImage myImage;
int[] myMask;

void setup(){
w=400;
h=278;
size(w,h);
npixels=w*h;
myMask=new int[npixels];
for(int i=0; i<npixels; i++){
myMask[i]=color(int(random(255)));
}
myImage=loadImage("image.png");
myImage.loadPixels();
for(int i=0; i<npixels; i++){
myImage.pixels[i]=(myImage.pixels[i] & 0xffffff) | (myMask[i] << 24);
}
myImage.updatePixels();
image(myImage,0,0);
}
void draw(){
background(0);
image(myImage,0,0);
}



thanks, chr
Page Index Toggle Pages: 1