fixed for v4l2 captures, add colormodel uyuv
authorGood Guy <good1.2guy@gmail.com>
Thu, 20 Aug 2015 21:54:56 +0000 (15:54 -0600)
committerGood Guy <good1.2guy@gmail.com>
Thu, 20 Aug 2015 21:54:56 +0000 (15:54 -0600)
14 files changed:
cinelerra-5.0/cinelerra/cwindowgui.C
cinelerra-5.0/cinelerra/devicev4l2base.C
cinelerra-5.0/cinelerra/edit.C
cinelerra-5.0/cinelerra/resourcepixmap.C
cinelerra-5.0/cinelerra/vdevicev4l2.C
cinelerra-5.0/cinelerra/videodevice.C
cinelerra-5.0/guicast/bcbitmap.C
cinelerra-5.0/guicast/bccmdl.py
cinelerra-5.0/guicast/bccmodels.C
cinelerra-5.0/guicast/bccmodels.h
cinelerra-5.0/guicast/test4.C
cinelerra-5.0/guicast/vframe.C
cinelerra-5.0/guicast/xfer.C
cinelerra-5.0/quicktime/colormodels.h

index a0762595f48499208bb4ea030d4c922d3bb87cfb..470d0b02850042940c6a2e35e5cbe697ae394017 100644 (file)
@@ -902,7 +902,7 @@ void CWindowCanvas::draw_refresh(int flush)
        if(get_canvas() && !get_canvas()->get_video_on())
        {
 
-               if(refresh_frame)
+               if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
                {
                        float in_x1, in_y1, in_x2, in_y2;
                        float out_x1, out_y1, out_x2, out_y2;
@@ -2118,7 +2118,7 @@ int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
 
 
 
-       if(refresh_frame)
+       if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
        {
 
                if(draw)
@@ -2174,7 +2174,7 @@ int CWindowCanvas::do_eyedrop(int &rerender, int button_press, int draw)
 
 // Get color out of frame.
 // Doesn't work during playback because that bypasses the refresh frame.
-               if(refresh_frame)
+               if(refresh_frame && refresh_frame->get_w()>0 && refresh_frame->get_h()>0)
                {
                        float cursor_x = get_cursor_x();
                        float cursor_y = get_cursor_y();
index d78bd35cb9140944ecb7115ed427d8ac6efbca51..53c117229409abef2b7dc966aac247206fb26b0b 100644 (file)
@@ -304,7 +304,7 @@ int DeviceV4L2Base::v4l2_open(int color_model)
        int best_height = config_height;
        unsigned int best_format = 0;
        int best_merit = 0;
-       //int best_color_model = -1;
+       int best_color_model = -1;
        int best_area = 1;
        int driver = video_device->in_config->driver;
 
@@ -322,6 +322,7 @@ int DeviceV4L2Base::v4l2_open(int color_model)
                int cmodel = -1;
                switch(fmt.pixelformat)
                {
+               case V4L2_PIX_FMT_UYVY:    cmodel = BC_UVY422;  merit = 4;  break;
                case V4L2_PIX_FMT_YUYV:    cmodel = BC_YUV422;  merit = 4;  break;
                case V4L2_PIX_FMT_Y41P:    cmodel = BC_YUV411P; merit = 1;  break;
                case V4L2_PIX_FMT_YVU420:  cmodel = BC_YUV420P; merit = 3;  break;
@@ -340,7 +341,7 @@ int DeviceV4L2Base::v4l2_open(int color_model)
                {
                        best_merit = merit;
                        best_format = fmt.pixelformat;
-                       //best_color_model = cmodel;
+                       best_color_model = cmodel;
                }
 
                for( int n=0; n<20; ++n ) {
@@ -379,6 +380,7 @@ int DeviceV4L2Base::v4l2_open(int color_model)
                        best_format = V4L2_PIX_FMT_MPEG;
                        break;
                default:
+                       best_color_model = color_model;
                        best_format = cmodel_to_device(color_model);
                        break;
                }
@@ -588,7 +590,7 @@ int DeviceV4L2Base::v4l2_open(int color_model)
                        perror("DeviceV4L2Base::v4l2_open VIDIOC_S_JPEGCOMP");
        }
 
-       this->color_model = color_model;
+       this->color_model = best_color_model;
        return 0;
 }
 
@@ -739,6 +741,7 @@ unsigned int DeviceV4L2Base::cmodel_to_device(int color_model)
        {
        case BC_COMPRESSED:     return V4L2_PIX_FMT_MJPEG;
        case BC_YUV422:         return V4L2_PIX_FMT_YUYV;
+       case BC_UVY422:         return V4L2_PIX_FMT_UYVY;
        case BC_YUV411P:        return V4L2_PIX_FMT_Y41P;
        case BC_YUV420P:        return V4L2_PIX_FMT_YVU420;
        case BC_YUV422P:        return V4L2_PIX_FMT_YUV422P;
index 6bf265d761b4d684734e0bf8ac579c9af0834ef0..d1421020e42536a57a2a393ae560f6f5f1960513 100644 (file)
@@ -340,16 +340,16 @@ double Edit::frame_w()
 
 double Edit::picon_w()
 {
-       if(asset)
-               return (double)edl->local_session->zoom_track * 
-                       asset->width / 
-                       asset->height;
-       if(nested_edl)
-               return (double)edl->local_session->zoom_track * 
-                       nested_edl->session->output_w / 
-                       nested_edl->session->output_h;
-
-       return 0;
+       int w = 0, h = 0;
+       if(asset) {
+               w = asset->width;
+               h = asset->height;
+       }
+       else if(nested_edl) {
+               w = nested_edl->session->output_w;
+               h = nested_edl->session->output_h;
+       }
+       return w>0 && h>0 ? ((double)edl->local_session->zoom_track*w)/h : 0;
 }
 
 int Edit::picon_h()
index 4cfea84328104e1c177e01495e05909e1c435cf2..a8c0f8a758f59d8a43683484413d435b20b9d07f 100644 (file)
@@ -851,8 +851,8 @@ void ResourcePixmap::draw_video_resource(TrackCanvas *canvas,
        int64_t picon_h = edit->picon_h();
 
 
-// Don't draw video if picon is bigger than edit
-       if(picon_w > edit_w) return;
+// Don't draw video if picon is empty or bigger than edit
+       if( picon_w <= 0 || picon_w > edit_w ) return;
 
 // pixels spanned by a frame
        double frame_w = edit->frame_w();
index 49c233405adc285353624e2853358b2a9b66530f..c2ca9e97bb4df6b057253759d1830a1bd93ee094 100644 (file)
@@ -52,8 +52,15 @@ int VDeviceV4L2::open_input()
        int result = get_sources();
        if( !result )
        {
-               device->channel->use_frequency = 1;
-               device->channel->use_fine = 1;
+               ArrayList<Channel*> *inputs = device->get_inputs();
+               for( int i=0; i<inputs->size(); ++i ) {
+                       if( inputs->get(i)->tuner ) {
+                               device->channel->use_frequency = 1;
+                               device->channel->use_fine = 1;
+                       }
+                       else
+                               device->channel->use_input = 1;
+               }
        }
        return result;
 }
@@ -99,7 +106,7 @@ int VDeviceV4L2::read_buffer(VFrame *frame)
                        VFrame *buffer = device_buffer(bfr);
 //printf("VDeviceV4L2::read_buffer %d %p %p\n", 
 //  __LINE__, frame->get_data(), buffer->get_data());
-                       frame->copy_from(buffer);
+                       frame->transfer_from(buffer);
                        put_buffer(bfr);
                }
                else
index eceb75c8a85a9714b90d5cbe5ec1e457d97a4bfd..104f11fba644b7ee84fe08f6a9fba8dd809e6acc 100644 (file)
@@ -360,7 +360,6 @@ int VideoDevice::is_compressed(int driver, int use_file, int use_fixed)
 // FileMOV needs to have write_frames called so the start codes get scanned.
        return ((driver == CAPTURE_BUZ && use_fixed) ||
                (driver == VIDEO4LINUX2JPEG && use_fixed) || 
-               (driver == VIDEO4LINUX2MPEG && use_fixed) || 
                (driver == CAPTURE_JPEG_WEBCAM && use_fixed) || 
                driver == CAPTURE_LML || 
                driver == CAPTURE_FIREWIRE ||
index 6515d1853b9ba69557744cd9e8f8c3eaae0b2ab1..8289c5994a155433bfc9ef5e3c52a8ed31f05c4a 100644 (file)
@@ -150,7 +150,7 @@ BC_XvShmImage::BC_XvShmImage(BC_Bitmap *bitmap, int index,
        h = xv_image->height;
        if(!XShmAttach(top_level->display, &shm_info))
                perror("BC_XvShmImage::BC_XvShmImage XShmAttach");
-       if( color_model == BC_YUV422 ) {
+       if( color_model == BC_YUV422 || color_model == BC_UVY422 ) {
                bytesPerLine = w*2;
                bitsPerPixel = 12;
                row_data = new unsigned char*[h];
@@ -223,7 +223,7 @@ BC_XvImage::BC_XvImage(BC_Bitmap *bitmap, int index,
        xv_image->data = (char *) data;
        w = xv_image->width;
        h = xv_image->height;
-       if( color_model == BC_YUV422 ) {
+       if( color_model == BC_YUV422 || color_model == BC_UVY422 ) {
                int bytesPerLine = w*2;
                row_data = new unsigned char*[h];
                for( int i=0; i<h; ++i )
@@ -652,6 +652,7 @@ int BC_Bitmap::read_frame(VFrame *frame,
                        break;
                default:
                case BC_YUV422:
+               case BC_UVY422:
                        memcpy(get_data(), frame->get_data(), w * h + w * h);
                        break;
                }
index bc5138d1eff6d62689fdb271cc6cb999eb147010..2850fe503ad810865b806c0091aedd2bdc90b57b 100755 (executable)
@@ -192,6 +192,19 @@ base = {
     },
   },
 
+  "uyvy8888": {
+    "i8": {
+      "r": " int32_t u = inp[0], iy = inp[((i&1)<<1)+1], y = iy*0x010101u, v = inp[2];",
+      "w": " if( !(j&1) ) { *out++ = u; *out++ = y; *out++ = v; *out = y; }\n" +
+           " else { *out++= y; }",
+    },
+    "i16": {
+      "r": " int32_t u = inp[0]<<8, iy = inp[((i&1)<<1)+1], y = iy*0x010101u, v = inp[2]<<8;",
+      "w": " if( !(j&1) ) { *out++ = u>>8; *out++ = y>>8; *out++ = v>>8; *out = y>>8; }\n" +
+           " else { *out++= y>>8; }",
+    },
+  },
+
   "yuv10101010": {
     "i8": {
       "r": " uint32_t it = *(uint32_t*)inp;\n" +
@@ -414,6 +427,7 @@ add_cmodel("bc_yuv161616", "i16", "yuv161616")
 add_cmodel("bc_yuva16161616", "i16", "yuv161616", "a16")
 
 add_cmodel("bc_yuv422", "i8", "yuyv8888")
+add_cmodel("bc_uvy422", "i8", "uyvy8888")
 add_cmodel("bc_a8")
 add_cmodel("bc_a16")
 add_cmodel("bc_a_float")
@@ -468,9 +482,9 @@ def is_rgb(nm):
 
 def is_yuv(nm):
   return nm in [ "bc_yuv888", "bc_yuva8888", "bc_yuv161616", \
-    "bc_yuva16161616", "bc_yuv422", "bc_yuv101010", "bc_vyu888", \
-    "bc_uyva8888", "bc_yuv420p", "bc_yuv422p", "bc_yuv444p", \
-    "bc_yuv411p", "bc_yuv410p", ]
+    "bc_yuva16161616", "bc_yuv422", "bc_uvy422", "bc_yuv101010", \
+    "bc_vyu888", "bc_uyva8888", "bc_yuv420p", "bc_yuv422p", \
+    "bc_yuv444p", "bc_yuv411p", "bc_yuv410p", ]
 
 def is_planar(nm):
   return nm in [ "bc_yuv420p", "bc_yuv422p", "bc_yuv444p", \
index 0d92551f0754108dc8a776217ce37b185d024a56..6abfe00f96b27da44c813ca76d6d0d382bab585d 100644 (file)
@@ -94,6 +94,7 @@ int BC_CModels::calculate_pixelsize(int colormodel)
        case BC_YUV422P:      return 1;
        case BC_YUV444P:      return 1;
        case BC_YUV422:       return 2;
+       case BC_UVY422:       return 2;
        case BC_YUV411P:      return 1;
        case BC_YUV410P:      return 1;
        case BC_RGB_FLOATP:   return 4;
@@ -146,6 +147,7 @@ int BC_CModels::bc_to_x(int color_model)
        switch(color_model) {
        case BC_YUV420P: return FOURCC_YV12;
        case BC_YUV422:  return FOURCC_YUV2;
+       case BC_UVY422:  return FOURCC_UYVY;
        }
        return -1;
 }
@@ -225,6 +227,7 @@ int BC_CModels::is_yuv(int colormodel)
        case BC_YUV161616:
        case BC_YUVA16161616:
        case BC_YUV422:
+       case BC_UVY422:
        case BC_YUV101010:
        case BC_VYU888:
        case BC_UYVA8888:
index 92f4cf3821162717eab7b484c3ae495706440aa5..e4e1cba432753ca17bb36f7705d6939d21384dec 100644 (file)
@@ -42,6 +42,7 @@
 #define BC_YUVA8888     14
 #define BC_YUV161616    15
 #define BC_YUVA16161616 16
+#define BC_UVY422       18
 #define BC_YUV422       19
 #define BC_A8           22
 #define BC_A16          23
@@ -53,9 +54,9 @@
 #define BC_RGBA_FLOAT   30
 // Planar
 #define BC_YUV420P      7
-#define BC_YUV422P      17
+#define BC_YUV422P      8
 #define BC_YUV444P      27
-#define BC_YUV411P      18
+#define BC_YUV411P      17
 #define BC_YUV410P      28
 #define BC_RGB_FLOATP   32
 #define BC_RGBA_FLOATP  33
@@ -65,6 +66,7 @@
 // For communication with the X Server
 #define FOURCC_YV12 0x32315659  /* YV12   YUV420P */
 #define FOURCC_YUV2 0x32595559  /* YUV2   YUV422 */
+#define FOURCC_UYVY 0x59565955  /* UYVY   UVY422 */
 #define FOURCC_I420 0x30323449  /* I420   Intel Indeo 4 */
 
 
index 09237a766a62b5c9ef8c46c7e0d3ad209a2d8209..e28ec10b1725b45077fda2f79722550977f523a8 100644 (file)
@@ -78,10 +78,10 @@ void TestWindow::show_text(int tx, int ty, const char *fmt, ...)
 
 const char *cmdl[] = {
  "transparency", "compressed", "rgb8", "rgb565", "bgr565", "bgr888", "bgr8888", "yuv420p",
- "none", "rgb888", "rgba8888", "rgb161616", "rgba16161616", "yuv888", "yuva8888", "yuv161616",
- "yuva16161616", "yuv422p", "yuv411p", "yuv422", "argb8888", "abgr8888", "a8", "a16",
+ "yuv422p", "rgb888", "rgba8888", "rgb161616", "rgba16161616", "yuv888", "yuva8888", "yuv161616",
+ "yuva16161616", "yuv411p", "uvy422", "yuv422", "argb8888", "abgr8888", "a8", "a16",
  "yuv101010", "vyu888", "uyva8888", "yuv444p", "yuv410p", "rgb_float", "rgba_float", "a_float",
- "rgb_floatp",
+ "rgb_floatp", "rgba_floatp",
 };
 
 void write_pbm(uint8_t *tp, int w, int h, const char *fmt, ...)
index a3b09324bd6f59f5e5122874fd82094615925054..e3f5bf0a9e668cd1ac401658d6f7e7f492bc2c7a 100644 (file)
@@ -1042,6 +1042,7 @@ int VFrame::transfer_from(VFrame *that, int bg_color)
                return this->copy_from(that);
 
        timestamp = that->timestamp;
+#if 0
        BC_CModels::transfer(
                this->get_rows(), that->get_rows(),          // Packed data out/in
                this->get_y(), this->get_u(), this->get_v(), // Planar data out/in
@@ -1051,6 +1052,33 @@ int VFrame::transfer_from(VFrame *that, int bg_color)
                that->get_color_model(), this->get_color_model(), // Color models in/out
                bg_color,                                    // alpha blend bg_color
                that->get_w(), this->get_w());               // rowspans (of luma for YUV)
+#else
+       unsigned char *in_ptrs[4], *out_ptrs[4];
+       unsigned char **inp, **outp;
+       if( BC_CModels::is_planar(that->get_color_model()) ) {
+               in_ptrs[0] = that->get_y();
+               in_ptrs[1] = that->get_u();
+               in_ptrs[2] = that->get_v();
+               in_ptrs[3] = that->get_a();
+               inp = in_ptrs;
+       }
+       else
+               inp = that->get_rows(); 
+       if( BC_CModels::is_planar(this->get_color_model()) ) {
+               out_ptrs[0] = this->get_y();
+               out_ptrs[1] = this->get_u();
+               out_ptrs[2] = this->get_v();
+               out_ptrs[3] = this->get_a();
+               outp = out_ptrs;
+       }
+       else
+               outp = this->get_rows();        
+       BC_CModels::transfer(outp, this->get_color_model(),
+                       0, 0, this->get_w(), this->get_h(), this->get_w(),
+               inp, that->get_color_model(),
+                       0, 0, that->get_w(), that->get_h(), that->get_w(),
+               bg_color);
+#endif
        return 0;
 }
 
index 3e0e3bd24accfef298f44c7fac598453c63f803e..c689b6b6a8b4cf3be0f7085d8b726626001cc5df 100644 (file)
@@ -104,6 +104,7 @@ void BC_Xfer::init(
 {
        // prevent bounds errors on poorly dimensioned macro pixel formats
        switch( in_colormodel ) {
+       case BC_UVY422:
        case BC_YUV422:   in_w &= ~1;               break;  // 2x1
        case BC_YUV420P:  in_w &= ~1;  in_h &= ~1;  break;  // 2x2
        case BC_YUV422P:  in_w &= ~1;               break;  // 2x1
@@ -111,6 +112,7 @@ void BC_Xfer::init(
        case BC_YUV411P:  in_w &= ~3;               break;  // 4x1
        }
        switch( out_colormodel ) {
+       case BC_UVY422:
        case BC_YUV422:  out_w &= ~1;               break;
        case BC_YUV420P: out_w &= ~1; out_h &= ~1;  break;
        case BC_YUV422P: out_w &= ~1;               break;
@@ -165,7 +167,8 @@ void BC_Xfer::init(
         double hscale = (double)in_w/out_w;
        for( int i=0; i<out_w; ++i ) {
                        column_table[i] = ((int)(hscale * i) + in_x) * in_pixelsize;
-                       if( in_colormodel == BC_YUV422 ) column_table[i] &= ~3;
+                       if( in_colormodel == BC_YUV422 || in_colormodel == BC_UVY422 )
+                               column_table[i] &= ~3;
        }
         double vscale = (double)in_h/out_h;
        row_table = new int[out_h];
index 049484f8e944f2ca45dd5c94b2c8627284579b9b..88060e3c54905777996e38faeaa92dc34fa4454a 100644 (file)
@@ -38,6 +38,7 @@
 #define BC_YUVA8888     14
 #define BC_YUV161616    15
 #define BC_YUVA16161616 16
+#define BC_UVY422       18
 #define BC_YUV422       19
 #define BC_A8           22
 #define BC_A16          23
@@ -49,8 +50,8 @@
 #define BC_RGBA_FLOAT   30
 // Planar
 #define BC_YUV420P      7
-#define BC_YUV422P      17
-//#define BC_YUV411P      18   // broken
+#define BC_YUV422P      8
+//#define BC_YUV411P      17   // broken
 #define BC_YUV444P      27
 #define BC_YUV9P        28     // Disasterous cmodel from Sorenson
 
@@ -59,6 +60,7 @@
 // For communication with the X Server
 #define FOURCC_YV12 0x32315659  /* YV12   YUV420P */
 #define FOURCC_YUV2 0x32595559  /* YUV2   YUV422 */
+#define FOURCC_UYVY 0x59565955  /* UYVY   UVY422 */
 #define FOURCC_I420 0x30323449  /* I420   Intel Indeo 4 */
 
 #undef CLAMP