[svn] / branches / release-1_3-branch / xvidcore / src / image / image.c Repository:
ViewVC logotype

Diff of /branches/release-1_3-branch/xvidcore/src/image/image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1566, Sun Dec 5 13:56:13 2004 UTC revision 1733, Fri Oct 13 07:38:09 2006 UTC
# Line 19  Line 19 
19   *  along with this program ; if not, write to the Free Software   *  along with this program ; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: image.c,v 1.30 2004-12-05 13:56:13 syskin Exp $   * $Id: image.c,v 1.36 2006-10-13 07:38:09 Skal Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 34  Line 34 
34  #include "interpolate8x8.h"  #include "interpolate8x8.h"
35  #include "../utils/mem_align.h"  #include "../utils/mem_align.h"
36  #include "../motion/sad.h"  #include "../motion/sad.h"
37    #include "../utils/emms.h"
38    
39  #include "font.h"               /* XXX: remove later */  #include "font.h"               /* XXX: remove later */
40    
# Line 236  Line 237 
237          }          }
238  }  }
239    
 /* bframe encoding requires image-based u,v interpolation */  
240  void  void
241  image_interpolate(const IMAGE * refn,  image_interpolate(const uint8_t * refn,
242                                    IMAGE * refh,                                    uint8_t * refh,
243                                    IMAGE * refv,                                    uint8_t * refv,
244                                    IMAGE * refhv,                                    uint8_t * refhv,
245                                    uint32_t edged_width,                                    uint32_t edged_width,
246                                    uint32_t edged_height,                                    uint32_t edged_height,
247                                    uint32_t quarterpel,                                    uint32_t quarterpel,
# Line 249  Line 249 
249  {  {
250          const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); /* we only interpolate half of the edge area */          const uint32_t offset = EDGE_SIZE2 * (edged_width + 1); /* we only interpolate half of the edge area */
251          const uint32_t stride_add = 7 * edged_width;          const uint32_t stride_add = 7 * edged_width;
 #if 0  
         const uint32_t edged_width2 = edged_width / 2;  
         const uint32_t edged_height2 = edged_height / 2;  
         const uint32_t offset2 = EDGE_SIZE2 * (edged_width2 + 1);  
         const uint32_t stride_add2 = 7 * edged_width2;  
 #endif  
         uint8_t *n_ptr, *h_ptr, *v_ptr, *hv_ptr;  
         uint32_t x, y;  
252    
253            uint8_t *n_ptr;
254            uint8_t *h_ptr, *v_ptr, *hv_ptr;
255            uint32_t x, y;
256    
257          n_ptr = refn->y;          n_ptr = (uint8_t*)refn;
258          h_ptr = refh->y;          h_ptr = refh;
259          v_ptr = refv->y;          v_ptr = refv;
260    
261          n_ptr -= offset;          n_ptr -= offset;
262          h_ptr -= offset;          h_ptr -= offset;
# Line 290  Line 285 
285                          n_ptr += stride_add;                          n_ptr += stride_add;
286                  }                  }
287    
288                  h_ptr = refh->y + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2;                  h_ptr = refh + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2;
289                  hv_ptr = refhv->y + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2;                  hv_ptr = refhv + (edged_height - EDGE_SIZE - EDGE_SIZE2)*edged_width - EDGE_SIZE2;
290    
291                  for (y = 0; y < (edged_height - EDGE_SIZE); y = y + 8) {                  for (y = 0; y < (edged_height - EDGE_SIZE); y = y + 8) {
292                          hv_ptr -= stride_add;                          hv_ptr -= stride_add;
# Line 307  Line 302 
302                  }                  }
303          } else {          } else {
304    
305                  hv_ptr = refhv->y;                  hv_ptr = refhv;
306                  hv_ptr -= offset;                  hv_ptr -= offset;
307    
308                  for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) {                  for (y = 0; y < (edged_height - EDGE_SIZE); y += 8) {
# Line 333  Line 328 
328                          n_ptr += stride_add;                          n_ptr += stride_add;
329                  }                  }
330          }          }
 /*  
 #ifdef BFRAMES  
         n_ptr = refn->u;  
         h_ptr = refh->u;  
         v_ptr = refv->u;  
         hv_ptr = refhv->u;  
   
         n_ptr -= offset2;  
         h_ptr -= offset2;  
         v_ptr -= offset2;  
         hv_ptr -= offset2;  
   
         for (y = 0; y < edged_height2; y += 8) {  
                 for (x = 0; x < edged_width2; x += 8) {  
                         interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding);  
                         interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding);  
                         interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding);  
   
                         n_ptr += 8;  
                         h_ptr += 8;  
                         v_ptr += 8;  
                         hv_ptr += 8;  
                 }  
                 h_ptr += stride_add2;  
                 v_ptr += stride_add2;  
                 hv_ptr += stride_add2;  
                 n_ptr += stride_add2;  
         }  
   
         n_ptr = refn->v;  
         h_ptr = refh->v;  
         v_ptr = refv->v;  
         hv_ptr = refhv->v;  
   
         n_ptr -= offset2;  
         h_ptr -= offset2;  
         v_ptr -= offset2;  
         hv_ptr -= offset2;  
   
         for (y = 0; y < edged_height2; y = y + 8) {  
                 for (x = 0; x < edged_width2; x = x + 8) {  
                         interpolate8x8_halfpel_h(h_ptr, n_ptr, edged_width2, rounding);  
                         interpolate8x8_halfpel_v(v_ptr, n_ptr, edged_width2, rounding);  
                         interpolate8x8_halfpel_hv(hv_ptr, n_ptr, edged_width2, rounding);  
   
                         n_ptr += 8;  
                         h_ptr += 8;  
                         v_ptr += 8;  
                         hv_ptr += 8;  
                 }  
                 h_ptr += stride_add2;  
                 v_ptr += stride_add2;  
                 hv_ptr += stride_add2;  
                 n_ptr += stride_add2;  
         }  
 #endif  
 */  
         /*  
            interpolate_halfpel_h(  
            refh->y - offset,  
            refn->y - offset,  
            edged_width, edged_height,  
            rounding);  
   
            interpolate_halfpel_v(  
            refv->y - offset,  
            refn->y - offset,  
            edged_width, edged_height,  
            rounding);  
   
            interpolate_halfpel_hv(  
            refhv->y - offset,  
            refn->y - offset,  
            edged_width, edged_height,  
            rounding);  
          */  
   
         /* uv-image-based compensation  
            offset = EDGE_SIZE2 * (edged_width / 2 + 1);  
   
            interpolate_halfpel_h(  
            refh->u - offset,  
            refn->u - offset,  
            edged_width / 2, edged_height / 2,  
            rounding);  
   
            interpolate_halfpel_v(  
            refv->u - offset,  
            refn->u - offset,  
            edged_width / 2, edged_height / 2,  
            rounding);  
   
            interpolate_halfpel_hv(  
            refhv->u - offset,  
            refn->u - offset,  
            edged_width / 2, edged_height / 2,  
            rounding);  
   
   
            interpolate_halfpel_h(  
            refh->v - offset,  
            refn->v - offset,  
            edged_width / 2, edged_height / 2,  
            rounding);  
   
            interpolate_halfpel_v(  
            refv->v - offset,  
            refn->v - offset,  
            edged_width / 2, edged_height / 2,  
            rounding);  
   
            interpolate_halfpel_hv(  
            refhv->v - offset,  
            refn->v - offset,  
            edged_width / 2, edged_height / 2,  
            rounding);  
          */  
331  }  }
332    
333    
# Line 717  Line 595 
595                           int height,                           int height,
596                           uint32_t edged_width,                           uint32_t edged_width,
597                           uint8_t * dst[4],                           uint8_t * dst[4],
598                           uint32_t dst_stride[4],                           int dst_stride[4],
599                           int csp,                           int csp,
600                           int interlacing)                           int interlacing)
601  {  {
# Line 1078  Line 956 
956  }  }
957    
958  void  void
959  output_slice(IMAGE * cur, int std, int width, xvid_image_t* out_frm, int mbx, int mby,int mbl) {  output_slice(IMAGE * cur, int stride, int width, xvid_image_t* out_frm, int mbx, int mby,int mbl) {
960    uint8_t *dY,*dU,*dV,*sY,*sU,*sV;    uint8_t *dY,*dU,*dV,*sY,*sU,*sV;
961    int std2 = std >> 1;    int stride2 = stride >> 1;
962    int w = mbl << 4, w2,i;    int w = mbl << 4, w2,i;
963    
964    if(w > width)    if(w > width)
# Line 1090  Line 968 
968    dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4);    dY = (uint8_t*)out_frm->plane[0] + (mby << 4) * out_frm->stride[0] + (mbx << 4);
969    dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3);    dU = (uint8_t*)out_frm->plane[1] + (mby << 3) * out_frm->stride[1] + (mbx << 3);
970    dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3);    dV = (uint8_t*)out_frm->plane[2] + (mby << 3) * out_frm->stride[2] + (mbx << 3);
971    sY = cur->y + (mby << 4) * std + (mbx << 4);    sY = cur->y + (mby << 4) * stride + (mbx << 4);
972    sU = cur->u + (mby << 3) * std2 + (mbx << 3);    sU = cur->u + (mby << 3) * stride2 + (mbx << 3);
973    sV = cur->v + (mby << 3) * std2 + (mbx << 3);    sV = cur->v + (mby << 3) * stride2 + (mbx << 3);
974    
975    for(i = 0 ; i < 16 ; i++) {    for(i = 0 ; i < 16 ; i++) {
976      memcpy(dY,sY,w);      memcpy(dY,sY,w);
977      dY += out_frm->stride[0];      dY += out_frm->stride[0];
978      sY += std;      sY += stride;
979    }    }
980    for(i = 0 ; i < 8 ; i++) {    for(i = 0 ; i < 8 ; i++) {
981      memcpy(dU,sU,w2);      memcpy(dU,sU,w2);
982      dU += out_frm->stride[1];      dU += out_frm->stride[1];
983      sU += std2;      sU += stride2;
984    }    }
985    for(i = 0 ; i < 8 ; i++) {    for(i = 0 ; i < 8 ; i++) {
986      memcpy(dV,sV,w2);      memcpy(dV,sV,w2);
987      dV += out_frm->stride[2];      dV += out_frm->stride[2];
988      sV += std2;      sV += stride2;
989    }    }
990  }  }
991    
# Line 1137  Line 1015 
1015                  p += edged_width/2;                  p += edged_width/2;
1016          }          }
1017  }  }
1018    
1019    /****************************************************************************/
1020    
1021    static void (*deintl_core)(unsigned char *, int width, int height, const int stride) = 0;
1022    extern void xvid_deinterlace_sse(unsigned char *, int width, int height, const int stride);
1023    
1024    #define CLIP_255(x)   ( ((x)&~255) ? ((-(x)) >> (8*sizeof((x))-1))&0xff : (x) )
1025    
1026    static void deinterlace_c(unsigned char *pix, int width, int height, const int bps)
1027    {
1028      pix += bps;
1029      while(width-->0)
1030      {
1031        int p1 = pix[-bps];
1032        int p2 = pix[0];
1033        int p0 = p2;
1034        int j = (height>>1) - 1;
1035        int V;
1036        unsigned char *P = pix++;
1037        while(j-->0)
1038        {
1039          const int  p3 = P[  bps];
1040          const int  p4 = P[2*bps];
1041          V =  ((p1+p3+1)>>1) + ((p2 - ((p0+p4+1)>>1)) >> 2);
1042          P[0] = CLIP_255( V );
1043          p0 = p2;
1044          p1 = p3;
1045          p2 = p4;
1046          P += 2*bps;
1047        }
1048        V =  ((p1+p1+1)>>1) + ((p2 - ((p0+p2+1)>>1)) >> 2);
1049        P[0] = CLIP_255( V );
1050      }
1051    }
1052    #undef CLIP_255
1053    
1054    int xvid_image_deinterlace(xvid_image_t* img, int width, int height, int bottom_first)
1055    {
1056            if (height&1)
1057                    return 0;
1058            if (img->csp!=XVID_CSP_PLANAR && img->csp!=XVID_CSP_I420 && img->csp!=XVID_CSP_YV12)
1059                    return 0;       /* not yet supported */
1060            if (deintl_core==0) {
1061                    const int cpu_flags = check_cpu_features();
1062                    deintl_core = deinterlace_c;
1063    #ifdef ARCH_IS_IA32
1064                    if (cpu_flags & XVID_CPU_MMX)
1065                            deintl_core = xvid_deinterlace_sse;
1066    #endif
1067            }
1068            if (!bottom_first) {
1069                    deintl_core(img->plane[0], width,    height,    img->stride[0]);
1070                    deintl_core(img->plane[1], width>>1, height>>1, img->stride[1]);
1071                    deintl_core(img->plane[2], width>>1, height>>1, img->stride[2]);
1072            }
1073            else {
1074                    deintl_core(img->plane[0] + ( height    -1)*img->stride[0], width,    height,    -img->stride[0]);
1075                    deintl_core(img->plane[1] + ((height>>1)-1)*img->stride[1], width>>1, height>>1, -img->stride[1]);
1076                    deintl_core(img->plane[2] + ((height>>1)-1)*img->stride[2], width>>1, height>>1, -img->stride[2]);
1077            }
1078            emms();
1079    
1080            return 1;
1081    }
1082    

Legend:
Removed from v.1566  
changed lines
  Added in v.1733

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4