diff options
author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/toolbox_basic/io/read422.m | |
parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/io/read422.m')
-rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/io/read422.m | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/io/read422.m b/SD-VBS/common/toolbox/toolbox_basic/io/read422.m new file mode 100755 index 0000000..31a27f9 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/io/read422.m | |||
@@ -0,0 +1,45 @@ | |||
1 | function I = read422(fname,nc); | ||
2 | % | ||
3 | % I = read422(fname,width); | ||
4 | % | ||
5 | % read in a .422 file, need to pass image width, default = 640 | ||
6 | % | ||
7 | |||
8 | % assume image width = 640 | ||
9 | if nargin<2, | ||
10 | nc = 640; | ||
11 | end | ||
12 | |||
13 | %% find the image size | ||
14 | fid = fopen(fname); | ||
15 | fseek(fid,0,1); | ||
16 | fsize = ftell(fid); | ||
17 | |||
18 | nr = fsize/nc/2; | ||
19 | fseek(fid,0,-1); | ||
20 | |||
21 | %% read in Ybr data | ||
22 | data = fread(fid,fsize,'uchar'); | ||
23 | |||
24 | %%% extract Y, Cb, Cr | ||
25 | Y1 = data(1:2:end); Y1 = reshape(Y1,nc,nr)'; | ||
26 | Cb1 = data(2:4:end); Cb1 = reshape(Cb1,nc/2,nr)'; | ||
27 | Cr1 = data(4:4:end); Cr1 = reshape(Cr1,nc/2,nr)'; | ||
28 | |||
29 | Cb = zeros(size(Y1)); | ||
30 | Cr = zeros(size(Y1)); | ||
31 | |||
32 | Cb(:,1:2:end) = Cb1; Cb(:,2:2:end) = Cb1; | ||
33 | %Cb(:,2:2:end) = 0.5*(Cb1+[Cb1(:,2:end),Cb1(:,end)]); | ||
34 | |||
35 | Cr(:,1:2:end) = Cr1; Cr(:,2:2:end) = Cr1; | ||
36 | %Cr(:,2:2:end) = 0.5*(Cr1+[Cr1(:,2:end),Cr1(:,end)]); | ||
37 | |||
38 | %%% convert to r,g,b | ||
39 | r = 1.164*(Y1-16.0) + 1.596*(Cr-128.0); | ||
40 | g = 1.164*(Y1-16.0) - 0.813*(Cr-128.0) - 0.391*(Cb-128.0); | ||
41 | b = 1.164*(Y1-16.0) + 2.018*(Cb-128.0); | ||
42 | |||
43 | I = cat(3,r,g,b); | ||
44 | I = max(0,min(I,255)); | ||
45 | I = I/255; | ||