JSFiddle - React, Tailwind, and code Playground

by Matt Jack

HTML

<canvas id="canvas" width="512" height="512"></canvas>
<img src="http://www.childrenoftm.fr/teamspeak/templates/images/viewer/channel_flag_default.png" id="background" />

JavaScript

var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var pictureToBlit = document.getElementById('background');

// Turn it to true to test the first algorithm.
//   The first algorithm is working well with Chrome 40.0.2214.94 m :
//   The source image is displayed with a nice bilinear stretching.
//
// Turn it to false to test the 2nd algorithm.
//   2nd algorithm is the same as first algorithm, excepted with use a temporary offscreen.
//   With the 2nd algorithm, the image looks to be stretched linearly on X axis, 
//   but with a nearest point technics on Y axis.
if (true)
{ 
    // Expected visual result.
    var destY = 0;
    for (i=0; i<16; i++)
    {
        context.drawImage(pictureToBlit, 
                          0, i, 16, 1,
                          0,destY,512,i*3);
        destY+=i*3;
    }
}
else
{ 
    // Wrong visual result.
    var offscreenCanvas = document.createElement('canvas');
	offscreenCanvas.width = 1024;
	offscreenCanvas.height = 1024;
    var offscreenContext = offscreenCanvas.getContext('2d');
    offscreenContext.drawImage(pictureToBlit,0,0);
    
    var destY = 0;
    for (i=0; i<16; i++)
    {
        context.drawImage(offscreenCanvas,
                          0, i, 16, 1,
                          0,destY,512,i*3);
        destY+=i*3;
    }
}