function [pred_block, valid] = get_pred_block_qpel(PixY,PixX,block_size,vecy,vecx,anchor_frame,component) 
pred_block = zeros(block_size,block_size) ;
PixX = PixX - 1 ; PixY = PixY - 1 ; 
valid = 1 ;
Height = size(anchor_frame,1) ; Width = size(anchor_frame,2) ; 
if component > 1
    Height = Height*2 ; Width = Width*2 ;
    PixX = PixX/2 ; PixY = PixY/2 ;
    pred_block = zeros(block_size/2,block_size/2) ;
end

if component == 1
    f1 = 4 ; f2 = 3 ; f3 = f1*f1 ; f4 = f3/2 ;
    for j=0 : block_size-1
        if valid == 0
            break ;
        end
        for i=0 : block_size-1
            
            ii=floor((PixX+i)*f1 + vecx) ;
            jj=floor((PixY+j)*f1 + vecy) ;
%             ii0 = max([0 min([Width-1  floor(ii/f1)])]);
%             jj0 = max([0 min([Height-1 floor(jj/f1)])]);
%             ii1 = max([0 min([Width-1  floor((ii+f2)/f1)])]);
%             jj1 = max([0 min([Height-1 floor((jj+f2)/f1)])]);

            ii0 = floor(ii/f1) ;
            jj0 = floor(jj/f1) ;
            ii1 = floor((ii+f2)/f1) ;
            jj1 = floor((jj+f2)/f1) ;

            if ( (jj0+1 < 1) | (jj0+1 > Height) | (jj1+1 < 1) | (jj1+1 > Height) )
                valid = 0 ;
                break ;
            end
            if ( (ii0+1 < 1) | (ii0+1 > Width ) | (ii1+1 < 1) | (ii1+1 > Width ) )
                valid = 0 ;
                break ;
            end
            if1=bitand(ii,f2);
            jf1=bitand(jj,f2);
            if0=f1-if1;
            jf0=f1-jf1;

            pred_block(j+1,i+1) = (if0*jf0*anchor_frame(jj0+1,ii0+1) + ...
                                        	      if1*jf0*anchor_frame(jj0+1,ii1+1) + ...
                                        	      if0*jf1*anchor_frame(jj1+1,ii0+1) + ...
                	                              if1*jf1*anchor_frame(jj1+1,ii1+1))/f3  ;
        end
    end
else %% component=2 or 3
    f1 = 8 ; f2 = 7 ; f3 = f1*f1 ; f4 = f3/2 ;
    for j=0 : block_size/2-1
        if valid == 0
            break ;
        end

        for i=0 : block_size/2-1

            ii=floor((PixX+i)*f1 + vecx) ;
            jj=floor((PixY+j)*f1 + vecy) ;
%             ii0 = max([0 min([Width/2-1  floor(ii/f1)])]);
%             jj0 = max([0 min([Height/2-1 floor(jj/f1)])]);
%             ii1 = max([0 min([Width/2-1  floor((ii+f2)/f1)])]);
%             jj1 = max([0 min([Height/2-1 floor((jj+f2)/f1)])]);

            ii0 = floor(ii/f1) ;
            jj0 = floor(jj/f1) ;
            ii1 = floor((ii+f2)/f1) ;
            jj1 = floor((jj+f2)/f1) ;

            if ( (jj0+1 < 1) | (jj0+1 > Height/2) | (jj1+1 < 1) | (jj1+1 > Height/2) )
                valid = 0 ;
                break ;
            end
            if ( (ii0+1 < 1) | (ii0+1 > Width/2 ) | (ii1+1 < 1) | (ii1+1 > Width/2 ) )
                valid = 0 ;
                break ;
            end

            if1=bitand(ii,f2);
            jf1=bitand(jj,f2);
            if0=f1-if1;
            jf0=f1-jf1;
            
            pred_block(j+1,i+1) = (if0*jf0*anchor_frame(jj0+1,ii0+1) + ...
                                        	      if1*jf0*anchor_frame(jj0+1,ii1+1) + ...
                                        	      if0*jf1*anchor_frame(jj1+1,ii0+1) + ...
                	                              if1*jf1*anchor_frame(jj1+1,ii1+1))/f3  ;
        end
    end
end