blackjack / webcam

Golang webcam library for Linux
MIT License
411 stars 90 forks source link

UYVY format support #37

Closed youssefoumate closed 4 years ago

youssefoumate commented 4 years ago

Hello, I want to modify the http_mjpeg_streamer so it can support also the UYVY format. How can I change the following code to do that:

switch format {
case V4L2_PIX_FMT_YUYV:
    yuyv := image.NewYCbCr(image.Rect(0, 0, int(w), int(h)), image.YCbCrSubsampleRatio422)
    for i := range yuyv.Cb {
        ii := i * 4
        yuyv.Y[i*2] = frame[ii]
        yuyv.Y[i*2+1] = frame[ii+2]
        yuyv.Cb[i] = frame[ii+1]
        yuyv.Cr[i] = frame[ii+3]
    }
    img = yuyv

Thank you,

youssefoumate commented 4 years ago

I added V4L2_PIX_FMT_UYVY (0x59565955) case and it works:

switch format {
case V4L2_PIX_FMT_UYVY:
    uyvy := image.NewYCbCr(image.Rect(0, 0, int(w), int(h)), image.YCbCrSubsampleRatio422)
    for i := range uyvy.Cb {
        ii := i * 4
        uyvy.Y[i*2] = frame[ii+1]
        uyvy.Y[i*2+1] = frame[ii+3]
        uyvy.Cb[i] = frame[ii]
        uyvy.Cr[i] = frame[ii+2]
    }
    img = uyvy