Here's an extract of what I had in one of my branches for mti, with a slight cleanup to reduce diffs in texgetimage.c. Tested on i965 and softpipe. This code can also be found in the mti-getteximage branch of my personal tree.