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

Robert Tsai rtsai1111 at comcast.net
Fri Jan 20 03:31:38 UTC 2006


On Thu, Jan 19, 2006 at 06:49:13PM -0800, Jim Westfall wrote:
> 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.

You want a combo of min/max:

	MIN(UCHAR_MAX, MAX(0, (a)))

> 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

> 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,

> _______________________________________________
> mythtv-dev mailing list
> mythtv-dev at mythtv.org
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev


--Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20060119/2f71bbe8/attachment.pgp


More information about the mythtv-dev mailing list