Changeset 313

Show
Ignore:
Timestamp:
01/29/07 00:02:58 (2 years ago)
Author:
astrange
Message:

Renderer for SSA subtitles. (!!!)
Supports most files, w/ text styles.
Add ssa/ass to external imports.
Refs #17.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Perian.xcodeproj/project.pbxproj

    r312 r313  
    105105                3D211A200B6B1A540051299D /* SSADocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D211A1F0B6B1A540051299D /* SSADocument.m */; }; 
    106106                3D211A230B6B1A660051299D /* Categories.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D211A220B6B1A660051299D /* Categories.m */; }; 
    107                 3D211A300B6B1AD80051299D /* SSATagParsing.m.rl in Resources */ = {isa = PBXBuildFile; fileRef = 3D211A2F0B6B1AD80051299D /* SSATagParsing.m.rl */; }; 
     107                3D211A300B6B1AD80051299D /* SSATagParsing.m.rl in Sources */ = {isa = PBXBuildFile; fileRef = 3D211A2F0B6B1AD80051299D /* SSATagParsing.m.rl */; }; 
    108108                3D4A7A990B5533BC004C5D6A /* ColorConversions.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D4A7A980B5533BC004C5D6A /* ColorConversions.c */; }; 
     109                3DAD32DA0B6DB26100DA0A72 /* StdIOCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 61CB114D0ACDF3C2007994BD /* StdIOCallback.cpp */; }; 
    109110                3DB2BB290B6C92F000416863 /* SSARenderCodec.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DB2BB280B6C92F000416863 /* SSARenderCodec.m */; }; 
    110111                6116E5510B43C27B0020F1CE /* ACBaseCodec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6116E5370B43C27B0020F1CE /* ACBaseCodec.cpp */; }; 
     
    246247 
    247248/* Begin PBXBuildRule section */ 
    248                 3D211A2D0B6B1A880051299D /* PBXBuildRule */ = { 
     249                3D74F53C0B6DB50C0018BAC0 /* PBXBuildRule */ = { 
    249250                        isa = PBXBuildRule; 
    250251                        compilerSpec = com.apple.compilers.proxy.script; 
     
    254255                        outputFiles = ( 
    255256                                "$(DERIVED_FILES_DIR)/$(INPUT_FILE_BASE)", 
    256                         ); 
    257                         script = "RAGEL=${PROJECT_DIR}/ragel\nRLCODEGEN=${PROJECT_DIR}/rlcodegen\n\n${RAGEL} -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.ragel ${INPUT_FILE_PATH} || exit\n${RLCODEGEN} -T1 -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE} ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.ragel || exit"; 
     257                                "$(DERIVED_FILES_DIR)/$(INPUT_FILE_BASE).dot", 
     258                        ); 
     259                        script = "RAGEL=${PROJECT_DIR}/ragel\nRLCODEGEN=${PROJECT_DIR}/rlcodegen\n${RAGEL} -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.ragel ${INPUT_FILE_PATH} || exit\n${RLCODEGEN} -T1 -o ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE} ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.ragel || exit\n${RLCODEGEN} -V ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.ragel > ${DERIVED_FILES_DIR}/${INPUT_FILE_BASE}.dot"; 
    258260                }; 
    259261/* End PBXBuildRule section */ 
     
    441443                3D211A220B6B1A660051299D /* Categories.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = Categories.m; path = ../../SSAView/Categories.m; sourceTree = SOURCE_ROOT; }; 
    442444                3D211A2E0B6B1AD80051299D /* SSATagParsing.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SSATagParsing.h; sourceTree = "<group>"; }; 
    443                 3D211A2F0B6B1AD80051299D /* SSATagParsing.m.rl */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 30; path = SSATagParsing.m.rl; sourceTree = "<group>"; }; 
     445                3D211A2F0B6B1AD80051299D /* SSATagParsing.m.rl */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; fileEncoding = 4; path = SSATagParsing.m.rl; sourceTree = "<group>"; }; 
    444446                3D4A7A970B5533BC004C5D6A /* ColorConversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorConversions.h; sourceTree = "<group>"; }; 
    445447                3D4A7A980B5533BC004C5D6A /* ColorConversions.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ColorConversions.c; sourceTree = "<group>"; }; 
     
    12081210                        ); 
    12091211                        buildRules = ( 
    1210                                 3D211A2D0B6B1A880051299D /* PBXBuildRule */, 
     1212                                3D74F53C0B6DB50C0018BAC0 /* PBXBuildRule */, 
    12111213                        ); 
    12121214                        dependencies = ( 
     
    13711373                                11A70AD90A3D0149002058D4 /* FFusion.icns in Resources */, 
    13721374                                11C85FE70A64315500DF3D73 /* Perian-Info.plist in Resources */, 
    1373                                 3D211A300B6B1AD80051299D /* SSATagParsing.m.rl in Resources */, 
    13741375                        ); 
    13751376                        runOnlyForDeploymentPostprocessing = 0; 
     
    14911492                        buildActionMask = 2147483647; 
    14921493                        files = ( 
     1494                                3D211A300B6B1AD80051299D /* SSATagParsing.m.rl in Sources */, 
    14931495                                11C85ED80A641E6400DF3D73 /* ff_dataref.c in Sources */, 
    14941496                                11C85EDA0A641E6400DF3D73 /* ff_private.c in Sources */, 
     
    15181520                                3D211A230B6B1A660051299D /* Categories.m in Sources */, 
    15191521                                3DB2BB290B6C92F000416863 /* SSARenderCodec.m in Sources */, 
     1522                                3DAD32DA0B6DB26100DA0A72 /* StdIOCallback.cpp in Sources */, 
    15201523                        ); 
    15211524                        runOnlyForDeploymentPostprocessing = 0; 
  • trunk/SSADocument.h

    r310 r313  
    5555-(NSString *)header; 
    5656-(SSAEvent *)movPacket:(int)i; 
     57-(void) loadHeader:(NSString*)path; 
    5758-(unsigned)packetCount; 
    5859@end 
  • trunk/SSADocument.m

    r312 r313  
    5858        resX = rX; resY = rY; 
    5959         
    60         timescale = (field = [hDict objectForKey:@"Timer"])? [field doubleValue] / 100. : 1
     60        timescale = (field = [hDict objectForKey:@"Timer"])? [field doubleValue] / 100. : 1.
    6161        collisiontype = Normal; 
    6262        if ((field = [hDict objectForKey:@"Collisions"]) && [field isEqualToString:@"Reverse"]) collisiontype = Reverse; 
     
    337337        while (1) { 
    338338                ns = (NSString*)[lenum nextObject]; 
    339                 if ([ns length] == 0) continue; 
     339                if (!ns || [ns length] == 0) continue; 
    340340                else { 
    341341                        cai = [ns characterAtIndex:0]; 
     
    386386} 
    387387 
    388 -(void) loadHeader:(NSString*)path 
     388-(void) loadHeader:(NSString*)ssa 
    389389{ 
    390390        NSError *err; 
    391391        NSStringEncoding se = NSUTF8StringEncoding; 
    392         NSString *ssa = [[NSString stringWithContentsOfFile:path encoding:se error:&err] stringByStandardizingNewlines]; 
    393392        if (!ssa) return; 
    394393        NSArray *lines = [ssa componentsSeparatedByString:@"\n"]; 
     
    410409        while (1) { 
    411410                ns = (NSString*)[lenum nextObject]; 
    412                 if ([ns length] == 0) continue; 
     411                if (!ns || [ns length] == 0) continue; 
    413412                else { 
    414413                        cai = [ns characterAtIndex:0]; 
     
    441440         
    442441        while (1) { 
    443                 if ([ns length] != 0) { 
     442                if (!ns) break; 
     443                else if ([ns length] != 0) { 
    444444                        cai = [ns characterAtIndex:0]; 
    445445                         
     
    530530        for (i = 0; i < packetCount; i++) { 
    531531                SSAEvent *p = [ssa movPacket:i]; 
     532                TimeRecord movieStartTime = {SInt64ToWide(p->begin_time), 100, 0}; 
     533                TimeValue sampleTime; 
    532534                const char *str = [p->line UTF8String]; 
    533535                sampleLen = strlen(str); 
     
    535537                PtrToHand(str,&sampleHndl,sampleLen); 
    536538                 
    537                 err=AddMediaSample(theMedia,sampleHndl,0,sampleLen, p->end_time - p->begin_time,(SampleDescriptionHandle)textDesc, 1, 0, NULL); 
    538                 if (err != noErr) {NSLog(@"a %d",GetMoviesError()); goto bail;} 
    539                  
     539                err=AddMediaSample(theMedia,sampleHndl,0,sampleLen, p->end_time - p->begin_time,(SampleDescriptionHandle)textDesc, 1, 0, &sampleTime); 
     540                if (err != noErr) goto bail; 
     541                 
     542                ConvertTimeScale(&movieStartTime, GetMovieTimeScale(theMovie)); 
     543 
     544                err = InsertMediaIntoTrack(theTrack, movieStartTime.value.lo, sampleTime, p->end_time - p->begin_time, fixed1); 
     545                if (err != noErr) {goto bail;} 
     546 
    540547                DisposeHandle(sampleHndl); 
    541548        } 
     
    543550        EndMediaEdits(theMedia); 
    544551         
    545         InsertMediaIntoTrack(theTrack,0,0,GetMediaDuration(theMedia),fixed1);  
    546         if (err != noErr) NSLog(@"i %d",GetMoviesError()); 
    547  
    548552        if (*firstSubTrack == NULL) 
    549553                *firstSubTrack = theTrack; 
  • trunk/SSATagParsing.m.rl

    r312 r313  
    9393                NSString *sn = [ar objectAtIndex:2]; 
    9494                int j; 
     95 
    9596                for (j=0; j < ssa->stylecount; j++) { 
    9697                        if ([sn isEqualToString:ssa->styles[j].name])  { 
  • trunk/SubImport.c

    r311 r313  
    201201 
    202202                                        err = InsertMediaIntoTrack(theTrack, movieStartTime.value.lo, sampleTime, duration, fixed1); 
     203 
    203204                                        if (err) goto bail; 
    204205                                } 
     
    300301                                LoadSubRipSubtitles(&parentDir, cfFoundFilename, theMovie, &firstSubTrack); 
    301302                         
     303                        // SubStationAlpha 
    302304                        actRange = CFStringFind(cfFoundFilename, CFSTR(".ass"), kCFCompareCaseInsensitive | kCFCompareBackwards); 
    303305                        if (actRange.location == extRange.location) 
    304306                                LoadSubStationAlphaSubtitles(&parentDir, cfFoundFilename, theMovie, &firstSubTrack); 
    305307 
     308                        actRange = CFStringFind(cfFoundFilename, CFSTR(".ssa"), kCFCompareCaseInsensitive | kCFCompareBackwards); 
     309                        if (actRange.location == extRange.location) 
     310                                LoadSubStationAlphaSubtitles(&parentDir, cfFoundFilename, theMovie, &firstSubTrack); 
     311                         
    306312                        // VobSub 
    307313                        actRange = CFStringFind(cfFoundFilename, CFSTR(".idx"), kCFCompareCaseInsensitive | kCFCompareBackwards); 
  • trunk/TextSubCodec.c

    r287 r313  
    1010 
    1111#include "TextSubCodec.h" 
     12#include "SSARenderCodec.h" 
    1213 
    1314#define SubFontName "Helvetica" 
     
    3233        ATSUStyle                               textStyle, italicStyle, boldStyle, biStyle; 
    3334        ATSUTextLayout                  textLayout; 
    34         //Ptr                     textBuffer; 
     35 
     36        SSARenderGlobalsPtr             ssa; 
     37        Boolean                                 useSSA; 
    3538} TextSubGlobalsRecord, *TextSubGlobals; 
    3639 
     
    8184#endif 
    8285         
    83 /* -- This Image Decompressor User the Base Image Decompressor Component -- 
     86/* -- This Image Decompressor Uses the Base Image Decompressor Component -- 
    8487        The base image decompressor is an Apple-supplied component 
    8588        that makes it easier for developers to create new decompressors. 
     
    105108        if (err = MemError()) goto bail; 
    106109        glob->drawBandUPP = NULL; 
     110        glob->ssa = NULL; 
     111        glob->useSSA = false; 
    107112         
    108113        // Open and target an instance of the base decompressor as we delegate 
     
    149154                        ATSUDisposeTextLayout(glob->textLayout); 
    150155                } 
     156                if (glob->useSSA) SSA_Dispose(glob->ssa); 
    151157                DisposePtr((Ptr)glob); 
    152158        } 
     
    278284        myDrp->depth = (**p->imageDescription).depth; 
    279285    myDrp->dataSize = p->bufferSize; 
     286         
     287        glob->useSSA = (**p->imageDescription).cType == kSubFormatSSA; 
     288        if (glob->useSSA) { 
     289                long count; 
     290                CountImageDescriptionExtensionType(p->imageDescription,kSubFormatSSA,&count); 
     291                if (count == 1) { 
     292                        Handle ssaheader; 
     293                        GetImageDescriptionExtension(p->imageDescription,&ssaheader,kSubFormatSSA,1); 
     294                         
     295                        glob->ssa = SSA_Init(*ssaheader, GetHandleSize(ssaheader)); 
     296                } 
     297        } 
    280298         
    281299        return noErr; 
     
    306324                                                                                   8, drp->rowBytes,  glob->colorSpace, 
    307325                                                                                   kCGImageAlphaPremultipliedFirst); 
     326         
     327        if (glob->useSSA) { 
     328                SSA_RenderLine(glob->ssa,c,drp->codecData,myDrp->dataSize,myDrp->width,myDrp->height); 
     329                return noErr; 
     330        } 
    308331         
    309332        if (!glob->textStyle) { //TODO: set language region based on track language... does that even matter? 
  • trunk/TextSubCodec.h

    r218 r313  
    1010 
    1111#define kTextSubCodecFormatName "Text Subtitle" 
     12#define kSSASubCodecFormatName  "SSA Text Subtitle" 
    1213 
    1314#define kManufacturer           'Peri' 
     
    1516#define kTextSubCodecVersion    (0x00020001) 
    1617 
     18#define kSSASubCodecResource   250 
    1719#define kTextSubCodecResource   252 
  • trunk/TextSubCodec.r

    r218 r313  
    6969resource 'cdci' (kTextSubCodecResource) { 
    7070        kTextSubCodecFormatName,        // Type 
     71        1,                                              // Version 
     72        1,                                              // Revision level 
     73        kManufacturer,                  // Manufacturer 
     74        kTextSubDecoFlags,              // Decompression Flags 
     75        0,                                              // Compression Flags 
     76        kTextSubFormatFlags,    // Format Flags 
     77        128,                                    // Compression Accuracy 
     78        128,                                    // Decomression Accuracy 
     79        200,                                    // Compression Speed 
     80        200,                                    // Decompression Speed 
     81        128,                                    // Compression Level 
     82        0,                                              // Reserved 
     83        1,                                              // Minimum Height 
     84        1,                                              // Minimum Width 
     85        0,                                              // Decompression Pipeline Latency 
     86        0,                                              // Compression Pipeline Latency 
     87        0                                               // Private Data 
     88}; 
     89 
     90// Component Description 
     91resource 'cdci' (kSSASubCodecResource) { 
     92        kSSASubCodecFormatName, // Type 
    7193        1,                                              // Version 
    7294        1,                                              // Revision level 
     
    138160}; 
    139161 
     162resource 'thng' (kSSASubCodecResource) { 
     163        decompressorComponentType,                              // Type                  
     164        kSubFormatSSA,                                                  // SubType 
     165        kManufacturer,                                                  // Manufacturer 
     166                                                                                        // - use componentHasMultiplePlatforms 
     167        0,                                                                              // not used Component flags 
     168        0,                                                                              // not used Component flags Mask 
     169        0,                                                                              // not used Code Type 
     170        0,                                                                              // not used Code ID 
     171        'STR ',                                                                 // Name Type 
     172        kSSASubCodecResource,                                   // Name ID 
     173        'STR ',                                                                 // Info Type 
     174        kSSASubCodecResource + 1,                               // Info ID 
     175        0,                                                                              // Icon Type 
     176        0,                                                                              // Icon ID 
     177        kTextSubCodecVersion,                                   // Version 
     178        componentHasMultiplePlatforms +                 // Registration Flags  
     179        componentDoAutoVersion, 
     180        0,                                                                              // Resource ID of Icon Family 
     181{ 
     182#if TARGET_OS_MAC 
     183#if TARGET_REZ_CARBON_MACHO 
     184#if !(TARGET_REZ_MAC_PPC || TARGET_REZ_MAC_X86) 
     185#error "Platform architecture not defined, TARGET_REZ_MAC_PPC and/or TARGET_REZ_MAC_X86 must be defined!" 
     186#endif 
     187#if TARGET_REZ_MAC_PPC 
     188        kTextSubDecoFlags,  
     189        'dlle',                                                         // Code Resource type - Entry point found by symbol name 'dlle' resource 
     190        kTextSubCodecResource,                          // ID of 'dlle' resource 
     191        platformPowerPCNativeEntryPoint,        // PPC 
     192#endif 
     193#if TARGET_REZ_MAC_X86 
     194        kTextSubDecoFlags,  
     195        'dlle', 
     196        kTextSubCodecResource, 
     197        platformIA32NativeEntryPoint,           // INTEL 
     198#endif 
     199#else 
     200#error "At least one non-obsolete TARGET_REZ_XXX_XXX platform must be defined." 
     201#endif 
     202#endif 
     203#if TARGET_OS_WIN32 
     204        kTextSubDecoFlags,  
     205        'dlle', 
     206        kTextSubCodecResource, 
     207        platformWin32, 
     208#endif 
     209}; 
     210}; 
     211 
    140212// Component Name 
    141213resource 'STR ' (kTextSubCodecResource) { 
     
    143215}; 
    144216 
     217resource 'STR ' (kSSASubCodecResource) { 
     218        "SSA Text Subtitle" 
     219}; 
     220 
    145221// Component Information 
     222 
    146223resource 'STR ' (kTextSubCodecResource + 1) { 
    147224        "Renders subtitles stored as text." 
     225}; 
     226 
     227resource 'STR ' (kSSASubCodecResource + 1) { 
     228        "Renders subtitles stored in SubStation Alpha format." 
    148229}; 
    149230