i'm looking example of how save yuyv format frame jpeg file using libjpeg
library.
in typical computer apis, "yuv" means ycbcr, , "yuyv" means "ycbcr 4:2:2" stored y0, cb01, y1, cr01, y2 ...
thus, if have "yuv" image, can save libjpeg using jcs_ycbcr color space.
when have 422 image (yuyv) have duplicate cb/cr values 2 pixels need them before writing scanline libjpeg. thus, write loop you:
// "base" unsigned char const * yuyv data // jrow libjpeg row of samples array of 1 row pointer cinfo.image_width = width & -1; cinfo.image_height = height & -1; cinfo.input_components = 3; cinfo.in_color_space = jcs_ycbcr; jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, 92, true); jpeg_start_compress(&cinfo, true); unsigned char *buf = new unsigned char[width * 3]; while (cinfo.next_scanline < height) { (int = 0; < cinfo.image_width; += 2) { buf[i*3] = base[i*2]; buf[i*3+1] = base[i*2+1]; buf[i*3+2] = base[i*2+3]; buf[i*3+3] = base[i*2+2]; buf[i*3+4] = base[i*2+1]; buf[i*3+5] = base[i*2+3]; } jrow[0] = buf; base += width * 2; jpeg_write_scanlines(&cinfo, jrow, 1); } jpeg_finish_compress(&cinfo); delete[] buf;
use favorite auto-ptr avoid leaking "buf" if error or write function can throw / longjmp.
providing ycbcr libjpeg directly preferrable converting rgb, because store directly in format, saving lot of conversion work. when image comes webcam or other video source, it's efficient in ycbcr of sort (such yuyv.)
finally, "u" , "v" mean different in analog component video, naming of yuv in computer apis mean ycbcr highly confusing.
Comments
Post a Comment