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 › argb and rgba reversal question
Page Index Toggle Pages: 1
argb and rgba reversal question (Read 818 times)
argb and rgba reversal question
Nov 6th, 2006, 11:33am
 
I have a code which basically bitshifts the alpha of the pixel array and brings it back in, essentially fading the background.  however, when I shift it, the white parts of the original background becomes blue.  is there a reverse somewhere I just don't know about? here's my code

PImage last;
float x,y;
float dx, dy;
void setup(){
 colorMode(RGB,255,255,255,100);
 size(400,400);
 last = new PImage(width,height);
 x=50;
 y=50;
 for(int i=0; i<last.pixels.length; i++){
   last.pixels[i]=color(0);
 }
 dx =350;
 dy=50;
}
void draw(){
 loadPixels();
 arraycopy(last.pixels, pixels);
 updatePixels();

 //draw beneath here if you want to keep

 noStroke();
 fill(0,125,255);
 ellipse(x,y,5,5);
 x++;
 y++;

 //draw above here if you want to keep

 loadPixels();
 for(int i=0; i<pixels.length;i++){

   int a = 10;
   a=a << 24;
   int b=pixels[i] & 0xFF;
   int r=pixels[i] >> 16 & 0xFF;
   int g=pixels[i] >> 8 & 0xFF;


   last.pixels[i]=a | r | g | b ;

   /* float r = red(pixels[i]);
    float g = green(pixels[i]);
    float b = blue(pixels[i]);
    last.pixels[i]=color(r,g,b,10);*/
   //last.pixels[i]=pixels[i];
 }

 //draw below here if you want to refresh every frame

 noStroke();
 fill(255,0,0);
 ellipse(dx,dy,5,5);
 dx--;
 dy++;

}


the white ball should leave a white streak but the red should slowly fade out.

.... any help would be appreciated
Re: argb and rgba reversal question
Reply #1 - Nov 6th, 2006, 5:59pm
 
I think the problem is in your bitwise ops. See if this does it.

Code:

PImage last;
float x, y;
float dx, dy;
void setup(){
size(400, 400);
background(0);
last = createImage(width, height, RGB);
x = 50;
y = 50;
for(int i=0; i<last.pixels.length; i++){
last.pixels[i]=color(0);
}
dx = 350;
dy = 50;
noStroke();
}
void draw(){
loadPixels();
arraycopy(last.pixels, pixels);
updatePixels();

//draw beneath here if you want to keep
fill(255, 255, 255);
ellipse(x, y, 5, 5);
x++;
y++;

//draw above here if you want to keep
loadPixels();
for(int i=0; i<pixels.length;i++){
int a = color(0, 10) >> 24 & 0xFF;
int r = pixels[i] >> 16 & 0xFF;
int g = pixels[i] >> 8 & 0xFF;
int b = pixels[i] & 0xFF;
last.pixels[i]= (a<<24) | (r<<16) | (g<<8) | b ;
}

//draw below here if you want to refresh every frame
fill(255, 0 , 0);
ellipse(dx, dy, 5, 5);
dx--;
dy++;
}
Re: argb and rgba reversal question
Reply #2 - Nov 6th, 2006, 6:30pm
 
Or since you're only modifying the alpha value, not the rgb values, you could further simplify your inner loop as:

   int a = 10; // any value in 0..255
   last.pixels[i]= (a<<24) | (pixels[i]&0xFFFFFF);
Re: argb and rgba reversal question
Reply #3 - Nov 6th, 2006, 7:11pm
 
nice.
Re: argb and rgba reversal question
Reply #4 - Nov 8th, 2006, 3:51pm
 
nice indeed
Page Index Toggle Pages: 1