jsjpeg.js
/**
 * Implements the EXTEND function to scale the value of a coefficient
 * 
 * F.2.2.1
 * Figure F.12
 * 
 * @param {*} v 
 * @param {*} t 
 */
Implements the EXTEND function to scale the value of a coefficient




Implements the EXTEND function to scale the value of a coefficient
function extend(v, t) {
    if (t === 0) {
        return 0;
    }
    let vt = 1 << (t - 1);      
    if (v < vt) {
        vt = (-1 << t) + 1;
        v += vt
    }
    return v;
}
function extend ( v , t ) { if ( t === 0 ) { return 0 ; } let vt = 1 << ( t - 1 ) ; if ( v < vt ) { vt = ( - 1 << t ) + 1 ; v += vt } return v ; }
Implements the EXTEND function to scale the value of a coefficient
Implements the EXTEND function to scale the value of a coefficient
// Same as 2 ** (t - 1), which is what the JPEG spec uses