-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCheckingContrastController.j
More file actions
65 lines (53 loc) · 2.7 KB
/
CheckingContrastController.j
File metadata and controls
65 lines (53 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
This file is part of FrACT10, a vision test battery.
© 2025 Michael Bach, bach@uni-freiburg.de, <https://michaelbach.de>
CheckingContrastController.j
Created by mb on 2025-02-09.
*/
/**
CheckingContrastController
Dealing with the Checking Contrast stuff: Init, and responding to buttons
*/
@implementation CheckingContrastController : CPWindowController {
CPColor weberFieldColor1 @accessors;
CPColor weberFieldColor2 @accessors;
float actualWeberPercent @accessors;
float actualMichelsonPercent @accessors;
}
- (id) init { //console.info("CheckingContrastController>Init");
[self buttonCheckContrast_action: null]; //populate fields
return self;
}
//all buttons to this action, discriminated by tag value
- (IBAction) buttonCheckContrast_action: (id) sender { //console.info("CheckingContrastController>buttonCheckContrast_action");
const tag = sender ? [sender tag] : 3; //if sender===null select 10%
let contrastWeberPercent = 0;
if ((tag > 0) && (tag <= 5)) contrastWeberPercent = [1, 3, 10, 30, 90][tag - 1];
const contrastLogCSWeber = [MiscLight contrastLogCSWeberFromWeberPercent: contrastWeberPercent];
let gray1 = [MiscLight lowerLuminanceFromContrastLogCSWeber: contrastLogCSWeber];
gray1 = [MiscLight devicegrayFromLuminance: gray1];
let gray2 = [MiscLight upperLuminanceFromContrastLogCSWeber: contrastLogCSWeber];
gray2 = [MiscLight devicegrayFromLuminance: gray2];
if (![Settings isContrastDarkOnLight]) {
[gray1, gray2] = [gray2, gray1]; //"modern" swapping of variables
}
//console.log("Wperc ", contrastWeberPercent, ", lgCSW ", contrastLogCSWeber, ", g1 ", gray1, ", g2 ", gray2);
//const c1 = [CPColor colorWithWhite: gray1 alpha: 1], c2 = [CPColor colorWithWhite: gray2 alpha: 1];
let c1 = [MiscLight colorFromGreyBitStealed: gray1];
let c2 = [MiscLight colorFromGreyBitStealed: gray2];
if ([Settings isContrastDithering]) {
c1 = [CPColor colorWithPatternImage: [Dithering image3x3withGray: gray1]];
c2 = [CPColor colorWithPatternImage: [Dithering image3x3withGray: gray2]];
}
[self setWeberFieldColor1: c1];
[self setWeberFieldColor2: c2];
let actualMichelsonPerc = [MiscLight contrastMichelsonPercentFromColor1: c1 color2: c2];
let actualWeberPerc = [MiscLight contrastWeberPercentFromMichelsonPercent: actualMichelsonPerc];
if ([Settings isContrastDithering]) {
actualMichelsonPerc = [MiscLight contrastMichelsonPercentFromWeberPercent: contrastWeberPercent];
actualWeberPerc = contrastWeberPercent;
}
[self setActualMichelsonPercent: Math.round(actualMichelsonPerc * 10) / 10];
[self setActualWeberPercent: Math.round(actualWeberPerc * 10) / 10];
}
@end