loadPixel()+updatePixels() issue with P3D

edited August 2016 in Questions about Code

Hi,

I have an app showing 2 windows with exactly the same images (taken from a Video stream)

I would like to make one of those images brighter than the other

I've created a simple method to increase the brightness of each pixel in the image

Because I've seen the method was returning images inverted in x and y I've commented out the part that change brightness on the pixels so the following code should not do anything else other than loadPixels() and updatePixels()

class ImgProcess {
  ImgProcess () {
  }

  void setBrightness (PImage pi, int brightness_level_percent) {
    int ba = (int) ((float) brightness_level_percent * 2.55); 

    pi.loadPixels();

    //for (int iii = 0; iii < pi.pixels.length; iii++) {
    //  int r = (int) constrain(red(pi.pixels[iii]) + ba , 0, 255);
    //  int g = (int) constrain(green(pi.pixels[iii]) + ba, 0, 255);
    //  int b = (int) constrain(blue(pi.pixels[iii]) + ba, 0, 255);
    //  pi.pixels[iii] = color(r, g, b);
    //}
    pi.updatePixels();
  }
}

This code is still inverting axis for the image

I have the feeling this is a trivial mistake I'm doing here!!!

Any idea why calling this method swap x and y of my image?

Thanks, Marco

Answers

  • I've narrowed down the weird behavior to a simple example

    In my case the following code draw a line from the top-left to the bottom right

    PGraphics offscreen;
    
    void setup() {
      size(300,300,P3D);
    
      offscreen = createGraphics(300, 300,P3D);
    }
    
    void draw() {
      offscreen.beginDraw();
      offscreen.background(255, 0);
      offscreen.line(0, 0, offscreen.width, offscreen.height);
      offscreen.endDraw();
    
      // add back this two lines to see the issue
      //offscreen.loadPixels();
      //offscreen.updatePixels();
    
      image(offscreen,0,0);
    }
    

    But if I'm adding back the two lines:

          //offscreen.loadPixels();
          //offscreen.updatePixels();
    

    I'm actually getting a line from top-right to bottom-left

    I've also found how to solve the issue: remove the P3D renderer from size() and createGraphics()

    Can somebody confirm this is a real problem or is just an issue with my machine?

    Thanks, Marco

  • Answer ✓

    Hey

    I have the same problem. I solved it by using updatePixels() instead of offscreen.updatePixels()

    I do find it odd. For this case I will stick to what I have seen in examples: they call updatePixels() by itself.

    Kf

  • Hi Kf,

    Thank for confirming that.

    (Unfortunately I can't use just updatePixels(); my final code is more complex than my example here.)

    I've opened a issue ticket in GitHub

    https://github.com/processing/processing/issues/4637

    Marco

Sign In or Register to comment.