24 #include <core/exception.h> 25 #include <fvutils/writers/fvraw.h> 41 const unsigned int FvRawWriter::FILE_IDENTIFIER = 0x17559358;
50 FvRawWriter::FvRawWriter()
91 colorspace_t colorspace,
unsigned char *buffer)
101 this->buffer = buffer;
123 this->buffer = buffer;
131 throw Exception(
"Cannot write if no file name given");
133 if ( header.
width == 0 ) {
134 throw Exception(
"Cannot write if width = 0");
136 if ( header.
height == 0 ) {
137 throw Exception(
"Cannot write if height = 0");
140 throw Exception(
"Cannot write if colorspace unknown");
142 if ( buffer == NULL ) {
143 throw Exception(
"Cannot write if no buffer set");
146 FILE *imagefile=fopen(
filename,
"w");
147 if( imagefile == NULL) {
148 throw Exception(
"Cannot not open file for writing");
151 unsigned int buffer_size = colorspace_buffer_size(header.
colorspace,
155 if ( fwrite((
const char *)&header, 1,
sizeof(header), imagefile) !=
sizeof(header) ) {
156 throw Exception(
"Cannot write header to file", errno);
160 if ( fwrite((
const char *)buffer, 1, buffer_size, imagefile) != buffer_size ) {
161 throw Exception(
"Cannot write data to file", errno);
virtual void set_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer.
colorspace_t cspace
The colorspace of the image.
Fawkes library namespace.
Interface to write images.
static const unsigned int FILE_IDENTIFIER
File identifier for FvRaw images.
Base class for exceptions in Fawkes.
virtual void set_dimensions(unsigned int width, unsigned int height)
Set dimensions of image in pixels.
virtual void write()
Write to file.
virtual void set_filename(const char *filename)
Set filename.
virtual ~FvRawWriter()
Destructor.
virtual unsigned char * get_write_buffer()
Get write buffer.
unsigned int width
The width of the image.
unsigned int height
The height of the image.
FvRawWriter()
Constructor.
char * filename
The complete filename.