This file is indexed.

/usr/share/psychtoolbox-3/PsychHardware/BrightSideDisplay/HDRViewer.m is in psychtoolbox-3-common 3.0.11.20140816.dfsg1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
function HDRViewer(imfilepattern, dummymode, sf)
% HDRViewer([imfilepattern][, dummymode][, scalefactor]) -- Load and show high
% dynamic range images on the BrightSide Technologies High Dynamic Range
% display device.
%
% The viewer allows to cycle through a sequence of images in the given
% folder, matching the given filename pattern. It allows to adjust the
% intensity online, as well as to zoom into regions of the image.
%
% 'imfilepattern' - Filename search pattern of the HDR images to load,
% e.g., 'myimages*.hdr' would load all images starting with 'myimages' and
% ending with extension '.hdr'. 
%
% 'dummymode' - If set to 1 we only run in emulation mode without use of
% the HDR device or BrightSide core library.
%
% Control keys:
%
% You can cycle through all images by pressing the space-bar. You can change
% image intensity scaling by pressing the cursor up- and down-keys. You can
% exit the viewer by pressing ESCape. By pressing the 'q' key, you can
% toggle between float precision HDR and 256 level 8 bit quantized output.
%
% Zoom mode:
% Pressing the left mouse button will enable zoom mode. Dragging the mouse
% while the button is depressed allows to change the region which should be
% zoomed. Releasing the mouse button will show the selected region zoomed
% up to fullscreen. A single mouse click will reset to the full image.
%
% Btw. you can find lot's of nice free HDR images by Googling on the
% internet!
%
% This is an extension of SimpleHDRDemo.m, see that file for basic usage of
% HDR displays with Psychtoolbox.
%
% History:
% Written 2006 by Mario Kleiner - MPI for Biological Cybernetics, Tuebingen, Germany
% and Oguz Ahmet Akyuz - Department of Computer Science, University of Central Florida.

% Make sure we run on OpenGL-Psychtoolbox. Abort otherwise.
PsychDefaultSetup(1);

% Shorten display timing tests - Pretty futile on such a slow device
% anyway...
Screen('Preference', 'SkipSyncTests', 1);

% Startup with black screen to not hurt our eyes:
Screen('Preference', 'VisualDebugLevel', 3);

% Run demo in dummy mode? We default to the real thing.
if nargin < 2 || isempty(dummymode)
    dummymode = 0;
end

% Name of an image file passed? If not, we default to all *.hdr files in
% current working directory:
if nargin < 1 || isempty(imfilepattern)
    % No pattern provided. Search in current working directory.
    imfilepattern = '*.hdr';
end

if nargin < 3
    sf = [];
end

imfilenames = dir(imfilepattern)

try
    % Disable keypress output to Matlab window:
    ListenChar(2);
    
    % Find screen to display: We choose the one with the highest number,
    % assuming this is the HDR display:
    screenid=max(Screen('Screens'));
    
    % Open a standard fullscreen onscreen window, double-buffered with black
    % background color instead of the default white one: win is the window
    % handle for this window. We use the BrightSideHDR() command instead of
    % Screen(). It is a convenience wrapper around Screen, doing all the
    % additional setup work for the HDR display:
    if dummymode
        % Dummy mode: Don't run on real HDR display:
        win = BrightSideHDR('DummyOpenWindow', screenid, 0);
    else
        % HDR mode: Setup everything for HDR rendering:
        win = BrightSideHDR('OpenWindow', screenid, 0);
    end

    winrect = Screen('Rect', win);
    
    iteration = 0;
    abortit=0;

    % Set text properties:
    Screen('TextSize', win, 24);
    Screen('TextStyle', win , 0);

    % Multiply all image values by a scaling factor: The HDR accepts
    % values between zero and infinity, but the useable range seems to be
    % zero (Dark) to something around 3000-4000. At higher values, it
    % saturates in a non-linear fashion. Fractional values, e.g,. 0.5 are
    % resolved at an unknown quantization level, so the range of
    % displayable intensity levels is more than 3000-4000 steps. We don't
    % know the real resolution without proper calibration, but according to
    % their Siggraph 2004 paper its supposed to be more than 14000 levels,
    % covering the full operating range in steps of single JND's. Who
    % knows...

    % Initial flip to black background:
    Screen('Flip', win);
    
    while ~abortit
        iteration=iteration + 1;
        imagename=imfilenames(mod(iteration, size(imfilenames,1))+1).name;
        
        % Show some status info:
        DrawFormattedText(win, ['Loading image: ' imagename '...'], 'center', 'center', [0 255 0]);
        Screen('Flip', win);
        
        % Read image into Matlab matrix:
        img = HDRRead(imagename, 1);
        if isempty(img)
            continue;
        end

        % Set step size for change of scaling factor:
        sfstep = 3500 / max(max(max(img))) * 0.01;
        
        % Scale intensities by some factor. Here we set the default value:
        if isempty(sf)
            if ~dummymode
                sf = 3500 / max(max(max(img)));
            else
                sf = 0.005;
            end
        end
        
        % Build a Psychtoolbox 32 bpc float texture from the image array
        % by setting the (optional) 'floatprecision' flag to 2.
        texid = Screen('MakeTexture', win, img, [], 2, 2);

        % Build also a version of the image that is quantized to 8 Bit:
        quantimg = uint8((img / max(max(max(img)))) * 255);
        ldrtexid = Screen('MakeTexture', win, quantimg, [], 2);
        
        needupdate = 1;
        zoomset = 0;
        xleft=0;
        xtop=0;
        xright=-1;
        xbottom=-1;
        hdrmode = 1;
        
        while(needupdate)            
            % Compute source and destination regions for zoom mode:
            srcleft=min(xleft, xright);
            srctop=min(xtop, xbottom);
            srcright=max(xleft, xright);
            srcbottom=max(xtop, xbottom);
            
            if zoomset==2
                % Zoom set: Show selected region, expanded to full screen:
                texrect=CenterRect(Screen('Rect', texid), winrect);
                srcrect=[srcleft - texrect(1) srctop - texrect(2) srcright - texrect(1) srcbottom - texrect(2)];
                rscale = min(RectWidth(winrect) / RectWidth(srcrect), RectHeight(winrect) / RectHeight(srcrect));
                dstrect=CenterRect([0 0 RectWidth(srcrect)*rscale RectHeight(srcrect)*rscale], winrect);                
            else
                % No zoom: Show image 1-1:
                srcrect=[];
                dstrect=[];
                rscale=1;
            end
            
            % Draw selected srcrect region of our HDR image to selected
            % dstrect region of the screen:
            if hdrmode
                % Draw HDR texture:
                Screen('DrawTexture', win, texid, srcrect, dstrect, [], [], [], [sf sf sf]);
            else
                % Draw quantized 8bpc version:
                Screen('DrawTexture', win, ldrtexid, srcrect, dstrect, [], [], [], [sf sf sf]);
            end
            
            % Some status text:
            if hdrmode
                quantized = 'Floating point HDR';
            else
                quantized = 'Quantized to 8 bpc LDR';
            end
            
            DrawFormattedText(win, ['Image: ' imagename ' : Zoom=' num2str(rscale) ' : Intensity scaling: ' num2str(sf) ' : ' quantized ], 0, 0, [0 255 0]);

            % Show selected ROI during zoom selection, if any:
            if xright~=-1 && xbottom~=-1 && zoomset==1
                Screen('FrameRect', win, [255 0 0], [srcleft srctop srcright srcbottom]);
            end

            % Show updated HDR framebuffer at next vertical retrace:
            Screen('Flip', win);
                        
            % Clear backbuffer by overdrawing with a black full screen rect:
            Screen('FillRect', win, 0);

            % Keypress and what key?
            [pressed secs keycode] = KbCheck;
            if pressed
                % Key pressed: Dispatch...
                if keycode(KbName('space'))
                    % Load next image in folder:
                    needupdate = 0;

                    % Debounce key:
                    while KbCheck; end;
                end

                if keycode(KbName('q'))
                    % Switch between display of float32 HDR image and 8 bpc
                    % LDR image:
                    needupdate = 1;
                    hdrmode = 1 - hdrmode;
                    
                    % Debounce key:
                    while KbCheck; end;
                end
                
                if keycode(KbName('ESCAPE'))
                    % Exit viewer:
                    needupdate = 0;
                    abortit = 1;
                end

                if keycode(KbName('UpArrow'))
                    % Increase intensity scaling factor:
                    needupdate = 1;
                    sf = sf + sfstep;
                end

                if keycode(KbName('DownArrow'))
                    % Decrease intensity scaling factor:
                    needupdate = 1;
                    sf = sf - sfstep;
                end
            else
                % No key pressed: Check for mouse actions...
                [xm, ym, buttons]=GetMouse(win);

                if buttons(1)
                    % Left button pressed:
                    if zoomset==0
                        % Initial press: Reset and Setup zoom operation...
                        xleft=xm;
                        xtop=ym;
                        xright=-1;
                        xbottom=-1;
                        zoomset=1;
                    else
                        if zoomset==1
                            % Continued press: Update zoom area:
                            xright=xm;
                            xbottom=ym;
                        else
                            % Pressed while zoomed in: Reset...
                            while buttons(1)
                                [xm, ym, buttons]=GetMouse(win);
                            end
                            zoomset=0;                            
                        end
                    end
                else
                    % Left button released:
                    if zoomset==1
                        zoomset=2;
                    end
                end
            end
        end
        
        % Done with this image. Release its texture and next one...
        Screen('Close', texid);
        Screen('Close', ldrtexid);
        clear img;
        clear quantimg;
    end

    % Enable keypress output to Matlab window:
    ListenChar(0);
    
    % Release all textures, close all windows, shutdown BrightSide library:
    Screen('CloseAll');
    
    % Well done!
    fprintf('Bye bye!\n');
catch
    % Error handler: If something goes wrong between try and catch, we
    % close the window and abort.

    % Enable keypress output to Matlab window:
    ListenChar(0);

    % Release all textures, close all windows, shutdown BrightSide library:
    Screen('CloseAll');

    % Rethrow the error, so higher level routines can handle it:
    psychrethrow(psychlasterror);
end;