Openfl.geom.ColorTransform.concat

The current (3.3.6) implementation of openfl.geom.ColorTransform.concat is:

public function concat (second:ColorTransform):Void {
redMultiplier += second.redMultiplier;
greenMultiplier += second.greenMultiplier;
blueMultiplier += second.blueMultiplier;
alphaMultiplier += second.alphaMultiplier;
}

I’m pretty sure this isn’t correct. On Windows, HTML5 and iOS I’m getting results identical to Flash if I change to this method:

public function concat (second:ColorTransform):Void {

	redMultiplier 	*= second.redMultiplier;   
	greenMultiplier *= second.greenMultiplier;
	blueMultiplier 	*= second.blueMultiplier;
	alphaMultiplier *= second.alphaMultiplier;
	
	// -255 to 255
	redOffset 	  =  second.redMultiplier   * redOffset 	+ second.redOffset;
	greenOffset =  second.greenMultiplier * greenOffset + second.greenOffset;
	blueOffset   =  second.blueMultiplier  * blueOffset  + second.blueOffset;
	alphaOffset =  second.alphaMultiplier * alphaOffset + second.alphaOffset;

}

Is this the correct place to report bugs?
I hope this helps, Jake

1 Like

You are perfectly right. If we do the math, with a single color transform we have:

new_value1 = multiplier1*initial_value + offset1

So if we apply a second colortransform to this new value:

new_value2 = multiplier2*new_value1 + offset2
           = multiplier2*(multiplier1*initial_value + offset1) + offset2 
           = multiplier2*multiplier1*initial_value + (multiplier2*offset1 + offset2) 

So

concat_multiplier = multiplier2*multiplier1;
concat_offset = multiplier2*offset1 + offset2;

:wink:

Just committed the update, thank you! :slight_smile:

windows and ios builds now seem to have reverted to the _legacy branch, (openfl 3.3.6, lime 2.6.6). What caused this change back to _legacy and how can I change it back?

Can you please commit the concat() method fix to _legacy.geom.ColorTransform too.

Regards, Jake

Are you using HaxeFlixel? It uses legacy by default, and has an added “-Dnext” define to disable it

No HaxeFlixel, but I am using HaxeUI and it does seem that that forces _legacy. I’m not sure how to disable that, but it’s not urgent.