24#include <core/exception.h>
25#include <core/exceptions/system.h>
26#include <fvutils/color/colorspaces.h>
27#include <fvutils/color/conversions.h>
28#include <fvutils/readers/pnm.h>
48 m_filename = strdup(filename);
49 m_pnmfile = fopen(m_filename,
"rb");
51 if (m_pnmfile == NULL) {
52 throw Exception(
"PNMReader::ctor: cannot open PNM file");
56 char *line = (
char *)malloc(80);
59 if (fgets(line, 80, m_pnmfile) == NULL) {
63 if (strcmp(
"P6", line) > 0) {
64 throw Exception(
"PNMReader::ctor: unknown magic value");
69 if (fgets(line, 80, m_pnmfile) == NULL) {
72 }
while (strncmp(
"#", line, 1) == 0);
75 char *tmp = (
char *)malloc(10);
77 token = strtok(line,
" ");
78 if (atoi(token) >= 0) {
79 m_img_width = (
unsigned int)atoi(token);
81 throw Exception(
"PNMReader::ctor: could not read out image width");
83 token = strtok(NULL,
" ");
84 if (atoi(token) >= 0) {
85 m_img_height = (
unsigned int)atoi(token);
87 throw Exception(
"PNMReader::ctor: could not read out image height");
92 if (fgets(line, 80, m_pnmfile) == NULL) {
99 case 1: m_img_depth = 1;
break;
101 case 15: m_img_depth = 2;
break;
103 case 255: m_img_depth = 3;
break;
108 throw Exception(
"PNMReader::ctor: unknown color depth");
111 size_t img_size = (size_t)m_img_width * m_img_height * m_img_depth;
112 m_pnm_buffer = (
unsigned char *)malloc(img_size);
126 m_yuv_buffer = buffer;
132 return YUV422_PLANAR;
150 if (m_yuv_buffer == NULL) {
151 throw Exception(
"PNMReader::read: buffer = NULL");
154 if (fread(m_pnm_buffer, m_img_depth, (
size_t)m_img_width * m_img_height, m_pnmfile)
155 != (
size_t)m_img_width * m_img_height) {
158 convert(RGB, YUV422_PLANAR, m_pnm_buffer, m_yuv_buffer, m_img_width, m_img_height);
Base class for exceptions in Fawkes.
virtual void set_buffer(unsigned char *yuv422planar_buffer)
Set buffer that the read image should be written to.
PNMReader(const char *filename)
Constructor.
virtual unsigned int pixel_width()
Get width of read image in pixels.
virtual ~PNMReader()
Destructor.
virtual unsigned int pixel_height()
Get height of read image in pixels.
virtual colorspace_t colorspace()
Get colorspace from the just read image.
virtual void read()
Read data from file.
Fawkes library namespace.