From 5d3400c1d9fa519622719397e845d8ce7779a65a Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Fri, 24 Dec 2021 00:03:09 -0500 Subject: [PATCH] Color: Remove copyGammaToLinear, copyLinearToGamma, convertGammaToLinear, convertLinearToGamma. See: #23080 --- src/math/Color.js | 38 ----------------------------- test/unit/src/math/Color.tests.js | 40 +++++++++++++++---------------- 2 files changed, 20 insertions(+), 58 deletions(-) diff --git a/src/math/Color.js b/src/math/Color.js index 295c60e1a1766b..96541f8983556b 100644 --- a/src/math/Color.js +++ b/src/math/Color.js @@ -298,44 +298,6 @@ class Color { } - copyGammaToLinear( color, gammaFactor = 2.0 ) { - - this.r = Math.pow( color.r, gammaFactor ); - this.g = Math.pow( color.g, gammaFactor ); - this.b = Math.pow( color.b, gammaFactor ); - - return this; - - } - - copyLinearToGamma( color, gammaFactor = 2.0 ) { - - const safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0; - - this.r = Math.pow( color.r, safeInverse ); - this.g = Math.pow( color.g, safeInverse ); - this.b = Math.pow( color.b, safeInverse ); - - return this; - - } - - convertGammaToLinear( gammaFactor ) { - - this.copyGammaToLinear( this, gammaFactor ); - - return this; - - } - - convertLinearToGamma( gammaFactor ) { - - this.copyLinearToGamma( this, gammaFactor ); - - return this; - - } - copySRGBToLinear( color ) { this.r = SRGBToLinear( color.r ); diff --git a/test/unit/src/math/Color.tests.js b/test/unit/src/math/Color.tests.js index dea4624cd54848..0cdd02fe38b4c6 100644 --- a/test/unit/src/math/Color.tests.js +++ b/test/unit/src/math/Color.tests.js @@ -177,49 +177,49 @@ export default QUnit.module( 'Maths', () => { } ); - QUnit.test( 'copyGammaToLinear', ( assert ) => { + QUnit.test( 'copySRGBToLinear', ( assert ) => { var c = new Color(); var c2 = new Color(); c2.setRGB( 0.3, 0.5, 0.9 ); - c.copyGammaToLinear( c2 ); - assert.ok( c.r == 0.09, 'Red c: ' + c.r + ' Red c2: ' + c2.r ); - assert.ok( c.g == 0.25, 'Green c: ' + c.g + ' Green c2: ' + c2.g ); - assert.ok( c.b == 0.81, 'Blue c: ' + c.b + ' Blue c2: ' + c2.b ); + c.copySRGBToLinear( c2 ); + assert.numEqual( c.r, 0.09, 'Red c: ' + c.r + ' Red c2: ' + c2.r ); + assert.numEqual( c.g, 0.25, 'Green c: ' + c.g + ' Green c2: ' + c2.g ); + assert.numEqual( c.b, 0.81, 'Blue c: ' + c.b + ' Blue c2: ' + c2.b ); } ); - QUnit.test( 'copyLinearToGamma', ( assert ) => { + QUnit.test( 'copyLinearToSRGB', ( assert ) => { var c = new Color(); var c2 = new Color(); c2.setRGB( 0.09, 0.25, 0.81 ); - c.copyLinearToGamma( c2 ); - assert.ok( c.r == 0.3, 'Red c: ' + c.r + ' Red c2: ' + c2.r ); - assert.ok( c.g == 0.5, 'Green c: ' + c.g + ' Green c2: ' + c2.g ); - assert.ok( c.b == 0.9, 'Blue c: ' + c.b + ' Blue c2: ' + c2.b ); + c.copyLinearToSRGB( c2 ); + assert.numEqual( c.r, 0.3, 'Red c: ' + c.r + ' Red c2: ' + c2.r ); + assert.numEqual( c.g, 0.5, 'Green c: ' + c.g + ' Green c2: ' + c2.g ); + assert.numEqual( c.b, 0.9, 'Blue c: ' + c.b + ' Blue c2: ' + c2.b ); } ); - QUnit.test( 'convertGammaToLinear', ( assert ) => { + QUnit.test( 'convertSRGBToLinear', ( assert ) => { var c = new Color(); c.setRGB( 0.3, 0.5, 0.9 ); - c.convertGammaToLinear(); - assert.ok( c.r == 0.09, 'Red: ' + c.r ); - assert.ok( c.g == 0.25, 'Green: ' + c.g ); - assert.ok( c.b == 0.81, 'Blue: ' + c.b ); + c.convertSRGBToLinear(); + assert.numEqual( c.r, 0.09, 'Red: ' + c.r ); + assert.numEqual( c.g, 0.25, 'Green: ' + c.g ); + assert.numEqual( c.b, 0.81, 'Blue: ' + c.b ); } ); - QUnit.test( 'convertLinearToGamma', ( assert ) => { + QUnit.test( 'convertLinearToSRGB', ( assert ) => { var c = new Color(); c.setRGB( 4, 9, 16 ); - c.convertLinearToGamma(); - assert.ok( c.r == 2, 'Red: ' + c.r ); - assert.ok( c.g == 3, 'Green: ' + c.g ); - assert.ok( c.b == 4, 'Blue: ' + c.b ); + c.convertLinearToSRGB(); + assert.numEqual( c.r, 1.82, 'Red: ' + c.r ); + assert.numEqual( c.g, 2.58, 'Green: ' + c.g ); + assert.numEqual( c.b, 3.29, 'Blue: ' + c.b ); } );