Changeset 343

Show
Ignore:
Timestamp:
02/15/07 15:11:35 (2 years ago)
Author:
astrange
Message:

Allow negative numbers in SSA tags, and be more forgiving about weird color syntax.
Remove some old debugging prints. Fix serializer when the second-to-last line ends after the last one.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SSADocument.m

    r342 r343  
    551551 
    552552                err=AddMediaSample(theMedia,sampleHndl,0,sampleLen, p->end_time - p->begin_time,(SampleDescriptionHandle)textDesc, 1, 0, &sampleTime); 
    553                 if (err != noErr) {NSLog(@"error adding %d-%d",p->begin_time, p->end_time); err = GetMoviesError(); goto loopend;} 
     553                if (err != noErr) {err = GetMoviesError(); NSLog(@"external SSA: error %d adding %d-%d line",err, p->begin_time, p->end_time); goto loopend;} 
    554554                 
    555555                ConvertTimeScale(&movieStartTime, movieTimeScale); 
    556556 
    557557                err = InsertMediaIntoTrack(theTrack, movieStartTime.value.lo, sampleTime, p->end_time - p->begin_time, fixed1); 
    558                 if (err != noErr) {err = GetMoviesError(); goto bail;} 
     558                if (err != noErr) {goto loopend;} 
    559559 
    560560loopend: 
     561                err = noErr; 
    561562                DisposeHandle(sampleHndl); 
    562563        } 
  • trunk/SSARenderCodec.m

    r342 r343  
    6868                OSStatus err; 
    6969                 
    70                 //[[NSColor redColor] set]; 
    71                 //NSBezierPath *path = [NSBezierPath bezierPath]; 
    7270                err=ATSUGetGlyphBounds(re->layout,baseX,FloatToFixed(iheight) - baseY,breaks[i],end-breaks[i],kATSUseDeviceOrigins,1,&trap,&trapCount); 
    7371                 
     
    7674                 
    7775                baseY += ascent + descent; 
    78                 /*       
    79                         [path moveToPoint:np(trap.lowerLeft)]; 
    80                  [path lineToPoint:np(trap.lowerRight)]; 
    81                  [path lineToPoint:np(trap.upperRight)]; 
    82                  [path lineToPoint:np(trap.upperLeft)]; 
    83                  [path closePath]; 
    84                  [path stroke]; 
    85                  */ 
     76 
    8677                rect.bottom = MAX(trap.lowerLeft.y, trap.lowerRight.y); 
    8778                rect.left = MIN(trap.lowerLeft.x, trap.upperLeft.x); 
     
    166157                                        break; 
    167158                                case S_MiddleAlign: // center 
    168                                         penY = (lastCenterPenY!=-1)?lastCenterPenY:(FloatToFixed((cHeight - FixedToFloat(total)) / 2.));  direction = -1; 
     159                                        penY = (lastCenterPenY!=-1)?lastCenterPenY:(FloatToFixed((ssa->resY - FixedToFloat(total)) / 2.));  direction = -1; 
    169160                                        lstart = 0; lend = breakCount+1; lstep = 1; 
    170161                                        storePenY = &lastCenterPenY; 
     
    185176                        GetTypographicRectangleForLayout(re,breaks,breakCount,&imageHeight,&imageWidth,penX,penY,ssa->resY); 
    186177                         
    187                         storePenY = &ignoredPenY; 
    188178                        penX = IntToFixed(re->posx); 
    189179                        penY = FloatToFixed((ssa->resY - re->posy)); 
    190                         /*                       
    191                                 NSBezierPath *posPath = [NSBezierPath bezierPath]; 
    192                         [[NSColor redColor] set]; 
    193                         [posPath setLineWidth:2.5]; 
    194                         [posPath moveToPoint:NSMakePoint(re->posx,0)]; 
    195                         [posPath lineToPoint:NSMakePoint(re->posx,ssa->resY)]; 
    196                         [posPath moveToPoint:NSMakePoint(0,re->posy)]; 
    197                         [posPath lineToPoint:NSMakePoint(ssa->resX,re->posy)]; 
    198                         [posPath closePath]; 
    199                         [posPath stroke]; 
    200                         */ 
     180//                      NSLog(@"pos (%d,%d) w %d (image: %f, %f)",re->posx,re->posy,re->usablewidth,FixedToFloat(imageWidth),FixedToFloat(imageHeight));                         
    201181                        switch(re->halign) { 
    202182                                case S_CenterAlign: 
     
    217197                        direction = 1; 
    218198                        lstart = breakCount; lend = -1; lstep = -1; 
     199                        storePenY = &ignoredPenY; 
    219200                } 
    220201                 
  • trunk/SSATagParsing.m.rl

    r342 r343  
    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" 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) 
  • trunk/SubImport.mm

    r342 r343  
    1212#import "Categories.h" 
    1313#include "CommonUtils.h" 
     14 
     15//#define SS_DEBUG 
    1416 
    1517// if the subtitle filename is something like title.en.srt or movie.fre.srt 
     
    405407        unsigned min_allowed = finished ? 1 : 2; 
    406408        if (num < min_allowed) return; 
    407         unsigned times[num*2+1], last_last_end = 0; 
     409        unsigned times[num*2], last_last_end = 0; 
    408410        SubLine *slines[num], *last=nil; 
    409411        bool last_has_invalid_end = false, all_overlap = true; 
     
    411413        [lines sortUsingFunction:cmp_line context:nil]; 
    412414        [lines getObjects:slines]; 
    413 //      NSLog(@"pre - %@",lines); 
    414          
     415#ifdef SS_DEBUG 
     416        NSLog(@"pre - %@",lines); 
     417#endif   
    415418        //leave early if all subtitle lines overlap 
    416419        if (!finished) { 
     
    436439                times[i*2+1] = slines[i]->end_time; 
    437440        } 
    438          
    439         times[num * 2] = times[num * 2 - 1]; 
    440          
     441                 
    441442        qsort(times, num*2, sizeof(unsigned), cmp_uint); 
    442443         
    443444        for (int i=0;i < num*2; i++) { 
    444445                if (i > 0 && times[i-1] == times[i]) continue; 
    445                 NSMutableString *accum = [NSMutableString string]
    446                 unsigned start = times[i], last_end = start, next_start=slines[num-1]->begin_time, end = start; 
    447                 bool startedOutput = false, finishedOutput = false; 
     446                NSMutableString *accum = nil
     447                unsigned start = times[i], last_end = start, next_start=times[num*2-1], end = start; 
     448                bool finishedOutput = false, is_last_line = false; 
    448449                 
    449450                // Add on packets until we find one that marks it ending (by starting later) 
    450451                // ...except if we know this is the last input packet from the stream, then we have to explicitly flush it 
    451                 if (finished && i >= (num*2)-2) finishedOutput = true;  
     452                if (finished && (times[i] == slines[num-1]->begin_time || times[i] == slines[num-1]->end_time)) finishedOutput = is_last_line = true; 
    452453                         
    453454                for (int j=0; j < num; j++) { 
    454455                        if (isinrange(times[i], slines[j]->begin_time, slines[j]->end_time)) { 
    455                                 unsigned ns = slines[j]->end_time; 
    456456                                 
    457457                                // find the next line that starts after this one 
    458                                 if (j != num-1) 
     458                                if (j != num-1) { 
     459                                        unsigned ns = slines[j]->end_time; 
    459460                                        for (int h = j; h < num; h++) if (slines[h]->begin_time != slines[j]->begin_time) {ns = slines[h]->begin_time; break;} 
     461                                        next_start = MIN(next_start, ns); 
     462                                } else next_start = slines[j]->end_time; 
    460463                                         
    461464                                last_end = MAX(slines[j]->end_time, last_end); 
    462                                 next_start = MIN(next_start, ns); 
    463                                 [accum appendString:slines[j]->line]; 
    464                                 startedOutput = true; 
     465                                if (accum) [accum appendString:slines[j]->line]; else accum = [slines[j]->line mutableCopy]; 
    465466                        } else if (j == num-1) finishedOutput = true; 
    466467                } 
    467468                                 
    468                 if (finishedOutput && startedOutput) { 
     469                if (accum && finishedOutput) { 
    469470                        [accum deleteCharactersInRange:NSMakeRange([accum length] - 1, 1)]; // delete last newline 
    470                 //      NSLog(@"%d - %d %d",start,last_end,next_start);                  
     471#ifdef SS_DEBUG 
     472                        NSLog(@"%d - %d %d",start,last_end,next_start);  
     473#endif 
    471474                        if (last_has_invalid_end) { 
    472475                                if (last_end < next_start) {  
     
    479482                        end = last_end; 
    480483                        last_has_invalid_end = false; 
    481                         if (last_end > next_start) last_has_invalid_end = true; 
     484                        if (last_end > next_start && !is_last_line) last_has_invalid_end = true; 
    482485                        SubLine *event = [[SubLine alloc] initWithLine:accum start:start end:end]; 
    483486                         
     
    492495                last->end_time = slines[num-1]->begin_time; 
    493496        } 
    494 //      NSLog(@"out - %@",outpackets); 
    495  
     497#ifdef SS_DEBUG 
     498        NSLog(@"out - %@",outpackets); 
     499#endif 
     500         
    496501        if (finished) [lines removeAllObjects]; 
    497502        else { 
     
    502507                } 
    503508        } 
    504 //      NSLog(@"post - %@",lines); 
     509#ifdef SS_DEBUG 
     510        NSLog(@"post - %@",lines); 
     511#endif 
    505512} 
    506513