https://github.com/bjorn/tiled/blob/master/src/tiled/tilepainter.cpp

@bjorn I had actually taken this code from line 92. I saw that it got all the cells so I quickly pieced together the tile selection.