Extract code from scalarToRawData
Extract code from scalarToRawData

The same code was repeated several time for different data types, so
it was extracted as a templated function to improve maintability and
make a code more clear.

opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv,opencv/opencv