Created
June 15, 2015 19:28
-
-
Save reportbase/edc7959244d18128c3c9 to your computer and use it in GitHub Desktop.
Linear interpolate of image buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function data_a_interpolate(data, alpha, width, height, red, green, blue) | |
{ | |
var m = 0; | |
for(var n = 0; n < width * height * 4; n += 4, m++) | |
{ | |
data[n + 0] = Math.linear_interpolate(alpha, red, data[n + 0]); | |
data[n + 1] = Math.linear_interpolate(alpha, green, data[n + 1]); | |
data[n + 2] = Math.linear_interpolate(alpha, blue, data[n + 2]); | |
data[n + 3] = 0xff; | |
} | |
} | |
function data_interpolate(data, arr, width, height, red, green, blue) | |
{ | |
var m = 0; | |
for(var n = 0; n < width * height * 4; n += 4, m++) | |
{ | |
data[n + 0] = Math.linear_interpolate(arr[m + 0], red, 0x00); | |
data[n + 1] = Math.linear_interpolate(arr[m + 1], green, 0x00); | |
data[n + 2] = Math.linear_interpolate(arr[m + 2], blue, 0x00); | |
data[n + 3] = 0xff; | |
} | |
} | |
//if alpha is 255, then all weight is val1, if alpha is 0, then all weight is val2 | |
Math.linear_interpolate = function(alpha, val1, val2) | |
{ | |
return ((val1 + 1) * alpha >> 8) - ((val2 + 1) * alpha >> 8) + val2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment