24 #include <core/exception.h> 25 #include <fvutils/writers/jpeg.h> 26 #include <fvutils/color/yuvrgb.h> 52 JpegWriter::JpegWriter(
int quality)
57 this->quality = (quality > 0) ? quality : -quality;
71 this->quality = (quality > 0) ? quality : -quality;
84 if (cspace == YUV422_PLANAR) {
87 throw Exception(
"Incompatible colorspace, can only hand YUV422_PLANAR images");
96 throw Exception(
"JpegWriter::read() error: buffer == NULL");
99 if ((outfile = fopen(
filename,
"wb")) == NULL) {
100 Exception e(
"Cannot open JPEG file for writing", errno);
106 struct jpeg_compress_struct cinfo;
107 struct jpeg_error_mgr jerr;
109 cinfo.err = jpeg_std_error( &jerr );
110 jpeg_create_compress( &cinfo );
111 jpeg_stdio_dest( &cinfo, outfile );
113 cinfo.image_width =
width;
114 cinfo.image_height =
height;
115 cinfo.input_components = 3;
116 cinfo.in_color_space = JCS_RGB;
118 jpeg_set_defaults(&cinfo);
119 jpeg_set_quality(&cinfo, quality,
true );
121 jpeg_start_compress( &cinfo,
true );
122 row_stride = cinfo.image_width * cinfo.input_components;
124 row_buffer = (
unsigned char *)malloc( row_stride );
126 while ( cinfo.next_scanline < cinfo.image_height ) {
127 convert_line_yuv422planar_to_rgb(
buffer, row_buffer,
128 cinfo.image_width, cinfo.image_height,
129 cinfo.next_scanline, 0 );
130 jpeg_write_scanlines( &cinfo, &row_buffer, 1 );
135 jpeg_finish_compress( &cinfo );
137 jpeg_destroy_compress( &cinfo );
colorspace_t cspace
The colorspace of the image.
virtual void set_buffer(colorspace_t cspace, unsigned char *buffer)
Set image buffer.
virtual ~JpegWriter()
Destructor.
Fawkes library namespace.
Interface to write images.
virtual void write()
Write to file.
Base class for exceptions in Fawkes.
JpegWriter(int quality=80)
Constructor.
virtual void set_filename(const char *filename)
Set filename.
unsigned int width
The width of the image.
unsigned char * buffer
The image-buffer.
unsigned int height
The height of the image.
char * filename
The complete filename.
void append(const char *format,...)
Append messages to the message list.