I recommend not to adapt a component that way; every new version has to be changed with your special code. The way to go is: post a message on the wish list of RSgallery.
It not so difficult to sort your pictures: just put the name of the gallery in the images filename, so you get something like this:
- gallery_yellow-picture1.jpg
- gallery_yellow-picture2.jpg
- gallery_yellow-picture3.jpg
- gallery_yellow-picture4.jpg
- gallery_green-picture1.jpg
- gallery_green-picture2.jpg
- gallery_black-picture1.jpg
- gallery_black-picture2.jpg
- gallery_black-picture3.jpg