function [ frame_encoded, u_p, v_p, u_f, v_f ] = encode_B_frame( frame_in, ref_past, ref_future, B_size, MB_size, Q, search_width )
% encodes a frame as P frame
%
% frame_in: the frame to be encoded
% ref_forw, ref_back: the reference frames on which to look for MBs to be moved
% B_size: block size (in pixels)
% MB_size: macro block (MB) size (in pixels)
% Q: quantization matrix to apply
% search_width: the area to look for moved MB (in pixels)

[Y,chroma] = RGB_to_YCbCr(frame_in);
[Y_ref_p, chroma_ref_p] = RGB_to_YCbCr(ref_past);
[Y_ref_f, chroma_ref_f] = RGB_to_YCbCr(ref_future);

Nmb = size(Y)/MB_size; % number of MBs

Y_mb = mat2cell(Y, repmat(MB_size,1,Nmb(1)), repmat(MB_size,1,Nmb(2)));
Y_encoded = cell(size(Y_mb));

chroma_mb = mat2cell(chroma, repmat(MB_size/2,1,Nmb(1)), repmat(MB_size/2,1,Nmb(2)),2);
chroma_encoded = cell(size(chroma_mb));

u_p = zeros(size(Y_mb));
v_p = zeros(size(Y_mb));
u_f = zeros(size(Y_mb));
v_f = zeros(size(Y_mb));

chromaMB_size = size(chroma_mb{1,1},1);

for m = 1 : Nmb(1)
    for n = 1 : Nmb(2)
        
        % This part has to be completed
        
    end
end

Y_encoded = cell2mat(Y_encoded);
chroma_encoded = cell2mat(chroma_encoded);
frame_encoded = struct('encoded_luma',Y_encoded,'encoded_chroma',chroma_encoded);

end


