Loading...
Logo
Processing Forum
Hey, everyone. I got a problem that Processing break down when I execute the following pieces of code:
Copy code
  1. PImage img;

  2. void setup () {
  3.   size(60, 60);
  4.   img = loadImage("aaa.png");
  5. }

  6. void draw () {
  7.   int count = 0;
  8.   loadPixels();
  9.   // Since we are going to access the image's pixels too;
  10.   img.loadPixels();
  11.   for (int y = 0; y < height; y++) {
  12.     for (int x = 0; x < width; x++) {
  13.       int loc = x + y * width;
  14.       
  15. ////////////////////////////////////////////////////////////////
  16.       count++;
  17.       println(count);
  18. ////////////////////////////////////////////////////////////////      

  19.       // Image Processing Algorithm would go here
  20.       float r = red  (img.pixels[loc]);
  21.       float g = green(img.pixels[loc]);
  22.       float b = blue (img.pixels[loc]);
  23.     
  24.       // Image Processing would go here
  25.     
  26.       // Set the display pixel to the image pixel
  27.       pixels[loc] = color(r, g, b);
  28.     }
  29.   }
  30.   updatePixels();
  31. }
And I guess the reason is line 19 and 20 which lead to more calculate. But if even this simple calculate can not undertake, how can I do other complex image processing? Cause I believe Processing is powerful, so can anyone points out where goes wrong that I do not know? Thanks first.

Replies(5)

I get it to work at quite a high frame rate... that is, once I add this line of code before updatePixels():

Copy code
  1. img.updatePixels();
Thans, I know where is wrong now.
Not too sure what you mean by "break down", exactly.

The img.updatePixels() isn't necessary because the img's pixels aren't updated.

Now, you are stressing quite a lot the console part of Processing. Filling it up with thousands of lines, that's quite some (useless) data to hold and it is limited.
In other words, that's the println() line which is stressing the PDE.
Thanks. The reason is as you say. And....."break down"......Maybe "crash" is more appropriate. Sorry for that word. English is not my native.