Skip to content

Commit

Permalink
Added converter for CGImageRef to CVPixelBufferRef and CMSampleBuffer…
Browse files Browse the repository at this point in the history
…Ref conversion

Implemented Animator for Video Creation:
-Create Animations of the Mandelbrot Set
-Animate all parameters
-Export as Quicktime Movie
Renamed ViewController to MandelbrotRenderViewController
Created CLMandelbrotViewDelegate for Render Feedback for Animation
Moved Setup for CLMandelbrotView in new method
Optimized Start Parameters
Now, the device pixel ratio is determined once for performance reasons
The device pixel ratio is now determined by the screen of the window and not the main screen
textures are now initialized empty for performance reasons
Optimized preview mode: Main texture gets used as long as only shift and zoom change for better image quality, Pixels which are inside the mandelbrot set are now black instead of transparent
Added option to turn off automatic updates
Bug fixes
  • Loading branch information
Palle Klewitz authored and Palle Klewitz committed Aug 10, 2015
1 parent fd8cc9e commit 27da291
Show file tree
Hide file tree
Showing 20 changed files with 2,236 additions and 205 deletions.
45 changes: 38 additions & 7 deletions Mandelbrot2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
E64D57691B72E400006DF75A /* UnifiedTitleBarWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = E64D57681B72E400006DF75A /* UnifiedTitleBarWindowController.m */; };
E6AADCA31B74592B006CE608 /* CVImageUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = E6AADCA21B74592B006CE608 /* CVImageUtils.m */; };
E6CE1F0E1B742DEB004B5DCC /* AnimationSetupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E6CE1F0D1B742DEB004B5DCC /* AnimationSetupViewController.m */; };
E6F918151B72FA8200EE5029 /* MandelbrotRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = E6F918141B72FA8200EE5029 /* MandelbrotRenderer.m */; };
E6FAF680199EED9A009792F6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E6FAF67F199EED9A009792F6 /* main.m */; };
E6FAF683199EED9A009792F6 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E6FAF682199EED9A009792F6 /* ViewController.m */; };
E6FAF683199EED9A009792F6 /* MandelbrotRenderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E6FAF682199EED9A009792F6 /* MandelbrotRenderViewController.m */; };
E6FAF686199EED9A009792F6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E6FAF685199EED9A009792F6 /* AppDelegate.m */; };
E6FAF688199EED9A009792F6 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E6FAF687199EED9A009792F6 /* Images.xcassets */; };
E6FAF68B199EED9A009792F6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E6FAF689199EED9A009792F6 /* Main.storyboard */; };
Expand All @@ -33,11 +37,20 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
E64D57671B72E400006DF75A /* UnifiedTitleBarWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnifiedTitleBarWindowController.h; sourceTree = "<group>"; };
E64D57681B72E400006DF75A /* UnifiedTitleBarWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UnifiedTitleBarWindowController.m; sourceTree = "<group>"; };
E6AADCA11B74592B006CE608 /* CVImageUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CVImageUtils.h; sourceTree = "<group>"; };
E6AADCA21B74592B006CE608 /* CVImageUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CVImageUtils.m; sourceTree = "<group>"; };
E6AADCA41B74ECBB006CE608 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Main.strings; sourceTree = "<group>"; };
E6CE1F0C1B742DEB004B5DCC /* AnimationSetupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimationSetupViewController.h; sourceTree = "<group>"; };
E6CE1F0D1B742DEB004B5DCC /* AnimationSetupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AnimationSetupViewController.m; sourceTree = "<group>"; };
E6F918131B72FA8200EE5029 /* MandelbrotRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MandelbrotRenderer.h; sourceTree = "<group>"; };
E6F918141B72FA8200EE5029 /* MandelbrotRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MandelbrotRenderer.m; sourceTree = "<group>"; };
E6FAF67A199EED9A009792F6 /* Mandelbrot.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mandelbrot.app; sourceTree = BUILT_PRODUCTS_DIR; };
E6FAF67E199EED9A009792F6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E6FAF67F199EED9A009792F6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
E6FAF681199EED9A009792F6 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
E6FAF682199EED9A009792F6 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
E6FAF681199EED9A009792F6 /* MandelbrotRenderViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MandelbrotRenderViewController.h; sourceTree = "<group>"; };
E6FAF682199EED9A009792F6 /* MandelbrotRenderViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MandelbrotRenderViewController.m; sourceTree = "<group>"; };
E6FAF684199EED9A009792F6 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
E6FAF685199EED9A009792F6 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
E6FAF687199EED9A009792F6 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -100,14 +113,22 @@
E6FAF67C199EED9A009792F6 /* Mandelbrot2 */ = {
isa = PBXGroup;
children = (
E6AADCA11B74592B006CE608 /* CVImageUtils.h */,
E6AADCA21B74592B006CE608 /* CVImageUtils.m */,
E6FAF684199EED9A009792F6 /* AppDelegate.h */,
E6FAF685199EED9A009792F6 /* AppDelegate.m */,
E6FAF681199EED9A009792F6 /* ViewController.h */,
E6FAF682199EED9A009792F6 /* ViewController.m */,
E6FAF681199EED9A009792F6 /* MandelbrotRenderViewController.h */,
E6FAF682199EED9A009792F6 /* MandelbrotRenderViewController.m */,
E6FAF6A0199EEEAD009792F6 /* CLMandelbrotView.h */,
E6FAF6A1199EEEAD009792F6 /* CLMandelbrotView.m */,
E6F918131B72FA8200EE5029 /* MandelbrotRenderer.h */,
E6F918141B72FA8200EE5029 /* MandelbrotRenderer.m */,
E6FAF6AE199EF7B0009792F6 /* kernels.cl */,
E6FAF689199EED9A009792F6 /* Main.storyboard */,
E6CE1F0C1B742DEB004B5DCC /* AnimationSetupViewController.h */,
E6CE1F0D1B742DEB004B5DCC /* AnimationSetupViewController.m */,
E64D57671B72E400006DF75A /* UnifiedTitleBarWindowController.h */,
E64D57681B72E400006DF75A /* UnifiedTitleBarWindowController.m */,
E6FAF67D199EED9A009792F6 /* Supporting Files */,
);
path = Mandelbrot2;
Expand Down Expand Up @@ -197,7 +218,7 @@
E6FAF672199EED9A009792F6 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0600;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Palle Klewitz";
TargetAttributes = {
E6FAF679199EED9A009792F6 = {
Expand Down Expand Up @@ -268,11 +289,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E6FAF683199EED9A009792F6 /* ViewController.m in Sources */,
E6FAF683199EED9A009792F6 /* MandelbrotRenderViewController.m in Sources */,
E6CE1F0E1B742DEB004B5DCC /* AnimationSetupViewController.m in Sources */,
E6F918151B72FA8200EE5029 /* MandelbrotRenderer.m in Sources */,
E64D57691B72E400006DF75A /* UnifiedTitleBarWindowController.m in Sources */,
E6FAF6AF199EF7B0009792F6 /* kernels.cl in Sources */,
E6FAF680199EED9A009792F6 /* main.m in Sources */,
E6FAF686199EED9A009792F6 /* AppDelegate.m in Sources */,
E6FAF6A2199EEEAD009792F6 /* CLMandelbrotView.m in Sources */,
E6AADCA31B74592B006CE608 /* CVImageUtils.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -299,6 +324,7 @@
isa = PBXVariantGroup;
children = (
E6FAF68A199EED9A009792F6 /* Base */,
E6AADCA41B74ECBB006CE608 /* de */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand Down Expand Up @@ -326,6 +352,7 @@
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -390,6 +417,7 @@
INFOPLIST_FILE = Mandelbrot2/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "PK.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -402,6 +430,7 @@
INFOPLIST_FILE = Mandelbrot2/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_BUNDLE_IDENTIFIER = "PK.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -421,6 +450,7 @@
);
INFOPLIST_FILE = Mandelbrot2Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "PK.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Mandelbrot2.app/Contents/MacOS/Mandelbrot2";
};
Expand All @@ -437,6 +467,7 @@
);
INFOPLIST_FILE = Mandelbrot2Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "PK.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Mandelbrot2.app/Contents/MacOS/Mandelbrot2";
};
Expand Down
35 changes: 35 additions & 0 deletions Mandelbrot2/AnimationSetupViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// AnimationSetupViewController.h
// Mandelbrot2
//
// Created by Palle Klewitz on 07.08.15.
// Copyright © 2015 Palle Klewitz. All rights reserved.
//

@import Cocoa;
#import "MandelbrotRenderer.h"

@interface AnimationSetupViewController : NSViewController <MandelbrotRendererDelegate>

@property (weak) IBOutlet NSTextField *txtStartPositionX;
@property (weak) IBOutlet NSTextField *txtStartPositionY;
@property (weak) IBOutlet NSTextField *txtStartZoom;
@property (weak) IBOutlet NSTextField *txtStartIterations;
@property (weak) IBOutlet NSTextField *txtStartColorFactor;
@property (weak) IBOutlet NSTextField *txtStartColorShift;

@property (weak) IBOutlet NSTextField *txtEndPositionX;
@property (weak) IBOutlet NSTextField *txtEndPositionY;
@property (weak) IBOutlet NSTextField *txtEndZoom;
@property (weak) IBOutlet NSTextField *txtEndIterations;
@property (weak) IBOutlet NSTextField *txtEndColorFactor;
@property (weak) IBOutlet NSTextField *txtEndColorShift;

@property (weak) IBOutlet NSTextField *txtVideoFramesPerSecond;
@property (weak) IBOutlet NSTextField *txtVideoLength;

@property (weak) IBOutlet NSProgressIndicator *piRenderProgress;

- (IBAction)renderButtonClicked:(id)sender;

@end
124 changes: 124 additions & 0 deletions Mandelbrot2/AnimationSetupViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// AnimationSetupViewController.m
// Mandelbrot2
//
// Created by Palle Klewitz on 07.08.15.
// Copyright © 2015 Palle Klewitz. All rights reserved.
//

#import "AnimationSetupViewController.h"
#import "MandelbrotRenderer.h"
#import "AppDelegate.h"
#import "MandelbrotRenderViewController.h"

@interface AnimationSetupViewController ()

@property (nonatomic, strong) MandelbrotRenderer *renderer;

@end

@implementation AnimationSetupViewController

- (void)viewDidLoad
{
[super viewDidLoad];

_piRenderProgress.hidden = YES;

AppDelegate *del = (AppDelegate *)([NSApplication sharedApplication].delegate);
CLMandelbrotView *mandelbrotView = del.mainViewController.mandelbrotView;
del = nil;

_txtStartPositionX.doubleValue = mandelbrotView.shift.x;
_txtStartPositionY.doubleValue = mandelbrotView.shift.y;
_txtStartZoom.doubleValue = mandelbrotView.zoom;
_txtStartIterations.integerValue = mandelbrotView.iterations;
_txtStartColorFactor.doubleValue = mandelbrotView.color_factor;
_txtStartColorShift.doubleValue = mandelbrotView.color_shift;

_txtEndPositionX.doubleValue = mandelbrotView.shift.x;
_txtEndPositionY.doubleValue = mandelbrotView.shift.y;
_txtEndZoom.doubleValue = mandelbrotView.zoom;
_txtEndIterations.integerValue = mandelbrotView.iterations;
_txtEndColorFactor.doubleValue = mandelbrotView.color_factor;
_txtEndColorShift.doubleValue = mandelbrotView.color_shift;
}

- (IBAction)renderButtonClicked:(id)sender
{
/*NSSavePanel *savePanel = [[NSSavePanel alloc] init];
savePanel.title = @"Save Animation";
savePanel.showsHiddenFiles = NO;
savePanel.canCreateDirectories = YES;
savePanel.nameFieldStringValue = @"MandelbrotAnimation.mov";
savePanel.allowedFileTypes = @[@"mov"];
[savePanel beginSheetModalForWindow:self.view.window completionHandler:
^(NSInteger result)
{
if (result == NSModalResponseOK)
{
}
}];*/
_renderer = [[MandelbrotRenderer alloc] init];
_renderer.delegate = self;
_renderer.targetFile = [NSURL URLWithString:@"file:///Users/Palle/Desktop/mandelbrotanim.mov"];
[self startRendering];
}

- (void) startRendering
{
_piRenderProgress.hidden = NO;

AppDelegate *del = (AppDelegate *)([NSApplication sharedApplication].delegate);
_renderer.mandelbrotView = del.mainViewController.mandelbrotView;
del = nil;

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterDecimalStyle;

NSLog(@"startX: %f", [formatter numberFromString:_txtStartPositionX.stringValue].doubleValue);

_renderer.startX = [formatter numberFromString:_txtStartPositionX.stringValue].doubleValue;
_renderer.startY = [formatter numberFromString:_txtStartPositionY.stringValue].doubleValue;
_renderer.startZoom = [formatter numberFromString:_txtStartZoom.stringValue].doubleValue;
_renderer.startIterations = (unsigned int)[formatter numberFromString:_txtStartIterations.stringValue].integerValue;
_renderer.startColorFactor = [formatter numberFromString:_txtStartColorFactor.stringValue].doubleValue;;
_renderer.startColorShift = [formatter numberFromString:_txtStartColorShift.stringValue].doubleValue;

_renderer.endX = [formatter numberFromString:_txtEndPositionX.stringValue].doubleValue;
_renderer.endY = [formatter numberFromString:_txtEndPositionY.stringValue].doubleValue;
_renderer.endZoom = [formatter numberFromString:_txtEndZoom.stringValue].doubleValue;
_renderer.endIterations = (unsigned int)[formatter numberFromString:_txtEndIterations.stringValue].integerValue;
_renderer.endColorFactor = [formatter numberFromString:_txtEndColorFactor.stringValue].doubleValue;;
_renderer.endColorShift = [formatter numberFromString:_txtEndColorShift.stringValue].doubleValue;

_renderer.frames_per_second = _txtVideoFramesPerSecond.doubleValue;
_renderer.video_length = _txtVideoLength.doubleValue;

[_renderer startRendering];
}

- (void)didUpdateProgress
{
dispatch_async(dispatch_get_main_queue(),
^{
_piRenderProgress.doubleValue = (double)_renderer.frame / (double) (_renderer.frames_per_second * _renderer.video_length) * 100;
});

}

- (void)didFinishRendering
{
dispatch_async(dispatch_get_main_queue(),
^{
_piRenderProgress.hidden = YES;
});
}

- (void)mandelbrotRenderer:(MandelbrotRenderer *)renderer didFailWithError:(NSError *)error
{

}

@end
10 changes: 8 additions & 2 deletions Mandelbrot2/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
//

@import Cocoa;
@class ViewController;
@class MandelbrotRenderViewController;

#define CreateAnimationWindow @"CreateAnimationWindow"
#define MandelbrotRenderWindow @"MandelbrotRenderWindow"

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (nonatomic, weak) ViewController *mainViewController;
@property (nonatomic, weak) MandelbrotRenderViewController *mainViewController;

- (IBAction)resetZoom:(id)sender;
- (IBAction)zoomIn:(id)sender;
Expand All @@ -27,6 +30,9 @@
- (IBAction)decreaseColorShift:(id)sender;

- (IBAction)saveSnapshot:(id)sender;
- (IBAction)createAnimation:(id)sender;

- (IBAction)showRenderView:(id)sender;
- (IBAction)showControlPanel:(id)sender;
@end

24 changes: 23 additions & 1 deletion Mandelbrot2/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "MandelbrotRenderViewController.h"

@interface AppDelegate ()

Expand Down Expand Up @@ -74,4 +74,26 @@ - (IBAction)saveSnapshot:(id)sender
{
[_mainViewController saveSnapshot:sender];
}

- (IBAction)createAnimation:(id)sender
{
[_mainViewController createAnimation:sender];
}

- (IBAction)showRenderView:(id)sender
{
if (_mainViewController)
{
[_mainViewController.view.window makeKeyWindow];
}
else
{

}
}

- (IBAction)showControlPanel:(id)sender
{

}
@end
Loading

0 comments on commit 27da291

Please sign in to comment.