MCPcopy Create free account
hub / github.com/TruthHun/BookStack / detectSubsampling

Function detectSubsampling

static/webuploader/webuploader.html5nodepend.js:6312–6332  ·  view source on GitHub ↗

* Detect subsampling in loaded image. * In iOS, larger images than 2M pixels may be * subsampled in rendering.

( img )

Source from the content-addressed store, hash-verified

6310 * subsampled in rendering.
6311 */
6312 function detectSubsampling( img ) {
6313 var iw = img.naturalWidth,
6314 ih = img.naturalHeight,
6315 canvas, ctx;
6316
6317 // subsampling may happen overmegapixel image
6318 if ( iw * ih > 1024 * 1024 ) {
6319 canvas = document.createElement('canvas');
6320 canvas.width = canvas.height = 1;
6321 ctx = canvas.getContext('2d');
6322 ctx.drawImage( img, -iw + 1, 0 );
6323
6324 // subsampled image becomes half smaller in rendering size.
6325 // check alpha channel value to confirm image is covering
6326 // edge pixel or not. if alpha value is 0
6327 // image is not covering, hence subsampled.
6328 return ctx.getImageData( 0, 0, 1, 1 ).data[ 3 ] === 0;
6329 } else {
6330 return false;
6331 }
6332 }
6333
6334
6335 return function( canvas, img, x, y, width, height ) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected