Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created July 27, 2021 19:08
Show Gist options
  • Save rygorous/10bb29b5b9a331c073dc95fd58389f95 to your computer and use it in GitHub Desktop.
Save rygorous/10bb29b5b9a331c073dc95fd58389f95 to your computer and use it in GitHub Desktop.
BC4 interpolation formulas
# ---- Intel decoder impl
# matches 2014 HSW laptop
weights8_intel = [round(256*x/7) for x in range(8)]
weights6_intel = [round(256*x/5) for x in range(8)]
def intel_lerp8(a, b, w):
return ((256-w)*a + w*b + 128) >> 8
def interp_int_8col(a, b, x):
# 16-bit interpolation, 8-color mode (e0 > e1)
# not right yet!
return ((7-x)*a + x*b) * 257 // 7
def interp_int_6col(a, b, x):
# 16-bit interpolation, 6-color mode (e0 <= e1)
# not right yet!
return ((5-x)*a + x*b) * 257 // 5
def interp_int_8col_u8(a, b, x):
# 8-bit interpolation, 8-color mode (e0 > e1)
# this agrees exactly
return intel_lerp8(a, b, weights8_intel[x])
def interp_int_6col_u8(a, b, x):
# 8-bit interpolation, 6-color mode (e0 <= e1)
# this agrees exactly
return intel_lerp8(a, b, weights6_intel[x])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment