% Andrew Puryear
% 362 Project - decompress_jpega
%   Matlab file takes COLA-JPEG files and returns images.

function [ reim ] = decompress_jpega( imw, imsize)
hopsize=8;

for i=1:10:size(imw,1)
    for j=1:10:size(imw,2)
        imw(i:i+9, j:j+9) = idct2(imw(i:i+9, j:j+9));
    end
end


% reconstruct image
reim=zeros(4/5*size(imw,1)+2,4/5*size(imw,2)+2);
n=0;
for k=1:hopsize:4/5*size(imw,2)+2-4
    m=0;
    for p=1:hopsize:4/5*size(imw,1)+2-4
        reim(p:p+9,k:k+9) =  reim(p:p+9,k:k+9)+imw(m*10+1:m*10+10,n*10+1:n*10+10);
        m=m+1;
    end
    n=n+1;
end

dx=floor(size(reim,1)-imsize(1))/2;
dy=floor(size(reim,2)-imsize(2))/2;
reim=reim(dx-3:imsize(2)-2+dx,dy-3:imsize(2)+dy-2);

reim=round(reim/max(reim(:))*256);
