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
|
% TextInOffscreenWindowTest
%
% Compare text drawn into an offscreen window to text drawn into an
% onscreen window.
%
% HISTORY
%
% mm/dd/yy
%
% 3/18/04 awi Wrote it.
% 6/04/24 mk Fixups.
s=max(Screen('Screens'));
[w, wRect]=PsychImaging('OpenWindow', s);
[osw, oswRect]=Screen('OpenOffscreenWindow', w);
Screen('FillRect', osw, 0);
Screen('TextFont',osw, 'Courier');
Screen('TextSize', osw, 50);
Screen('TextStyle', osw, 0);
Screen('DrawText', osw, 'This is text.', 100, 100, [255, 255, 255]);
oswImage=double(Screen('GetImage', osw));
Screen('FillRect', w, 0);
Screen('TextFont',w, 'Courier');
Screen('TextSize', w, 50);
Screen('TextStyle', w, 0);
Screen('DrawText', w, 'This is text.', 100, 100, [255, 255, 255]);
wImage=double(Screen('GetImage', w, [], 'drawBuffer'));
Screen('Flip', w);
Screen('PutImage', w, abs(oswImage - wImage));
%Screen('PutImage', w, oswImage);
Screen('Flip', w);
% % wait for a mouse press
% fprintf('Click the mouse to proceed\n');
% [x,y,buttons] = GetMouse();
% while ~any(buttons)
% [x,y,buttons] = GetMouse();
% end
% fprintf('\n');
Screen('CloseAll');
doesMatch=isempty(find(oswImage ~= wImage));
di=oswImage - wImage;
maxDiff=abs(max(max(max(di))));
if maxDiff ~= 0
ampFactor=floor(255/maxDiff);
else
ampFactor=1;
end
fprintf('TextInOffscreenWindowTest results:\n\n');
if doesMatch
fprintf(' Passed the test; the contents of onscreen and offscreen windows match\n');
else
fprintf(' Failed the test; the contents of onscreen and offscreen windows do not match.\n');
fprintf(' Displaying the difference between onscreen and offscreen text using MATLAB''s\n');
fprintf(' "IMSHOW" command. To make small errors visible, the difference image has been \n');
fprintf([' multiplied by ' num2str(ampFactor) '.\n']);
fprintf('\n');
fprintf(' For further explanation and advice, see help for "TextInOffscreenWindowTest"\n');
imshow(di* ampFactor);
end
|