diff --git a/platform/cocoa/Makefile b/platform/cocoa/Makefile index 18792026..0d947342 100644 --- a/platform/cocoa/Makefile +++ b/platform/cocoa/Makefile @@ -19,6 +19,7 @@ cflags := $(mainflags) -c -mmacosx-version-min=10.6 main : $(CC) compile_time_code.c -o compile_time_code; \ ./compile_time_code; \ + rm main.o; \ make build; \ rm compile_time_code; \ rm app_window_title.h diff --git a/platform/cocoa/main.m b/platform/cocoa/main.m index 1d75799e..1b2e100b 100644 --- a/platform/cocoa/main.m +++ b/platform/cocoa/main.m @@ -1,6 +1,5 @@ /* Main file for mac - * Objective C gui. - * Code gone wrong */ + * Objective C gui. */ #import "Cocoa/Cocoa.h" @@ -167,8 +166,9 @@ int NSApplicationMain(int argc, const char * argv[]) /* Open MLV file button */ CREATE_BUTTON_LEFT_TOP( openMLVButton, 0, openMlvDialog, 0, @"Open MLV File" ); - /* Export a silly BMP sequence (we r that desparate) */ - CREATE_BUTTON_LEFT_BOTTOM( exportSequenceButton, 0, exportBmpSequence, 1, @"Export BMP Sequence" ); + /* Export an image sequence (temporary) - these buttons look awkward and awful :[ */ + CREATE_BUTTON_LEFT_BOTTOM( exportJpegSequenceButton, 1, exportJpegSequence, 1, @"Export JPEG Sequence" ); + CREATE_BUTTON_LEFT_BOTTOM( exportPngSequenceButton, 0, exportPngSequence, 1, @"Export PNG Sequence" ); /* Black level user input/adjustment */ // CREATE_INPUT_WITH_LABEL_LEFT( blackLevelEntry, 1, blackLevelSet, 0, @"Black Level:" ); diff --git a/platform/cocoa/main_methods.h b/platform/cocoa/main_methods.h index b11c74da..09c51dff 100644 --- a/platform/cocoa/main_methods.h +++ b/platform/cocoa/main_methods.h @@ -11,8 +11,9 @@ void setAppNewMlvClip(char * mlvPathString, char * mlvFileName); /* Opens a dialog to select MLV file + sets MLV file to that */ -(void)openMlvDialog; -/* Opens a dialog to select export location, then exports BMPs */ --(void)exportBmpSequence; +/* Opens a dialog to select export location, then exports images */ +-(void)exportJpegSequence; +-(void)exportPngSequence; @end diff --git a/platform/cocoa/main_methods.m b/platform/cocoa/main_methods.m index 9b1702f1..fa1ea271 100644 --- a/platform/cocoa/main_methods.m +++ b/platform/cocoa/main_methods.m @@ -163,8 +163,9 @@ -(void)openMlvDialog } ]; } -/* This feature is very temporary(bad) - will be replaced by prores and stuff */ --(void)exportBmpSequence +/* Yes, I duplicated the same method, the whole image-export thing is temporary + * (and I couldn't be bothered to firgure out a format dropdown menu in save panel) */ +-(void)exportJpegSequence { if (isMlvActive(videoMLV)) { @@ -183,43 +184,76 @@ -(void)exportBmpSequence { char * pathString = (char *)[pathURL.path UTF8String]; char * exportPath = malloc(2048); - int imageSize = getMlvWidth(videoMLV) * getMlvHeight(videoMLV) * 3; - - /* Export */ - imagestruct mlvImage = { getMlvWidth(videoMLV), - getMlvHeight(videoMLV), - malloc( imageSize ), 1 }; /* So we always get amaze frames for exporting */ setMlvAlwaysUseAmaze(videoMLV); + /* We will use the same NSBitmapImageRep as for exporting as for preview window */ for (int f = 0; f < getMlvFrames(videoMLV); ++f) { /* Generate file name for frame */ - snprintf(exportPath, 2047, "%s/%.8s_%.5i.BMP", pathString, MLVClipName, f); + snprintf(exportPath, 2047, "%s/%.8s_%.5i.jpg", pathString, MLVClipName, f); /* Get processed frame */ - getMlvProcessedFrame8(videoMLV, f, mlvImage.imagedata); + getMlvProcessedFrame8(videoMLV, f, rawImage); + + /* Export */ + NSData * imageFile = [rawBitmap representationUsingType: NSJPEGFileType properties: nil]; + [imageFile writeToFile: [NSString stringWithUTF8String:exportPath] atomically: NO]; + + NSLog(@"Exported frame %i to: %s", f, exportPath); + } - /* Swap B/R (remember this is temporary code) */ - uint8_t temp; - uint8_t * end = mlvImage.imagedata + imageSize; - for (uint8_t * pix = mlvImage.imagedata; pix < end; pix += 3) - { - temp = pix[0]; - pix[0] = pix[2]; - pix[2] = temp; - } + setMlvDontAlwaysUseAmaze(videoMLV); + + free(exportPath); + } + } + [panel release]; + } ]; + } +} +-(void)exportPngSequence +{ + if (isMlvActive(videoMLV)) + { + /* Create open panel */ + NSOpenPanel * panel = [[NSOpenPanel openPanel] retain]; + + [panel setCanChooseFiles: NO]; + [panel setCanChooseDirectories: YES]; + [panel setAllowsMultipleSelection: NO]; + + [panel beginWithCompletionHandler: ^ (NSInteger result) + { + if (result == NSFileHandlingPanelOKButton) + { + for (NSURL * pathURL in [panel URLs]) + { + char * pathString = (char *)[pathURL.path UTF8String]; + char * exportPath = malloc(2048); + + /* So we always get amaze frames for exporting */ + setMlvAlwaysUseAmaze(videoMLV); + + /* We will use the same NSBitmapImageRep as for exporting as for preview window */ + for (int f = 0; f < getMlvFrames(videoMLV); ++f) + { + /* Generate file name for frame */ + snprintf(exportPath, 2047, "%s/%.8s_%.5i.png", pathString, MLVClipName, f); + + /* Get processed frame */ + getMlvProcessedFrame8(videoMLV, f, rawImage); - /* Write BMP */ - write_bmp3_24(&mlvImage, exportPath); + /* Export */ + NSData * imageFile = [rawBitmap representationUsingType: NSPNGFileType properties: nil]; + [imageFile writeToFile: [NSString stringWithUTF8String:exportPath] atomically: NO]; NSLog(@"Exported frame %i to: %s", f, exportPath); } setMlvDontAlwaysUseAmaze(videoMLV); - free(mlvImage.imagedata); free(exportPath); } }