PImage Copy Strangeness
in
Programming Questions
•
1 year ago
Hi, I'm experiencing an unusual problem with PImage. That is I am repeatedly using get, set, and copy to copy from a source PImage to a destination PImage. The problem is that after each get/set/copy series of operations the image becomes progressively darker. This happens on 2 different systems running Processing 1.5.1 under Windows 7 64bit so I know it is not machine dependent.
In the image below, the left side is the original image and the right side is what it looks like after 160 copies. :
The code that follows is part of a much larger program in which I discovered the problem. Cutting out all the other code, I was able to isolate the source of the darkening to the code that appears below. Based on my understanding of get/set/copy, I am at a complete loss to explain why successive copy operations should cause the image being processed to darken.
Any suggestions as to how to overcome this will be greatly appreciated. Thanks.
In the image below, the left side is the original image and the right side is what it looks like after 160 copies. :
The code that follows is part of a much larger program in which I discovered the problem. Cutting out all the other code, I was able to isolate the source of the darkening to the code that appears below. Based on my understanding of get/set/copy, I am at a complete loss to explain why successive copy operations should cause the image being processed to darken.
Any suggestions as to how to overcome this will be greatly appreciated. Thanks.
- int maxFrames=160; // number of times to copy
- String inputFile="C:/a_PDE_Input/Mona_Lisa_smalllight.jpg";
- String filenam="C:/a_PDE_Output/Mona_Lisa_smalllight_output.jpg";
- PImage img, imgtmp;
- color c;
- int px;
- float cx,cy, mx,my;
- boolean looping=true;
- float h,w;
- void setup(){
- img = loadImage(inputFile);
- imgtmp = loadImage(inputFile);
- img.loadPixels();
- px = img.pixels.length;
- mx = img.width/2;
- my = img.height/2;
- h = img.height;
- w = img.width;
- noLoop();
- cx = mx; cy=mx;
- for(int i=1; i < maxFrames; i++) {
- if(i%30 == 0) print("*");
- copyit();
- }
- img.save(filenam);
- println(" -> Saved "+filenam);
- }
- void draw() {}
- void copyit() {
- int i,j;
- for (j=1; j < h-1; j++) {
- for (i=1; i < w-1; i++) {
- c = img.get(int(i),int(j));
- imgtmp.set(int(i), int(j), c);
- }
- }
- img.copy(imgtmp, 0,0, img.width, img.height, 0,0, img.width, img.height);
- }
1