Changeset 850
- Timestamp:
- 04/18/08 23:31:08 (6 months ago)
- Files:
-
- trunk/MatroskaImport.h (modified) (1 diff)
- trunk/MatroskaImportPrivate.cpp (modified) (2 diffs)
- trunk/Subtitles/SubATSUIRenderer.h (modified) (2 diffs)
- trunk/Subtitles/SubATSUIRenderer.m (modified) (3 diffs)
- trunk/Subtitles/SubImport.h (modified) (2 diffs)
- trunk/Subtitles/SubImport.mm (modified) (2 diffs)
- trunk/TextSubCodec.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/MatroskaImport.h
r658 r850 258 258 // value if not null, and seeks to the specified point in the file. 259 259 void SetContext(MatroskaSeekContext context); 260 261 // After the fonts are loaded, preplay the subtitle tracks to avoid an annoying pause 262 // from unavoidably lazy rendering APIs looking them up for the first time. 263 void PrerollSubtitleTracks(); 260 264 261 265 ComponentInstance self; trunk/MatroskaImportPrivate.cpp
r849 r850 111 111 112 112 } else if (EbmlId(*el_l1) == KaxAttachments::ClassInfos.GlobalId) { 113 ComponentResult res; 113 114 el_l1->Read(*aStream, KaxAttachments::ClassInfos.Context, upperLevel, dummyElt, true); 114 return ReadAttachments(*static_cast<KaxAttachments *>(el_l1)); 115 115 res = ReadAttachments(*static_cast<KaxAttachments *>(el_l1)); 116 PrerollSubtitleTracks(); 117 return res; 116 118 } else if (EbmlId(*el_l1) == KaxSeekHead::ClassInfos.GlobalId) { 117 119 el_l1->Read(*aStream, KaxSeekHead::ClassInfos.Context, upperLevel, dummyElt, true); … … 876 878 } 877 879 880 void MatroskaImport::PrerollSubtitleTracks() 881 { 882 if (!seenTracks) return; 883 884 for (int i = 0; i < tracks.size(); i++) { 885 if (tracks[i].type == track_subtitle) { 886 Handle subtitleDescriptionExt; 887 OSErr err = GetImageDescriptionExtension((ImageDescriptionHandle)tracks[i].desc, &subtitleDescriptionExt, kSubFormatSSA, 0); 888 889 if (err || !subtitleDescriptionExt) continue; 890 891 SubPrerollFromHeader(*subtitleDescriptionExt, GetHandleSize(subtitleDescriptionExt)); 892 } 893 } 894 } 878 895 879 896 MatroskaTrack::MatroskaTrack() trunk/Subtitles/SubATSUIRenderer.h
r669 r850 6 6 // Copyright 2007 __MyCompanyName__. All rights reserved. 7 7 // 8 9 #ifdef __cplusplus 10 extern "C" 11 { 12 #endif 8 13 9 14 #ifdef __OBJC__ … … 31 36 32 37 typedef void *SubtitleRendererPtr; 38 39 #endif 40 33 41 extern SubtitleRendererPtr SubInitForSSA(char *header, size_t headerLen, int width, int height); 34 42 extern SubtitleRendererPtr SubInitNonSSA(int width, int height); 35 43 extern CGColorSpaceRef SubGetColorSpace(SubtitleRendererPtr s); 36 44 extern void SubRenderPacket(SubtitleRendererPtr s, CGContextRef c, CFStringRef str, int cWidth, int cHeight); 45 extern void SubPrerollFromHeader(char *header, int headerLen); 37 46 extern void SubDisposeRenderer(SubtitleRendererPtr s); 38 47 48 #ifdef __cplusplus 49 } 39 50 #endif trunk/Subtitles/SubATSUIRenderer.m
r849 r850 286 286 } 287 287 288 static ATSFontRef gHelveticaATSRef = -1; 289 static ATSUFontID gHelveticaATSUID; 290 288 291 static ATSUFontID GetFontIDForSSAName(NSString *name, ATSFontRef *_fontRef) 289 292 { … … 301 304 302 305 if (font == kATSUInvalidFontID) { 303 fontRef = ATSFontFindFromName((CFStringRef)@"Helvetica",kATSOptionFlagsDefault); 304 font = FMGetFontFromATSFontRef(fontRef); 306 if (gHelveticaATSRef == -1) { 307 gHelveticaATSRef = ATSFontFindFromName((CFStringRef)@"Helvetica",kATSOptionFlagsDefault); 308 gHelveticaATSUID = FMGetFontFromATSFontRef(fontRef); 309 } 310 311 fontRef = gHelveticaATSRef; 312 font = gHelveticaATSUID; 305 313 } 306 314 } else fontRef = FMGetATSFontRefFromFont(font); … … 1097 1105 } 1098 1106 1107 void SubPrerollFromHeader(char *header, int headerLen) 1108 { 1109 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 1110 SubtitleRendererPtr s = headerLen ? SubInitForSSA(header, headerLen, 640, 480) 1111 : SubInitNonSSA(640, 480); 1112 1113 CGColorSpaceRef csp = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 1114 void *buf = malloc(640 * 480 * 4); 1115 CGContextRef c = CGBitmapContextCreate(buf,640,480,8,640 * 4,csp,kCGImageAlphaPremultipliedFirst); 1116 1117 if (!headerLen) { 1118 SubRenderPacket(s, c, (CFStringRef)@"to Be continued", 640, 480); 1119 } else { 1120 NSArray *styles = [s->context->styles allValues]; 1121 int i, nstyles = [styles count]; 1122 1123 for (i = 0; i < nstyles; i++) { 1124 SubStyle *sty = [styles objectAtIndex:i]; 1125 NSString *line = [NSString stringWithFormat:@"0,0,%@,,0,0,0,,to Be continued", sty->name]; 1126 SubRenderPacket(s, c, (CFStringRef)line, 640, 480); 1127 } 1128 } 1129 1130 CGContextRelease(c); 1131 free(buf); 1132 CGColorSpaceRelease(csp); 1133 [pool release]; 1134 } 1135 1099 1136 void SubDisposeRenderer(SubtitleRendererPtr s) 1100 1137 { trunk/Subtitles/SubImport.h
r806 r850 11 11 12 12 #include <QuickTime/QuickTime.h> 13 #ifndef __OBJC__ 14 #include "SubATSUIRenderer.h" 15 #endif 13 16 14 17 #ifndef __OBJC_GC__ … … 31 34 #import <Cocoa/Cocoa.h> 32 35 #import "SubContext.h" 36 #import "SubATSUIRenderer.h" 33 37 34 38 @interface SubLine : NSObject trunk/Subtitles/SubImport.mm
r806 r850 252 252 [ss setFinished:YES]; 253 253 254 SubPrerollFromHeader(header ? *header : NULL, header ? GetHandleSize(header) : 0); 255 254 256 Handle dataRefHndl = NewHandleClear(sizeof(Handle) + 1); 255 257 UInt32 emptyDataRefExt[2] = {EndianU32_NtoB(sizeof(UInt32)*2), EndianU32_NtoB(kDataRefExtensionInitializationData)}; … … 293 295 err = GetMoviesError(); 294 296 Codecprintf(stderr,"error %d adding line from %d to %d in external subtitles",err,sl->begin_time,sl->end_time); 295 goto inLoopError; 296 } 297 298 ConvertTimeScale(&startTime, movieTimeScale); 299 300 InsertMediaIntoTrack(theTrack, startTime.value.lo, sampleTime, sl->end_time - sl->begin_time, movieRate); 301 302 inLoopError: 297 } else { 298 ConvertTimeScale(&startTime, movieTimeScale); 299 InsertMediaIntoTrack(theTrack, startTime.value.lo, sampleTime, sl->end_time - sl->begin_time, movieRate); 300 } 301 303 302 err = noErr; 304 303 DisposeHandle(sampleHndl); trunk/TextSubCodec.c
r806 r850 248 248 249 249 if (!glob->ssa) glob->ssa = SubInitNonSSA((**p->imageDescription).width,(**p->imageDescription).height); 250 251 //SSA_PrerollFonts(glob->ssa); 252 250 253 251 glob->colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 254 252 }
