(imageData)
| 422 | } |
| 423 | |
| 424 | function detectBackgroundColor(imageData) { |
| 425 | const d = imageData.data; |
| 426 | const corners = [0, (imageData.width-1)*4, (imageData.height-1)*imageData.width*4, d.length-4]; |
| 427 | let r=0, g=0, b=0, a=0; |
| 428 | corners.forEach(i => { r+=d[i]; g+=d[i+1]; b+=d[i+2]; a+=d[i+3]; }); |
| 429 | return [Math.round(r/4), Math.round(g/4), Math.round(b/4), Math.round(a/4)]; |
| 430 | } |
| 431 | |
| 432 | function removeAntiAliasing(imageData, bg, threshold = 30) { |
| 433 | const d = imageData.data; |