module read(dataout,htpv);
output reg [0:1420479]dataout;
output reg [1:59186]htpv;
reg [24:1]error[59186:0];
reg [25:0]cpv,cpv_round,e_av;
reg [0:1420479]data[0:0];
reg [1:24]data_out;
parameter threshold =8388608,w1=2,w2=8,w3=4,w4=2;
integer i=0,f1;
initial
begin
$readmemb("image_24_bit.txt",data);
dataout=data[0];
end
initial
begin
error[0]=24'b0;
f1=$fopen("HTPimage.bmp","a");
for(i=0;i<306;i=i+1)
begin
data_out=dataout[(i*24)+:24];
e_av=(w1*error[i])>>4;
cpv= data_out + e_av;
cpv_round=(cpv<threshold)?0:16777215;
htpv[i+1]=(cpv_round==0)?0:1;
error[i+1]=cpv-cpv_round;
if(htpv[i]==1)
begin
$fwrite(f1,"1");
end
else
begin
$fwrite(f1,"0");
end
#1;
end
for(i=306;i<591886;i=i+1)
begin
data_out=dataout[(i*24)+:24];
e_av=(2*error[i]+8*error[i-306]+4*error[i-305]+2*error[i-304])>>4;
cpv= data_out + e_av;
cpv_round=(cpv<threshold)?0:16777215;
htpv[i+1]=(cpv_round==0)?0:1;
error[i+1]=cpv-cpv_round;
if(htpv[i]==1)
begin
$fwrite(f1,"1");
end
else
begin
$fwrite(f1,"0");
end
#1;
end
$fclose(f1);
end
endmodule