function [ pred ] = avc16x16( MB_in ,mode, upper, left )

MB_size = length(MB_in);
switch mode
    case 0
    % vertical prediction
        pred = repmat( upper(2:MB_size+1), MB_size, 1 );
    case 1
    % horizontal prediction
        pred = repmat( left, 1, MB_size );
    case 2
    % DC prediction    
        pred = ones( size(MB_in) )*( sum(left)+sum(upper(2:MB_size+1)))/(2*MB_size)  ;
    case 3
    % Plane fit
        left = [upper(1);left];
        H = 0; V = 0;
        for x = 0 : 7
        H = H + (x+1)*( upper( 8 + x + 2) - upper( 6 - x + 2 )  );
        V = V + (x+1)*( left( 8 + x + 2) - left( 6 - x + 2 )  );
        end
        a = 16*( left(17)+ upper(17) );
        b = (5*H )/64;
        c = (5*V )/64;
        for y = 0 : 15
            for x  = 0 : 15;
                pred(y+1, x+1) = (  a + b*(x-7)+c*(y-7) )/32;
            end
        end
end


end

