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 › basic pixel copy
Page Index Toggle Pages: 1
basic pixel copy (Read 460 times)
basic pixel copy
Nov 24th, 2007, 4:38pm
 
Hi,

I'm actually stuck with a simple thing but i'm not into the good context to get it working. I've actually 100 images generated randomly by a sketch.

I've stored them in a array of PImage's and load each image pixels in memory.  

I want to get each lines' pixels of each images and copy them into the final image.

So the first line of image 1 will be the first line of the final image, the second line of image 2 will be the second line of the final image and the like until the widht of the final image.

Here's my try so far but my loop algorithm isn't good.

Quote:


PImage[] images = new PImage[100];
PImage output = createImage(300, 100, ARGB);

size(300, 100);
background(0);

//load all the images (from 0001 to 0100) in the images array
for (int i=0; i<=99; i++){
 if (i<9)
 {
   images[i] = loadImage("pattern-000"+ (i+1) +".png");
   println("pattern-000"+ (i+1) +".png");
 }
 else if (i <99)
 {
   images[i] = loadImage("pattern-00"+ (i+1) +".png");
   println("pattern-00"+ (i+1) +".png");
 }
 else if (i == 99) {
   images[i] = loadImage("pattern-0"+ (i+1) +".png");
   println("pattern-0"+ (i+1) +".png");
 }

 images[i].loadPixels(); //load all images pixels in memory.

 
 for (int j=0; j< (width-1); j++){
   for (int k=1; k<height; k++){
    output.pixels[j*k] = images[i].pixels[j*k];
   }
 }

 /*
   for (int k=0; k<width; k++){
  for (int j=0; j<100 ;j++){
  output.pixels[j] = images[i].pixels[k];
  //translate(0, j);
  //output.pixels[j] = images[i].pixels[j];  
  }
  }
  */
}

image(output, 0, 0);



I'm sorry, i know that's very simple, but sometimes my brain seems like not working anymore.

Regards.
Re: basic pixel copy
Reply #1 - Nov 24th, 2007, 7:00pm
 
Here's a better version of the code for filling the output PImage pixel array with the correct loop i think. But actually only the last image pixel are get and set.

Quote:


PImage[] images = new PImage[100];
PImage output = createImage(300, 100, ARGB);

size(300, 100);
background(0);

//load all the images (from 0001 to 0100) in the images array
for (int i=0; i<=99; i++){
 if (i<9)
 {
   images[i] = loadImage("pattern-000"+ (i+1) +".png");
   println("pattern-000"+ (i+1) +".png");
 }
 else if (i <99)
 {
   images[i] = loadImage("pattern-00"+ (i+1) +".png");
   println("pattern-00"+ (i+1) +".png");
 }
 else if (i == 99)
 {
   images[i] = loadImage("pattern-0"+ (i+1) +".png");
   println("pattern-0"+ (i+1) +".png");
 }

 //this loop fill the output.pixel array well but only with the
 //last image pixels.
 for (int j=0; j<height; j++){
   for (int l=0; l<width; l++){
     output.pixels[l+(width*j)]= images[i].pixels[l];
   }
 }
}

image(output, 0, 0);
Re: basic pixel copy
Reply #2 - Nov 25th, 2007, 2:10pm
 
you can also use the nf() function to simplify that a lot, it will pad the frame numbers with zeroes.
Re: basic pixel copy
Reply #3 - Nov 26th, 2007, 9:49am
 
Thx a lot fry,

It's really a lot easier right now.

I'm still stuck trying to do the good pixel copy e.g copy one row of 100 images from 0 to 99 to the final PImage.

I'm just wondering why does the code can access the images pixel array withouth calling loadPixels before ?

Here's my last try:

Quote:

PImage[] images = new PImage[100];
PImage output = createImage(300, 100, ARGB);
String filename;

void setup(){
 size(300, 100);
 background(0);
 frameRate(24);
 for (int i=0; i<=99; i++){
   filename = "pattern-"+ nf((i+1), 4)+".png";
   println(filename);
   images[i] = loadImage(filename);
 }
}

void draw(){
 for (int j=0; j<height; j++){
   for (int l=0; l<width; l++){
     //images[j].loadPixels();
     output.pixels[l+(width*j)]= images[j].pixels[(height*j)+l];
   }
 }
 image(output, 0, 0);
}


Regards
a.
Page Index Toggle Pages: 1