Pixel copy performance
in
Programming Questions
•
1 year ago
I am trying to make a "wall painting" application with kinect. It will check the user pixels positions and switch the image pixels based on it. My issue is that the sensor image res is 640x480 and I need to convert it to a higher res, like 1024x768 or even widescreen (1280x720), before searching the pixels (or it will appear on the top left of screen).
In this little working sample, I want the white pixel to move to the bottom right of the image, it takes around 21ms to finish the copy command (about 60ms on my application). I wish to know if someone has a good way of making this copy manually (to improve performance), I tried a few for-loops but resizing the pixels ends up with weird-looking results.
In this little working sample, I want the white pixel to move to the bottom right of the image, it takes around 21ms to finish the copy command (about 60ms on my application). I wish to know if someone has a good way of making this copy manually (to improve performance), I tried a few for-loops but resizing the pixels ends up with weird-looking results.
- PImage image1;
- PImage image2;
- void setup() {
- size(1024, 768);
- image1 = new PImage(640, 480);
- image2 = new PImage(1024, 768);
- image1.set(630, 470, color(255));
-
- background(0);
- image(image2, 0, 0);
- }
- void draw() {
- fPaint();
- }
- void fPaint() {
- int startTime = millis();
- loadPixels();
- // how to improve the performance of copy??
- image2.copy(image1, 0, 0, 640, 480, 0, 0, 1024, 768);
- println("Pixel copy finished in: " + (millis() - startTime) + " milliseconds");
- for (int x = 0; x < image2.width; x++ ) {
- for (int y = 0; y < image2.height; y++ ) {
- int loc = x + y*image2.width;
- color pixelsTest = image2.pixels[loc];
- if (red(pixelsTest) > 0 || green(pixelsTest) > 0 || blue(pixelsTest) > 0) {
- pixels[loc] = image2.pixels[loc];
- }
- }
- }
- updatePixels();
- println("Function finished in: " + (millis() - startTime) + " milliseconds");
- }
Any ideas on making a better test to see if the pixel is not black is welcome as well.
1