function copyRect(from, to, x1, y1, w, h, x2, y2) local fp, tp = from.pixels, to.pixels local fw, tw = from.width, to.width local ww, hh = w-1, h-1 for y=0, hh do local to, fo = x2+(y2+y)*tw+1, x1+(y1+y)*fw+1 for x=0, ww do tp[to+x] = fp[fo+x] end end end