File: SRGBGammaUncorrect.m

package info (click to toggle)
psychtoolbox-3 3.0.17.9.dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 84,408 kB
  • sloc: ansic: 171,572; cpp: 20,885; objc: 5,164; sh: 1,878; python: 1,366; php: 384; makefile: 193; java: 113
file content (28 lines) | stat: -rw-r--r-- 708 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
function rgb = SRGBGammaUncorrect(RGB)
% rgb = SRGBGammaUncorrect(RGB)
%
% Undo standard sRGB gamma correction, taking [0-255] -> [0-1].
%
% See XYZToSRGBPrimary for comment on evolution of the standard
% and of this implementation.
%
% See comments inn XYZToSRGBPrimary for info on standard.
%
% 2/9/06	dhb	 Wrote it.
% 7/8/10    dhb  Rewrote to match current standard.
% 8/16/10   dhb  Fix typo in header.

% Apply sRGB gamma correction according to formulae
cutoff = 0.03928;
RGB = double(RGB)/255;
rgb = RGB;
index = find(RGB < cutoff);
if (~isempty(index))
	rgb(index) = RGB(index)/(12.92);
end
index = find(rgb >= cutoff);
if (~isempty(index))
    rgb(index) = (((RGB(index))+0.055)/1.055).^2.4;
end