[mythtv] [mythtv-commits] Ticket #1071: completely wrong colors in preview window of Watch Recordings

Jim Westfall jwestfall at surrealistic.net
Fri Jan 20 02:49:13 UTC 2006


you want to give this patch a try.

problem seems to be the cast from the calculated int to unsigned char.  
If the int is negative it will get truncated and become a postive number, 
when really the value should be 0.  Same deal if the int is greater then 
255.

there a built in C function that does what my clip() function does? seems 
like there should be, but cant recall ever seeing one.

jim

Nigel Pearson <nigel at ind.tansu.com.au> wrote [01.20.06]:
> > so the C version of the yuv2rgb is broken?
> 
> 	Yes. I got similar behaviour (although not quite that bad?)
> when I first started creating a Mac OS X output class. I deduced
> that there are errors in the code, but didn't understand the
> algorithm well enough to do anything about fixing it.
> 
> --
> Nigel Pearson, nigel at ind.tansu.com.au | "Reality is that which,
> Telstra Dev. Lab, Sydney, Australia   |  when you stop believing
> Office: 9814 4803    Fax:  9814 4897  |  in it, doesn't go away."
> Mobile: 0408 664435  Home: 9792 6998  |  Philip K. Dick - 'Valis'
> 
> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
-------------- next part --------------
Index: libs/libmythtv/yuv2rgb.cpp
===================================================================
--- libs/libmythtv/yuv2rgb.cpp	(revision 8626)
+++ libs/libmythtv/yuv2rgb.cpp	(working copy)
@@ -388,12 +388,21 @@
 #define C_GU (13954 >> (16 - SCALE_BITS))
 #define C_GV (34903 >> (16 - SCALE_BITS))
 
+unsigned char clip(int a) {
+  if(a < 0)
+     return 0;
+  else if(a > 255)
+     return 255;
+  else
+     return a;
+}
+
 #define RGBOUT(r, g, b, y1)\
 {\
     y = (y1 - 16) * C_Y;\
-    r = (y + r_add) >> SCALE_BITS;\
-    g = (y + g_add) >> SCALE_BITS;\
-    b = (y + b_add) >> SCALE_BITS;\
+    r = clip((y + r_add) >> SCALE_BITS);\
+    g = clip((y + g_add) >> SCALE_BITS);\
+    b = clip((y + b_add) >> SCALE_BITS);\
 }
 
 static void yuv420_argb32_non_mmx(unsigned char *image, unsigned char *py,


More information about the mythtv-dev mailing list