You wil need lipjpeg to do your request.
I copy for you a small function save YUV420 into a jpeg file. Hope it works.
/**
* put_jpeg_yuv420p_file
* Converts an YUV420P coded image to a jpeg image and writes
* it to an already open file.
*
* Inputs:
* - image is the image in YUV420P format.
* - width and height are the dimensions of the image
* - quality is the jpeg encoding quality 0-100%
*
* Output:
* - The jpeg is written directly to the file given by the file pointer fp
*
* Returns nothing
*/
static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width,
int height, int quality)
{
int i, j;
JSAMPROW y[16],cb[16],cr[16]; // y[2][5] = color sample of row 2 and
pixel column 5; (one plane)
JSAMPARRAY data[3]; // t[0][2][5] = color sample 0 of row 2 and column 5
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
data[0] = y;
data[1] = cb;
data[2] = cr;
cinfo.err = jpeg_std_error(&jerr); // Errors get written to stderr
jpeg_create_compress(&cinfo);
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
jpeg_set_defaults(&cinfo);
jpeg_set_colorspace(&cinfo, JCS_YCbCr);
cinfo.raw_data_in = TRUE; // Supply downsampled data
#if JPEG_LIB_VERSION >= 70
#warning using JPEG_LIB_VERSION >= 70
cinfo.do_fancy_downsampling = FALSE; // Fix segfault with v7
#endif
cinfo.comp_info[0].h_samp_factor = 2;
cinfo.comp_info[0].v_samp_factor = 2;
cinfo.comp_info[1].h_samp_factor = 1;
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1;
cinfo.comp_info[2].v_samp_factor = 1;
jpeg_set_quality(&cinfo, quality, TRUE);
cinfo.dct_method = JDCT_FASTEST;
jpeg_stdio_dest(&cinfo, fp); // Data written to file
jpeg_start_compress(&cinfo, TRUE);
for (j = 0; j < height; j += 16) {
for (i = 0; i < 16; i++) {
y[i] = image + width * (i + j);
if (i % 2 == 0) {
cb[i / 2] = image + width * height + width / 2 * ((i + j) /
2);
cr[i / 2] = image + width * height + width * height / 4 +
width / 2 * ((i + j) / 2);
}
}
jpeg_write_raw_data(&cinfo, data, 16);
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
}
On Thu, Jul 22, 2010 at 9:22 AM, Glen Ruedinger <[email protected]>wrote:
> Sounds like you need lipjpeg maybe?
>
>
>
>
>
> On Jul 21, 2010, at 8:24 AM, Tomas Härdin <[email protected]>
> wrote:
>
> On Mon, 2010-07-19 at 17:27 +0200, Denis Gottardello wrote:
>>
>>> Have you got an example on how to convert a just in memory image from yuv
>>> to
>>> jpg in C++?
>>>
>>> Thanks.
>>>
>>>
>>>
>> Check out libavformat/output-example.c and use "mjpeg" as your codec.
>>
>> /Tomas
>> _______________________________________________
>> libav-user mailing list
>> [email protected]
>> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>>
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user