File: PrimaryToGamut.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (46 lines) | stat: -rw-r--r-- 1,402 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
function [gamut, badIndex] = PrimaryToGamut(cal,primary)
% [gamut, badIndex] = PrimaryToGamut(cal,primary)
%
% Check that primary coordinates are in range [0,1].
% Force them to be so if not.  The indices of the
% out of gamut primary settings are returned as 'badIndex'.
%
% 9/8/93    jms   Set global flag if there was a gamut problem.
% 9/13/93   jms   Took out the global flag and instead return
%                 a flag vector for the ones that were changed.
% 9/26/93	  dhb   Added calData argument.  It is not used, but
%                 I want to pass it through these routines generally
% 9/27/93   jms   Commented out the messages for going out of gamut.
%	3/7/94		dhb		Modified so that badIndex return respects tolerance.
% 4/5/02    dhb, ly  New naming convention.

gamut = primary;
tolerance = 1e-10;

[m,n] = size(primary);
badIndex = zeros(1,n);

% Check lower bound by rows
for (i=1:m)
  index = find(primary(i,:) < 0);
  if (~isempty(index))
    gamut(i,index) = zeros(1,length(index));
		index = find(primary(i,:) < -tolerance);
		if (~isempty(index))
			badIndex(index) = ones(1,length(index));
		end
  end
end


% Check upper bound by rows
for (i=1:m)
  index = find(primary(i,:) > 1);
  if (~isempty(index))
    gamut(i,index) = ones(1,length(index));
		index = find(primary(i,:) > 1+tolerance);
		if (~isempty(index))
    	badIndex(index) = ones(1,length(index));
		end
  end
end