Yes. I had this exact same logic built into something I called `ImageUtils` when I was working on software zoom. I can probably resurrect that module to replace the code here.