hdrpng.js
/** Convert a float buffer to a RGBE buffer.
    * @param {Float32Array} Buffer Floating point input buffer (96 bits/pixel).
    * @param {Uint8Array} [res] Optional output buffer with 32 bit RGBE per pixel.
    * @returns {Uint8Array} A 32bit uint8 array in RGBE
    */
Convert a float buffer to a RGBE buffer.
@param {Float32Array} Buffer Floating point input buffer (96 bits/pixel).
@param {Uint8Array} [res] Optional output buffer with 32 bit RGBE per pixel.
@returns {Uint8Array} A 32bit uint8 array in RGBE
Convert a float buffer to a RGBE buffer . @param { Float32Array } Buffer Floating point input buffer ( 96 bits / pixel ) . @param { Uint8Array } [ res ] Optional output buffer with 32 bit RGBE per pixel . @returns { Uint8Array } A 32bit uint8 array in RGBE
function floatToRgbe(buffer,res) {
    var r,g,b,v,s,l=(buffer.byteLength/12)|0, res=res||new Uint8Array(l*4);
    for (var i=0;i<l;i++) {
      r = buffer[i*3]; g = buffer[i*3+1]; b = buffer[i*3+2];
      v = Math.max(Math.max(r,g),b); e = Math.ceil(Math.log2(v)); s = Math.pow(2,e-8);
      res[i*4]   = (r/s)|0;
      res[i*4+1] = (g/s)|0;
      res[i*4+2] = (b/s)|0;
      res[i*4+3] = (e+128);
    }
    return res;
  }
function floatToRgbe ( buffer , res ) { var r , g , b , v , s , l = ( buffer . byteLength / 12 ) | 0 , res = res || new Uint8Array ( l * 4 ) ; for ( var i = 0 ; i < l ; i ++ ) { r = buffer [ i * 3 ] ; g = buffer [ i * 3 + 1 ] ; b = buffer [ i * 3 + 2 ] ; v = Math . max ( Math . max ( r , g ) , b ) ; e = Math . ceil ( Math . log2 ( v ) ) ; s = Math . pow ( 2 , e - 8 ) ; res [ i * 4 ] = ( r / s ) | 0 ; res [ i * 4 + 1 ] = ( g / s ) | 0 ; res [ i * 4 + 2 ] = ( b / s ) | 0 ; res [ i * 4 + 3 ] = ( e + 128 ) ; } return res ; }
Convert a float buffer to a RGBE buffer.
Convert a float buffer to a RGBE buffer .