24 #include <core/exception.h>
25 #include <fvutils/writers/fvraw.h>
34 namespace firevision {
37 const unsigned int FvRawWriter::FILE_IDENTIFIER = 0x17559358;
46 FvRawWriter::FvRawWriter() :
Writer(
"raw")
84 colorspace_t colorspace,
85 unsigned char *buffer)
95 this->buffer = buffer;
114 this->buffer = buffer;
121 throw Exception(
"Cannot write if no file name given");
123 if (header.
width == 0) {
124 throw Exception(
"Cannot write if width = 0");
127 throw Exception(
"Cannot write if height = 0");
130 throw Exception(
"Cannot write if colorspace unknown");
132 if (buffer == NULL) {
133 throw Exception(
"Cannot write if no buffer set");
136 FILE *imagefile = fopen(
filename,
"w");
137 if (imagefile == NULL) {
138 throw Exception(
"Cannot not open file for writing");
143 if (fwrite((
const char *)&header, 1,
sizeof(header), imagefile) !=
sizeof(header)) {
144 throw Exception(
"Cannot write header to file", errno);
148 if (fwrite((
const char *)buffer, 1, buffer_size, imagefile) != buffer_size) {
149 throw Exception(
"Cannot write data to file", errno);
Base class for exceptions in Fawkes.
static const unsigned int FILE_IDENTIFIER
File identifier for FvRaw images.
FvRawWriter()
Constructor.
virtual void set_dimensions(unsigned int width, unsigned int height)
Set dimensions of image in pixels.
virtual void write()
Write to file.
virtual unsigned char * get_write_buffer()
Get write buffer.
virtual void set_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer.
virtual ~FvRawWriter()
Destructor.
Interface to write images.
unsigned int width
The width of the image.
colorspace_t cspace
The colorspace of the image.
virtual void set_filename(const char *filename)
Set filename.
unsigned int height
The height of the image.
char * filename
The complete filename.
Fawkes library namespace.