jsjpeg.js
/**
 * Convert the 3 YCrCB components to RGB and combine them into a single output image,
 * then draw the image to the output canvas.
 * 
 * @param {*} components List of components
 * @param {*} colorConvFn Function to use for colorspace conversion
 */
Convert the 3 YCrCB components to RGB and combine them into a single output image,
then draw the image to the output canvas.

@param {*} components List of components
@param {*} colorConvFn Function to use for colorspace conversion
Convert the 3 YCrCB components to RGB and combine them into a single output image then draw the image to the output canvas . @param { * } components List of components @param { * } colorConvFn Function to use for colorspace conversion
function combineComponents(components, colorConvFn) {
    let canvas = document.getElementById("outputCanvas");
    canvas.setAttribute("width", img.frame.outputX);
    canvas.setAttribute("height", img.frame.outputY);
    let ctx = canvas.getContext("2d");
    let imgData = ctx.createImageData(canvas.width, canvas.height);
    let data = imgData.data;
    let Y, Cb, Cr;
    let pixel = [0, 0, 0, 0];
    let width = img.frame.outputX;
    let height = img.frame.outputY;
    let index = 0;
    if (frame.numComponents === 1) {
        for (let y = 0; y < height; y++) {
            for (let x = 0; x < width; x++, index++) {
                Y = components[0].outputBuff[index];
                pixel = [Y, Y, Y, 255];
                setPixel(data, width, x, y, pixel);
            }
        }
    } else if (frame.numComponents === 3) {
        let buff0 = components[0].outputBuff;
        let buff1 = components[1].outputBuff;
        let buff2 = components[2].outputBuff;
        for (let y = 0; y < height; y++) {
            for (let x = 0; x < width; x++, index++) {
                Y = buff0[index];
                Cb = buff1[index];
                Cr = buff2[index];
                colorConvFn(Y, Cb, Cr, pixel);
                setPixel(data, width, x, y, pixel);
            }
        }
    } else {
        console.error("Error: Image has " + frame.numComponents + " components; we only support 1 or 3 for JFIF");
    }
    ctx.putImageData(imgData, 0, 0);
}
function combineComponents ( components , colorConvFn ) { let canvas = document . getElementById ( "outputCanvas" ) ; canvas . setAttribute ( "width" , img . frame . outputX ) ; canvas . setAttribute ( "height" , img . frame . outputY ) ; let ctx = canvas . getContext ( "2d" ) ; let imgData = ctx . createImageData ( canvas . width , canvas . height ) ; let data = imgData . data ; let Y , Cb , Cr ; let pixel = [ 0 , 0 , 0 , 0 ] ; let width = img . frame . outputX ; let height = img . frame . outputY ; let index = 0 ; if ( frame . numComponents === 1 ) { for ( let y = 0 ; y < height ; y ++ ) { for ( let x = 0 ; x < width ; x ++ , index ++ ) { Y = components [ 0 ] . outputBuff [ index ] ; pixel = [ Y , Y , Y , 255 ] ; setPixel ( data , width , x , y , pixel ) ; } } } else if ( frame . numComponents === 3 ) { let buff0 = components [ 0 ] . outputBuff ; let buff1 = components [ 1 ] . outputBuff ; let buff2 = components [ 2 ] . outputBuff ; for ( let y = 0 ; y < height ; y ++ ) { for ( let x = 0 ; x < width ; x ++ , index ++ ) { Y = buff0 [ index ] ; Cb = buff1 [ index ] ; Cr = buff2 [ index ] ; colorConvFn ( Y , Cb , Cr , pixel ) ; setPixel ( data , width , x , y , pixel ) ; } } } else { console . error ( "Error: Image has " + frame . numComponents + " components; we only support 1 or 3 for JFIF" ) ; } ctx . putImageData ( imgData , 0 , 0 ) ; }
Convert the 3 YCrCB components to RGB and combine them into a single output image,
 then draw the image to the output canvas.
Convert the 3 YCrCB components to RGB and combine them into a single output image then draw the image to the output canvas .
// Combine images via YCbCr --> YUV conversion // JFIF grayscale // JFIF YcbCr