//SOLUTION: Use bitwise operators and drop sstreams completely. atoi does not properly accept hex.//
namespace color_tools{
std::stringstream sstream;
}
int RGB_256_to_hex(signed short r, signed short g, signed short b){
std::string hex_col;
color_tools::sstream << std::hex << r << g << b;
hex_col = color_tools::sstream.str();
color_tools::sstream.str("");
color_tools::sstream.clear();
return atoi(hex_col.c_str());
}
If I pass, for example, (0,0,255) then the function returns 0. This is not correct as the color blue is 0000ff. If I change the return type of the function to a string and just return hex_col I get the proper result. I'm assuming the issue must be with atoi()?
A bit off topic: Can I replace the signed short components with the __int8 type since this perfectly fits 256 color steps?
Miscellaneous suggestions would also be appreciated.