Skip to content

Commit

Permalink
Cocoa GUI: Add PNG/JPEG exporting.
Browse files Browse the repository at this point in the history
Added JPEG and PNG export using MacOS functions, now two awkwardly placed buttons at the bottom, will eventually get to the stage of video file export. 
App is definitely a bit more useable now, JPEG files are very small.
Should have done this earlier, as it pretty much took just these two lines:
NSData * imageFile = [rawBitmap representationUsingType: NSJPEGFileType properties: nil];
[imageFile writeToFile: [NSString stringWithUTF8String:exportPath] atomically: NO];
  • Loading branch information
ilia3101 authored Jul 19, 2017
1 parent 67ae12e commit 9597553
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 28 deletions.
1 change: 1 addition & 0 deletions platform/cocoa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions platform/cocoa/main.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* Main file for mac
* Objective C gui.
* Code gone wrong */
* Objective C gui. */

#import "Cocoa/Cocoa.h"

Expand Down Expand Up @@ -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:" );

Expand Down
5 changes: 3 additions & 2 deletions platform/cocoa/main_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
78 changes: 56 additions & 22 deletions platform/cocoa/main_methods.m
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 9597553

Please sign in to comment.