[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xine-cvslog
Subject:    [xine-cvs] =?utf-8?q?HG=3A_xine-lib-1=2E2=3A_yuv2rgb=3A_added_col?= =?utf-8?q?or_matrix_and_fullrang
From:       Torsten_Jager <t.jager () gmx ! de>
Date:       2012-07-06 19:03:17
Message-ID: 07304594511a9efac1f4.1341601109 () hg ! debian ! org
[Download RAW message or body]

# HG changeset patch
# User Torsten Jager <t.jager@gmx.de>
# Date 1341601109 -10800
# Node ID 07304594511a9efac1f4842ab5b284e60c80147d
# Branch  default
# Parent  ce737ffb372d584c80b971594b85a1778f544c36
yuv2rgb: added color matrix and fullrange support

diff --git a/src/video_out/video_out_caca.c b/src/video_out/video_out_caca.c
--- a/src/video_out/video_out_caca.c
+++ b/src/video_out/video_out_caca.c
@@ -285,7 +285,7 @@
   this->vo_driver.dispose              = caca_dispose_driver;
 
   this->yuv2rgb_factory = yuv2rgb_factory_init(MODE_32_RGB, 0, NULL);
-  this->yuv2rgb_factory->set_csc_levels(this->yuv2rgb_factory, 0, 128, 128);
+  this->yuv2rgb_factory->set_csc_levels(this->yuv2rgb_factory, 0, 128, 128, CM_DEFAULT);
 
   if (dp) {
     this->cv = caca_get_canvas(dp);
 --git a/src/video_out/video_out_fb.c b/src/video_out/video_out_fb.c
--- a/src/video_out/video_out_fb.c
+++ b/src/video_out/video_out_fb.c
@@ -622,7 +622,8 @@
       this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
                                              this->yuv2rgb_brightness,
                                              this->yuv2rgb_contrast,
-                                             this->yuv2rgb_saturation);
+                                             this->yuv2rgb_saturation,
+                                             CM_DEFAULT);
       break;
 
     case VO_PROP_CONTRAST:
@@ -630,7 +631,8 @@
       this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
                                              this->yuv2rgb_brightness,
                                              this->yuv2rgb_contrast,
-                                             this->yuv2rgb_saturation);
+                                             this->yuv2rgb_saturation,
+                                             CM_DEFAULT);
       break;
 
     case VO_PROP_SATURATION:
@@ -638,7 +640,8 @@
       this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
                                              this->yuv2rgb_brightness,
                                              this->yuv2rgb_contrast,
-                                             this->yuv2rgb_saturation);
+                                             this->yuv2rgb_saturation,
+                                             CM_DEFAULT);
       break;
 
     default:
@@ -894,7 +897,8 @@
   this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
                                          this->yuv2rgb_brightness,
                                          this->yuv2rgb_contrast,
-                                         this->yuv2rgb_saturation);
+                                         this->yuv2rgb_saturation,
+                                         CM_DEFAULT);
 
   return 1;
 }
 --git a/src/video_out/video_out_opengl.c b/src/video_out/video_out_opengl.c
--- a/src/video_out/video_out_opengl.c
+++ b/src/video_out/video_out_opengl.c
@@ -1640,7 +1640,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
   case VO_PROP_CONTRAST:
@@ -1648,7 +1649,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
   case VO_PROP_SATURATION:
@@ -1656,7 +1658,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
   default:
@@ -1889,7 +1892,8 @@
   this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					 this->yuv2rgb_brightness,
 					 this->yuv2rgb_contrast,
-					 this->yuv2rgb_saturation);
+					 this->yuv2rgb_saturation,
+					 CM_DEFAULT);
 
   XLockDisplay (this->display);
   this->xoverlay = x11osd_create (this->xine, this->display, this->screen,
 --git a/src/video_out/video_out_xcbshm.c b/src/video_out/video_out_xcbshm.c
--- a/src/video_out/video_out_xcbshm.c
+++ b/src/video_out/video_out_xcbshm.c
@@ -863,7 +863,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
 
@@ -872,7 +873,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
 
@@ -881,7 +883,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
 
@@ -1323,7 +1326,8 @@
   this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					 this->yuv2rgb_brightness,
 					 this->yuv2rgb_contrast,
-					 this->yuv2rgb_saturation);
+					 this->yuv2rgb_saturation,
+					 CM_DEFAULT);
 
   this->xoverlay = xcbosd_create(this->xine, this->connection, this->screen,
                                  this->window, XCBOSD_SHAPED);
 --git a/src/video_out/video_out_xshm.c b/src/video_out/video_out_xshm.c
--- a/src/video_out/video_out_xshm.c
+++ b/src/video_out/video_out_xshm.c
@@ -951,7 +951,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
 
@@ -960,7 +961,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
 
@@ -969,7 +971,8 @@
     this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					   this->yuv2rgb_brightness,
 					   this->yuv2rgb_contrast,
-					   this->yuv2rgb_saturation);
+					   this->yuv2rgb_saturation,
+					   CM_DEFAULT);
     this->sc.force_redraw = 1;
     break;
 
@@ -1364,7 +1367,8 @@
   this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
 					 this->yuv2rgb_brightness,
 					 this->yuv2rgb_contrast,
-					 this->yuv2rgb_saturation);
+					 this->yuv2rgb_saturation,
+					 CM_DEFAULT);
 
   LOCK_DISPLAY(this);
   this->xoverlay = x11osd_create (this->xine, this->display, this->screen,
 --git a/src/video_out/yuv2rgb.c b/src/video_out/yuv2rgb.c
--- a/src/video_out/yuv2rgb.c
+++ b/src/video_out/yuv2rgb.c
@@ -2289,7 +2289,7 @@
 }
 
 static void yuv2rgb_set_csc_levels (yuv2rgb_factory_t *this,
-				    int brightness, int contrast, int saturation)
+  int brightness, int contrast, int saturation, int colormatrix)
 {
   int i;
   uint8_t table_Y[1024];
@@ -2300,18 +2300,40 @@
   void *table_r = 0, *table_g = 0, *table_b = 0;
   int shift_r = 0, shift_g = 0, shift_b = 0;
 
-  int crv = Inverse_Table_6_9[this->matrix_coefficients][0];
-  int cbu = Inverse_Table_6_9[this->matrix_coefficients][1];
-  int cgu = -Inverse_Table_6_9[this->matrix_coefficients][2];
-  int cgv = -Inverse_Table_6_9[this->matrix_coefficients][3];
+  int yoffset = -16;
+  int ygain = (1 << 16) * 255 / 219;
+
+  int cm = (colormatrix >> 1) & 7;
+  int crv = Inverse_Table_6_9[cm][0];
+  int cbu = Inverse_Table_6_9[cm][1];
+  int cgu = -Inverse_Table_6_9[cm][2];
+  int cgv = -Inverse_Table_6_9[cm][3];
 
   int mode = this->mode;
   int swapped = this->swapped;
 
+  /* nasty workaround for xine-ui not sending exact defaults */
+  if (brightness == -1) brightness = 0;
+  if (contrast == 127) contrast = 128;
+  if (saturation == 127) saturation = 128;
+
+  /* full range mode */
+  if (colormatrix & 1) {
+    yoffset = 0;
+    ygain = (1 << 16);
+
+    crv = (crv * 112 + 63) / 127;
+    cbu = (cbu * 112 + 63) / 127;
+    cgu = (cgu * 112 + 63) / 127;
+    cgv = (cgv * 112 + 63) / 127;
+  }
+
+  yoffset += brightness;
+    
   for (i = 0; i < 1024; i++) {
     int j;
 
-    j = (76309 * (i - 384 - 16 + brightness) + 32768) >> 16;
+    j = (ygain * (i - 384 + yoffset) + 32768) >> 16;
     j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
     table_Y[i] = j;
   }
@@ -2470,16 +2492,16 @@
 
   for (i = 0; i < 256; i++) {
     this->table_rV[i] = (((uint8_t *) table_r) +
-			 entry_size * div_round (crv * (i-128), 76309));
+			 entry_size * div_round (crv * (i-128), ygain));
     this->table_gU[i] = (((uint8_t *) table_g) +
-			 entry_size * div_round (cgu * (i-128), 76309));
-    this->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
+			 entry_size * div_round (cgu * (i-128), ygain));
+    this->table_gV[i] = entry_size * div_round (cgv * (i-128), ygain);
     this->table_bU[i] = (((uint8_t *)table_b) +
-			 entry_size * div_round (cbu * (i-128), 76309));
+			 entry_size * div_round (cbu * (i-128), ygain));
   }
 
 #if defined(ARCH_X86) || defined(ARCH_X86_64)
-  mmx_yuv2rgb_set_csc_levels (this, brightness, contrast, saturation);
+  mmx_yuv2rgb_set_csc_levels (this, brightness, contrast, saturation, colormatrix);
 #endif
 }
 
@@ -3243,12 +3265,11 @@
   this->create_converter    = yuv2rgb_create_converter;
   this->set_csc_levels      = yuv2rgb_set_csc_levels;
   this->dispose             = yuv2rgb_factory_dispose;
-  this->matrix_coefficients = 6;
   this->table_base          = NULL;
   this->table_mmx           = NULL;
 
 
-  yuv2rgb_set_csc_levels (this, 0, 128, 128);
+  yuv2rgb_set_csc_levels (this, 0, 128, 128, CM_DEFAULT);
 
   /*
    * auto-probe for the best yuv2rgb function
 --git a/src/video_out/yuv2rgb.h b/src/video_out/yuv2rgb.h
--- a/src/video_out/yuv2rgb.h
+++ b/src/video_out/yuv2rgb.h
@@ -45,6 +45,15 @@
 #define	MODE_8_GRAY  11
 #define MODE_PALETTE 12
 
+  /*
+   * colormatrix values - (mpeg_matrix_index << 1) | fullrange
+   */
+
+#define CM_DEFAULT   10
+#define CM_SD        10
+#define CM_HD         2
+#define CM_FULLRANGE  1
+
 struct yuv2rgb_s {
   /*
    * configure converter for scaling factors
@@ -129,7 +138,7 @@
    * for all converters produced by this factory
    */
   void (*set_csc_levels) (yuv2rgb_factory_t *this,
-			  int brightness, int contrast, int saturation);
+    int brightness, int contrast, int saturation, int colormatrix);
 
   /*
    * free resources
@@ -142,8 +151,6 @@
   int      swapped;
   uint8_t *cmap;
 
-  uint32_t matrix_coefficients;
-
   void    *table_base;
   void    *table_rV[256];
   void    *table_gU[256];
@@ -166,7 +173,7 @@
  */
 
 void mmx_yuv2rgb_set_csc_levels(yuv2rgb_factory_t *this,
-				int brightness, int contrast, int saturation);
+  int brightness, int contrast, int saturation, int colormatrix);
 void yuv2rgb_init_mmxext (yuv2rgb_factory_t *this);
 void yuv2rgb_init_mmx (yuv2rgb_factory_t *this);
 void yuv2rgb_init_mlib (yuv2rgb_factory_t *this);
 --git a/src/video_out/yuv2rgb_mmx.c b/src/video_out/yuv2rgb_mmx.c
--- a/src/video_out/yuv2rgb_mmx.c
+++ b/src/video_out/yuv2rgb_mmx.c
@@ -70,14 +70,19 @@
 extern const int32_t Inverse_Table_6_9[8][4];
 
 void mmx_yuv2rgb_set_csc_levels(yuv2rgb_factory_t *this,
-				int brightness, int contrast, int saturation)
+  int brightness, int contrast, int saturation, int colormatrix)
 {
-  int crv, cbu, cgu, cgv, cty;
-  int i;
+  int i, cty;
 
   int yoffset = -16;
   int ygain = ((1 << 16) * 255) / 219;
 
+  int cm = (colormatrix >> 1) & 7;
+  int crv = Inverse_Table_6_9[cm][0];
+  int cbu = Inverse_Table_6_9[cm][1];
+  int cgu = Inverse_Table_6_9[cm][2];
+  int cgv = Inverse_Table_6_9[cm][3];
+
   mmx_csc_t *csc;
 
   /* 'table_mmx' is 64bit aligned for better performance */
@@ -85,20 +90,27 @@
     this->table_mmx = av_mallocz(sizeof(mmx_csc_t));
   }
 
+  /* full range mode */
+  if (colormatrix & 1) {
+    yoffset = 0;
+    ygain = (1 << 16);
+
+    crv = (crv * 112 + 63) / 127;
+    cbu = (cbu * 112 + 63) / 127;
+    cgu = (cgu * 112 + 63) / 127;
+    cgv = (cgv * 112 + 63) / 127;
+  }
+
   yoffset += brightness;
   /* TV set behaviour: contrast affects color difference as well */
   saturation = (contrast * saturation + 64) >> 7;
 
   csc = (mmx_csc_t *) this->table_mmx;
 
-  crv = Inverse_Table_6_9[this->matrix_coefficients][0];
   crv = (crv * saturation + 512) / 1024;
-  cbu = Inverse_Table_6_9[this->matrix_coefficients][1];
   cbu = (cbu * saturation + 512) / 1024;
   cbu = (cbu > 32767) ? 32767 : cbu;
-  cgu = Inverse_Table_6_9[this->matrix_coefficients][2];
   cgu = (cgu * saturation + 512) / 1024;
-  cgv = Inverse_Table_6_9[this->matrix_coefficients][3];
   cgv = (cgv * saturation + 512) / 1024;
   cty = (ygain * contrast + 512) / 1024;
 
 --git a/src/xine-engine/video_out.c b/src/xine-engine/video_out.c
--- a/src/xine-engine/video_out.c
+++ b/src/xine-engine/video_out.c
@@ -537,13 +537,17 @@
 
   /* initialize yuv2rgb factory */
   if (!frame->yuv2rgb_factory) {
+    int cm = VO_GET_FLAGS_CM (vo_frame->flags);
     frame->yuv2rgb_factory = yuv2rgb_factory_init(MODE_24_RGB, 0, NULL);
     if (!frame->yuv2rgb_factory) {
       vo_frame_dec_lock(vo_frame);
       return -1; /* error happened */
     }
-    frame->yuv2rgb_factory->matrix_coefficients = 1; /* ITU-R Rec. 709 (1990) */
-    frame->yuv2rgb_factory->set_csc_levels (frame->yuv2rgb_factory, 0, 128, 128);
+    if ((cm >> 1) == 2) /* color matrix undefined */
+      cm = (cm & 1) | (vo_frame->height - vo_frame->crop_top - vo_frame->crop_bottom >= 720 ? 2 : 10);
+    else if ((cm >> 1) == 0) /* converted RGB source, always ITU 601 */
+      cm = (cm & 1) | 10;
+    frame->yuv2rgb_factory->set_csc_levels (frame->yuv2rgb_factory, 0, 128, 128, cm);
   }
 
   /* retrieve a yuv2rgb converter */

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Xine-cvslog mailing list
Xine-cvslog@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xine-cvslog
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic