PImage color format

edited April 2014 in How To...

Hey

I'm current sending live footage from a HD camera to processing. The image formats between processing and the c++ program are different. So the image/video that I'm sending is current in a RGBA image format (also can supports BGRA), so as I know in processing/Java only supports ARGB color format and RGB.

Here is the reading image code in processing.

        public PImage GetImage() {
            PImage img = parent.createImage(WIDTH, HEIGHT, parent.ARGB);
            PApplet.arrayCopy(Nui_GetImage(), img.pixels);
            img.updatePixels();
            return img;
        }

Is there a way to make a fast the conversion between RGBA to ARGB because the incoming video is in 1080p, or there is another Image library that supports RGBA format in processing or java.

Thomas

Tagged:

Answers

  • edited May 2015 Answer ✓

    Perhaps something like this? %%-

    /**
     * RGBa_&_BGRa_To_aRGB (v1.04)
     * by GoToLoop (2014/Apr)
     *
     * forum.processing.org/two/discussion/4461/pimage-color-format
     */
    
    static final color RGBa_To_aRGB(final color c) {
      return c<<030 | c>>>010;
    }
    
    static final color BGRa_To_aRGB(final color c) {
      final color a = c<<030;
      final color b = c>>>030;
    
      final color r = c<<010 & PImage.RED_MASK;
      final color g = c>>010 & PImage.GREEN_MASK;
    
      return a|r|g|b;
    }
    
    void setup() {
      println(hex(RGBa_To_aRGB(0x8040BBaa)));
      println(hex(BGRa_To_aRGB(0xBB4080aa)));
      exit();
    }
    
Sign In or Register to comment.