Yes, the VideoDevice has an Image member, here is it:
Image.h
Code:
#ifndef IMAGE_H
#define IMAGE_H
#include <stdio.h>
#include <jpeglib.h>
class Image
{
public:
Image(unsigned char* data, int width, int height, int depth = 24);
~Image();
void convertToGray();
void save(const char* filename, int format = Image::JPEG, int jpegQuality = 80);
unsigned char* data;
int width;
int height;
int depth;
int size;
const static short int JPEG = 0;
const static short int PNM = 1;
protected:
private:
};
#endif // IMAGE_H
Image.cpp
Code:
#include "Image.h"
Image::Image(unsigned char* data, int width, int height, int depth)
{
this->data = data;
this->width = width;
this->height = height;
this->depth = depth;
this->size = width * height;
}
Image::~Image()
{
//dtor
}
void Image::convertToGray()
{
//TODO - fix seg fault in VideoDevice before
}
void Image::save(const char* filename, int format, int jpegQuality)
{
FILE* file = fopen(filename, "w");
if (format == Image::PNM)
{
fprintf(file, "P6\n%d %d\n255\n", width, height);
fwrite(data, width * height * 3, 1, file);
}
else if (format == Image::JPEG)
{
unsigned int lineSize = width * 3;
unsigned char* line;
struct jpeg_compress_struct compressInfo;
struct jpeg_error_mgr error;
compressInfo.err = jpeg_std_error(&error);
jpeg_create_compress(&compressInfo);
jpeg_stdio_dest(&compressInfo, file);
compressInfo.image_width = width;
compressInfo.image_height = height;
compressInfo.input_components = 3;
compressInfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&compressInfo);
jpeg_set_quality(&compressInfo, jpegQuality, true);
jpeg_start_compress(&compressInfo, true);
line = data;
for (int i = 1;i <= height;i++)
{
jpeg_write_scanlines(&compressInfo, &line, 1);
line = data + (lineSize * i);
}
jpeg_finish_compress(&compressInfo);
jpeg_destroy_compress(&compressInfo);
}
fclose(file);
}