(Cross posted to libjpeg-turbo-users list.)
I'm having a problem with libjpeg-turbo.
The tjCompress2 function requires an RGB or Greyscale image to compress.
http://libjpeg-turbo.sourceforge.net/ljtdoc.branches_1.3.x/turbojpeg-c/group___turbo_j_p_e_g.html#gaba62b7a98f960839b588579898495cf2
(Sorry, you'll have to paste that link as it breaks markdown.)
My webcam (a PS3 EyeToy) has the following characteristics:
chris@raspberrypi ~ $ v4l2-ctl --get-fmt-video
Format Video Capture:
Width/Height : 320/240
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 640
Size Image : 153600
Colorspace : SRGB
From http://en.wikipedia.org/wiki/JPEG#Color_space_transformation it looks like YUYV is equivalent to the YCbCr that JPEG needs (though it has half the Cb and Cr data, compared with luminance). Have I understood correctly?
I know how to turn YUYV into RGB, using a matrix, but it seems a waste of scarce CPU cycles and colour accuracy, to perform two colour space changes when none are needed.
Is there a function which can directly compress a YUYV image into a JPEG?
Since the time the question was asked, a
tjCompressFromYUV
function has been implemented in the TurboJPEG API. It takes an image in theYCbCr
orYUV
format and transforms it into a JPEG image.However, to compress a
YUYV
image using the TurboJPEG API you'd still need to transform theYUYV
into aY-Cb-Cr
pixel format.There might also be a little chance to use the
YUYV
image asYUV
image with a subsampling of4:2:2
, as this would result in twoY
components perUV
components, but if this source is exact, there are four different possible ways to place theYUVY
components. But to be positive, there is a chance of 1/4 for this to work.Otherwise you might also transform the image using PNGU or something similar before you transform it to JPEG, as this library is able to "save YCbYCr images in png RGB8 format."