| 1322 | } |
| 1323 | |
| 1324 | _getBayerValue(x, y, size) { |
| 1325 | if (size === 2) { |
| 1326 | const matrix = [ |
| 1327 | [0, 2], |
| 1328 | [3, 1] |
| 1329 | ]; |
| 1330 | return matrix[y % 2][x % 2] / 4; |
| 1331 | } else if (size === 4) { |
| 1332 | const matrix = [ |
| 1333 | [0, 8, 2, 10], |
| 1334 | [12, 4, 14, 6], |
| 1335 | [3, 11, 1, 9], |
| 1336 | [15, 7, 13, 5] |
| 1337 | ]; |
| 1338 | return matrix[y % 4][x % 4] / 16; |
| 1339 | } else { |
| 1340 | const base = this._getBayerValue(Math.floor(x / 2), Math.floor(y / 2), 4); |
| 1341 | const sub = this._getBayerValue(x, y, 2); |
| 1342 | return base * 0.25 + sub; |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | _applyDither(data, width, height, params) { |
| 1347 | const levels = params.levels; |