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
|
function BitsPlusImagingMonoTest(testdrawingcmds)
% BitsPlusImagingMonoTest([testdrawingcmds])
%
% Test of built-in Mono++ output conversion shader of PTB
% imaging pipeline. This is meant to test Bits++ Mono++
% conversion of GPU against reference implementation of
% Matlab BitsPlus toolbox.
%
% First the stimulus is generated via Matlab conversion routine.
% Then it is drawn via PTB imaging pipeline conversion.
% Then the PTB imaging result is read back and compared against
% the result of the Matlab implementation and the maximum error
% is returned. This error should be zero.
%
% The optional parameter 'testdrawingcmds' specs if pure texture
% mapping should be tested, or if a combo of texture mapping and
% Screen 2D drawing commands gets tested (1).
%
% THIS TEST IS NOT FINISHED. EARLY BETA.
%
if nargin < 1
testdrawingcmds = 0;
end
testdrawingcmds
% Define screen
whichScreen=max(Screen('Screens'));
% Increase level of verbosity so we get all the debug-messages:
%Screen('Preference', 'Verbosity', 6);
% Open window, fill frame buffer with black background.
% Enable imaging pipeline with HDR framebuffer:
%imagingmode = mor(kPsychNeedFastBackingStore, kPsychNeedOutputConversion, kPsychNeed16BPCFixed);
imagingmode = 0;
[window,screenRect] = BitsPlusPlus('OpenWindowMono++', whichScreen, 0, [], [], [], [], [], imagingmode);
% [window,screenRect] = Screen(whichScreen,'OpenWindow',0,[],[],[],[],[], imagingmode);
%
% % First load the graphics hardwares gamma table with an identity mapping,
% % so it doesn't interfere with Bits++
% LoadIdentityClut(window);
%
% % Set color range to 0 to 65535:
% %Screen('ColorRange', window, 2^16 - 1);
% Screen('ColorRange', window, 1);
%
% % Setup Bits++ Mono++ formatting shader:
% % Now enable output formatter hook chain and load them with the special Bits++
% % Mono++ data formatting shader:
%
% shader = LoadGLSLProgramFromFiles('Bits++_Mono++_FormattingShader', 1);
% Screen('Preference', 'Enable3DGraphics', 0);
% glUseProgram(shader);
% glUniform1i(glGetUniformLocation(shader, 'Image'), 0);
% %glUniform1i(glGetUniformLocation(shader, 'moduloLUT'), 1);
% glUseProgram(0);
%
% % global GL;
% %
% % moduloLUTtex = glGenTextures(1);
% % glBindTexture(GL.TEXTURE_1D, moduloLUTtex);
% % moduloLUT=uint8(0:255);
% % glTexImage1D(GL.TEXTURE_1D, 0, GL.LUMINANCE8, 256, 0, GL.LUMINANCE, GL.UNSIGNED_BYTE, moduloLUT);
% %
% % % Make sure we use nearest neighbour sampling:
% % glTexParameteri(GL.TEXTURE_1D, GL.TEXTURE_MIN_FILTER, GL.NEAREST);
% % glTexParameteri(GL.TEXTURE_1D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);
% %
% % % And that we wrap around, aka repeat:
% % glTexParameteri(GL.TEXTURE_1D, GL.TEXTURE_WRAP_S, GL.REPEAT);
% % glBindTexture(GL.TEXTURE_1D, 0);
%
% %Screen('HookFunction', window, 'PrependShader', 'FinalOutputFormattingBlit', 'Mono++ output formatting shader for CRS Bits++', shader, ['TEXTURE1D(1)=' num2str(moduloLUTtex)]);
% Screen('HookFunction', window, 'PrependShader', 'FinalOutputFormattingBlit', 'Mono++ output formatting shader for CRS Bits++', shader);
% Screen('HookFunction', window, 'Enable', 'FinalOutputFormattingBlit');
s=256
dstrect = CenterRect([0 0 s s], Screen('Rect', window));
if testdrawingcmds
colorval = 65462 / 65535;
inimg=colorval * ones(256, 256);
else
inimg=reshape(double(linspace(0, 2^16 - 1, 2^16)), 256, 256)' / (2^16 - 1);
end
tic;
monoImage = BitsPlusPackMonoImage(inimg * 65535);
toc
msize=size(monoImage)
mclass=class(monoImage)
for i=1:10
tex = Screen('MakeTexture', window, inimg, [], [], 2);
Screen('DrawTexture', window, tex, [], dstrect, [], 0);
Screen('Close', tex);
if testdrawingcmds
Screen(window,'FillOval', colorval, dstrect - [0 0 100 100]);
end
glFinish;
tic
Screen('DrawingFinished', window);
glFinish;
toc
convImage = Screen('GetImage', window, dstrect,'backBuffer');
Screen('Flip', window, 0, 0, 2);
rm=max(max(monoImage(:,:,1)))
gm=max(max(monoImage(:,:,2)))
bm=max(max(monoImage(:,:,3)))
% imwrite(monoImage, '/Users/kleinerm/Desktop/MEncoded.bmp');
rc=max(max(convImage(:,:,1)))
gc=max(max(convImage(:,:,2)))
bc=max(max(convImage(:,:,3)))
% imwrite(convImage, '/Users/kleinerm/Desktop/GEncoded.bmp');
diffred = abs(double(monoImage(:,:,1)) - double(convImage(:,:,1)));
diffgreen = abs(double(monoImage(:,:,2)) - double(convImage(:,:,2)));
mdr = max(max(diffred));
mdg = max(max(diffgreen));
fprintf('Maximum difference: red (hi) = %f green (low)= %f\n', mdr, mdg);
if mdr>0 || mdg>0
close all;
imagesc(diffred);
figure;
imagesc(diffgreen);
end
end
KbWait;
% Close the window.
Screen('CloseAll');
% Blank the screen
% BitsPlusBlank(whichScreen);
|