~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to Psychtoolbox/PsychBasic/ScreenDrawDots.m

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
function ScreenDrawDots(windowPtr, varargin)
2
2
% Workaround-Wrapper for the Screen('DrawDots') function.
3
3
%
4
 
% Usage: ScreenDrawDots(windowPtr, xy [, dotdiameter=1][, dotcolor=255][, center2D][, dot_type=1]);
 
4
% Usage: ScreenDrawDots(windowPtr, xy [, dotdiameter=1][, dotcolor=white][, center2D][, dot_type=1]);
5
5
%
6
6
% This function is the equivalent of the Screen('DrawDots') subfunction
7
7
% for fast drawing of 2D dots. It has the same parameters as that function,
42
42
 
43
43
% History:
44
44
% 03.04.2010  mk  Written to compensate for severe OS/X 10.6.3 OpenGL bugs.
 
45
% 05.09.2013  mk  Use WhiteIndex() instead of hard-coded 255 color value.
45
46
 
46
47
persistent needWorkaround
47
48
persistent spriteTextures
114
115
end
115
116
 
116
117
% Must be a 2D matrix:
117
 
if ndims(xy)~=2
 
118
if ndims(xy)~=2 %#ok<ISMAT>
118
119
    error('"xy" dot position argument is not a 2D matrix! This is required!');
119
120
end
120
121
 
164
165
    end
165
166
else
166
167
    ncolors = 0; %#ok<NASGU>
167
 
    dotcolor = 255;
 
168
    dotcolor = WhiteIndex(windowPtr);
168
169
end
169
170
 
170
171
% 'center2D' argument specified?
249
250
function tex = BuildDotTextures(w, maxms)
250
251
    % Prealloc texture vector:
251
252
    tex = zeros(1, maxms);
 
253
    
 
254
    % Get white value:
 
255
    white = WhiteIndex(w);
252
256
 
253
257
    % Create images for different diameters and corresponding textures:
254
258
    for ms = 1:maxms
255
259
        % Two-Layer Luminance+Alpha image: 1st Layer - Luminance - is
256
 
        % always a full 255 white. We extend the dotimage by 2 pixels in
 
260
        % always a full white white. We extend the dotimage by 2 pixels in
257
261
        % each direction to have some safety margin around the dot:
258
 
        dotimage = ones(ms+2, ms+2, 2) * 255;
 
262
        dotimage = ones(ms+2, ms+2, 2) * white;
259
263
 
260
264
        % 2nd alpha layer starts with zero:
261
265
        dotimage(:,:,2) = 0;
284
288
        end
285
289
 
286
290
        % Normalize the score between 0 and 16 for each pixel to 0.0 - 1.0,
287
 
        % then map to alpha range 0 - 255 to build final alpha-layer:
288
 
        dotimage(:,:,2) = dotimage(:,:,2) / 16 * 255;
 
291
        % then map to alpha range 0 - white to build final alpha-layer:
 
292
        dotimage(:,:,2) = dotimage(:,:,2) / 16 * white;
289
293
 
290
294
        if 0
291
295
            imagesc(dotimage(:,:,2));
295
299
        end
296
300
        
297
301
        % Build texture from it and assign it to proper index in vector:
298
 
        tex(ms) = Screen('MakeTexture', w, dotimage);
 
302
        tex(ms) = Screen('MakeTexture', w, dotimage, [], 32);
299
303
        
300
304
        % Build next diameter's texture...
301
305
    end