Changeset 1170

Show
Ignore:
Timestamp:
10/21/09 23:18:10 (5 months ago)
Author:
astrange
Message:

Set video colorspace info on import via 'nclc'.

Fixes the colors for every video ever. Closes #410

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MatroskaImportPrivate.cpp

    r1149 r1170  
    472472         
    473473        set_track_clean_aperture_ext(imgDesc, width, height, IntToFixed(uint32(pxl_width)), IntToFixed(uint32(pxl_height))); 
     474        set_track_colorspace_ext(imgDesc, width, height); 
    474475        mkvTrack.desc = (SampleDescriptionHandle) imgDesc; 
    475476         
  • trunk/ff_private.c

    r1169 r1170  
    587587} 
    588588 
     589// Create the 'pasp' atom for video tracks. No guesswork required. 
     590// References http://www.uwasa.fi/~f76998/video/conversion/ 
    589591void set_track_clean_aperture_ext(ImageDescriptionHandle imgDesc, Fixed displayW, Fixed displayH, Fixed pixelW, Fixed pixelH) 
    590592{ 
     
    607609         
    608610        DisposeHandle((Handle)pasp); 
     611} 
     612 
     613// Create the 'nclc' atom for video tracks. Guessed entirely from image size following ffdshow. 
     614// FIXME read H.264 VUI/MPEG2 etc and especially read chroma positioning information. 
     615// this needs the parsers working 
     616// References: http://developer.apple.com/quicktime/icefloe/dispatch019.html 
     617// http://www.mir.com/DMG/chroma.html 
     618void set_track_colorspace_ext(ImageDescriptionHandle imgDescHandle, Fixed displayW, Fixed displayH) 
     619{ 
     620        ImageDescription *imgDesc = *imgDescHandle; 
     621        Boolean isHd, isPAL; // otherwise NTSC 
     622        AVRational palRatio = (AVRational){5, 4}, displayRatio = (AVRational){displayW, displayH}; 
     623        int colorPrimaries, transferFunction, yuvMatrix; 
     624         
     625        isHd  = imgDesc->height >  576; 
     626        isPAL = imgDesc->height == 576 || av_cmp_q(palRatio, displayRatio) == 0; 
     627         
     628        NCLCColorInfoImageDescriptionExtension **nclc = (NCLCColorInfoImageDescriptionExtension**)NewHandle(sizeof(NCLCColorInfoImageDescriptionExtension)); 
     629                 
     630        if (isHd) { 
     631                colorPrimaries = kQTPrimaries_ITU_R709_2; 
     632                transferFunction = kQTTransferFunction_ITU_R709_2; 
     633                yuvMatrix = kQTMatrix_ITU_R_709_2; 
     634        } else if (isPAL) { 
     635                colorPrimaries = kQTPrimaries_EBU_3213; 
     636                transferFunction = kQTTransferFunction_ITU_R709_2; 
     637                yuvMatrix = kQTMatrix_ITU_R_601_4; 
     638        } else { 
     639                colorPrimaries = kQTPrimaries_SMPTE_C; 
     640                transferFunction = kQTTransferFunction_ITU_R709_2; 
     641                yuvMatrix = kQTMatrix_ITU_R_601_4; 
     642        } 
     643         
     644        **nclc = (NCLCColorInfoImageDescriptionExtension){EndianU32_NtoB(kVideoColorInfoImageDescriptionExtensionType), 
     645                                                                                                          EndianU16_NtoB(colorPrimaries), 
     646                                                                                                          EndianU16_NtoB(transferFunction), 
     647                                                                                                          EndianU16_NtoB(yuvMatrix)}; 
     648         
     649        AddImageDescriptionExtension(imgDescHandle, (Handle)nclc, kColorInfoImageDescriptionExtension); 
     650         
     651        DisposeHandle((Handle)nclc); 
    609652} 
    610653 
     
    647690                        initialize_video_map(&map[j], track, dataRef, dataRefType, storage->firstFrames + j); 
    648691                        set_track_clean_aperture_ext((ImageDescriptionHandle)map[j].sampleHdl, width, height, IntToFixed(st->codec->width), IntToFixed(st->codec->height)); 
     692                        set_track_colorspace_ext((ImageDescriptionHandle)map[j].sampleHdl, width, height); 
    649693                } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { 
    650694                        if (st->codec->sample_rate > 0) { 
  • trunk/ff_private.h

    r1052 r1170  
    113113Handle create_strf_ext(AVCodecContext *codec); 
    114114void set_track_clean_aperture_ext(ImageDescriptionHandle imgDesc, Fixed displayW, Fixed displayH, Fixed pixelW, Fixed pixelH); 
     115void set_track_colorspace_ext(ImageDescriptionHandle imgDescHandle, Fixed displayW, Fixed displayH); 
    115116 
    116117uint8_t *write_int32(uint8_t *target, int32_t data);