File: CalibrateManualDrvr.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (142 lines) | stat: -rw-r--r-- 4,726 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
% CalibrateManualDrvr
%
% Get some manual measurements from radiometer/photometer.

% 3/8/02  dhb, ly  Wrote it.
% 2/21/03 dhb, ly  Specify input units.
% 6/30/23 mk       Use new clut mapping to fix this mess on standard gpus.

global g_usebitspp;

% If the global flag for using Bits++ is empty, then it hasn't been
% initialized and default it to 0.
if isempty(g_usebitspp)
    g_usebitspp = 0;
end

if USERPROMPT
    if cal.describe.whichScreen == 0
        fprintf('Hit any key to proceed past this message and display a box.\n');
        fprintf('Insert manual photometer/radiometer.\n');
        fprintf('Once meter is set up, hit any key to proceed\n');
        KbStrokeWait(-1);
    else
        fprintf('Insert manual photometer/radiometer.\n');
        fprintf('Once meter is set up, hit any key to proceed\n');
    end
end

% Blank other screen
if blankOtherScreen
    Screen('OpenWindow', cal.describe.whichBlankScreen, 0);
end

% Setup screen to be measured
% ---------------------------

% Prepare imaging pipeline for Bits+ Bits++ CLUT mode, or DataPixx/ViewPixx
% L48 CLUT mode (which is pretty much the same). If such a special output
% device is used, the Screen('LoadNormalizedGammatable', win, clut, 2);
% command uploads 'clut's into the device at next Screen('Flip'), taking
% care of possible graphics driver bugs and other quirks:
PsychImaging('PrepareConfiguration');

if g_usebitspp == 0
    % Setup for imaging pipeline based clut mapping:
    PsychImaging('AddTask', 'AllViews', 'EnableCLUTMapping', 256, 1);
end

if g_usebitspp == 1
    % Setup for Bits++ CLUT mode. This will automatically load proper
    % identity gamma tables into the graphics hardware and into the Bits+:
    PsychImaging('AddTask', 'General', 'EnableBits++Bits++Output');
end

if g_usebitspp == 2
    % Setup for DataPixx/ViewPixx etc. L48 CLUT mode. This will
    % automatically load proper identity gamma tables into the graphics
    % hardware and into the device:
    PsychImaging('AddTask', 'General', 'EnableDataPixxL48Output');
end

% Open the window:
[window, screenRect] = PsychImaging('OpenWindow', cal.describe.whichScreen, 0);

% Only need to set identity mapping for standard display mode, as all needed setup
% is already done automatically for CRS, VPixx devices etc. by PsychImaging():
if g_usebitspp == 0
    % Upload an identity gamma ramp into all channels. Upload a LUT with exactly
    % as many slots as the operating system + gpu driver expects, so we pass through
    % the full framebuffer precision one-to-one, as much as framebuffer depths allows.
    % Don't use LoadIdentityClut here, as it configures for a 8 bpc identity lut,
    % suitable for special display devices, but may lose a bit of precision for
    % conventional display setups:
    [~, ~, nslots] = Screen('ReadNormalizedGammaTable', window);
    Screen('LoadNormalizedGammaTable', window, (linspace(0, 1, nslots)' * ones(1, 3)), 0);
end

if (cal.describe.whichScreen == 0)
    HideCursor(window);
end

% Load zero theClut into device:
theClut = zeros(256,3);
Screen('LoadNormalizedGammaTable', window, theClut, 2);
Screen('Flip', window);

% Draw a box in the center of the screen
if ~isfield(cal.describe, 'boxRect')
    boxRect = [0 0 cal.describe.boxSize cal.describe.boxSize];
    boxRect = CenterRect(boxRect,screenRect);
else
    boxRect = cal.describe.boxRect;
end

theClut(2,:) = [1 1 1];
Screen('FillRect', window, 1, boxRect);
Screen('LoadNormalizedGammaTable', window, theClut, 2);
Screen('Flip', window, 0, 1);

% Wait for user
if USERPROMPT == 1
  KbStrokeWait(-1);
end

% Put correct surround for measurements.
theClut(1,:) = cal.bgColor';
Screen('LoadNormalizedGammaTable', window, theClut, 2);
Screen('Flip', window, 0, 1);

% We have put up white:
cal.manual.white = [];
while isempty(cal.manual.white)
    if cal.manual.photometer
        cal.manual.white = input('Enter photometer reading (cd/m2): ');
    else
        cal.manual.white = 1e-6*input('Enter radiometer reading (micro Watts): ');
    end
end

theClut(2,:) = [0 , 0 , 0];
Screen('LoadNormalizedGammaTable', window, theClut, 2);
Screen('Flip', window, 0, 1);

cal.manual.black = [];
while isempty(cal.manual.black)
    if cal.manual.photometer
        cal.manual.black = input('Enter photometer reading (cd/m2): ');
    else
        cal.manual.black = 1e-6*input('Enter radiometer reading (micro Watts): ');
    end
end
cal.manual.increment = cal.manual.white - cal.manual.black;

% Close the screen, restore cluts:
if g_usebitspp
    % Load identity clut on Bits++ / DataPixx et al.:
    BitsPlusPlus('LoadIdentityClut', window);
    Screen('Flip', window);
end

% Restore graphics card gamma tables to original state, close windows etc.:
sca;