int CJpegEncoder::SetQuality(int quality)
{
	if(setjmp(returnPoint))
	{
		return -1;
	}

	jpeg_set_quality(&cinfo, quality, FALSE);
	jpeg_suppress_tables(&cinfo, FALSE);
	jpeg_write_tables(&cinfo);
	return 0;
}
Beispiel #2
0
static void init_libjpeg_cinfo(struct v4lconvert_data *data)
{
	struct jpeg_compress_struct cinfo;
	unsigned char *jpeg_header = NULL;
	unsigned long jpeg_header_size = 0;

	if (data->cinfo_initialized)
		return;

	/* Setup our error handling */
	jpeg_std_error(&data->jerr);
	data->jerr.error_exit = jerr_error_exit;
	data->jerr.emit_message = jerr_emit_message;

	/* Create a jpeg compression object with default params and write
	   default jpeg headers to a mem buffer, so that we can use them to
	   pre-fill a jpeg_decompress_struct with default quant and huffman
	   tables, so that libjpeg can be used to parse [m]jpg-s with
	   incomplete headers */
	cinfo.err = &data->jerr;
	cinfo.client_data = data;
	jpeg_create_compress(&cinfo);
	jpeg_mem_dest(&cinfo, &jpeg_header, &jpeg_header_size);
	cinfo.input_components = 3;
	cinfo.in_color_space = JCS_RGB;
	jpeg_set_defaults(&cinfo);
	jpeg_write_tables(&cinfo);
	jpeg_destroy_compress(&cinfo);

	/* Init the jpeg_decompress_struct */
	data->cinfo.err = &data->jerr;
	data->cinfo.client_data = data;
	jpeg_create_decompress(&data->cinfo);
	jpeg_mem_src(&data->cinfo, jpeg_header, jpeg_header_size);
	jpeg_read_header(&data->cinfo, FALSE);

	free(jpeg_header);
	data->cinfo_initialized = 1;
}