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

Function detectSubsampling

static/webuploader/webuploader.html5only.js:5782–5802  ·  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

5780 * subsampled in rendering.
5781 */
5782 function detectSubsampling( img ) {
5783 var iw = img.naturalWidth,
5784 ih = img.naturalHeight,
5785 canvas, ctx;
5786
5787 // subsampling may happen overmegapixel image
5788 if ( iw * ih > 1024 * 1024 ) {
5789 canvas = document.createElement('canvas');
5790 canvas.width = canvas.height = 1;
5791 ctx = canvas.getContext('2d');
5792 ctx.drawImage( img, -iw + 1, 0 );
5793
5794 // subsampled image becomes half smaller in rendering size.
5795 // check alpha channel value to confirm image is covering
5796 // edge pixel or not. if alpha value is 0
5797 // image is not covering, hence subsampled.
5798 return ctx.getImageData( 0, 0, 1, 1 ).data[ 3 ] === 0;
5799 } else {
5800 return false;
5801 }
5802 }
5803
5804
5805 return function( canvas, img, x, y, width, height ) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected