%-------------------------------------------------------------------
%
%  Filename      : dat2jpg.v
%  Author        : Huang Lei Lei
%  Created       : 2015-09-09
%  Description   : convert dat to jpg file
%
%-------------------------------------------------------------------

clear;
clc;

HON = 640 ;
VER = 480 ;
INPUT = 'img_i.dat';
OUTPUT = 'img_o.jpg';

fp_i = fopen(INPUT);
Dat = uint8(fread(fp_i,'uint8'));
fclose(fp_i);
Dat_reshape = reshape(Dat, 1024*8, []);
Dat_valid = Dat_reshape(1:4096, :);
Dat_r = reshape(Dat_valid(1:4:HON*VER*4), HON, VER);
Dat_g = reshape(Dat_valid(2:4:HON*VER*4), HON, VER);
Dat_b = reshape(Dat_valid(3:4:HON*VER*4), HON, VER);
Dat_rgb = uint8(zeros(VER, HON, 3));
Dat_rgb(:,:,1) = Dat_r' ;
Dat_rgb(:,:,2) = Dat_g' ;
Dat_rgb(:,:,3) = Dat_b' ;
imshow(Dat_rgb);
imwrite(Dat_rgb, OUTPUT);