loadPixel()+updatePixels() issue with P3D

edited August 2016 in Questions about Code


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); 


    //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);

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


  • 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() {
      offscreen = createGraphics(300, 300,P3D);
    void draw() {
      offscreen.background(255, 0);
      offscreen.line(0, 0, offscreen.width, offscreen.height);
      // add back this two lines to see the issue

    But if I'm adding back the two lines:


    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 ✓


    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.


  • 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



Sign In or Register to comment.