Skip to content

Commit

Permalink
Added (temporary) BMP sequence export.
Browse files Browse the repository at this point in the history
Just for fun.
  • Loading branch information
ilia3101 authored Jul 16, 2017
1 parent 9600794 commit a752502
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 142 deletions.
5 changes: 4 additions & 1 deletion platform/cocoa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ appname = "MLV App"
# List of all objects to link
objects = main.o video_mlv.o debayer.o amaze_demosaic.o raw_processing.o \
main_methods.o useful_methods.o background_thread.o matrix.o \
camera_matrices.o frame_caching.o
camera_matrices.o frame_caching.o bitmap.o

# Compiler
CC = gcc # Normal
Expand Down Expand Up @@ -52,6 +52,9 @@ raw_processing.o : ../../src/processing/raw_processing.c
matrix.o : ../../src/matrix/matrix.c
$(CC) $(cflags) ../../src/matrix/matrix.c

bitmap.o : ../../src/imageio/bitmap/bitmap.c
$(CC) $(cflags) ../../src/imageio/bitmap/bitmap.c


# Type 'make clean' to remove mess
.PHONY : clean
Expand Down
7 changes: 6 additions & 1 deletion platform/cocoa/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
mlvObject_t * videoMLV;
processingObject_t * processingSettings;

char * MLVClipName;

/* Holds rawBitmap inside it or something */
NSImage * rawImageObject;
/* Holds a (THE) processed frame that is displayed */
Expand Down Expand Up @@ -68,6 +70,9 @@ int main(int argc, char * argv[])

int NSApplicationMain(int argc, const char * argv[])
{
/* Just for easyness */
MLVClipName = malloc(1);

/* Don't draw as there's no clip loaded */
dontDraw = 1;

Expand Down Expand Up @@ -164,7 +169,7 @@ 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" );
CREATE_BUTTON_LEFT_BOTTOM( exportSequenceButton, 0, exportBmpSequence, 1, @"Export BMP Sequence" );
/* Black level user input/adjustment */
// CREATE_INPUT_WITH_LABEL_LEFT( blackLevelEntry, 1, blackLevelSet, 0, @"Black Level:" );

Expand Down
86 changes: 65 additions & 21 deletions platform/cocoa/main_methods.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@

#include "background_thread.h"

/* My horrible old bitmap export module (temporary export solution) */
#include "../../src/imageio/imageio.h"

/* Methods for user interface interactions
* this is where some real code goes */

/* Make sure we hav these - or dusnt work :[ */
extern mlvObject_t * videoMLV;
extern processingObject_t * processingSettings;

extern char * MLVClipName;

extern NSImage * rawImageObject;
/* Holds a (the) processed frame that is displayed
* Will be changed with methods from this file */
Expand Down Expand Up @@ -53,6 +58,10 @@
/* This is now a function so that it can be accessedd from any part of the app, not just a button press */
void setAppNewMlvClip(char * mlvPathString, char * mlvFileName)
{
free(MLVClipName);
MLVClipName = malloc( strlen(mlvFileName) );
memcpy(MLVClipName, mlvFileName, strlen(mlvFileName));

/* Set app name to include MLV clip's name */
[window setTitle: [NSString stringWithFormat: @ APP_NAME " | %s", mlvFileName]];

Expand Down Expand Up @@ -154,34 +163,69 @@ -(void)openMlvDialog
} ];
}

/* (unfinished btw) */
/* This feature is very temporary(bad) - will be replaced by prores and stuff */
-(void)exportBmpSequence
{
/* Create open panel */
NSOpenPanel * panel = [[NSOpenPanel openPanel] retain];
if (isMlvActive(videoMLV))
{
/* Create open panel */
NSOpenPanel * panel = [[NSOpenPanel openPanel] retain];

[panel setCanChooseFiles: NO];
[panel setCanChooseDirectories: YES];
[panel setAllowsMultipleSelection: YES];
[panel setCanChooseFiles: NO];
[panel setCanChooseDirectories: YES];
[panel setAllowsMultipleSelection: NO];

/* Can only choose MLV files */
[panel setAllowedFileTypes: [NSArray arrayWithObject: @"mlv"]];

[panel beginWithCompletionHandler: ^ (NSInteger result)
{
if (result == NSFileHandlingPanelOKButton)
[panel beginWithCompletionHandler: ^ (NSInteger result)
{
/* What stackoverflow said */
for (NSURL * fileURL in [panel URLs])
if (result == NSFileHandlingPanelOKButton)
{
const char * mlvPathString = [fileURL.path UTF8String];
const char * mlvFileName = [[[fileURL.path lastPathComponent] stringByDeletingPathExtension] UTF8String];

NSLog(@"Export to: %s", mlvPathString);
for (NSURL * pathURL in [panel URLs])
{
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);

for (int f = 0; f < getMlvFrames(videoMLV); ++f)
{
/* Generate file name for frame */
snprintf(exportPath, 2047, "%s/%.8s_%.5i.BMP", pathString, MLVClipName, f);

/* Get processed frame */
getMlvProcessedFrame8(videoMLV, f, mlvImage.imagedata);

/* 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;
}

/* Write BMP */
write_bmp3_24(&mlvImage, exportPath);

NSLog(@"Exported frame %i to: %s", f, exportPath);
}

setMlvDontAlwaysUseAmaze(videoMLV);

free(mlvImage.imagedata);
free(exportPath);
}
}
}
[panel release];
} ];
[panel release];
} ];
}
}

@end
Expand Down
Loading

0 comments on commit a752502

Please sign in to comment.