function x = jpeg2mat(y);

% y is a structure created by the MAT2JPEG and has the fields stated above

% First go back to matrix from huffman
A = huff2mat(y.Coeff);

% Create the original order
load zigzag64rev.mat;           % revOrder order now available

NumOfBlocks = y.NumOfBlocks;
for i = 1:NumOfBlocks
    A(:,i) = A(revOrder,i);
end

% inverse DPCM on DC
A(1,:) = cumsum(A(1,:));

% Reshape
rows = y.size(1);
cols = y.size(2);

z = col2im(A,[8 8],[rows cols],'distinct');

% multiply with Q
load QTable.mat;
Q = Q/y.quality;
x = blkproc(z,[8 8],[0 0],'round(x.*P1)',Q);

% Apply IDCT
x = round(blkproc(x,[8 8],[0 0],'idct2'));

% level shift input
[max(x(:)) min(x(:))]
x = uint8(x+128);
%x = round(x+128); 