Skip to content

Commit

Permalink
Merge pull request #30 from niklasr22/28-sdr-videos-do-not-get-extra-…
Browse files Browse the repository at this point in the history
…brightness-applied

28 New method for increasing brightness
  • Loading branch information
niklasr22 authored Aug 5, 2023
2 parents 1c52ab3 + af310df commit bdc93eb
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 106 deletions.
32 changes: 18 additions & 14 deletions BrightIntosh.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
9C8803762A72625E00476017 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1DF94512A5EF20E00FA285F /* AppDelegate.swift */; };
9C8803772A72625E00476017 /* OverlayWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D044EA2A60205E0022B970 /* OverlayWindow.swift */; };
9C8803782A72625E00476017 /* AccessibilityService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CBD4E942A67E9F600C7A625 /* AccessibilityService.swift */; };
9C8803792A72625E00476017 /* overlay_shader.metal in Sources */ = {isa = PBXBuildFile; fileRef = C1DF944F2A5EF20E00FA285F /* overlay_shader.metal */; };
9C88037A2A72625E00476017 /* Overlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1DF94502A5EF20E00FA285F /* Overlay.swift */; };
9C88037B2A72625E00476017 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1B521142A5EF85500E9B7AC /* main.swift */; };
9C88037E2A72625E00476017 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9C9C78022A62AEE800778CAE /* Assets.xcassets */; };
9C9C78032A62AEE800778CAE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9C9C78022A62AEE800778CAE /* Assets.xcassets */; };
9CBD4E952A67E9F600C7A625 /* AccessibilityService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CBD4E942A67E9F600C7A625 /* AccessibilityService.swift */; };
C1B5215A2A5EFFDB00E9B7AC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1DF94512A5EF20E00FA285F /* AppDelegate.swift */; };
C1B5215B2A5EFFDB00E9B7AC /* overlay_shader.metal in Sources */ = {isa = PBXBuildFile; fileRef = C1DF944F2A5EF20E00FA285F /* overlay_shader.metal */; };
C1B5215C2A5EFFDB00E9B7AC /* Overlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1DF94502A5EF20E00FA285F /* Overlay.swift */; };
C1B5215D2A5EFFDB00E9B7AC /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1B521142A5EF85500E9B7AC /* main.swift */; };
C1D044EB2A60205E0022B970 /* OverlayWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1D044EA2A60205E0022B970 /* OverlayWindow.swift */; };
Expand All @@ -34,7 +32,6 @@
C1B521172A5EFCB300E9B7AC /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C1B521482A5EFF5800E9B7AC /* BrightIntosh.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BrightIntosh.app; sourceTree = BUILT_PRODUCTS_DIR; };
C1D044EA2A60205E0022B970 /* OverlayWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverlayWindow.swift; sourceTree = "<group>"; };
C1DF944F2A5EF20E00FA285F /* overlay_shader.metal */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.metal; path = overlay_shader.metal; sourceTree = "<group>"; };
C1DF94502A5EF20E00FA285F /* Overlay.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Overlay.swift; sourceTree = "<group>"; };
C1DF94512A5EF20E00FA285F /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C1DF94572A5EF66200FA285F /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -81,7 +78,6 @@
children = (
C1B521172A5EFCB300E9B7AC /* Info.plist */,
C1DF94512A5EF20E00FA285F /* AppDelegate.swift */,
C1DF944F2A5EF20E00FA285F /* overlay_shader.metal */,
C1DF94502A5EF20E00FA285F /* Overlay.swift */,
C1B521142A5EF85500E9B7AC /* main.swift */,
C1D044EA2A60205E0022B970 /* OverlayWindow.swift */,
Expand Down Expand Up @@ -139,8 +135,12 @@
LastSwiftUpdateCheck = 1430;
LastUpgradeCheck = 1430;
TargetAttributes = {
9C8803732A72625E00476017 = {
LastSwiftMigration = 1430;
};
C1B521472A5EFF5800E9B7AC = {
CreatedOnToolsVersion = 14.3.1;
LastSwiftMigration = 1430;
};
};
};
Expand Down Expand Up @@ -191,7 +191,6 @@
9C8803762A72625E00476017 /* AppDelegate.swift in Sources */,
9C8803772A72625E00476017 /* OverlayWindow.swift in Sources */,
9C8803782A72625E00476017 /* AccessibilityService.swift in Sources */,
9C8803792A72625E00476017 /* overlay_shader.metal in Sources */,
9C88037A2A72625E00476017 /* Overlay.swift in Sources */,
9C88037B2A72625E00476017 /* main.swift in Sources */,
);
Expand All @@ -205,7 +204,6 @@
C1B5215A2A5EFFDB00E9B7AC /* AppDelegate.swift in Sources */,
C1D044EB2A60205E0022B970 /* OverlayWindow.swift in Sources */,
9CBD4E952A67E9F600C7A625 /* AccessibilityService.swift in Sources */,
C1B5215B2A5EFFDB00E9B7AC /* overlay_shader.metal in Sources */,
C1B5215C2A5EFFDB00E9B7AC /* Overlay.swift in Sources */,
C1B5215D2A5EFFDB00E9B7AC /* main.swift in Sources */,
);
Expand All @@ -220,10 +218,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 13;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9K32WDUN2H;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -248,7 +247,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0.9;
MARKETING_VERSION = 1.0.10;
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand All @@ -257,6 +256,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG STORE";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
Expand All @@ -267,10 +267,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 13;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9K32WDUN2H;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -295,7 +296,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0.9;
MARKETING_VERSION = 1.0.10;
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand All @@ -314,10 +315,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 13;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9K32WDUN2H;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -342,14 +344,15 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0.9;
MARKETING_VERSION = 1.0.10;
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = macosx;
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
Expand All @@ -360,10 +363,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = BrightIntosh/BrightIntosh.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 12;
CURRENT_PROJECT_VERSION = 13;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = 9K32WDUN2H;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -388,7 +392,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0.9;
MARKETING_VERSION = 1.0.10;
PRODUCT_BUNDLE_IDENTIFIER = de.brightintosh.app;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down
63 changes: 60 additions & 3 deletions BrightIntosh/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import Cocoa
import ServiceManagement
import Carbon

extension NSScreen {
var displayId: CGDirectDisplayID? {
return deviceDescription[NSDeviceDescriptionKey(rawValue: "NSScreenNumber")] as? CGDirectDisplayID
}
}

class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
private var statusItem: NSStatusItem!
Expand All @@ -30,6 +35,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
private let BRIGHTINTOSH_URL = "https://brightintosh.de"
private let BRIGHTINTOSH_VERSION_URL = "https://api.github.com/repos/niklasr22/BrightIntosh/releases/latest"

private var gamma: Float = 1.7

func applicationDidFinishLaunching(_ aNotification: Notification) {

appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
Expand Down Expand Up @@ -66,8 +73,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
addKeyListeners()
}*/

// Schedule version check every 3 hours
#if !STORE
// Schedule version check every 3 hours
let versionCheckDate = Date()
let versionCheckTimer = Timer(fire: versionCheckDate, interval: 10800, repeats: true, block: {t in self.fetchNewestVersion()})
RunLoop.main.add(versionCheckTimer, forMode: RunLoop.Mode.default)
Expand All @@ -88,9 +95,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
}

func setupOverlay(screen: NSScreen) {
let rect = NSRect(x: screen.visibleFrame.origin.x, y: screen.visibleFrame.origin.y, width: screen.frame.width, height: screen.frame.height)
let rect = NSRect(x: screen.visibleFrame.origin.x, y: screen.visibleFrame.origin.y, width: 1, height: 1)
overlayWindow = OverlayWindow(rect: rect, screen: screen)
overlayAvailable = true
adjustGammaTable(screen: screen)
}

func destroyOverlay() {
Expand All @@ -100,6 +108,38 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
}

func adjustGammaTable(screen: NSScreen) {
if let displayId = screen.displayId {
resetGammaTable()

let tableSize: Int = 256 // The size of the gamma table
var redTable = [CGGammaValue](repeating: 0, count: tableSize)
var greenTable = [CGGammaValue](repeating: 0, count: tableSize)
var blueTable = [CGGammaValue](repeating: 0, count: tableSize)
var sampleCount: UInt32 = 0
let result = CGGetDisplayTransferByTable(displayId, UInt32(tableSize), &redTable, &greenTable, &blueTable, &sampleCount)

guard result == CGError.success else {
return
}

for i in 0..<redTable.count {
redTable[i] = redTable[i] * gamma
}
for i in 0..<greenTable.count {
greenTable[i] = greenTable[i] * gamma
}
for i in 0..<redTable.count {
blueTable[i] = blueTable[i] * gamma
}
CGSetDisplayTransferByTable(displayId, UInt32(tableSize), &redTable, &greenTable, &blueTable)
}
}

func resetGammaTable() {
CGDisplayRestoreColorSyncSettings()
}

func getBuiltInScreen() -> NSScreen? {
for screen in NSScreen.screens {
let screenNumber = screen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")]
Expand Down Expand Up @@ -142,6 +182,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
menu.addItem(toggleLaunchAtLogin)
menu.addItem(exit)

#if DEBUG
let increase = NSMenuItem(title: "Increase gamma", action: #selector(increase), keyEquivalent: "")
menu.addItem(increase)
let decrease = NSMenuItem(title: "Decrease gamma", action: #selector(decrease), keyEquivalent: "")
menu.addItem(decrease)
#endif

/* TODO: Use this once Carbon is fully deprecated without a better successor.
if !AXIsProcessTrusted() {
let requestAccessibilityFeaturesItem = NSMenuItem(title: "Enable global hot key", action: #selector(requestAccessibilityFeatures), keyEquivalent: "")
Expand All @@ -157,6 +204,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
statusItem.menu = menu
}

@objc func increase() {
gamma += 0.05
adjustGammaTable(screen: overlayWindow!.screen!)
}

@objc func decrease() {
gamma -= 0.05
adjustGammaTable(screen: overlayWindow!.screen!)
}

/* TODO: Use this once Carbon is fully deprecated without a better successor.
@objc func requestAccessibilityFeatures() {
let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true]
Expand All @@ -172,7 +229,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {

func addKeyListeners() {
/* TODO: Use this once Carbon is fully deprecated without a better successor.

NSEvent.addGlobalMonitorForEvents(matching: NSEvent.EventTypeMask.keyDown, handler: {(event: NSEvent) -> Void in
if let chars = event.characters, event.modifierFlags.contains(NSEvent.ModifierFlags.command) && event.modifierFlags.contains(NSEvent.ModifierFlags.shift) && chars.contains("b") {
self.toggleBrightIntosh()
Expand All @@ -191,6 +247,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
} else {
destroyOverlay()
resetGammaTable()
}
}

Expand Down
2 changes: 0 additions & 2 deletions BrightIntosh/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSBackgroundOnly</key>
<true/>
<key>LSUIElement</key>
<true/>
</dict>
Expand Down
Loading

0 comments on commit bdc93eb

Please sign in to comment.