Image manipulation with OSL

I’m aware this may not be the greatest use-case for OSL, but I have seen it used for this in other places…

Any way, what I would like to do is load a UV mapped texture without margins (and probably a mask that indicates where the islands are). Then with OSL create nicer margins than what you can currently get in blender (which seems to use the ‘Inpaint’ method to create them).

Something similar to what you get in marmoset would be ideal, but really anything that avoids the sharp seams that blender currently produces is an improvement!

I’m imagining doing this via some sort of gather operation, but I’m not quite sure how to weight the values in that scenario or if that’s the best approach… There aren’t a lot of good, in-depth OSL resources on the 'net so any thoughts on this and pointers would be much appreciated!