hdrpng.js
/** Convert an float buffer to LDR with given exposure and display gamma.
    * @param {Float32Array} buffer The input buffer in floating point format. 
    * @param {float} [exposure=1] Optional exposure value. (1=default, 2=1 step up, 3=2 steps up, -2 = 3 steps down)
    * @param {float} [gamma=2.2]  Optional display gamma to respect. (1.0 = linear, 2.2 = default monitor)
    * @param {Array} [res] res Optional result buffer.
    */
Convert an float buffer to LDR with given exposure and display gamma.
@param {Float32Array} buffer The input buffer in floating point format.
@param {float} [exposure=1] Optional exposure value.
Convert an float buffer to LDR with given exposure and display gamma . @param { Float32Array } buffer The input buffer in floating point format . @param { float } [ exposure = 1 ] Optional exposure value .
function floatToLDR(buffer,exposure,gamma,res) {
    exposure = Math.pow(2,exposure===undefined?1:exposure)/2;
    if (gamma===undefined) gamma = 2.2;
    var one_over_gamma=1/gamma,s,l=(buffer.byteLength/12)|0, res=res||new Uint8ClampedArray(l*4);
    for (var i=0;i<l;i++) {
      res[i*4]  =255*Math.pow(buffer[i*3]*exposure,one_over_gamma);
      res[i*4+1]=255*Math.pow(buffer[i*3+1]*exposure,one_over_gamma);
      res[i*4+2]=255*Math.pow(buffer[i*3+2]*exposure,one_over_gamma);
      res[i*4+3]=255;
    }
    return res;
  }
function floatToLDR ( buffer , exposure , gamma , res ) { exposure = Math . pow ( 2 , exposure === undefined ? 1 : exposure ) / 2 ; if ( gamma === undefined ) gamma = 2.2 ; var one_over_gamma = 1 / gamma , s , l = ( buffer . byteLength / 12 ) | 0 , res = res || new Uint8ClampedArray ( l * 4 ) ; for ( var i = 0 ; i < l ; i ++ ) { res [ i * 4 ] = 255 * Math . pow ( buffer [ i * 3 ] * exposure , one_over_gamma ) ; res [ i * 4 + 1 ] = 255 * Math . pow ( buffer [ i * 3 + 1 ] * exposure , one_over_gamma ) ; res [ i * 4 + 2 ] = 255 * Math . pow ( buffer [ i * 3 + 2 ] * exposure , one_over_gamma ) ; res [ i * 4 + 3 ] = 255 ; } return res ; }
Convert an float buffer to LDR with given exposure and display gamma.
Convert an float buffer to LDR with given exposure and display gamma .