24 #include <fvutils/readers/pnm.h> 25 #include <fvutils/color/colorspaces.h> 26 #include <fvutils/color/conversions.h> 27 #include <core/exception.h> 28 #include <core/exceptions/system.h> 49 PNMReader::PNMReader(
const char* filename)
51 m_filename = strdup(filename);
52 m_pnmfile = fopen(m_filename,
"rb");
54 if ( m_pnmfile == NULL )
56 throw Exception(
"PNMReader::ctor: cannot open PNM file");
60 char* line = (
char*) malloc(80);
63 if (fgets(line, 80, m_pnmfile) == NULL)
68 if ( strcmp(
"P6", line) > 0 )
70 throw Exception(
"PNMReader::ctor: unknown magic value");
76 if (fgets(line, 80, m_pnmfile) == NULL)
80 }
while ( strncmp(
"#", line, 1) == 0);
83 char* tmp = (
char*) malloc(10);
85 token = strtok(line,
" ");
86 if ( atoi(token) >= 0 ) { m_img_width = (
unsigned int) atoi(token); }
87 else {
throw Exception(
"PNMReader::ctor: could not read out image width"); };
88 token = strtok(NULL,
" ");
89 if ( atoi(token) >= 0 ) { m_img_height = (
unsigned int) atoi(token); }
90 else {
throw Exception(
"PNMReader::ctor: could not read out image height"); };
94 if (fgets(line, 80, m_pnmfile) == NULL)
122 throw Exception(
"PNMReader::ctor: unknown color depth");
125 size_t img_size = m_img_width * m_img_height * m_img_depth;
126 m_pnm_buffer = (
unsigned char*) malloc(img_size);
130 PNMReader::~PNMReader()
138 PNMReader::set_buffer(
unsigned char* buffer)
140 m_yuv_buffer = buffer;
144 PNMReader::colorspace()
146 return YUV422_PLANAR;
150 PNMReader::pixel_width()
156 PNMReader::pixel_height()
164 if (m_yuv_buffer == NULL)
166 throw Exception(
"PNMReader::read: buffer = NULL");
169 if (fread(m_pnm_buffer, m_img_depth, m_img_width * m_img_height, m_pnmfile) != m_img_width * m_img_height)
173 convert(RGB, YUV422_PLANAR, m_pnm_buffer, m_yuv_buffer, m_img_width, m_img_height);
Fawkes library namespace.
Base class for exceptions in Fawkes.