Changeset 1202

Show
Ignore:
Timestamp:
11/19/09 00:35:58 (4 months ago)
Author:
astrange
Message:

Apply transparent subtitle hack to VobSub?.

Also add the track colorspace atoms.
Add a missing process name to the list for transparent subtitles.

Fixes #456.

Files:

Legend:

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

    r1194 r1202  
    314314 
    315315static const CFStringRef defaultTransparentSubtitleList_10_6[] = { 
     316        CFSTR("CoreMediaAuthoringSessionHelper"), 
    316317        CFSTR("CoreMediaAuthoringSourcePropertyHelper"), 
    317318        CFSTR("Front Row"), 
     
    589590        return sRGBColorSpace; 
    590591} 
     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 
     596void 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  
    7878CGColorSpaceRef GetSRGBColorSpace(); 
    7979 
     80// postprocess RGBA+8-bit to not look terrible when displayed with 'transparent' blend mode 
     81void ConvertImageToQDTransparent(Ptr baseAddr, OSType pixelFormat, int rowBytes, int width, int height); 
     82         
    8083#define PERIAN_PREF_DOMAIN CFSTR("org.perian.Perian") 
    8184 
  • trunk/MatroskaImportPrivate.cpp

    r1193 r1202  
    597597                } 
    598598                 
     599                set_track_colorspace_ext(imgDesc, width, height); 
     600                 
    599601                mkvTrack.theTrack = NewMovieTrack(theMovie, trackWidth, trackHeight, kNoVolume); 
    600602                if (mkvTrack.theTrack == NULL) 
     
    607609                // finally, say that we're transparent 
    608610                mh = GetMediaHandler(mkvTrack.theMedia); 
    609                 MediaSetGraphicsMode(mh, graphicsModePreBlackAlpha, NULL); 
     611                SetSubtitleMediaHandlerTransparent(mh); 
    610612                 
    611613                // subtitle tracks should be above the video track, which should be layer 0 
     
    622624                 
    623625                PtrAndHand(&emptyDataRefExtension[0], mkvTrack.subDataRefHandler, sizeof(emptyDataRefExtension)); 
    624                  
     626                                
    625627                mkvTrack.theTrack = CreatePlaintextSubTrack(theMovie, imgDesc, GetMovieTimeScale(theMovie), mkvTrack.subDataRefHandler, HandleDataHandlerSubType, (*imgDesc)->cType, NULL, movieBox); 
    626628                if (mkvTrack.theTrack == NULL) 
  • trunk/Subtitles/SubImport.h

    r1201 r1202  
    4141short GetFilenameLanguage(CFStringRef filename); 
    4242ComponentResult LoadExternalSubtitlesFromFileDataRef(Handle dataRef, OSType dataRefType, Movie theMovie); 
     43void SetSubtitleMediaHandlerTransparent(MediaHandler mh); 
    4344Track CreatePlaintextSubTrack(Movie theMovie, ImageDescriptionHandle imgDesc, TimeScale timescale, Handle dataRef, OSType dataRefType, FourCharCode subType, Handle imageExtension, Rect movieBox); 
    4445 
  • trunk/Subtitles/SubImport.mm

    r1201 r1202  
    3232extern "C" { 
    3333        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); 
    3435} 
    3536 
     
    7980                                                                   kICMImageDescriptionPropertyID_ICCProfile, sizeof(CFDataRef), &cSpaceICC); 
    8081        CFRelease(cSpaceICC); 
     82} 
     83 
     84void 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); 
    8192} 
    8293 
     
    113124                        MediaHandler mh = GetMediaHandler(theMedia); 
    114125                         
    115                         if (IsTransparentSubtitleHackEnabled()) { 
    116                                 RGBColor blendColor = {0x0000, 0x0000, 0x0000}; 
    117                                 MediaSetGraphicsMode(mh, transparent, &blendColor); 
    118                         } 
    119                         else MediaSetGraphicsMode(mh, graphicsModePreBlackAlpha, NULL); 
     126                        SetSubtitleMediaHandlerTransparent(mh); 
    120127                         
    121128                        // subtitle tracks should be above the video track, which should be layer 0 
     
    678685        (*imgDesc)->width = FixedToInt(trackWidth); 
    679686        (*imgDesc)->height = FixedToInt(trackHeight); 
     687        set_track_colorspace_ext(imgDesc, (*imgDesc)->width, (*imgDesc)->height); 
    680688        Track theTrack = NewMovieTrack(theMovie, trackWidth, trackHeight, kNoVolume); 
    681689        if(theTrack == NULL) 
     
    688696                return NULL; 
    689697        } 
    690         MediaHandler mh = GetMediaHandler(theMedia); 
    691         MediaSetGraphicsMode(mh, graphicsModePreBlackAlpha, NULL); 
     698        MediaHandler mh = GetMediaHandler(theMedia);    
     699        SetSubtitleMediaHandlerTransparent(mh); 
    692700        SetTrackLayer(theTrack, -1); 
    693701         
  • trunk/TextSubCodec.c

    r1189 r1202  
    332332        SubRenderPacket(glob->ssa,c,buf,myDrp->width,myDrp->height); 
    333333         
    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); 
    360336                 
    361337        CFRelease(buf); 
  • trunk/VobSubCodec.c

    r1180 r1202  
    395395        } 
    396396         
     397        if (IsTransparentSubtitleHackEnabled()) 
     398                ConvertImageToQDTransparent(drp->baseAddr, k32ARGBPixelFormat, drp->rowBytes, myDrp->width, myDrp->height); 
     399         
    397400        return err; 
    398401}