简体   繁体   中英

How to compress a YUYV image into a jpeg

(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 the YCbCr or YUV format and transforms it into a JPEG image.

However, to compress a YUYV image using the TurboJPEG API you'd still need to transform the YUYV into a Y-Cb-Cr pixel format.

There might also be a little chance to use the YUYV image as YUV image with a subsampling of 4:2:2 , as this would result in two Y components per UV components, but if this source is exact, there are four different possible ways to place the YUVY 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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM