Changeset 1202
- Timestamp:
- 11/19/09 00:35:58 (4 months ago)
- Files:
-
- trunk/CommonUtils.c (modified) (2 diffs)
- trunk/CommonUtils.h (modified) (1 diff)
- trunk/MatroskaImportPrivate.cpp (modified) (3 diffs)
- trunk/Subtitles/SubImport.h (modified) (1 diff)
- trunk/Subtitles/SubImport.mm (modified) (5 diffs)
- trunk/TextSubCodec.c (modified) (1 diff)
- trunk/VobSubCodec.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/CommonUtils.c
r1194 r1202 314 314 315 315 static const CFStringRef defaultTransparentSubtitleList_10_6[] = { 316 CFSTR("CoreMediaAuthoringSessionHelper"), 316 317 CFSTR("CoreMediaAuthoringSourcePropertyHelper"), 317 318 CFSTR("Front Row"), … … 589 590 return sRGBColorSpace; 590 591 } 592 593 // Map 8-bit alpha (graphicsModePreBlackAlpha) to 1-bit alpha (transparent) 594 // Pretty much this is just mapping all opaque black to (1,1,1,255) 595 // Leaves ugly borders where AAing turned into opaque colors, but that's harder to deal with 596 void ConvertImageToQDTransparent(Ptr baseAddr, OSType pixelFormat, int rowBytes, int width, int height) 597 { 598 UInt32 alphaMask = EndianU32_BtoN((pixelFormat == k32ARGBPixelFormat) ? 0xFF000000 : 0xFF), 599 replacement = EndianU32_BtoN((pixelFormat == k32ARGBPixelFormat) ? 0xFF010101 : 0x010101FF); 600 Ptr p = baseAddr; 601 int y, x; 602 603 for (y = 0; y < height; y++) { 604 UInt32 *p32 = (UInt32*)p; 605 for (x = 0; x < width; x++) { 606 UInt32 px = *p32; 607 608 // if px is black, and opaque (alpha == 255) 609 if (!(px & ~alphaMask) && (px & alphaMask == alphaMask)) { 610 // then set it to not-quite-black so it'll show up 611 *p32 = replacement; 612 } 613 614 p32++; 615 } 616 617 p += rowBytes; 618 } 619 } trunk/CommonUtils.h
r1193 r1202 78 78 CGColorSpaceRef GetSRGBColorSpace(); 79 79 80 // postprocess RGBA+8-bit to not look terrible when displayed with 'transparent' blend mode 81 void ConvertImageToQDTransparent(Ptr baseAddr, OSType pixelFormat, int rowBytes, int width, int height); 82 80 83 #define PERIAN_PREF_DOMAIN CFSTR("org.perian.Perian") 81 84 trunk/MatroskaImportPrivate.cpp
r1193 r1202 597 597 } 598 598 599 set_track_colorspace_ext(imgDesc, width, height); 600 599 601 mkvTrack.theTrack = NewMovieTrack(theMovie, trackWidth, trackHeight, kNoVolume); 600 602 if (mkvTrack.theTrack == NULL) … … 607 609 // finally, say that we're transparent 608 610 mh = GetMediaHandler(mkvTrack.theMedia); 609 MediaSetGraphicsMode(mh, graphicsModePreBlackAlpha, NULL);611 SetSubtitleMediaHandlerTransparent(mh); 610 612 611 613 // subtitle tracks should be above the video track, which should be layer 0 … … 622 624 623 625 PtrAndHand(&emptyDataRefExtension[0], mkvTrack.subDataRefHandler, sizeof(emptyDataRefExtension)); 624 626 625 627 mkvTrack.theTrack = CreatePlaintextSubTrack(theMovie, imgDesc, GetMovieTimeScale(theMovie), mkvTrack.subDataRefHandler, HandleDataHandlerSubType, (*imgDesc)->cType, NULL, movieBox); 626 628 if (mkvTrack.theTrack == NULL) trunk/Subtitles/SubImport.h
r1201 r1202 41 41 short GetFilenameLanguage(CFStringRef filename); 42 42 ComponentResult LoadExternalSubtitlesFromFileDataRef(Handle dataRef, OSType dataRefType, Movie theMovie); 43 void SetSubtitleMediaHandlerTransparent(MediaHandler mh); 43 44 Track CreatePlaintextSubTrack(Movie theMovie, ImageDescriptionHandle imgDesc, TimeScale timescale, Handle dataRef, OSType dataRefType, FourCharCode subType, Handle imageExtension, Rect movieBox); 44 45 trunk/Subtitles/SubImport.mm
r1201 r1202 32 32 extern "C" { 33 33 int ExtractVobSubPacket(UInt8 *dest, const UInt8 *framedSrc, int srcSize, int *usedSrcBytes, int index); 34 void set_track_colorspace_ext(ImageDescriptionHandle imgDescHandle, Fixed displayW, Fixed displayH); 34 35 } 35 36 … … 79 80 kICMImageDescriptionPropertyID_ICCProfile, sizeof(CFDataRef), &cSpaceICC); 80 81 CFRelease(cSpaceICC); 82 } 83 84 void SetSubtitleMediaHandlerTransparent(MediaHandler mh) 85 { 86 if (IsTransparentSubtitleHackEnabled()) { 87 RGBColor blendColor = {0x0000, 0x0000, 0x0000}; 88 MediaSetGraphicsMode(mh, transparent, &blendColor); 89 } 90 else 91 MediaSetGraphicsMode(mh, graphicsModePreBlackAlpha, NULL); 81 92 } 82 93 … … 113 124 MediaHandler mh = GetMediaHandler(theMedia); 114 125 115 if (IsTransparentSubtitleHackEnabled()) { 116 RGBColor blendColor = {0x0000, 0x0000, 0x0000}; 117 MediaSetGraphicsMode(mh, transparent, &blendColor); 118 } 119 else MediaSetGraphicsMode(mh, graphicsModePreBlackAlpha, NULL); 126 SetSubtitleMediaHandlerTransparent(mh); 120 127 121 128 // subtitle tracks should be above the video track, which should be layer 0 … … 678 685 (*imgDesc)->width = FixedToInt(trackWidth); 679 686 (*imgDesc)->height = FixedToInt(trackHeight); 687 set_track_colorspace_ext(imgDesc, (*imgDesc)->width, (*imgDesc)->height); 680 688 Track theTrack = NewMovieTrack(theMovie, trackWidth, trackHeight, kNoVolume); 681 689 if(theTrack == NULL) … … 688 696 return NULL; 689 697 } 690 MediaHandler mh = GetMediaHandler(theMedia); 691 MediaSetGraphicsMode(mh, graphicsModePreBlackAlpha, NULL);698 MediaHandler mh = GetMediaHandler(theMedia); 699 SetSubtitleMediaHandlerTransparent(mh); 692 700 SetTrackLayer(theTrack, -1); 693 701 trunk/TextSubCodec.c
r1189 r1202 332 332 SubRenderPacket(glob->ssa,c,buf,myDrp->width,myDrp->height); 333 333 334 if (IsTransparentSubtitleHackEnabled()) { 335 // Map 8-bit alpha (graphicsModePreBlendAlpha) to 1-bit alpha (transparent) 336 // Pretty much this is just mapping all opaque black to (1,1,1,255) 337 // Leaves ugly borders where AAing turned into opaque colors, but that's harder to deal with 338 Ptr p = drp->baseAddr; 339 int y, x; 340 UInt32 alphaMask = EndianU32_BtoN((myDrp->pixelFormat == k32ARGBPixelFormat) ? 0xFF000000 : 0xFF), 341 replacement = EndianU32_BtoN((myDrp->pixelFormat == k32ARGBPixelFormat) ? 0xFF010101 : 0x010101FF); 342 343 for (y = 0; y < myDrp->height; y++) { 344 UInt32 *p32 = (UInt32*)p; 345 for (x = 0; x < myDrp->width; x++) { 346 UInt32 px = *p32; 347 348 // if px is black, and opaque (alpha == 255) 349 if (!(px & ~alphaMask) && (px & alphaMask == alphaMask)) { 350 // then set it to not-quite-black so it'll show up 351 *p32 = replacement; 352 } 353 354 p32++; 355 } 356 357 p += drp->rowBytes; 358 } 359 } 334 if (IsTransparentSubtitleHackEnabled()) 335 ConvertImageToQDTransparent(drp->baseAddr, myDrp->pixelFormat, drp->rowBytes, myDrp->width, myDrp->height); 360 336 361 337 CFRelease(buf); trunk/VobSubCodec.c
r1180 r1202 395 395 } 396 396 397 if (IsTransparentSubtitleHackEnabled()) 398 ConvertImageToQDTransparent(drp->baseAddr, k32ARGBPixelFormat, drp->rowBytes, myDrp->width, myDrp->height); 399 397 400 return err; 398 401 }
