binary string question

Peter Abel PeterAbel at gmx.net
Mon Nov 10 23:13:12 CET 2003


Dan Jones <djones at shcorp.com> wrote in message news:<mailman.567.1068251716.702.python-list at python.org>...
...
...
...
> static void ccvt_420p(int width, int height, const unsigned char *src,
> unsigned char *dst, int push)
> {
>         int line, col, linewidth;
>         int y, u, v, yy, vr, ug, vg, ub;
>         int r, g, b;
>         const unsigned char *py, *pu, *pv;
>                                                                                               
>         linewidth = width >> 1;
>         py = src;
>         pu = py + (width * height);
>         pv = pu + (width * height) / 4;
>                                                                                               
>         y = *py++;

I guess here you're using char as int.

>         yy = y << 8;
>         u = *pu - 128;
...
...
...
>         for (line = 0; line < height; line++) {
>                 for (col = 0; col < width; col++) {
>                         r = (yy +      vr) >> 8;
>                         g = (yy - ug - vg) >> 8;
>                         b = (yy + ub     ) >> 8;
...
...
...
                
> And here's what I have so far:
> 
> 
> def yuv420p_to_rgb24(WIDTH, HEIGHT, source):
>         line, col, linewidth = 0,0,0
>         y,u,v,yy,vr,ug,vg,ub = 0,0,0,0,0,0,0,0
>         r,g,b = 0,0,0
>         linewidth = WIDTH >> 1

To do the same in pyhton ...
>         sourceframe = list(source)
 ... use  sourceframe = map(ord,source) instead !!



>         py = 0 
>         pu = py + (WIDTH * HEIGHT) 
>         pv = pu + (WIDTH * HEIGHT) / 4 
>         destination = []
>         destindex = 0
>                                                                                               
!!!! *y* becomes an int because  *sourceframe* is a list of ints !!!!
>         y = sourceframe[py]
>         py += 1

*********The following line has no effect**********************
>         int(y)
***************************************************************

!!!! Now *y* is an int and can be shifted !!!!
>         yy = y << 8 # This is where it blows up

...
...
...

Regards
Peter




More information about the Python-list mailing list