diff options
Diffstat (limited to 'source/blender/quicktime/apple/qtkit_export.m')
-rw-r--r-- | source/blender/quicktime/apple/qtkit_export.m | 199 |
1 files changed, 121 insertions, 78 deletions
diff --git a/source/blender/quicktime/apple/qtkit_export.m b/source/blender/quicktime/apple/qtkit_export.m index 9f2a97dee23..1466d3a3a09 100644 --- a/source/blender/quicktime/apple/qtkit_export.m +++ b/source/blender/quicktime/apple/qtkit_export.m @@ -39,6 +39,7 @@ #include "BKE_global.h" #include "BKE_scene.h" +#include "BKE_report.h" #include "BLI_blenlib.h" @@ -49,10 +50,6 @@ #include "MEM_guardedalloc.h" -#include "quicktime_import.h" -#include "quicktime_export.h" - - #ifdef __APPLE__ /* evil */ #ifndef __AIFF__ @@ -60,6 +57,14 @@ #endif #import <Cocoa/Cocoa.h> #import <QTKit/QTKit.h> + +#if (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4) || !__LP64__ +#error 64 bit build & OSX 10.5 minimum are needed for QTKit +#endif + +#include "quicktime_import.h" +#include "quicktime_export.h" + #endif /* __APPLE__ */ typedef struct QuicktimeExport { @@ -73,36 +78,65 @@ typedef struct QuicktimeExport { static struct QuicktimeExport *qtexport; +#pragma mark rna helper functions -static NSString *stringWithCodecType(int codecType) { - switch (codecType) { - case QT_CODECTYPE_RAW: - return @"raw "; - case QT_CODECTYPE_MJPEGA: - return @"mjpa"; - case QT_CODECTYPE_MJPEGB: - return @"mjpb"; - case QT_CODECTYPE_DVCPAL: - return @"dvcp"; - case QT_CODECTYPE_DVCNTSC: - return @"dvc "; - case QT_CODECTYPE_MPEG4: - return @"mp4v"; - case QT_CODECTYPE_H263: - return @"h263"; - case QT_CODECTYPE_H264: - return @"avc1"; - case QT_CODECTYPE_DVCPROHD720p: - return @"dvhp"; - case QT_CODECTYPE_DVCPROHD1080i50: - return @"dvh5"; - case QT_CODECTYPE_DVCPROHD1080i60: - return @"dvh6"; - - case QT_CODECTYPE_JPEG: - default: - return @"jpeg"; + +static QuicktimeCodecTypeDesc qtCodecList[] = { + {kRawCodecType, 1, "Uncompressed"}, + {kJPEGCodecType, 2, "JPEG"}, + {kMotionJPEGACodecType, 3, "M-JPEG A"}, + {kMotionJPEGBCodecType, 4, "M-JPEG B"}, + {kDVCPALCodecType, 5, "DV PAL"}, + {kDVCNTSCCodecType, 6, "DV/DVCPRO NTSC"}, + {kDVCPROHD720pCodecType, 7, "DVCPRO HD 720p"}, + {kDVCPROHD1080i50CodecType, 8, "DVCPRO HD 1080i50"}, + {kDVCPROHD1080i60CodecType, 9, "DVCPRO HD 1080i60"}, + {kMPEG4VisualCodecType, 10, "MPEG4"}, + {kH263CodecType, 11, "H.263"}, + {kH264CodecType, 12, "H.264"}, + {0,0,NULL}}; + +static int qtCodecCount = 12; + +int quicktime_get_num_codecs() { + return qtCodecCount; +} + +QuicktimeCodecTypeDesc* quicktime_get_codecType_desc(int indexValue) { + if ((indexValue>=0) && (indexValue < qtCodecCount)) + return &qtCodecList[indexValue]; + else + return NULL; +} + +int quicktime_rnatmpvalue_from_codectype(int codecType) { + int i; + for (i=0;i<qtCodecCount;i++) { + if (qtCodecList[i].codecType == codecType) + return qtCodecList[i].rnatmpvalue; } + + return 0; +} + +int quicktime_codecType_from_rnatmpvalue(int rnatmpvalue) { + int i; + for (i=0;i<qtCodecCount;i++) { + if (qtCodecList[i].rnatmpvalue == rnatmpvalue) + return qtCodecList[i].codecType; + } + + return 0; +} + + +static NSString *stringWithCodecType(int codecType) { + char str[5]; + + *((int*)str) = EndianU32_NtoB(codecType); + str[4] = 0; + + return [NSString stringWithCString:str encoding:NSASCIIStringEncoding]; } void makeqtstring (RenderData *rd, char *string) { @@ -119,65 +153,70 @@ void makeqtstring (RenderData *rd, char *string) { } } +#pragma mark export functions -void start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty) +int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, ReportList *reports) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSError *error; char name[2048]; + int success= 1; - if(qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport"); - - if (G.afbreek != 1) { - /* Check first if the QuickTime 7.2.1 initToWritableFile: method is available */ - if ([[[[QTMovie alloc] init] autorelease] respondsToSelector:@selector(initToWritableFile:error:)] != YES) { - G.afbreek = 1; - fprintf(stderr, "\nUnable to create quicktime movie, need Quicktime rev 7.2.1 or later"); - } - else { - makeqtstring(rd, name); - qtexport->filename = [NSString stringWithCString:name - encoding:[NSString defaultCStringEncoding]]; - qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->filename error:&error]; - - if(qtexport->movie == nil) { - G.afbreek = 1; - NSLog(@"Unable to create quicktime movie : %@",[error localizedDescription]); - } else { - [qtexport->movie retain]; - [qtexport->filename retain]; - [qtexport->movie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute]; - [qtexport->movie setAttribute:@"Made with Blender" forKey:QTMovieCopyrightAttribute]; - - qtexport->frameDuration = QTMakeTime(rd->frs_sec_base*1000, rd->frs_sec*1000); - - /* specifying the codec attributes : try to retrieve them from render data first*/ - if (rd->qtcodecsettings.codecType) { - qtexport->frameAttributes = [NSDictionary dictionaryWithObjectsAndKeys: - stringWithCodecType(rd->qtcodecsettings.codecType), - QTAddImageCodecType, - [NSNumber numberWithLong:((rd->qtcodecsettings.codecSpatialQuality)*codecLosslessQuality)/100], - QTAddImageCodecQuality, - nil]; - } - else { - qtexport->frameAttributes = [NSDictionary dictionaryWithObjectsAndKeys:@"jpeg", - QTAddImageCodecType, - [NSNumber numberWithLong:codecHighQuality], - QTAddImageCodecQuality, - nil]; - } - [qtexport->frameAttributes retain]; + + [QTMovie enterQTKitOnThread]; + + /* Check first if the QuickTime 7.2.1 initToWritableFile: method is available */ + if ([[[[QTMovie alloc] init] autorelease] respondsToSelector:@selector(initToWritableFile:error:)] != YES) { + BKE_report(reports, RPT_ERROR, "\nUnable to create quicktime movie, need Quicktime rev 7.2.1 or later"); + success= 0; + } + else { + makeqtstring(rd, name); + qtexport->filename = [NSString stringWithCString:name + encoding:[NSString defaultCStringEncoding]]; + qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->filename error:&error]; + + if(qtexport->movie == nil) { + BKE_report(reports, RPT_ERROR, "Unable to create quicktime movie."); + success= 0; + NSLog(@"Unable to create quicktime movie : %@",[error localizedDescription]); + [QTMovie exitQTKitOnThread]; + } else { + [qtexport->movie retain]; + [qtexport->filename retain]; + [qtexport->movie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute]; + [qtexport->movie setAttribute:@"Made with Blender" forKey:QTMovieCopyrightAttribute]; + + qtexport->frameDuration = QTMakeTime(rd->frs_sec_base*1000, rd->frs_sec*1000); + + /* specifying the codec attributes : try to retrieve them from render data first*/ + if (rd->qtcodecsettings.codecType) { + qtexport->frameAttributes = [NSDictionary dictionaryWithObjectsAndKeys: + stringWithCodecType(rd->qtcodecsettings.codecType), + QTAddImageCodecType, + [NSNumber numberWithLong:((rd->qtcodecsettings.codecSpatialQuality)*codecLosslessQuality)/100], + QTAddImageCodecQuality, + nil]; + } + else { + qtexport->frameAttributes = [NSDictionary dictionaryWithObjectsAndKeys:@"jpeg", + QTAddImageCodecType, + [NSNumber numberWithLong:codecHighQuality], + QTAddImageCodecQuality, + nil]; } + [qtexport->frameAttributes retain]; } } [pool drain]; + + return success; } -void append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int recty) +int append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int recty, ReportList *reports) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSBitmapImageRep *blBitmapFormatImage; @@ -197,7 +236,7 @@ void append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int rec bitsPerPixel:32]; if (!blBitmapFormatImage) { [pool drain]; - return; + return 0; } from_Ptr = (unsigned char*)pixels; @@ -219,6 +258,8 @@ void append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int rec [blBitmapFormatImage release]; [frameImage release]; [pool drain]; + + return 1; } @@ -235,6 +276,8 @@ void end_qt(void) [qtexport->frameAttributes release]; [qtexport->movie release]; } + + [QTMovie exitQTKitOnThread]; if(qtexport) { MEM_freeN(qtexport); @@ -253,7 +296,7 @@ void quicktime_verify_image_type(RenderData *rd) (rd->qtcodecsettings.codecSpatialQuality <0) || (rd->qtcodecsettings.codecSpatialQuality > 100)) { - rd->qtcodecsettings.codecType = QT_CODECTYPE_JPEG; + rd->qtcodecsettings.codecType = kJPEGCodecType; rd->qtcodecsettings.codecSpatialQuality = (codecHighQuality*100)/codecLosslessQuality; } } |