Sounds conceptually similar to EPX/Scale2x: https://en.wikipedia.org/wiki/Pixel-art_scaling_algorithms#EPX/Scale2%C3%97/AdvMAME2%C3%97
There are a number of pixel art scaling algorithms, if you want to generalize this they're worth looking into.
@NebbishHacker started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Sounds conceptually similar to EPX/Scale2x: https://en.wikipedia.org/wiki/Pixel-art_scaling_algorithms#EPX/Scale2%C3%97/AdvMAME2%C3%97
There are a number of pixel art scaling algorithms, if you want to generalize this they're worth looking into.