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 <[EMAIL PROTECTED]> 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, [EMAIL PROTECTED] | "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
> > [email protected]
> > 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
> [email protected]
> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
--Rob
signature.asc
Description: Digital signature
_______________________________________________ mythtv-dev mailing list [email protected] http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
