* Detect subsampling in loaded image. * In iOS, larger images than 2M pixels may be * subsampled in rendering.
( img )
| 5465 | * subsampled in rendering. |
| 5466 | */ |
| 5467 | function detectSubsampling( img ) { |
| 5468 | var iw = img.naturalWidth, |
| 5469 | ih = img.naturalHeight, |
| 5470 | canvas, ctx; |
| 5471 | |
| 5472 | // subsampling may happen overmegapixel image |
| 5473 | if ( iw * ih > 1024 * 1024 ) { |
| 5474 | canvas = document.createElement('canvas'); |
| 5475 | canvas.width = canvas.height = 1; |
| 5476 | ctx = canvas.getContext('2d'); |
| 5477 | ctx.drawImage( img, -iw + 1, 0 ); |
| 5478 | |
| 5479 | // subsampled image becomes half smaller in rendering size. |
| 5480 | // check alpha channel value to confirm image is covering |
| 5481 | // edge pixel or not. if alpha value is 0 |
| 5482 | // image is not covering, hence subsampled. |
| 5483 | return ctx.getImageData( 0, 0, 1, 1 ).data[ 3 ] === 0; |
| 5484 | } else { |
| 5485 | return false; |
| 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | |
| 5490 | return function( canvas, img, x, y, width, height ) { |