Skip to content

Commit

Permalink
Color: Remove copyGammaToLinear, copyLinearToGamma, convertGammaToLin…
Browse files Browse the repository at this point in the history
…ear, convertLinearToGamma.

See: mrdoob#23080
  • Loading branch information
donmccurdy committed Dec 24, 2021
1 parent 192e1ab commit 5d3400c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 58 deletions.
38 changes: 0 additions & 38 deletions src/math/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
40 changes: 20 additions & 20 deletions test/unit/src/math/Color.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

} );

Expand Down

0 comments on commit 5d3400c

Please sign in to comment.