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

Function detectSubsampling

static/webuploader/webuploader.js:6694–6714  ·  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

6692 * subsampled in rendering.
6693 */
6694 function detectSubsampling( img ) {
6695 var iw = img.naturalWidth,
6696 ih = img.naturalHeight,
6697 canvas, ctx;
6698
6699 // subsampling may happen overmegapixel image
6700 if ( iw * ih > 1024 * 1024 ) {
6701 canvas = document.createElement('canvas');
6702 canvas.width = canvas.height = 1;
6703 ctx = canvas.getContext('2d');
6704 ctx.drawImage( img, -iw + 1, 0 );
6705
6706 // subsampled image becomes half smaller in rendering size.
6707 // check alpha channel value to confirm image is covering
6708 // edge pixel or not. if alpha value is 0
6709 // image is not covering, hence subsampled.
6710 return ctx.getImageData( 0, 0, 1, 1 ).data[ 3 ] === 0;
6711 } else {
6712 return false;
6713 }
6714 }
6715
6716
6717 return function( canvas, img, x, y, width, height ) {

Callers 1

webuploader.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected