File: AlphaDestinationTerm.m

package info (click to toggle)
psychtoolbox-3 3.0.9%2Bsvn2579.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 63,408 kB
  • sloc: ansic: 73,310; cpp: 11,139; objc: 3,129; sh: 1,669; python: 382; php: 272; makefile: 172; java: 113
file content (63 lines) | stat: -rw-r--r-- 2,712 bytes parent folder | download | duplicates (7)
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
function newDestinationMat=AlphaDestinationTerm(destinationFactorStr, sourceMat, destinationMat)

% newDestinationMat=AlphaDestinationTerm(destinationFactorStr, sourceMatrix, destinationMatrix)
%
% AlphaDestinationTerm simuluates the step of multplying an alpha factor with the
% destination image in OpenGL alpha blending.    
%
% Apply an OpenGL source factor rule such as 'GL_ZERO' to the image matrix
% 'destinationMat', returing the dot product of destinationMat and the
% alpha factor selected by string 'sourceFactor'.  
%
% The source image matrix 'sourceMat' is required because destination
% factor strings may select alpha values from the source image.
%
% AlphaDestinationTerm calculates with double-precision (64-bit) floating
% point arithmatitic whereas the precision of an OpenGL renderer which it
% simulates is unspecified, except that OpenGL guarantees perfect precision
% for alpha values 0 and 1 (255 via Screen).  Comparison of
% AlphaDestinationTerm with the OpenGL renderer shows that alpha
% multiplicaion discards up to one bit of precision.  
%
% see also: AlphaSourceTerm, PsychAlphaBlending

% HISTORY
% 
% mm/dd/yy
% 
%  2/11/05  awi wrote it.


sourceMatDims=size(sourceMat);
destinationMatDims=size(destinationMat);
if length(sourceMatDims) ~= 3 ||  sourceMatDims(3) ~= 4                     
    error('Argument ''sourceMat'' must be a matrix with dimensions [x,y,4]');
end
if length(destinationMatDims) ~= 3 ||  destinationMatDims(3) ~= 4                     
    error('Argument ''destinationMat'' must be a matrix with dimensions [x,y,4]');
end
sourceMatAlphaPlane=sourceMat(:,:,4);
destinationMatAlphaPlane=destinationMat(:,:,4);
  

if strcmp(destinationFactorStr, 'GL_ZERO')
    newDestinationMat=AlphaTimes(destinationMat,0);
elseif strcmp(destinationFactorStr, 'GL_ONE')
    newDestinationMat=AlphaTimes(destinationMat,255);
elseif strcmp(destinationFactorStr, 'GL_SRC_COLOR')
    newDestinationMat=AlphaTimes(destinationMat, sourceMat);
elseif strcmp(destinationFactorStr, 'GL_ONE_MINUS_SRC_COLOR')
     newDestinationMat=AlphaTimes(destinationMat, 255 - sourceMat);
elseif strcmp(destinationFactorStr, 'GL_SRC_ALPHA');
    newDestinationMat=AlphaTimes(destinationMat, sourceMat(:,:,4));
elseif strcmp(destinationFactorStr, 'GL_ONE_MINUS_SRC_ALPHA')
    newDestinationMat=AlphaTimes(destinationMat, 255 - sourceMat(:,:,4));
elseif strcmp(destinationFactorStr, 'GL_DST_ALPHA');
    newDestinationMat=AlphaTimes(destinationMat, destinationMat(:,:,4));
elseif strcmp(destinationFactorStr, 'GL_ONE_MINUS_DST_ALPHA');
    newDestinationMat=AlphaTimes(destinationMat, 255-destinationMat(:,:,4));
else
    error('Argument "sourceFactor" is unrecognized or invalid');
end