[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

trunk/xvidcore/src/image/image.c revision 1815, Fri Nov 28 10:58:07 2008 UTC branches/release-1_3-branch/xvidcore/src/image/image.c revision 1932, Thu Dec 30 11:47:06 2010 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Image management functions -   *  - Image management functions -
5   *   *
6   *  Copyright(C) 2001-2004 Peter Ross <pross@xvid.org>   *  Copyright(C) 2001-2010 Peter Ross <pross@xvid.org>
7   *   *
8   *  This program is free software ; you can redistribute it and/or modify   *  This program is free software ; you can redistribute it and/or modify
9   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
# 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.43 2008-11-28 10:58:07 Isibaar Exp $   * $Id: image.c,v 1.46.2.1 2010-12-30 11:46:58 Isibaar Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
# Line 149  Line 149 
149    
150          /* According to the Standard Clause 7.6.4, padding is done starting at 16          /* According to the Standard Clause 7.6.4, padding is done starting at 16
151           * pixel width and height multiples. This was not respected in old xvids */           * pixel width and height multiples. This was not respected in old xvids */
152          if (bs_version == 0 || bs_version >= SETEDGES_BUG_BEFORE) {          if (bs_version >= SETEDGES_BUG_BEFORE) {
153                  width  = (width+15)&~15;                  width  = (width+15)&~15;
154                  height = (height+15)&~15;                  height = (height+15)&~15;
155          }          }
# Line 390  Line 390 
390  {  {
391          int width_opt, width_c, height_opt;          int width_opt, width_c, height_opt;
392    
393      if (width==1 || height==1) return; /* forget about it */      if (width<0 || width==1 || height==1) return; /* forget about it */
394    
395          if (func_opt != func_c && x_stride < size*((width+15)/16)*16)          if (func_opt != func_c && x_stride < size*((width+15)/16)*16)
396          {          {
397                  width_opt = width & (~15);                  width_opt = width & (~15);
398                  width_c = (width - width_opt) & (~1);                  width_c = (width - width_opt) & (~1);
399          }          }
400          else          else if (func_opt != func_c && !(width&1) && (size==3))
401          {          {
402            /* MMX reads 4 bytes per pixel for RGB/BGR */
403            width_opt = width - 2;
404            width_c = 2;
405        }
406        else {
407          /* Enforce the width to be divisable by two. */          /* Enforce the width to be divisable by two. */
408                  width_opt = width & (~1);                  width_opt = width & (~1);
409                  width_c = 0;                  width_c = 0;
# Line 857  Line 862 
862          return (sse);          return (sse);
863  }  }
864    
865    void image_block_variance(IMAGE * orig_image,
866                                              uint16_t stride,
867                                              MACROBLOCK *mbs,
868                                              uint16_t mb_width,
869                                              uint16_t mb_height)
870    {
871            DECLARE_ALIGNED_MATRIX(sums, 1, 4, uint16_t, CACHE_LINE);
872            DECLARE_ALIGNED_MATRIX(squares, 1, 4, uint32_t, CACHE_LINE);
873    
874            int x, y, i, j;
875            uint8_t *orig_y = orig_image->y;
876            uint8_t *orig_u = orig_image->u;
877            uint8_t *orig_v = orig_image->v;
878    
879            for (y = 0; y < mb_height; y++) {
880                    for (x = 0; x < mb_width; x++) {
881                            MACROBLOCK *pMB = &mbs[x + y * mb_width];
882                            uint32_t var4[4];
883                            uint32_t sum = 0, square = 0;
884    
885                            /* y-blocks */
886                            for (j = 0; j < 2; j++) {
887                                    for (i = 0; i < 2; i++) {
888                                            int lsum = blocksum8(orig_y + ((y<<4) + (j<<3))*stride + (x<<4) + (i<<3),
889                                                                                     stride, sums, squares);
890                                            int lsquare = (squares[0] + squares[1] + squares[2] + squares[3])<<6;
891    
892                                            sum += lsum;
893                                            square += lsquare;
894    
895                                            var4[0] = (squares[0]<<4) - sums[0]*sums[0];
896                                            var4[1] = (squares[1]<<4) - sums[1]*sums[1];
897                                            var4[2] = (squares[2]<<4) - sums[2]*sums[2];
898                                            var4[3] = (squares[3]<<4) - sums[3]*sums[3];
899    
900                                            pMB->rel_var8[j*2 + i] = lsquare - lsum*lsum;
901                                            if (pMB->rel_var8[j*2 + i])
902                                                    pMB->rel_var8[j*2 + i] = ((var4[0] + var4[1] + var4[2] + var4[3])<<8) /
903                                                                                                     pMB->rel_var8[j*2 + i]; /* 4*(Var(Di)/Var(D)) */
904                                            else
905                                                    pMB->rel_var8[j*2 + i] = 64;
906                                    }
907                            }
908    
909                            /* u */
910                            {
911                                    int lsum = blocksum8(orig_u + (y<<3)*(stride>>1) + (x<<3),
912                                                                             stride, sums, squares);
913                                    int lsquare = (squares[0] + squares[1] + squares[2] + squares[3])<<6;
914    
915                                    sum += lsum;
916                                    square += lsquare;
917    
918                                    var4[0] = (squares[0]<<4) - sums[0]*sums[0];
919                                    var4[1] = (squares[1]<<4) - sums[1]*sums[1];
920                                    var4[2] = (squares[2]<<4) - sums[2]*sums[2];
921                                    var4[3] = (squares[3]<<4) - sums[3]*sums[3];
922    
923                                    pMB->rel_var8[4] = lsquare - lsum*lsum;
924                                    if (pMB->rel_var8[4])
925                                            pMB->rel_var8[4] = ((var4[0] + var4[1] + var4[2] + var4[3])<<8) /
926                                                                                     pMB->rel_var8[4]; /* 4*(Var(Di)/Var(D)) */
927                                    else
928                                            pMB->rel_var8[4] = 64;
929                            }
930    
931                            /* v */
932                            {
933                                    int lsum = blocksum8(orig_v + (y<<3)*(stride>>1) + (x<<3),
934                                                                             stride, sums, squares);
935                                    int lsquare = (squares[0] + squares[1] + squares[2] + squares[3])<<6;
936    
937                                    sum += lsum;
938                                    square += lsquare;
939    
940                                    var4[0] = (squares[0]<<4) - sums[0]*sums[0];
941                                    var4[1] = (squares[1]<<4) - sums[1]*sums[1];
942                                    var4[2] = (squares[2]<<4) - sums[2]*sums[2];
943                                    var4[3] = (squares[3]<<4) - sums[3]*sums[3];
944    
945                                    pMB->rel_var8[5] = lsquare - lsum*lsum;
946                                    if (pMB->rel_var8[5])
947                                            pMB->rel_var8[5] = ((var4[0] + var4[1] + var4[2] + var4[3])<<8) /
948                                                                                     pMB->rel_var8[5]; /* 4*(Var(Di)/Var(D)) */
949                                    else
950                                            pMB->rel_var8[5] = 64;
951                            }
952    
953                    }
954            }
955    }
956    
957  #if 0  #if 0
958    
959  #include <stdio.h>  #include <stdio.h>

Legend:
Removed from v.1815  
changed lines
  Added in v.1932

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