Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to stop RGB from being multiplied by Alpha

$
0
0

Hey everyone,

Goal : Pack 32bit values into a single pixel and send via texture over Spout.

Problem : The RGB values of color() are multiplied by the alpha, so even if R, G, and B are set to 255, if the Alpha is set to 0, get() returns R,G,B values of 0.

Question : Is there a way to prevent RGB from being multiplied by Alpha? I've tested this in different software and it works fine.

I've made an example :

Sender > The canvas is split into 2, the left side has 0 Alpha, and the right has full Alpha. Other than that they are the same.

import spout.*;

Spout spout;

float rate = 1.0;
float amplitude = 255;

void setup() {

  size(640, 360, P3D);
  colorMode(RGB, 255);
  frameRate(30);

  // spout object
  spout = new Spout(this);
  // name sender
  spout.createSender("Spout Processing");

} // end setup

void draw() {

  background(0,0,0,0);

  int m = millis();
  float Hz = rate  * 1000;
  float lfo = map(sin(radians(360) * m % Hz), -1, 1, 0, amplitude); //Sinewave LFO

  // left -- 0 alpha
  noStroke();
  fill(lfo,lfo,lfo,0);
  rect(0,0,320,360);

  // right -- full alpha
  noStroke();
  fill(lfo,lfo,lfo,255);
  rect(321,0,640,360);

  spout.sendTexture();

} // end draw

Receiver > Captures the texture via spout and analyzes pixels from each half and prints out the values in the textport.

import spout.*;

Spout spout;

void setup() {

  size(640, 360, P3D);
  colorMode(RGB, 255);
  frameRate(30);

  spout = new Spout(this);

} // end setup

void draw() {

    background(0,0,0,0);

    spout.receiveTexture();

    // left -- 0 alpha
    color l = get(0,0);
    // right -- full alpha
    color r = get(321,0);

    print("0 ALPHA >>> ");
    print(red(l), blue(l), green(l), alpha(l));

    print(" --- FULL ALPHA >>> ");
    println(red(r), blue(r), green(r), alpha(r));

} // end draw

Thanks!


Viewing all articles
Browse latest Browse all 2896

Trending Articles