Changeset 344

Show
Ignore:
Timestamp:
02/16/07 12:59:27 (2 years ago)
Author:
astrange
Message:

Use unsigned int in ColorConversions?.c; clean up loops to only multiply IVs and not divide them. Fix y420->y422+sse2 footer loop (closes #107).
Simplify SSA tag machine's number parser.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ColorConversions.c

    r334 r344  
    6363//also, big-endian only 
    6464 
    65 static void Y420toY422_ppc_scalar(UInt8* baseAddr, int outRB, int width, int height, AVFrame * picture) 
    66 { 
    67          int             y = height >> 1
    68          int             halfWidth = width >> 1, halfHalfWidth = halfWidth >> 1
     65static void Y420toY422_ppc_scalar(UInt8* baseAddr, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
     66{ 
     67         unsigned             y = height / 2
     68         unsigned             halfWidth = width / 2, halfHalfWidth = width / 4
    6969         UInt8          *inY = picture->data[0], *inU = picture->data[1], *inV = picture->data[2]; 
    7070         int             rB = picture->linesize[0], rbU = picture->linesize[1], rbV = picture->linesize[2]; 
     
    106106 } 
    107107 
    108 static void Y420toY422_ppc_altivec(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
    109 { 
    110         UInt8          *yc = picture->data[0], *uc = picture->data[1], *vc = picture->data[2]; 
    111         int             rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2]; 
    112         int                            y,x,x2,x4, vWidth = width >> 5, halfheight = height >> 1
     108static void Y420toY422_ppc_altivec(UInt8 * o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
     109{ 
     110        UInt8                  *yc = picture->data[0], *uc = picture->data[1], *vc = picture->data[2]; 
     111        unsigned               rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2]; 
     112        unsigned               y,x,x2,x4, vWidth = width / 32, halfheight = height / 2
    113113         
    114114        for (y = 0; y < halfheight; y ++) { 
     
    139139                        UInt8 *o2 = o + outRB, *yc2 = yc + rY; 
    140140                        for (x = vWidth * 32, x2 = x*2; x < width; x += 2, x2 += 4) { 
    141                                 int             hx = x >> 1
     141                                unsigned             hx = x / 2
    142142                                o2[x2] = o[x2] = uc[hx]; 
    143143                                o[x2 + 1] = yc[x]; 
     
    156156} 
    157157 
    158 void Y420toY422(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
    159 { 
    160         static void (*y420_function)(UInt8* baseAddr, int outRB, int width, int height, AVFrame * picture) = NULL; 
     158void Y420toY422(UInt8 * o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
     159{ 
     160        static void (*y420_function)(UInt8* baseAddr, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) = NULL; 
    161161        if (!y420_function) { 
    162162                int sels[2] = { CTL_HW, HW_VECTORUNIT }; // from http://developer.apple.com/hardwaredrivers/ve/g3_compatibility.html 
     
    174174#include <emmintrin.h> 
    175175 
    176 static void Y420toY422_sse2(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
     176#define TRUNCATE(x, power) (x & ~(power-1)) 
     177 
     178static void Y420toY422_sse2(UInt8 * o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
    177179{ 
    178180        UInt8          *yc = picture->data[0], *uc = picture->data[1], *vc = picture->data[2]; 
    179         int             rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2]; 
    180         int                            y,x, vWidth = width >> 4, halfheight = height >> 1, halfwidth = width >> 1
     181        unsigned               rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2]; 
     182        unsigned               y,x, vWidth = width / 16, halfheight = height / 2, halfwidth = width / 2
    181183         
    182184        for (y = 0; y < halfheight; y ++) { 
     
    189191                        * sse2 can do 64-bit loads, so we do that. (apple's h264 doesn't seem to, maybe we should copy them?) 
    190192                        * unrolling loops is very bad on x86 */ 
    191                         int x2 = x*2; 
     193                        unsigned x2 = x*2; 
    192194                        __builtin_prefetch(&yv[x+1], 0, 0); __builtin_prefetch(&yv2[x+1], 0, 0); // prefetch next y vectors, throw it out of cache immediately after use 
    193195                        __builtin_prefetch(&uv[x+1], 0, 0); __builtin_prefetch(&vv[x+1], 0, 0); // and chroma too 
     
    206208                } 
    207209                 
    208                 if (__builtin_expect(width & 15, FALSE)) { //spill to scalar for the end if the row isn't a multiple of 16 
    209                         UInt8 *o2 = o + outRB, *yc2 = yc + rY
    210                         for (x = vWidth * 16; x < halfwidth; x ++) { 
    211                                 int             hx = x>>1, x2 = x*2; 
    212                                 o2[x2] = o[x2] = uc[hx]; 
    213                                 o[x2 + 1] = yc[x]; 
    214                                 o2[x2 + 1] = yc2[x]; 
    215                                 o2[x2 + 2] = o[x2 + 2] = vc[hx]; 
    216                                 o[x2 + 3] = yc[x + 1]; 
    217                                 o2[x2 + 3] = yc2[x + 1]; 
     210                if (__builtin_expect(width % 16 != 0, FALSE)) { //spill to scalar for the end if the row isn't a multiple of 16 
     211                        UInt8 *o2 = (UInt8*)ov2, *yc2 = (UInt8*)yv2
     212                        for (x = TRUNCATE(width, 16) / 2; x < halfwidth; x++) { 
     213                                unsigned x4 = x*4, x2 = x*2; 
     214                                o2[x4] = o[x4] = uc[x]; 
     215                                o[x4 + 1] = yc[x2]; 
     216                                o2[x4 + 1] = yc2[x2]; 
     217                                o2[x4 + 2] = o[x4 + 2] = vc[x]; 
     218                                o[x4 + 3] = yc[x2 + 1]; 
     219                                o2[x4 + 3] = yc2[x2 + 1]; 
    218220                        }                        
    219221                } 
     
    228230 
    229231 
    230 static void Y420toY422_x86_scalar(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
    231 { 
    232         UInt8          *yc = picture->data[0], *u = picture->data[1], *v = picture->data[2]; 
    233         int             rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2], halfheight = height >> 1, halfwidth = width >> 1
    234         int                           y, x; 
     232static void Y420toY422_x86_scalar(UInt8 * o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
     233{ 
     234        UInt8          *yc = picture->data[0], *u = picture->data[1], *v = picture->data[2]; 
     235        unsigned       rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2], halfheight = height / 2, halfwidth = width / 2
     236        unsigned      y, x; 
    235237         
    236238        for (y = 0; y < halfheight; y ++) { 
    237239                UInt8 *o2 = o + outRB, *yc2 = yc + rY; 
    238240                 
    239                 for (x = 0; x < halfwidth; x ++) { 
    240                         int             hx = x>>1, x2 = x*2; 
    241                         o2[x2] = o[x2] = u[hx]; 
    242                         o[x2 + 1] = yc[x]; 
    243                         o2[x2 + 1] = yc2[x]; 
    244                         o2[x2 + 2] = o[x2 + 2] = v[hx]; 
    245                         o[x2 + 3] = yc[x + 1]; 
    246                         o2[x2 + 3] = yc2[x + 1]; 
     241                for (x = 0; x < halfwidth; x++) { 
     242                        unsigned x4 = x*4, x2 = x*2; 
     243                        o2[x4] = o[x4] = u[x]; 
     244                        o[x4 + 1] = yc[x2]; 
     245                        o2[x4 + 1] = yc2[x2]; 
     246                        o2[x4 + 2] = o[x4 + 2] = v[x]; 
     247                        o[x4 + 3] = yc[x2 + 1]; 
     248                        o2[x4 + 3] = yc2[x2 + 1]; 
    247249                } 
    248250                 
     
    254256} 
    255257 
    256 void Y420toY422(UInt8 * o, int outRB, int width, int height, AVFrame * picture) 
     258void Y420toY422(UInt8 * o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
    257259{ 
    258260        uintptr_t yc = (uintptr_t)picture->data[0]; 
     
    266268#endif 
    267269 
    268 void BGR24toRGB24(UInt8 *baseAddr, int rowBytes, int width, int height, AVFrame *picture) 
    269 { 
    270         int i, j; 
     270void BGR24toRGB24(UInt8 *baseAddr, unsigned rowBytes, unsigned width, unsigned height, AVFrame *picture) 
     271{ 
     272        unsigned i, j; 
    271273        UInt8 *srcPtr = picture->data[0]; 
    272274         
     
    284286} 
    285287 
    286 void RGB32toRGB32(UInt8 *baseAddr, int rowBytes, int width, int height, AVFrame *picture) 
    287 { 
    288         int x, y; 
     288void RGB32toRGB32(UInt8 *baseAddr, unsigned rowBytes, unsigned width, unsigned height, AVFrame *picture) 
     289{ 
     290        unsigned x, y; 
    289291        UInt8 *srcPtr = picture->data[0]; 
    290292         
     
    302304} 
    303305 
    304 void Y422toY422(UInt8* o, int outRB, int width, int height, AVFrame * picture) 
     306void Y422toY422(UInt8* o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
    305307{ 
    306308        UInt8          *yc = picture->data[0], *u = picture->data[1], *v = picture->data[2]; 
    307         int             rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2], y = 0, x, x2; 
    308          
    309         for (; y < height; y++) { 
    310                 for (x = 0, x2 = 0; x < width; x += 2, x2 += 4) { 
    311                         int             hx = x >> 1
    312                         o[x2] = u[hx]; 
    313                         o[x2 + 1] = yc[x]; 
    314                         o[x2 + 2] = v[hx]; 
    315                         o[x2 + 3] = yc[x + 1]; 
     309        unsigned       rY = picture->linesize[0], rU = picture->linesize[1], rV = picture->linesize[2], y, x, x2, halfwidth = width / 2; 
     310         
     311        for (y = 0; y < height; y++) { 
     312                for (x = 0; x < halfwidth; x++) { 
     313                        unsigned x2 = x * 2, x4 = x * 4
     314                        o[x4] = u[x]; 
     315                        o[x4 + 1] = yc[x2]; 
     316                        o[x4 + 2] = v[x]; 
     317                        o[x4 + 3] = yc[x2 + 1]; 
    316318                } 
    317319                 
  • trunk/ColorConversions.h

    r282 r344  
    2222 
    2323extern void FastY420(UInt8 *baseAddr, AVFrame *picture); 
    24 extern void Y420toY422(UInt8* baseAddr, int rowBytes, int width, int height, AVFrame * picture); 
    25 extern void RGB32toRGB32(UInt8 *baseAddr, int rowBytes, int width, int height, AVFrame *picture); 
    26 extern void BGR24toRGB24(UInt8 *baseAddr, int rowBytes, int width, int height, AVFrame *picture); 
    27 extern void Y422toY422(UInt8* o, int outRB, int width, int height, AVFrame * picture); 
     24extern void Y420toY422(UInt8* baseAddr, unsigned rowBytes, unsigned width, unsigned height, AVFrame * picture); 
     25extern void RGB32toRGB32(UInt8 *baseAddr, unsigned rowBytes, unsigned width, unsigned height, AVFrame *picture); 
     26extern void BGR24toRGB24(UInt8 *baseAddr, unsigned rowBytes, unsigned width, unsigned height, AVFrame *picture); 
     27extern void Y422toY422(UInt8* o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture); 
  • trunk/SSATagParsing.m.rl

    r343 r344  
    541541                                 
    542542                                flag = ([01] % {unichar fl = *(p-1); if (flag == '0' || flag == '1') flag = fl - '0';})? > {flag = 1;}; 
    543                                 num_ = "-"? digit* ('.' digit*)?; 
     543                                num_ = "-"? digit+ ('.' digit*)?; 
    544544                                num = num_ > {numbegin = p;} % {num = [[NSString stringWithCharacters:numbegin length:p-numbegin] doubleValue];}; 
    545545                                 
    546                                 intnum = "-"? (digit*) > {intbegin = p;} % {inum = [[NSString stringWithCharacters:intbegin length:p-intbegin] intValue];}; 
    547                                  
    548                                 color = ("H"|"&"){,2} (xdigit*) > {intbegin = p;} % color_end "&"; 
     546                                intnum = "-"? (digit+) > {intbegin = p;} % {inum = [[NSString stringWithCharacters:intbegin length:p-intbegin] intValue];}; 
     547                                 
     548                                color = ("H"|"&"){,2} (xdigit+) > {intbegin = p;} % color_end "&"; 
    549549 
    550550                                cmd_specific = (("pos(" [^)]+ > pos_begin ")" % pos_end)