0001
0002
0003 function [Results] = jpeg91_c_decoder(normaliz,To,dUmax,dVmax,directorio,fichero,niveles,bitmax)
0004 you_are_here=pwd;
0005
0006 if(nargin < 8 && niveles == 1)
0007 bitmax = 1;
0008 end
0009
0010 if niveles==0
0011 k = [];
0012 for canal=1:3
0013 [ciaf1D,N,iaf] = vqperc_crom_lin_2(16,1,2,0,0,uCP(canal),bitmax,32,canal,0);
0014 k=[k; N(1:16)];
0015 end
0016 M = maxi(k);
0017 k = k/M;
0018 else
0019 opcion = 1;
0020 Fc = 0;
0021 Pesos = [1 1 1];
0022 k = deal_levels(16,64,opcion,Fc,Pesos);
0023 end
0024
0025 cd(directorio)
0026 unzip([fichero '.zip']);
0027 ristra = read_code([fichero '.bin']);
0028
0029 delete([fichero '.bin']);
0030 TheCode=zeros(256,255,3);
0031
0032 posicion=length(ristra);
0033 queda_ristra=ristra;
0034 for cap=3:-1:1
0035 if cap==1
0036 for i=256:-1:1
0037 queda_ristra=ristra(1:posicion);
0038 ceros=find(queda_ristra==0);
0039 pos_cero=ceros(end);
0040 ceros_bloque=queda_ristra(pos_cero+1:end);
0041 queda_ristra=queda_ristra(1:pos_cero);
0042 posicion=pos_cero;
0043 bloque=[];
0044 long_bloque=0;
0045 while long_bloque<255
0046
0047 dato=queda_ristra(posicion);
0048 queda_ristra=queda_ristra(1:end-1);
0049 posicion=posicion-1;
0050 if dato==0
0051 bloque=[zeros(1,ceros_bloque(end)) bloque];
0052 ceros_bloque=ceros_bloque(1:end-1);
0053 long_bloque=length(bloque);
0054 else
0055 bloque=[dato bloque];
0056 long_bloque=length(bloque);
0057 end
0058 end
0059 TheCode(i,:,cap)=bloque;
0060 end
0061 else
0062 for i=256:-1:1
0063 queda_ristra=ristra(1:posicion);
0064 ceros=find(queda_ristra==0);
0065 pos_cero=ceros(end);
0066 ceros_bloque=queda_ristra(pos_cero+1:end);
0067 queda_ristra=queda_ristra(1:pos_cero);
0068 posicion=pos_cero;
0069 bloque=[];
0070 long_bloque=0;
0071 while long_bloque<63
0072
0073 dato=queda_ristra(posicion);
0074 queda_ristra=queda_ristra(1:end-1);
0075 posicion=posicion-1;
0076 if dato==0
0077 bloque=[zeros(1,ceros_bloque(end)) bloque];
0078 ceros_bloque=ceros_bloque(1:end-1);
0079 long_bloque=length(bloque);
0080 else
0081 bloque=[dato bloque];
0082 long_bloque=length(bloque);
0083 end
0084 end
0085 blo=zeros(16,16);
0086 bloo=[0 bloque];
0087 bloo=dezigzag(bloo);
0088 blo(1:8,1:8)=bloo;
0089 bloque=zigzag(blo);
0090 bloque=bloque(2:end);
0091 TheCode(i,:,cap)=bloque;
0092 end
0093 end
0094 end
0095
0096 bits=queda_ristra(end-2:end);
0097
0098 NumNiv=2.^bits;
0099 MM=0.8;
0100 TheRealCode=TheCode;
0101 for cap=1:3
0102 TheRealCode(:,:,cap)=TheCode(:,:,cap)*MM/NumNiv(cap);
0103 end
0104
0105 queda_ristra=queda_ristra(1:end-3);
0106 QE=queda_ristra(7:end);
0107 QQEE(:,:,1)=reshape(QE(1:256),16,16);
0108 QQEE(:,:,2)=reshape(QE(257:512),16,16);
0109 QQEE(:,:,3)=reshape(QE(513:end),16,16);
0110
0111 extr_err=zeros(2,3);
0112 extr_err(:,1)=queda_ristra(1:2)';
0113 extr_err(:,2)=queda_ristra(3:4)';
0114 extr_err(:,3)=queda_ristra(5:6)';
0115
0116 N=round(0.9*[40 10 10]);
0117 for i=1:3
0118 qe(:,:,i)=(extr_err(2,i)-extr_err(1,i))*QQEE(:,:,i)/(N(i)-1)+extr_err(1,i);
0119 end
0120
0121 for i=1:3
0122 Lmq(:,:,i)=iimdpcm(qe(:,:,i),1,To(i));
0123 end
0124
0125 Li = 256;
0126 Lb = 16;
0127
0128 aa = zeros(Lb);
0129 [r,alfa2d(:,:,1)]=respue_lin(aa,k,1);
0130 [r,alfa2d(:,:,2)]=respue_lin(aa,k,2);
0131 [r,alfa2d(:,:,3)]=respue_lin(aa,k,3);
0132 fprintf('Recovering the image:\n');
0133 fprintf(' Inverting from linear r to dct\n');
0134
0135 for capa = 1:3
0136 for bloque = 1:256
0137 aa = TheRealCode(bloque,:,capa);
0138 signosr(bloque,:,capa) = getsign(aa,Lb);
0139 end
0140 end
0141 for cap=1:3
0142 z = 1;
0143 for i=1:Lb:(Li-1)
0144 for j=1:Lb:(Li-1)
0145
0146 r_recon = abs(TheRealCode(z,:,cap))';
0147
0148 r_recon = [0; r_recon];
0149
0150 ac = r_recon./alfa2d(:,:,cap);
0151
0152 ac1 = obtainsign(ac(2:end),signosr(:,:,cap),Lb,z);
0153 ac1 = [0;ac1];
0154 ac1 = dezigzag(ac1);
0155
0156 dctc1(i:(i+(Lb-1)),j:(j+(Lb-1)),cap) = ac1;
0157
0158 z = z+1;
0159 end
0160 end
0161 end
0162 fprintf(' Inverting from dct-contrast to spatial domain\n');
0163
0164 dctc1i = icontras3(dctc1,Lmq,4,normaliz,To,dUmax,dVmax);
0165 for cap = 1:3
0166 ImRyuv(:,:,cap)=real(idct2r(dctc1i(:,:,cap),4));
0167 end
0168 ImR = my_yuv2rgb(ImRyuv);
0169
0170 Results = uint8(ImR);
0171 cd(you_are_here)