Skip to content

Commit

Permalink
Restored previous WIP code
Browse files Browse the repository at this point in the history
- All working, however the "Input rotation" parameter has some caching issues.
  • Loading branch information
latenitefilms committed Jul 11, 2023
1 parent 62902f5 commit 6d3f3c5
Show file tree
Hide file tree
Showing 25 changed files with 1,535 additions and 1,108 deletions.
2 changes: 1 addition & 1 deletion Scripts/build_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export SCRIPT_HOME ; SCRIPT_HOME="$(dirname "$(greadlink -f "$0")")"
export REPO_HOME ; REPO_HOME="$(greadlink -f "${SCRIPT_HOME}/../")"

cd "${REPO_HOME}/Source/Frameworks/gyroflow"
~/.cargo/bin/cargo clean
#~/.cargo/bin/cargo clean
~/.cargo/bin/cargo update
~/.cargo/bin/cargo build --release --target x86_64-apple-darwin
~/.cargo/bin/cargo build --release --target aarch64-apple-darwin
Expand Down
17 changes: 17 additions & 0 deletions Scripts/build_rust_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -eu
set -o pipefail

export SCRIPT_HOME ; SCRIPT_HOME="$(dirname "$(greadlink -f "$0")")"
export REPO_HOME ; REPO_HOME="$(greadlink -f "${SCRIPT_HOME}/../")"

cd "${REPO_HOME}/Source/Frameworks/gyroflow"
~/.cargo/bin/cargo clean
~/.cargo/bin/cargo update
~/.cargo/bin/cargo build --release --target x86_64-apple-darwin
~/.cargo/bin/cargo build --release --target aarch64-apple-darwin
lipo -create -output "${REPO_HOME}/Source/Frameworks/gyroflow/target/libgyroflow_toolbox.dylib" "${REPO_HOME}/Source/Frameworks/gyroflow/target/x86_64-apple-darwin/release/libgyroflow_toolbox.dylib" "${REPO_HOME}/Source/Frameworks/gyroflow/target/aarch64-apple-darwin/release/libgyroflow_toolbox.dylib"
/bin/mv "${REPO_HOME}/Source/Frameworks/gyroflow/target/libgyroflow_toolbox.dylib" "${REPO_HOME}/Source/Frameworks/gyroflow/binary/libgyroflow_toolbox.dylib"
cd "${REPO_HOME}/Source/Frameworks/gyroflow/binary"
/usr/bin/install_name_tool -id "@rpath/libgyroflow_toolbox.dylib" libgyroflow_toolbox.dylib
4 changes: 2 additions & 2 deletions Source/Frameworks/gyroflow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "gyroflow-toolbox"
version = "1.1.0"
authors = ["Chris Hocking <[email protected]>", "Adrian <[email protected]>"]
edition = "2021"
description = "Gyroflow Toolbox"
description = "Connects the Gyroflow Toolbox FxPlug4 API to the gyroflow_core Engine"

[lib]
crate-type =["cdylib"]
Expand All @@ -20,4 +20,4 @@ lazy_static = "1.4.0"
lru = "0.10"
nalgebra = { version = "0.32", features = ["serde-serialize"] }
once_cell = "1.16.0"
metal = { version = "0.25.0", git = "https://github.com/gfx-rs/metal-rs.git", rev = "a6a0446" }
metal = { version = "0.25.0", git = "https://github.com/gfx-rs/metal-rs.git", rev = "a6a0446" }
6 changes: 6 additions & 0 deletions Source/Frameworks/gyroflow/inc/gyroflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const char* processFrame(
double fov,
double smoothness,
double lens_correction,
double horizon_lock,
double horizon_roll,
double position_offset_x,
double position_offset_y,
double input_rotation,
double video_rotation,
void *in_mtl_texture,
void *out_mtl_texture,
void *command_queue
Expand Down
70 changes: 54 additions & 16 deletions Source/Frameworks/gyroflow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub extern "C" fn processFrame(
fov: f64,
smoothness: f64,
lens_correction: f64,
horizon_lock: f64,
horizon_roll: f64,
position_offset_x: f64,
position_offset_y: f64,
input_rotation: f64,
video_rotation: f64,
in_mtl_tex: *mut std::ffi::c_void,
out_mtl_tex: *mut std::ffi::c_void,
command_queue: *mut std::ffi::c_void,
Expand All @@ -61,13 +67,13 @@ pub extern "C" fn processFrame(
.init().ok();
Mutex::new(logger)
});

//---------------------------------------------------------
// Get Pixel Format:
//---------------------------------------------------------
let pixel_format_pointer = unsafe { CStr::from_ptr(pixel_format) };
let pixel_format_string = pixel_format_pointer.to_string_lossy();

// -------------------------------------------------------------------------------
// You can't use &str across FFI boundary, it's a Rust type.
// You have to use C-compatible char pointer, so path: *const c_char and then
Expand All @@ -76,13 +82,13 @@ pub extern "C" fn processFrame(
// -------------------------------------------------------------------------------
let path_pointer = unsafe { CStr::from_ptr(path) };
let path_string = path_pointer.to_string_lossy();

//---------------------------------------------------------
// Convert the output width and height to `usize`:
//---------------------------------------------------------
let output_width: usize = width as usize;
let output_height: usize = height as usize;

//---------------------------------------------------------
// Convert the number of bytes to `usize`:
//---------------------------------------------------------
Expand All @@ -103,7 +109,7 @@ pub extern "C" fn processFrame(
// Setup the Gyroflow Manager:
//---------------------------------------------------------
let manager = StabilizationManager::default();

//---------------------------------------------------------
// Import the Gyroflow Data:
//---------------------------------------------------------
Expand Down Expand Up @@ -164,27 +170,59 @@ pub extern "C" fn processFrame(
params.fov = fov;
params_changed = true;
}

//---------------------------------------------------------
// Set the Lens Correction:
//---------------------------------------------------------
if params.lens_correction_amount != lens_correction {
params.lens_correction_amount = lens_correction;
params_changed = true;
}

//---------------------------------------------------------
// Set the Position Offset X:
//---------------------------------------------------------
if params.adaptive_zoom_center_offset.0 != position_offset_x / 100.0 {
params.adaptive_zoom_center_offset.0 = position_offset_x / 100.0;
params_changed = true;
}

//---------------------------------------------------------
// Set the Position Offset Y:
//---------------------------------------------------------
if params.adaptive_zoom_center_offset.1 != position_offset_y / 100.0 {
params.adaptive_zoom_center_offset.1 = position_offset_y / 100.0;
params_changed = true;
}

//---------------------------------------------------------
// Set the Video Rotation:
//---------------------------------------------------------
if params.video_rotation != video_rotation {
params.video_rotation = video_rotation;
params_changed = true;
}
}

//---------------------------------------------------------
// Set the Smoothness:
//---------------------------------------------------------
{
//---------------------------------------------------------
// Set the Smoothness:
//---------------------------------------------------------
let mut smoothing = manager.smoothing.write();
if smoothing.current().get_parameter("smoothness") != smoothness {
smoothing.current_mut().set_parameter("smoothness", smoothness);
params_changed = true;
}

//---------------------------------------------------------
// Set the Horizon Lock:
//---------------------------------------------------------
if smoothing.horizon_lock.lock_enabled != (horizon_lock > 0.0) || smoothing.horizon_lock.horizonlockpercent != horizon_lock || smoothing.horizon_lock.horizonroll != horizon_roll {
smoothing.horizon_lock.set_horizon(horizon_lock, horizon_roll);
params_changed = true;
}
}

//---------------------------------------------------------
// If something has changed, Invalidate & Recompute, to
// make sure everything is up-to-date:
Expand All @@ -194,7 +232,7 @@ pub extern "C" fn processFrame(
manager.recompute_blocking();
manager.params.write().calculate_ramped_timestamps(&manager.keyframes.read(), false, false);
}

//---------------------------------------------------------
// Calculate buffer size and stride:
//---------------------------------------------------------
Expand All @@ -210,17 +248,17 @@ pub extern "C" fn processFrame(
rect: None,
data: BufferSource::Metal { texture: out_mtl_tex as *mut metal::MTLTexture, command_queue: command_queue as *mut metal::MTLCommandQueue },
rotation: None,
texture_copy: true,
texture_copy: false,
},
input: BufferDescription {
size: (output_width, output_height, input_stride),
rect: None,
data: BufferSource::Metal { texture: in_mtl_tex as *mut metal::MTLTexture, command_queue: command_queue as *mut metal::MTLCommandQueue },
rotation: None,
texture_copy: true,
rotation: Some(input_rotation as f32),
texture_copy: false,
}
};

let _stabilization_result = match pixel_format_string.as_ref() {
"BGRA8Unorm" => {
manager.process_pixels::<BGRA8>(timestamp, &mut buffers)
Expand All @@ -237,7 +275,7 @@ pub extern "C" fn processFrame(
return result.into_raw()
}
};

//---------------------------------------------------------
// Output the Stabilization result to the Console:
//---------------------------------------------------------
Expand Down
44 changes: 12 additions & 32 deletions Source/Gyroflow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
2239AB372943F8F600028B77 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2239AB352943F8F600028B77 /* InfoPlist.strings */; };
2239AB392943F8F600028B77 /* MetalDeviceCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 2239AB382943F8F600028B77 /* MetalDeviceCache.m */; };
2239AB3C2943F8F600028B77 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2239AB3A2943F8F600028B77 /* MainMenu.xib */; };
2239AB412943F8F600028B77 /* TileableRemoteGyroflow.metal in Sources */ = {isa = PBXBuildFile; fileRef = 2239AB402943F8F600028B77 /* TileableRemoteGyroflow.metal */; };
2239AB452943F8F600028B77 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2239AB442943F8F600028B77 /* main.m */; };
2239AB492943F8F600028B77 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2239AB472943F8F600028B77 /* InfoPlist.strings */; };
2239AB4C2943F8F600028B77 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2239AB4A2943F8F600028B77 /* Localizable.strings */; };
Expand All @@ -30,10 +29,9 @@
2239AB792945979800028B77 /* libgyroflow_toolbox.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = 2239AB772945979800028B77 /* libgyroflow_toolbox.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
224321B629615B0C00EA591A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 224321B529615B0C00EA591A /* Assets.xcassets */; };
224321B829615C4400EA591A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 224321B729615C4400EA591A /* Assets.xcassets */; };
228E9E1829517D8200B2571E /* ImportGyroflowProjectView.m in Sources */ = {isa = PBXBuildFile; fileRef = 228E9E1729517D8200B2571E /* ImportGyroflowProjectView.m */; };
228E9E1C2951DB6900B2571E /* ReloadGyroflowProjectView.m in Sources */ = {isa = PBXBuildFile; fileRef = 228E9E1B2951DB6900B2571E /* ReloadGyroflowProjectView.m */; };
22BED1C32A5D6805000562A3 /* CustomButtonView.m in Sources */ = {isa = PBXBuildFile; fileRef = 22BED1BF2A5D6805000562A3 /* CustomButtonView.m */; };
22BED1C42A5D6805000562A3 /* CustomDropZoneView.m in Sources */ = {isa = PBXBuildFile; fileRef = 22BED1C22A5D6805000562A3 /* CustomDropZoneView.m */; };
22DAC75F2953B1A7001F2E06 /* GyroflowDocument.icns in Resources */ = {isa = PBXBuildFile; fileRef = 22DAC75E2953B1A7001F2E06 /* GyroflowDocument.icns */; };
22DAC7622953CD4F001F2E06 /* LaunchGyroflowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 22DAC7602953CD4F001F2E06 /* LaunchGyroflowView.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -97,9 +95,7 @@
2239AB362943F8F600028B77 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
2239AB382943F8F600028B77 /* MetalDeviceCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MetalDeviceCache.m; sourceTree = "<group>"; };
2239AB3B2943F8F600028B77 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
2239AB402943F8F600028B77 /* TileableRemoteGyroflow.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = TileableRemoteGyroflow.metal; sourceTree = "<group>"; };
2239AB422943F8F600028B77 /* SandboxEntitlements.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SandboxEntitlements.entitlements; sourceTree = "<group>"; };
2239AB432943F8F600028B77 /* TileableRemoteGyroflowShaderTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TileableRemoteGyroflowShaderTypes.h; sourceTree = "<group>"; };
2239AB442943F8F600028B77 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
2239AB462943F8F600028B77 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2239AB482943F8F600028B77 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand All @@ -113,14 +109,12 @@
2239AB7C2945A69100028B77 /* lib.rs */ = {isa = PBXFileReference; lastKnownFileType = text; name = lib.rs; path = Frameworks/gyroflow/src/lib.rs; sourceTree = SOURCE_ROOT; };
224321B529615B0C00EA591A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
224321B729615C4400EA591A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
228E9E1629517D8200B2571E /* ImportGyroflowProjectView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImportGyroflowProjectView.h; sourceTree = "<group>"; };
228E9E1729517D8200B2571E /* ImportGyroflowProjectView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImportGyroflowProjectView.m; sourceTree = "<group>"; };
228E9E1929517DDA00B2571E /* GyroflowConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GyroflowConstants.h; sourceTree = "<group>"; };
228E9E1A2951DB6800B2571E /* ReloadGyroflowProjectView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReloadGyroflowProjectView.h; sourceTree = "<group>"; };
228E9E1B2951DB6900B2571E /* ReloadGyroflowProjectView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReloadGyroflowProjectView.m; sourceTree = "<group>"; };
22BED1BF2A5D6805000562A3 /* CustomButtonView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CustomButtonView.m; path = "../../../../../../Desktop/WIP Gyroflow on GitHub/GyroflowToolbox-df8de2438817be9f802629da3510916f78447d9c/Source/Gyroflow/Plugin/CustomButtonView.m"; sourceTree = "<group>"; };
22BED1C02A5D6805000562A3 /* CustomButtonView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomButtonView.h; path = "../../../../../../Desktop/WIP Gyroflow on GitHub/GyroflowToolbox-df8de2438817be9f802629da3510916f78447d9c/Source/Gyroflow/Plugin/CustomButtonView.h"; sourceTree = "<group>"; };
22BED1C12A5D6805000562A3 /* CustomDropZoneView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CustomDropZoneView.h; path = "../../../../../../Desktop/WIP Gyroflow on GitHub/GyroflowToolbox-df8de2438817be9f802629da3510916f78447d9c/Source/Gyroflow/Plugin/CustomDropZoneView.h"; sourceTree = "<group>"; };
22BED1C22A5D6805000562A3 /* CustomDropZoneView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CustomDropZoneView.m; path = "../../../../../../Desktop/WIP Gyroflow on GitHub/GyroflowToolbox-df8de2438817be9f802629da3510916f78447d9c/Source/Gyroflow/Plugin/CustomDropZoneView.m"; sourceTree = "<group>"; };
22DAC75E2953B1A7001F2E06 /* GyroflowDocument.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = GyroflowDocument.icns; sourceTree = "<group>"; };
22DAC7602953CD4F001F2E06 /* LaunchGyroflowView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LaunchGyroflowView.m; sourceTree = "<group>"; };
22DAC7612953CD4F001F2E06 /* LaunchGyroflowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LaunchGyroflowView.h; sourceTree = "<group>"; };
22E4989F29492E8100580F67 /* Cargo.toml */ = {isa = PBXFileReference; lastKnownFileType = text; name = Cargo.toml; path = Frameworks/gyroflow/Cargo.toml; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -208,7 +202,6 @@
2239AB7B2945A67600028B77 /* Rust */,
228E9E13294E815E00B2571E /* Code */,
228E9E12294E815200B2571E /* Metal Device Cache */,
228E9E14294E816D00B2571E /* Shader */,
228E9E15294E817700B2571E /* Extras */,
);
path = Plugin;
Expand Down Expand Up @@ -293,15 +286,6 @@
name = Code;
sourceTree = "<group>";
};
228E9E14294E816D00B2571E /* Shader */ = {
isa = PBXGroup;
children = (
2239AB402943F8F600028B77 /* TileableRemoteGyroflow.metal */,
2239AB432943F8F600028B77 /* TileableRemoteGyroflowShaderTypes.h */,
);
name = Shader;
sourceTree = "<group>";
};
228E9E15294E817700B2571E /* Extras */ = {
isa = PBXGroup;
children = (
Expand All @@ -317,12 +301,10 @@
22DAC7632953D1CF001F2E06 /* Custom Views */ = {
isa = PBXGroup;
children = (
22DAC7612953CD4F001F2E06 /* LaunchGyroflowView.h */,
22DAC7602953CD4F001F2E06 /* LaunchGyroflowView.m */,
228E9E1629517D8200B2571E /* ImportGyroflowProjectView.h */,
228E9E1729517D8200B2571E /* ImportGyroflowProjectView.m */,
228E9E1A2951DB6800B2571E /* ReloadGyroflowProjectView.h */,
228E9E1B2951DB6900B2571E /* ReloadGyroflowProjectView.m */,
22BED1C02A5D6805000562A3 /* CustomButtonView.h */,
22BED1BF2A5D6805000562A3 /* CustomButtonView.m */,
22BED1C12A5D6805000562A3 /* CustomDropZoneView.h */,
22BED1C22A5D6805000562A3 /* CustomDropZoneView.m */,
);
name = "Custom Views";
sourceTree = "<group>";
Expand Down Expand Up @@ -486,13 +468,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
228E9E1C2951DB6900B2571E /* ReloadGyroflowProjectView.m in Sources */,
2239AB392943F8F600028B77 /* MetalDeviceCache.m in Sources */,
228E9E1829517D8200B2571E /* ImportGyroflowProjectView.m in Sources */,
2239AB412943F8F600028B77 /* TileableRemoteGyroflow.metal in Sources */,
22BED1C32A5D6805000562A3 /* CustomButtonView.m in Sources */,
2239AB452943F8F600028B77 /* main.m in Sources */,
22BED1C42A5D6805000562A3 /* CustomDropZoneView.m in Sources */,
2239AB57294400B500028B77 /* GyroflowParameters.m in Sources */,
22DAC7622953CD4F001F2E06 /* LaunchGyroflowView.m in Sources */,
2239AB322943F8F600028B77 /* GyroflowPlugIn.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
22 changes: 22 additions & 0 deletions Source/Gyroflow/Plugin/CustomButtonView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CustomButtonView.h
// Gyroflow Toolbox Renderer
//
// Created by Chris Hocking on 29/01/2023.
//

#import <Cocoa/Cocoa.h>
#import <FxPlug/FxPlugSDK.h>

@interface CustomButtonView : NSView
{
id<PROAPIAccessing> _apiManager;
id _parentPlugin;
int _buttonID;
}

- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)apiManager
parentPlugin:(id)parentPlugin
buttonID:(UInt32)buttonID
buttonTitle:(NSString*)buttonTitle;
@end
Loading

0 comments on commit 6d3f3c5

Please sign in to comment.