43 #include <opencv2/core.hpp> 44 #include <opencv2/imgcodecs.hpp> 45 #include <opencv2/imgproc.hpp> 57 cv::Mat mat = cv::imread(filename);
63 cout <<
timestamp <<
"TextureFactory: Unable to read file '" 64 << filename <<
"'. Returning empty Texture." << endl;
71 cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB);
73 Texture ret(0, mat.cols, mat.rows, 3, 1, 1.0);
74 std::copy(mat.datastart, mat.dataend, ret.
m_data);
85 cout <<
timestamp <<
"TextureFactory: Texture will not be saved to file '" 86 << filename <<
"' because the texture has no data." << endl;
94 cout <<
timestamp <<
"TextureFactory: Texture will not be saved to file '" 95 << filename <<
"' because texture has more than 1 byte \ 96 per channel (currently only 1-byte channels are supported)." << endl;
103 cout <<
timestamp <<
"TextureFactory: Texture will not be saved to file '" 104 << filename <<
"' because the texture has an unsupported amount of channels \ 105 (currently only 1, 3 and 4 channels per pixel are supported)." << endl;
111 int mat_type = CV_8UC1;
112 int conversionCode = cv::COLOR_GRAY2BGR;
117 conversionCode = cv::COLOR_RGB2BGR;
124 conversionCode = cv::COLOR_RGBA2BGR;
131 std::copy(tex.
m_data, tex.
m_data + bytesToCopy, mat.data);
133 if (!(mat_type == CV_8UC1))
135 cv::cvtColor(mat, mat, conversionCode);
139 if (!cv::imwrite(filename, mat))
141 cout <<
timestamp <<
"TextureFactory: Unable to save texture to file '" 142 << filename <<
"'." << endl;
unsigned char m_numBytesPerChan
The number of bytes per channel.
static Timestamp timestamp
A global time stamp object for program runtime measurement.
static void saveTexture(const Texture &texture, std::string filename)
TODO.
This class represents a texture.
unsigned char * m_data
The texture data.
unsigned short int m_width
The dimensions of the texture.
static Texture readTexture(std::string filename)
Returns a new texture if the file contains readable image data or a null point if the file couldn't b...
unsigned char m_numChannels
The number of color channels.
unsigned short int m_height