Ticket #1641: bug_1641v2.diff
| File bug_1641v2.diff, 4.4 KB (added by , 16 years ago) |
|---|
-
libmpcodecs/vf_cropdetect.c
75 75 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ 76 76 mp_image_t *dmpi; 77 77 int bpp=mpi->bpp/8; 78 int w,h,x,y, shrink_by;78 int w,h,x,y,x2,y2,shrink_by; 79 79 80 80 // hope we'll get DR buffer: 81 81 dmpi=vf_get_image(vf->next,mpi->imgfmt, … … 92 92 dmpi->height=mpi->height; 93 93 94 94 if(++vf->priv->fno>0){ // ignore first 2 frames - they may be empty 95 int round_sig = 1; 95 96 96 97 // Reset the crop area every reset_count frames, if reset_count is > 0 97 98 if(vf->priv->reset_count > 0 && vf->priv->fno > vf->priv->reset_count){ … … 102 103 vf->priv->fno=1; 103 104 } 104 105 105 for(y=0;y<vf->priv->y1;y++){ 106 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ 106 // Do not check line 0 - CC information might confuse the result 107 for(y=1;y<vf->priv->y1;y++){ 108 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ 109 if(y == 1) // If line 1 is not empty assume line 0 is used as well 110 y = 0; 107 111 vf->priv->y1=y; 108 112 break; 109 113 } … … 130 134 } 131 135 } 132 136 133 // round x and y (up), important for yuv colorspaces 134 // make sure they stay rounded! 135 x=(vf->priv->x1+1)&(~1); 136 y=(vf->priv->y1+1)&(~1); 137 if (vf->priv->round < 0) 138 round_sig = -1; 137 139 138 w = vf->priv->x2 - x + 1; 139 h = vf->priv->y2 - y + 1; 140 x = vf->priv->x1; 141 y = vf->priv->y1; 142 x2 = vf->priv->x2; 143 y2 = vf->priv->y2; 140 144 141 // w and h must be divisible by 2 as well because of yuv 142 // colorspace problems. 143 if (vf->priv->round <= 1) 144 vf->priv->round = 16; 145 if (vf->priv->round % 2) 146 vf->priv->round *= 2; 145 // round x and y, important for yuv colorspaces 146 if (x%2) 147 x += round_sig; 148 if (y%2) 149 y += round_sig; 150 // and x2 and y2 are rounded to an odd number (this ensures 151 // w and h being even numbers 152 if (x2%2 == 0) 153 x += round_sig; 154 if (y2%2 == 0) 155 y += round_sig; 147 156 148 shrink_by = w % vf->priv->round; 157 w = x2 - x + 1; 158 h = y2 - y + 1; 159 160 // w and h must be divisible by 2 because of yuv colorspace problems. 161 // This is always true as round is even number != 0 162 163 // Modulus with negative divisor is implementation-defined, avoid 164 // problems. 165 shrink_by = w % abs(vf->priv->round); 166 if (shrink_by && vf->priv->round < 0) 167 shrink_by += vf->priv->round; 168 149 169 w -= shrink_by; 150 x += (shrink_by / 2 + 1) & ~1; 170 if (w>mpi->w) { 171 printf("\nBUG w: %d w0: %d\n",w,mpi->w); 172 w = mpi->w; 173 } 174 if (w<0) { 175 printf("\nBUG w: %d w0: %d\n",w,mpi->w); 176 w = 0; 177 } 178 x += shrink_by / 2; 179 // Necessary, x can go negative for shrink_by < 0 180 if (x<0) 181 x = 0; 182 // Sanity check 183 if (x+w>mpi->w) { 184 x = mpi->w-w; 185 } 151 186 152 shrink_by = h % vf->priv->round; 187 shrink_by = h % abs(vf->priv->round); 188 if (shrink_by && vf->priv->round < 0) 189 shrink_by += vf->priv->round; 190 153 191 h -= shrink_by; 154 y += (shrink_by / 2 + 1) & ~1; 192 if (h>mpi->h) { 193 printf("\nBUG h: %d h0: %d\n",h,mpi->h); 194 h = mpi->h; 195 } 196 if (h<0) { 197 printf("\nBUG h: %d h0: %d\n",h,mpi->h); 198 h = 0; 199 } 200 y += shrink_by / 2; 201 // Necessary, y can go negative for shrink_by < 0 202 if (y<0) 203 y = 0; 204 // Sanity check 205 if (y+h>mpi->h) { 206 y = mpi->h-h; 207 } 155 208 209 // make sure x and y stay rounded to even number 210 x = (x%2 ? x+round_sig : x); 211 y = (y%2 ? y+round_sig : y); 212 156 213 mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CropArea, 157 214 vf->priv->x1,vf->priv->x2, 158 215 vf->priv->y1,vf->priv->y2, … … 175 232 //===========================================================================// 176 233 177 234 static int vf_open(vf_instance_t *vf, char *args){ 235 int round_sig = 1; 178 236 vf->config=config; 179 237 vf->put_image=put_image; 180 238 vf->query_format=query_format; … … 186 244 &vf->priv->limit, 187 245 &vf->priv->round, 188 246 &vf->priv->reset_count); 247 248 if (vf->priv->round < 0) 249 round_sig = -1; 250 251 if (abs(vf->priv->round) <= 1) 252 vf->priv->round = 16*round_sig; 253 if (vf->priv->round % 2) 254 vf->priv->round += round_sig; // Increase by one, keep sign 255 189 256 return 1; 190 257 } 191 258
