Diageo has agreed a deal with the National Galleries of Scotland amid controversy over one of the country's most famous paintings.